Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 OTA Firmware Update Issue: SIM800L, ThingsBoard, and Chunk Size Anomalies #169

Closed
mrcl1234 opened this issue Dec 14, 2023 · 15 comments · Fixed by #180
Closed

ESP32 OTA Firmware Update Issue: SIM800L, ThingsBoard, and Chunk Size Anomalies #169

mrcl1234 opened this issue Dec 14, 2023 · 15 comments · Fixed by #180

Comments

@mrcl1234
Copy link

Hello community! I'm currently using a SIM800L module to establish a connection with ThingsBoard for performing OTA firmware updates on my ESP32. My program is based on the following example from the ThingsBoard Client SDK: 'thingsboard-client-sdk/examples/0009-esp8266_esp32_process_OTA_MQTT/'. The process seems to work fine initially, successfully downloading the firmware 2 or 3 times. However, at some point, I encounter an issue where the device starts receiving chunks with a size of 0 bytes. Any insights or suggestions for troubleshooting this intermittent challenge would be greatly appreciated. Thank you!"

@MathewHDYT
Copy link
Contributor

MathewHDYT commented Dec 14, 2023

Hard to say what exactly could be the problem, would it be possible to set THINGSBOARD_ENABLE_DEBUG to 1 with #define THINGSBOARD_ENABLE_DEBUG 1 before including <Thingsboard.h> in you rmain file.

And then add the log messages that occur, once the firmware size is 0 bytes. It might help solve the exact issue.


The only thing I could imagine is that there is not enough heap memory after a while. Would be nice if you could add this line to your main file as well. See more information on Heap Debugging on ESP32

#include "esp_heap_caps.h"

void heap_caps_alloc_failed_hook(size_t requested_size, uint32_t caps, const char *function_name)
{
  printf("%s was called but failed to allocate %d bytes with 0x%X capabilities. \n",function_name, requested_size, caps);
}

void app_main()
{
    ...
    esp_err_t error = heap_caps_register_failed_alloc_callback(heap_caps_alloc_failed_hook);
    ...
    void *ptr = heap_caps_malloc(allocation_size, MALLOC_CAP_DEFAULT);
    ...
}

@mrcl1234
Copy link
Author

Thank you for your guidance. I've implemented the recommended changes, including setting THINGSBOARD_ENABLE_DEBUG to 1 before including <Thingsboard.h>, adding log messages to track the issue when the firmware size becomes 0 bytes, and incorporating memory debugging using esp_heap_caps. I encountered the problem again, and below is the output from the Serial Monitor when the issue occurred:

08:41:49.912 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/42)
08:41:49.912 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:41:49.912 -> [TB] Receive chunk (42), with size (4096) bytes
08:41:49.945 -> Progress 16.60%
08:41:52.812 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/43)
08:41:52.812 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:41:52.845 -> [TB] Receive chunk (43), with size (4096) bytes
08:41:52.845 -> Progress 16.99%
08:41:54.712 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/44)
08:41:54.712 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:41:54.745 -> [TB] Receive chunk (44), with size (4096) bytes
08:41:54.745 -> Progress 17.37%
08:41:57.611 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/45)
08:41:57.611 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:41:57.644 -> [TB] Receive chunk (45), with size (4096) bytes
08:41:57.644 -> Progress 17.76%
08:42:00.776 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/46)
08:42:00.776 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:42:00.810 -> [TB] Receive chunk (46), with size (4096) bytes
08:42:00.810 -> Progress 18.15%
08:42:03.707 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/47)
08:42:03.707 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:42:03.707 -> [TB] Receive chunk (47), with size (4096) bytes
08:42:03.738 -> Progress 18.53%
08:42:05.604 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/48)
08:42:05.604 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:42:05.637 -> [TB] Receive chunk (48), with size (4096) bytes
08:42:05.637 -> Progress 18.92%
08:42:08.704 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/49)
08:42:08.738 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:42:08.738 -> [TB] Receive chunk (49), with size (0) bytes
08:42:08.738 -> Progress 19.31%
08:42:11.804 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/50)
08:42:11.804 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:42:11.838 -> [TB] Receive chunk (50), with size (0) bytes
08:42:11.838 -> Progress 19.69%
08:42:14.904 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/51)
08:42:14.904 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:42:14.904 -> [TB] Receive chunk (51), with size (0) bytes
08:42:14.904 -> Progress 20.08%
08:42:17.971 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/52)
08:42:17.971 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:42:18.004 -> [TB] Receive chunk (52), with size (0) bytes
08:42:18.004 -> Progress 20.46%
08:42:21.070 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/53)
08:42:21.070 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:42:21.103 -> [TB] Receive chunk (53), with size (0) bytes
08:42:21.103 -> Progress 20.85%
08:42:24.170 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/54)
08:42:24.170 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:42:24.170 -> [TB] Receive chunk (54), with size (0) bytes
08:42:24.170 -> Progress 21.24%

