I’ve written code for a BLE peripheral with a Pico W, defining a custom service and a custom characteristic.
It works fine until the peripheral sends data less than the MTU.
I changed the code as below but it stuck in the loop.
Any suggestions?
It works fine until the peripheral sends data less than the MTU.
Code:
int att_write_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size){ UNUSED(transaction_mode); UNUSED(offset); UNUSED(buffer_size); if (att_handle == ATT_CHARACTERISTIC_0000FF14_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE) { char buffer1[128]; if (something) { // This always work sprintf(buffer1, "short message"); att_server_notify(connection_handle, ATT_CHARACTERISTIC_0000FF14_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE, (uint8_t *) buffer1, strlen(buffer1)); } if (something else) { // This stops sending after a few messages for (int i=0; i<30; i++) { sprintf(buffer1, "short message"); att_server_notify(connection_handle, ATT_CHARACTERISTIC_0000FF14_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE, (uint8_t *) buffer1, strlen(buffer1)); } } } return 0;}
Code:
if (something else) { // This stops sending after a few messages for (int i=0; i<30; i++) { sprintf(buffer1, "short message"); while (!att_server_can_send_packet_now(connection_handle)) { printf("Cannot send, waiting...\n"); sleep_us(500); } att_server_notify(connection_handle, ATT_CHARACTERISTIC_0000FF14_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE, (uint8_t *) buffer1, strlen(buffer1)); }}
Statistics: Posted by fab64 — Tue Feb 18, 2025 7:24 am — Replies 0 — Views 15