From 0cefe61edc86d5b1bf422fd44c83ad48a62c12d5 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Fri, 6 Dec 2024 15:38:22 +0530 Subject: [PATCH] fix(nimble): Update hid device example in nimble to work with iOS --- components/esp_hid/src/nimble_hidd.c | 4 +++- examples/bluetooth/esp_hid_device/README.md | 3 ++- examples/bluetooth/esp_hid_device/main/esp_hid_gap.c | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/components/esp_hid/src/nimble_hidd.c b/components/esp_hid/src/nimble_hidd.c index 26bb6ea178..6c4904160c 100644 --- a/components/esp_hid/src/nimble_hidd.c +++ b/components/esp_hid/src/nimble_hidd.c @@ -381,8 +381,10 @@ static int nimble_hidd_dev_input_set(void *devp, size_t index, size_t id, uint8_ assert(p_rpt != NULL); om = ble_hs_mbuf_from_flat((void*)data, length); assert(om != NULL); + /* NOTE : om is freed by stack */ - rc = ble_att_svr_write_local(p_rpt->handle, om); + rc = ble_gatts_notify_custom(s_dev->conn_id, p_rpt->handle, om); + if (rc != 0) { ESP_LOGE(TAG, "Write Input Report Failed: %d", rc); return ESP_FAIL; diff --git a/examples/bluetooth/esp_hid_device/README.md b/examples/bluetooth/esp_hid_device/README.md index 02b8269aa4..2adafa6e7f 100644 --- a/examples/bluetooth/esp_hid_device/README.md +++ b/examples/bluetooth/esp_hid_device/README.md @@ -92,4 +92,5 @@ I (50557) HID_DEV_DEMO: Send the volume ## Troubleshooting -For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon. +1. When using NimBLE stack, some iOS devices do not show the volume pop up. To fix this, please set CONFIG_BT_NIMBLE_SM_LVL to value 2. iOS needs Authenticated Pairing with Encryption to show up the pop ups. +2. For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon. diff --git a/examples/bluetooth/esp_hid_device/main/esp_hid_gap.c b/examples/bluetooth/esp_hid_device/main/esp_hid_gap.c index 56f804e896..6cc854920b 100644 --- a/examples/bluetooth/esp_hid_device/main/esp_hid_gap.c +++ b/examples/bluetooth/esp_hid_device/main/esp_hid_gap.c @@ -766,6 +766,9 @@ esp_err_t esp_hid_ble_gap_adv_init(uint16_t appearance, const char *device_name) fields.flags = BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP; + fields.appearance = ESP_HID_APPEARANCE_GENERIC; + fields.appearance_is_present = 1; + /* Indicate that the TX power level field should be included; have the * stack fill this value automatically. This is done by assigning the * special value BLE_HS_ADV_TX_PWR_LVL_AUTO.