Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4416

SDK • Issue sending a large amount of data via Bluetooth

$
0
0
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.

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;}
I changed the code as below but it stuck in the loop.

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));    }}
Any suggestions?

Statistics: Posted by fab64 — Tue Feb 18, 2025 7:24 am — Replies 0 — Views 15



Viewing all articles
Browse latest Browse all 4416

Trending Articles