Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Want to control Smart TV with NimBLE used in esp-matter code (CON-1576) #1304

Open
Ajay2803 opened this issue Mar 3, 2025 · 12 comments
Open

Comments

@Ajay2803
Copy link

Ajay2803 commented Mar 3, 2025

Hi,

I am using esp-matter light example, for my development. I know matter uses Nimble stack, because it uses ble only for commissioning. But in my case i want to use ble for other purpose, like to control Smart TV's using HID Profile after commissioning and I got stuck at this point.

I have tried many different examples from esp-idf (Bluedroid and Nimble) and suggestions from esp-matter issues, but i am unable to solve this problem.

please Help me step by step to achieve this, and also let me know that if i'll do this kind of customisation will it break any matter law's or may issue while matter certification.
Or If you have any alternate way please suggest me, so i can continue with my development.

@github-actions github-actions bot changed the title Want to control Smart TV with NimBLE used in esp-matter code Want to control Smart TV with NimBLE used in esp-matter code (CON-1576) Mar 3, 2025
@wqx6
Copy link
Contributor

wqx6 commented Mar 7, 2025

Are you wanting to use BLE after Matter commissioning? If yes, you should disable CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING in menuconfig to prevent BLE from deinitialization after matter commissioning. And you should also use the external platform to add your own BLE codes to use HID profile.

@Ajay2803
Copy link
Author

Ajay2803 commented Mar 7, 2025

Thankyou for your reply,

yes i want to use BLE after commissioning, I have already disabled CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING. can you clarify what do you mean by External Platforms? I am unable to understand this.

@wqx6
Copy link
Contributor

wqx6 commented Mar 7, 2025

Can you clarify what do you mean by External Platforms? I am unable to understand this.

We will initialize BLE stack and advertise Matter-over-BLE services and handle Matter data in our platform codes https://github.com/project-chip/connectedhomeip/tree/master/src/platform/ESP32/nimble, but you are use BLE with HID profile to control Smart TV, so you must modify the BLE platform codes to support both Matter commissioning and HID Profile. And the external platform is the solution we provide to override the original platform codes. you can refer to https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html?#advanced-setup about how to use it.

@Ajay2803
Copy link
Author

Sorry, But we don't want to use this way.

I am sharing my sample code, please go through it and give me some suggestions. I am able to turn on BLE and it is visible in TV also but i am not able to connect it. Can you please help me to connect and control the TV using this way?

and also please reply to this question:
(please Help me step by step to achieve this, and also let me know that if i'll do this kind of customisation will it break any matter law's or may issue while matter certification.)

example_code.zip

@wqx6
Copy link
Contributor

wqx6 commented Mar 11, 2025

Sorry, But we don't want to use this way.

I cannot provide another way to enable HID with Matter. We have a example light_wifi_prov which will maintain two BLE advertisements and two BLE services. Seems it has met your requirements to add another BLE advertisement and service.

I am sharing my sample code, please go through it and give me some suggestions. I am able to turn on BLE and it is visible in TV also but i am not able to connect it. Can you please help me to connect and control the TV using this way?

After looking through your sample code, I find you didn't add the access_cb for the characteristics in your services. And since we already called ble_gatts_add_svcs() in Matter platform code. I am not sure it is OK to call it again to overwrite the BLE service.
You can use nrfconnect app to see whether your HID service is already added.

please Help me step by step to achieve this, and also let me know that if i'll do this kind of customisation will it break any matter law's or may issue while matter certification.

Normally we will add new BLE service and advertisement by modifying the platform code, and we haven't test to change the existing Matter BLE advertisement&service in example code. There is a state machine which maintains the Matter BLE service and the state machine might break the custom service you add. As for whether it will break Matter laws or Matter certification, I am not sure with your method. I can only ensure our example which enables two advs and services will not break the Matter laws or Matter certification.

@Ajay2803
Copy link
Author

Hi @wqx6,

-Thank you for your valuable Reply.
-After you said that we should try to add access callback and try it with nrfconnect app, I have tried and it works with nrfconnect app, but as per our requirement we need to connect it to TV, Device is visible in TV But when we try to connect it, it fails.

-This are the LOG' s can you please help us to solve the problem:
(142811) app_main: BLE Advertising Started Successfully
(157671) app_main: connection established; status=0
(160821) app_main: disconnect; reason=531
(160821) NimBLE: GAP procedure initiated: advertise;
(160821) NimBLE: disc_mode=2
(160831) NimBLE: adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
(160841) NimBLE:

@wqx6
Copy link
Contributor

wqx6 commented Mar 12, 2025

After you said that we should try to add access callback and try it with nrfconnect app, I have tried and it works with nrfconnect app

Did you check the service after connecting the BLE with nrfconnect app? Could you find the gatt service with the right UUID that you added? Normally there should be access_cb for the characteristics so that the device can handle the message sent by the peer(the TV in your scenario) and send the message to the peer in the access_cb. Did you add the logic in your access_cb? This might be the reason of BLE disconnection.

@Ajay2803
Copy link
Author

Image

This is my image from NRF Connect apk, I have registered HID service with UUID 1812 that is not visible yet, and yes i have added access_cb for the characteristics.Yes i have also added logic in access_cb.

Why my service is not visible yet, can you help me?

@dhrishi
Copy link
Collaborator

dhrishi commented Mar 13, 2025

@Ajay2803

Why my service is not visible yet, can you help me?

The questions seem to be specific to BLE. Can you please close this issue and ask the specifics on ESP IDF Github instead?

@wqx6
Copy link
Contributor

wqx6 commented Mar 14, 2025

Why my service is not visible yet, can you help me?

The reason is that we have already called ble_gatts_add_svcs() in Matter platform code to add Matter services. I am not sure whether NimBLE allows to call ble_gatts_add_svcs() multiple times to overwrite gatt services. Or the BLE state machine will break the custom services that you add. Looks like you have to use external platform feature to add your custom BLE services.

@Ajay2803
Copy link
Author

Hi @wqx6,

As you said that we need to use external platform feature to add our custom BLE services, I have not any kind of idea related to this feature can you guide me how can i use this feature and add my custom service t BLE.

I have tried https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html?#advanced-setup, but not able to understand what to do with this, if you have any references related to this or if anyone have added custom service using this feature there reference, any patch or something you can provide would be very helpful for us.

@wqx6
Copy link
Contributor

wqx6 commented Mar 20, 2025

You can refer to the example light_wifi_prov about how to add custom GATT services with external platform, or you can apply the patch project-chip/connectedhomeip#38067 which adds an API to add the custom GATT services.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants