Need help using BLE with esp-idf
Posted: Sat Apr 28, 2018 8:51 pm
Hello,
My goal: An "Adafruit ESP32 Feather" should send some sensor data (several different values) in short messages (one message per sensor value) directly behind each other to a BLE server and then go into sleep mode for a certain time.
I use both examples "esp-idf/examples/bluetooth/gatt_server" and "esp-idf/examples/bluetooth/ gatt_client" as a starting point for my goal. I use the latest version of esp-idf (v 3.0).
It (message transfer) works as desired as long as I do not insert the code for the sleep mode at the end of the client's "app_main". As soon as I activate the code for sleeping, no data will be sent.
The reason: The callback function "gattc_profile_event_handler" is executed completely asynchronously to the rest of the code and the CPU changes into sleep mode before the messages are sent. After running the code for the event "ESP_GATTC_WRITE_CHAR_EVT" ( one event call per message), no further events are generated.
I've tried to call "esp_ble_gattc_write_char" in "gattc_profile_event_handler" executing code for the event "ESP_GATTC_WRITE_DESCR_EVT" (as in the original example "gatt_client") and to call the same function ("esp_ble_gattc_write_char") from "app_main", but both variants lead to the same result!
Calling "esp_ble_gattc_close" before changing into the sleep mode cause the following error messages and my messages are not sent:
The code line leading to these error messages is
Interestingly, the field "gattc_if" has the value "3" and "conn_id" has the value "0" and are valid before calling the function "esp_ble_gattc_close". Somewhere in the code of "esp-idf" both arguments would be swapped!
I have read various documents about BLE on the internet, but can not find any solution to my problem.
Can somebody help me to find a solution please?
Thanks in advance,
Michael
My goal: An "Adafruit ESP32 Feather" should send some sensor data (several different values) in short messages (one message per sensor value) directly behind each other to a BLE server and then go into sleep mode for a certain time.
I use both examples "esp-idf/examples/bluetooth/gatt_server" and "esp-idf/examples/bluetooth/ gatt_client" as a starting point for my goal. I use the latest version of esp-idf (v 3.0).
It (message transfer) works as desired as long as I do not insert the code for the sleep mode at the end of the client's "app_main". As soon as I activate the code for sleeping, no data will be sent.
The reason: The callback function "gattc_profile_event_handler" is executed completely asynchronously to the rest of the code and the CPU changes into sleep mode before the messages are sent. After running the code for the event "ESP_GATTC_WRITE_CHAR_EVT" ( one event call per message), no further events are generated.
I've tried to call "esp_ble_gattc_write_char" in "gattc_profile_event_handler" executing code for the event "ESP_GATTC_WRITE_DESCR_EVT" (as in the original example "gatt_client") and to call the same function ("esp_ble_gattc_write_char") from "app_main", but both variants lead to the same result!
Calling "esp_ble_gattc_close" before changing into the sleep mode cause the following error messages and my messages are not sent:
Code: Select all
E (1634) BT: bta_gattc_cmpl_cback unknown conn_id = 3, ignore data
E (1635) BT: bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0016
Code: Select all
esp_ble_gattc_close(gattc_if, conn_id);
I have read various documents about BLE on the internet, but can not find any solution to my problem.
Can somebody help me to find a solution please?
Thanks in advance,
Michael