Skip to content

Commit 9ae615a

Browse files
authored
WIP: made BLE notification efficient
1 parent 6152d2d commit 9ae615a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

main/db_ble.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,20 @@ static const struct ble_gatt_svc_def new_ble_svc_gatt_defs[] = {
221221
* @param data_len Length of send buffer
222222
* @return 0 on success for all clients. -1 on failure to allocate buffer or ble_gatts_notify_custom return value
223223
*/
224-
int db_ble_send_data(const uint8_t *data, uint16_t data_len) {
224+
int db_ble_send_data(const uint8_t *data, uint16_t data_len) {
225225
for (int i = 0; i < CONFIG_BT_NIMBLE_MAX_CONNECTIONS; i++) {
226226
/* Check if the client has subscribed to notifications */
227227
if (conn_handle_subs[i]) {
228-
struct os_mbuf *txom;
229-
// Convert BleData_t struct data into an os_mbuf buffer
230-
txom = ble_hs_mbuf_from_flat(data, data_len);
231-
if (!txom) {
232-
ESP_LOGE(TAG, "Failed to allocate os_mbuf (data length: %i)", data_len);
233-
return -1; // maybe we ran out of memory
228+
229+
/* Write to the characteristics */
230+
int rc = ble_gatts_write(i,ble_spp_svc_gatt_notify_val_handle,data,data_len);
231+
if (rc != 0) {
232+
ESP_LOGE(TAG, "Failed to write characteristic value (rc = %d)", rc);
233+
return rc;
234234
}
235235

236-
// Send BLE notification
237-
int rc = ble_gatts_notify_custom(i, ble_spp_svc_gatt_notify_val_handle, txom);
236+
/* Now send a notification with the updated characteristic value */
237+
rc = ble_gatts_notify(i, ble_spp_svc_gatt_notify_val_handle);
238238
if (rc != 0) {
239239
ESP_LOGE(TAG, "Error sending BLE notification rc = %d", rc);
240240
return rc;

0 commit comments

Comments
 (0)