Additionally, I observed that the checksum is reported as invalid, and the system attempts to download the firmware again, but it continues to receive 0 bytes. Any insights or suggestions to address this issue would be greatly appreciated.

@mrcl1234
Copy link
Author

Here is the serial monitor output illustrating the issue with the invalid checksum.

08:52:20.631 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/258)
08:52:20.631 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:52:20.631 -> [TB] Receive chunk (258), with size (0) bytes
08:52:20.631 -> Progress 100.00%
08:52:20.631 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADED"})
08:52:20.664 -> [TB] (SHA256) actual checksum: (f9289024c1d1973d4087267968238119de2b665031c490234a9dee1d2afa5bf3)
08:52:20.664 -> [TB] (SHA256) expected checksum: (fbdeb22fa16f82c74d0c989518a949aff12074c924126ac7ebb5e38004439ce0)
08:52:20.664 -> [TB] Checksum verification failed
08:52:20.664 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_error":"Checksum verification failed","fw_state":"FAILED"})
08:52:23.765 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/0)
08:52:23.765 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:52:23.765 -> [TB] Receive chunk (0), with size (0) bytes
08:52:27.832 -> Progress 0.39%
08:52:31.360 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/1)
08:52:31.360 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:52:31.393 -> [TB] Receive chunk (1), with size (0) bytes
08:52:31.393 -> Progress 0.77%
08:52:34.451 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/2)
08:52:34.451 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:52:34.484 -> [TB] Receive chunk (2), with size (0) bytes
08:52:34.484 -> Progress 1.16%
08:52:37.517 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/3)
08:52:37.550 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
08:52:37.550 -> [TB] Receive chunk (3), with size (0) bytes
08:52:37.550 -> Progress 1.54%

@MathewHDYT
Copy link
Contributor

MathewHDYT commented Dec 15, 2023

The invalid checksum is a follow up issue because we do not receive the correct binary data, that of course makes sense because we do not receive any binary data and therefore having a incorrect checksum at the end is expected behaviour.

And it seems that allocating the payload is also not a problem either, because if it were the heap_caps_alloc_failed_hook function should print ... was called but failed to allocate 4096 bytes with .... capabilities., but I could not see that message in the log messages above.

Would it be possible to add the log messages below to the process_firmware_response callback, because it seems that the received message from the MQTT client itself is 0 bytes big.

inline void process_firmware_response(char * const topic, uint8_t * const payload, size_t const & length) {
    char test[Helper::detectSize("Receiving payload with original length %lu", length)] = {};
    snprintf(test, sizeof(test), "Receiving payload with original length %lu", length);
    Logger::log(test);
    ...
}

But It seems that I should probably add a check, that ensures the packet has the expected size because it should always be 4096 bytes big (if configuration was not changed) and perhaps less for the last packet. If it is not that size I could add special log messages. I will do that once we could debug the exact issue that is occurring and fix it.

@mrcl1234
Copy link
Author

mrcl1234 commented Dec 15, 2023

