ESP32 C3 mini. Where are the bytes from?
ESP32 C3 mini. Where are the bytes from?
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 (99.32 KiB) Viewed 1484 times
Re: ESP32 C3 mini. Where are the bytes from?
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.
-
- Posts: 1706
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: ESP32 C3 mini. Where are the bytes from?
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.
Re: ESP32 C3 mini. Where are the bytes from?
Thanks guys!
The problem was in the function ble_indicate, or rather in passing parameters to it
I called her like this:
So the size of the array was not determined correctly.
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");
}
}
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]);
Who is online
Users browsing this forum: No registered users and 108 guests