ESP32 C3 mini. Where are the bytes from?

Esp_Eugen
Posts: 4
Joined: Sun Feb 18, 2024 5:18 pm

ESP32 C3 mini. Where are the bytes from?

Postby Esp_Eugen » Sun Apr 07, 2024 1:44 pm

Hello. I have implemented a project with 4 characteristics. three of them update the data via notify. I get extra bytes in the message. I can't figure out where they come from. I am sending only 4 bytes in the program.
Attachments
photo_2024-04-07_16-41-56.jpg
photo_2024-04-07_16-41-56.jpg (99.32 KiB) Viewed 1483 times

liaifat85
Posts: 200
Joined: Wed Dec 06, 2023 2:46 pm

Re: ESP32 C3 mini. Where are the bytes from?

Postby liaifat85 » Sun Apr 07, 2024 3:27 pm

If the buffer used for storing the message data is too small, it could result in unexpected behavior, including extra bytes being added to the message.

MicroController
Posts: 1706
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP32 C3 mini. Where are the bytes from?

Postby MicroController » Mon Apr 08, 2024 8:55 am

Chances are there's either a) a problem in your code, or b) notifications (and/or NRF connect) working differently than you assume, maybe both.

Esp_Eugen
Posts: 4
Joined: Sun Feb 18, 2024 5:18 pm

Re: ESP32 C3 mini. Where are the bytes from?

Postby Esp_Eugen » Mon Apr 08, 2024 10:30 am

Thanks guys!
The problem was in the function ble_indicate, or rather in passing parameters to it

Code: Select all

static void ble_indicate(int *value, uint8_t len, uint16_t attr_handle)
{
	esp_err_t error;
	system_infos.timerTime_sec = 0;
    if (gatts_if_for_indicate == ESP_GATT_IF_NONE) {
        printf("cannot indicate because gatts_if_for_indicate is NONE\n");
        return;
    }
    //printf("indicate %d to gatts_if:%d\n", value[0], gatts_if_for_indicate);
    uint8_t value_len = len;
    uint8_t value_arr[value_len];
    for (uint8_t i = 0; i < value_len; i++)
    {
    	value_arr[i] = (uint8_t)value[i];
    }
    error = esp_ble_gatts_send_indicate(gatts_if_for_indicate, 0, attr_handle, value_len, value_arr, false);
    if (error != ESP_OK)
    {
    	printf("Indicate send error\n");
    }
}
I called her like this:

Code: Select all

int buffer[6];
pLidarTime = system_infos.timerTime;
buffer[0] = pLidarTime >> 24;
buffer[1] = pLidarTime >> 16;
buffer[2] = pLidarTime >> 8;
buffer[3] = pLidarTime;
buffer[4] = pDistanseLidar >> 8;
buffer[5] = pDistanseLidar;
ble_indicate(buffer, sizeof(buffer), heart_rate_handle_table[IDX_CHAR_VAL_LIDAR]);
So the size of the array was not determined correctly.

Who is online

Users browsing this forum: Google [Bot] and 109 guests