Thank you for your insights. I previously incorporated log messages into the process_firmware_response callback, and similarly, it consistently displayed 0 bytes received. Despite these efforts, the issue persists

Below I show you the serial monitor:

11:06:58.368 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/43)
11:06:58.368 -> [TB] Receiving payload with original length 4096
11:06:58.368 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
11:06:58.401 -> [TB] Receive chunk (43), with size (4096) bytes
11:06:58.401 -> Progress 16.99%
11:07:01.290 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/44)
11:07:01.290 -> [TB] Receiving payload with original length 4096
11:07:01.290 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
11:07:01.323 -> [TB] Receive chunk (44), with size (4096) bytes
11:07:01.323 -> Progress 17.37%
11:07:03.182 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/45)
11:07:03.182 -> [TB] Receiving payload with original length 4096
11:07:03.182 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
11:07:03.215 -> [TB] Receive chunk (45), with size (4096) bytes
11:07:03.215 -> Progress 17.76%
11:07:06.083 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/46)
11:07:06.116 -> [TB] Receiving payload with original length 4096
11:07:06.116 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
11:07:06.116 -> [TB] Receive chunk (46), with size (4096) bytes
11:07:06.116 -> Progress 18.15%
11:07:09.216 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/47)
11:07:09.216 -> [TB] Receiving payload with original length 0
11:07:09.216 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
11:07:09.216 -> [TB] Receive chunk (47), with size (0) bytes
11:07:09.216 -> Progress 18.53%
11:07:12.283 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/48)
11:07:12.316 -> [TB] Receiving payload with original length 0
11:07:12.316 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
11:07:12.316 -> [TB] Receive chunk (48), with size (0) bytes
11:07:12.316 -> Progress 18.92%
11:07:15.381 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/49)
11:07:15.381 -> [TB] Receiving payload with original length 0
11:07:15.381 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
11:07:15.414 -> [TB] Receive chunk (49), with size (0) bytes
11:07:15.414 -> Progress 19.31%
11:07:18.481 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/50)
11:07:18.481 -> [TB] Receiving payload with original length 0
11:07:18.481 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
11:07:18.515 -> [TB] Receive chunk (50), with size (0) bytes
11:07:18.515 -> Progress 19.69%

@MathewHDYT
Copy link
Contributor

MathewHDYT commented Dec 15, 2023

Okay that is already a bad sign, because it hints to a more underlying issue with the MQTT client. Can you print the length in the onMQTTMessage callback as well.

inline void onMQTTMessage(char * const topic, uint8_t * const payload, unsigned int length) {
    char test[Helper::detectSize("Receiving payload with original length %lu", length)] = {};
    snprintf(test, sizeof(test), "Receiving payload with original length %lu", length);
    Logger::log(test);
    ...
}

Because that is the earliest place we receive the message if it is already 0 bytes then, then that hints that the problem lies with the MQTT Client. If so I would need further information.

Are you using Arduino? Are you using the default Arduino_MQTT_Client?

@mrcl1234
Copy link
Author

mrcl1234 commented Dec 15, 2023

I am using Arduino IDE to program the ESP32. The ESP32 is utilizing FreeRTOS. These are some isolated lines used in the program:

#include <Arduino_MQTT_Client.h>

#if THINGSBOARD_ENABLE_PROGMEM
constexpr uint16_t MAX_MESSAGE_SIZE PROGMEM = 512U;
#else
constexpr uint16_t MAX_MESSAGE_SIZE = 512U;
#endif

// Initialize GSM client with TinyGSMClient
TinyGsmClient client(modem);

// Initialize the MQTT client instance
Arduino_MQTT_Client mqttClientgprs(client);

// Initialize ThingsBoard instance with the MQTT client and maximum message size
ThingsBoard tb_gprs(mqttClientgprs, MAX_MESSAGE_SIZE);

// Start firmware update with ThingsBoard instance and a callback function
tb_gprs.Start_Firmware_Update(callback);

Should you require further information, I am at your disposal.

@mrcl1234
Copy link
Author

After incorporating the suggested modification to the onMQTTMessage function, the serial monitor still displays empty chunks, indicating that the issue persists.

"12:23:58.451 -> [TB] Receiving payload with original length 4096
12:23:58.451 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/107)
12:23:58.484 -> [TB] Receiving payload with original length 4096
12:23:58.484 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
12:23:58.484 -> [TB] Receive chunk (107), with size (4096) bytes
12:23:58.484 -> Progress 41.70%
12:24:00.382 -> [TB] Receiving payload with original length 4096
12:24:00.382 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/108)
12:24:00.382 -> [TB] Receiving payload with original length 4096
12:24:00.382 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
12:24:00.415 -> [TB] Receive chunk (108), with size (4096) bytes
12:24:00.415 -> Progress 42.08%
12:24:02.307 -> [TB] Receiving payload with original length 4096
12:24:02.307 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/109)
12:24:02.307 -> [TB] Receiving payload with original length 4096
12:24:02.307 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
12:24:02.307 -> [TB] Receive chunk (109), with size (4096) bytes
12:24:02.340 -> Progress 42.47%
12:24:04.398 -> [TB] Receiving payload with original length 0
12:24:04.398 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/110)
12:24:04.398 -> [TB] Receiving payload with original length 0
12:24:04.398 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
12:24:04.431 -> [TB] Receive chunk (110), with size (0) bytes
12:24:04.431 -> Progress 42.86%
12:24:07.491 -> [TB] Receiving payload with original length 0
12:24:07.491 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/111)
12:24:07.491 -> [TB] Receiving payload with original length 0
12:24:07.491 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
12:24:07.525 -> [TB] Receive chunk (111), with size (0) bytes
12:24:07.525 -> Progress 43.24%
12:24:10.585 -> [TB] Receiving payload with original length 0
12:24:10.585 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/112)
12:24:10.585 -> [TB] Receiving payload with original length 0
12:24:10.618 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
12:24:10.618 -> [TB] Receive chunk (112), with size (0) bytes
12:24:10.618 -> Progress 43.63%"

@MathewHDYT
Copy link
Contributor

Would it be possible to enable verbose logging for the framework.

@mrcl1234
Copy link
Author

verbose logging.txt

@MathewHDYT
Copy link
Contributor

The .txt only contains the log messages of the build process, which isn't relevant. Instead it would be nice if you could attach the verbose logs, for the ongoing OTA process. Especially important would be the internal log messages produced by Arduino, which aren't shown per default but can be enabled with logging level verbose.

Enabling those might show some messages that can help discern why the packages are length 0 after a while.

@mrcl1234
Copy link
Author

I added the verbose, but it still shows the same thing when the issue occurs. "10:41:46.316 -> [TB] Receiving payload with original length 4096
10:41:46.316 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/109)
10:41:46.349 -> [TB] Receiving payload with original length 4096
10:41:46.349 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
10:41:46.349 -> [TB] Receive chunk (109), with size (4096) bytes
10:41:46.383 -> Progress 42.47%
10:41:49.215 -> [TB] Receiving payload with original length 4096
10:41:49.215 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/110)
10:41:49.215 -> [TB] Receiving payload with original length 4096
10:41:49.215 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
10:41:49.248 -> [TB] Receive chunk (110), with size (4096) bytes
10:41:49.248 -> Progress 42.86%
10:41:52.482 -> [TB] Receiving payload with original length 4096
10:41:52.482 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/111)
10:41:52.515 -> [TB] Receiving payload with original length 4096
10:41:52.515 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
10:41:52.515 -> [TB] Receive chunk (111), with size (4096) bytes
10:41:52.548 -> Progress 43.24%
10:41:54.581 -> [TB] Receiving payload with original length 0
10:41:54.581 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/112)
10:41:54.581 -> [TB] Receiving payload with original length 0
10:41:54.615 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
10:41:54.615 -> [TB] Receive chunk (112), with size (0) bytes
10:41:54.615 -> Progress 43.63%
10:41:57.682 -> [TB] Receiving payload with original length 0
10:41:57.682 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/113)
10:41:57.682 -> [TB] Receiving payload with original length 0
10:41:57.682 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
10:41:57.715 -> [TB] Receive chunk (113), with size (0) bytes
10:41:57.715 -> Progress 44.02%
10:42:00.781 -> [TB] Receiving payload with original length 0
10:42:00.781 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/114)
10:42:00.781 -> [TB] Receiving payload with original length 0
10:42:00.781 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
10:42:00.815 -> [TB] Receive chunk (114), with size (0) bytes
10:42:00.815 -> Progress 44.40%
10:42:03.882 -> [TB] Receiving payload with original length 0
10:42:03.882 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/115)
10:42:03.882 -> [TB] Receiving payload with original length 0
10:42:03.882 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
10:42:03.915 -> [TB] Receive chunk (115), with size (0) bytes
10:42:03.915 -> Progress 44.79%
10:42:06.983 -> [TB] Receiving payload with original length 0
10:42:06.983 -> [TB] Received data from server over topic (v2/fw/response/0/chunk/116)
10:42:06.983 -> [TB] Receiving payload with original length 0
10:42:06.983 -> [TB] Sending data to server over topic (v1/devices/me/telemetry) with data ({"fw_state":"DOWNLOADING"})
10:42:06.983 -> [TB] Receive chunk (116), with size (0) bytes
10:42:06.983 -> Progress 45.17%"

@MathewHDYT
Copy link
Contributor

MathewHDYT commented Dec 18, 2023

Can you adjust the Process_Firmware_Packet method in the OTA_Handler.h file like this. It will wait the timeout configured in the OTA_Update_Callback configuration (5 seconds per default) and then rerequest that chunk in hopes it is fully received now, if the size is not as expected.

void Process_Firmware_Packet(size_t const & current_chunk, uint8_t *payload, size_t const & total_bytes)  {
    ...
    else if ((m_requested_chunks + 1 < m_total_chunks && total_bytes != m_fw_callback->Get_Chunk_Size()) || (m_requested_chunks + 1 >= m_total_chunks && total_bytes != (m_fw_size % m_fw_callback->Get_Chunk_Size()))) {
        char message[Helper::detectSize("Expected chunk size of %u, but got %u", m_fw_callback->Get_Chunk_Size(), total_bytes)];
        snprintf(message, sizeof(message), "Expected chunk size of %u, but got %u", m_fw_callback->Get_Chunk_Size(), total_bytes);
        Logger::log(message);
        return;
    }
    ...
}

If this method solves the problem it would be nice if you could try the below method as well.

void Process_Firmware_Packet(size_t const & current_chunk, uint8_t *payload, size_t const & total_bytes)  {
    ...
    else if ((m_requested_chunks + 1 < m_total_chunks && total_bytes != m_fw_callback->Get_Chunk_Size()) || (m_requested_chunks + 1 >= m_total_chunks && total_bytes != (m_fw_size % m_fw_callback->Get_Chunk_Size()))) {
        char message[Helper::detectSize("Expected chunk size of %u, but got %u", m_fw_callback->Get_Chunk_Size(), total_bytes)];
        snprintf(message, sizeof(message), "Expected chunk size of %u, but got %u", m_fw_callback->Get_Chunk_Size(), total_bytes);
        Logger::log(message);
        (void)m_send_fw_state_callback(FW_STATE_FAILED, message);
        return Handle_Failure(OTA_Failure_Response::RETRY_CHUNK);
    }
    ...
}    

@mrcl1234
Copy link
Author

I'm pleased to share that the issue has been successfully resolved, and I want to extend my gratitude to you for the invaluable support. The solution involved updating the 'ArduinoJson' library from version 6.20.1 to the latest version, 6.21.4. Your consistent and prompt responses were greatly appreciated throughout this process. Thank you for your expertise.

@MathewHDYT
Copy link
Contributor

Good to know thanks a lot for the information, it's nice to know it wasn't an internal library issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants