thingsboard-client-sdk icon indicating copy to clipboard operation
thingsboard-client-sdk copied to clipboard

Error using ota functions

Open JfloresIoTF opened this issue 2 years ago • 1 comments

The use of the ota functions in version 0.7.1 restarts the ESP32 microcontroller but the functions of version 0.6 do not cause any errors, I use the arduino ide as a platform, and in both I have the same error.

[TB] ================================= [TB] A new Firmware is available: [TB] (1.0) => (1.1) [TB] Attempting to download over MQTT... Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.

Core 1 register dump: PC : 0x4008a956 PS : 0x00060030 A0 : 0x800dc386 A1 : 0x3ffb2290
A2 : 0x00000000 A3 : 0x00000000 A4 : 0x00000006 A5 : 0x00000000
A6 : 0x3ffc1fc4 A7 : 0x3ffb21f0 A8 : 0x00000000 A9 : 0x00000000
A10 : 0x00000000 A11 : 0x00000053 A12 : 0x3f4009b8 A13 : 0x00000001
A14 : 0x00000000 A15 : 0x00001032 SAR : 0x0000000a EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000 LBEG : 0x400857c9 LEND : 0x400857d1 LCOUNT : 0x00000027

Backtrace:0x4008a953:0x3ffb22900x400dc383:0x3ffb22b0 0x4015b625:0x3ffb2420 0x400d4de5:0x3ffb2440 0x400d691e:0x3ffb2590 0x4015b64d:0x3ffb26e0 0x400df8c1:0x3ffb2700 0x400daeab:0x3ffb2740 0x400e105c:0x3ffb2820

ELF file SHA256: 0000000000000000

Rebooting...

JfloresIoTF avatar Sep 13 '22 20:09 JfloresIoTF

Hi,

In order to understand what is happened - please decode your backtrace, you can do it using ESP32 Exception Decoder. And check the output - it should have a stacktrace for the issue.

imbeacon avatar Sep 16 '22 12:09 imbeacon

Hi @JfloresIoTF, did you manage to fix the issue? I have the same issue with example code and sdk version 0.7.1

@imbeacon I could not install "ESP32 Exception Decoder" on Arduino IDE 2.0.0 Mac OS

Thanks.

#include <WiFi.h>
#include "ThingsBoard.h"

#define CURRENT_FIRMWARE_TITLE    "ESP32"
#define CURRENT_FIRMWARE_VERSION  "0.0.1"

#define WIFI_SSID           "xxxx"
#define WIFI_PASSWORD       "xxxx"

// See https://thingsboard.io/docs/getting-started-guides/helloworld/
// to understand how to obtain an access token
#define TOKEN               "xxxx"
#define THINGSBOARD_SERVER  "xxxx"


// Baud rate for debug serial
#define SERIAL_DEBUG_BAUD   115200

// Initialize ThingsBoard client
WiFiClient espClient;
// Initialize ThingsBoard instance
//ThingsBoard tb(espClient);
ThingsBoardSized<512> tb(espClient); //increased size to allow read shared attributes

// the Wifi radio's status
int status = WL_IDLE_STATUS;

void InitWiFi()
{
  Serial.println("Connecting to AP ...");
  // attempt to connect to WiFi network

  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {

    delay(500);
    Serial.print(".");
  }
  Serial.println("Connected to AP");
}

void reconnect() {
  // Loop until we're reconnected
  status = WiFi.status();
  if ( status != WL_CONNECTED) {
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
    Serial.println("Connected to AP");
  }
}

void UpdatedCallback(const bool& success) {

  Serial.println("UpdatedCallback");

  if (success) {
    Serial.println("Done, Reboot now");
    esp_restart();
  } else {
    Serial.println("No new firmware");
  }
}

void setup() {
  // initialize serial for debugging
  Serial.begin(SERIAL_DEBUG_BAUD);
  Serial.println();

  Serial.println(CURRENT_FIRMWARE_TITLE);
  Serial.println(CURRENT_FIRMWARE_VERSION);
  
  InitWiFi();

  delay(1000);
}

void loop() {

  if (WiFi.status() != WL_CONNECTED) {
    reconnect();
  }

  if (!tb.connected()) {
    // Connect to the ThingsBoard
    Serial.print("Connecting to: ");
    Serial.print(THINGSBOARD_SERVER);
    Serial.print(" with token ");
    Serial.println(TOKEN);
    if (!tb.connect(THINGSBOARD_SERVER, TOKEN)) {
      Serial.println("Failed to connect");
      return;
    }

    Serial.println("Firwmare Update...");
    tb.Start_Firmware_Update(CURRENT_FIRMWARE_TITLE, CURRENT_FIRMWARE_VERSION, UpdatedCallback);
  }

  tb.loop();
  delay(10);


}
Firwmare Update...
[TB] Requesting shared attributes transformed from (fw_checksum,fw_checksum_algorithm,fw_size,fw_title,fw_version) into json ({"sharedKeys":"fw_checksum,fw_checksum_algorithm,fw_size,fw_title,fw_version"})
[TB] Callback on_message from topic: (v1/devices/me/attributes/response/1)
[TB] Received shared attribute request
[TB] Calling subscribed callback for response id (1)
[TB] {"fw_checksum":"12ec2ad164fc2f653bf1476cf7d21353","fw_size":241664,"fw_title":"ESP32","fw_checksum_algorithm":"MD5","fw_version":"0.0.3"}
[TB] =================================
[TB] A new Firmware is available:
[TB] (0.0.1) => (0.0.3)
[TB] Attempting to download over MQTT...
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x40089767  PS      : 0x00060b30  A0      : 0x800d45ab  A1      : 0x3ffb2410  
A2      : 0x00000000  A3      : 0x00000000  A4      : 0x00000006  A5      : 0x00000001  
A6      : 0x00000005  A7      : 0xff000000  A8      : 0x00000000  A9      : 0x00000000  
A10     : 0x00000001  A11     : 0x00000053  A12     : 0x3f4008e3  A13     : 0x00000001  
A14     : 0x00000000  A15     : 0x00001032  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x40084415  LEND    : 0x4008441d  LCOUNT  : 0x00000027  

AdrienAdB avatar Oct 28 '22 04:10 AdrienAdB

modify your thingboard.h file with the following:

1.- Change due to the fact that the comparison was not carried out correctly to verify if the download process has already started (DOWNLOAD status) in the function: process firmware response.

m_fwState = FW_STATE_FAILED; ----> m_fwState = FW_STATE_DOWNLOADING;

2.- change in size declaration due to overflow of large number m_fwsize:

uint16_t m_fwSize;  --->  const unsigned int m_fwSize;

 m_fwSize = data[FW_SIZE_KEY].as<const uint16_t>() ----> m_fwSize = data[FW_SIZE_KEY].as<const unsigned int>();

2.- Update.abort(); if initialization fails Update.begin() ;

    if (!Update.begin(m_fwSize)) {
      Logger::log(ERROR_UPDATE_BEGIN);
      m_fwState = FW_STATE_UPDATE_ERROR;
      Update.abort();
      return;
    }

3.- The nbRetry counter is reset to have more waiting time for the reception of the packets if I have already entered the download process

if (strncmp_P(FW_STATE_DOWNLOADING, m_fwState, strlen(FW_STATE_DOWNLOADING) == 0)) {
          currChunk++;
          nbRetry = 3U;//added line
        }

4.- The misplaced final parenthesis of the download status comparison is corrected

   if (strncmp_P(FW_STATE_DOWNLOADING, m_fwState, strlen(FW_STATE_DOWNLOADING) == 0)) {} 

before

  if (strncmp_P(FW_STATE_DOWNLOADING, m_fwState, strlen(FW_STATE_DOWNLOADING)) == 0) {}

5.-the MD5 verification error occurs due to a failure in the variable type *char (pointer) since the pointer data is lost to solve this problem change from *char to String along with the way to work the value of the variable.

in line 1410 const char m_fwChecksum; ---> String m_fwChecksum; in line 669
m_fwChecksum = nullptr; --->m_fwChecksum = ""; in line 775
m_fwChecksum = data[FW_CHKS_KEY].as<const char
>(); ----> m_fwChecksum = data[FW_CHKS_KEY].as<String>(); in line 779 m_currFwVersion == nullptr ---> m_fwChecksum[0] == '\0' in line 1211 JSON_STRING_SIZE(strlen(m_fwChecksum))]; ---->JSON_STRING_SIZE(strlen(m_fwChecksum.c_str()))]; in line 1212
m_fwChecksum); ---> m_fwChecksum.c_str()); in line 1215 if (strncmp(md5Str.c_str(), m_fwChecksum, md5Str.length()) != 0) { ---> if (strncmp(md5Str.c_str(), m_fwChecksum.c_str(), md5Str.length()) != 0) {

JfloresIoTF avatar Oct 28 '22 12:10 JfloresIoTF

Hi. I've been struggling with the same thing, after making the changes @JfloresIoTF suggested I get this:

In file included from C:\Users\timot\AppData\Local\Temp\.arduinoIDE-unsaved2022930-24268-1uph3aq.l90d\0009-esp8266_esp32_process_OTA_MQTT\0009-esp8266_esp32_process_OTA_MQTT.ino:7:
c:\Users\timot\Desktop\Isiklik\Arduino\libraries\thingsboard-arduino-sdk-master\src/ThingsBoard.h: In instantiation of 'ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::ThingsBoardSized(Client&, const bool&) [with unsigned int PayloadSize = 512; unsigned int MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger]':
C:\Users\timot\AppData\Local\Temp\.arduinoIDE-unsaved2022930-24268-1uph3aq.l90d\0009-esp8266_esp32_process_OTA_MQTT\0009-esp8266_esp32_process_OTA_MQTT.ino:28:35:   required from here
c:\Users\timot\Desktop\Isiklik\Arduino\libraries\thingsboard-arduino-sdk-master\src/ThingsBoard.h:383:12: error: uninitialized const member in 'const unsigned int' [-fpermissive]
     inline ThingsBoardSized(Client& client, const bool& enableQoS = false)
            ^~~~~~~~~~~~~~~~
c:\Users\timot\Desktop\Isiklik\Arduino\libraries\thingsboard-arduino-sdk-master\src/ThingsBoard.h:1424:21: note: 'const unsigned int ThingsBoardSized<512>::m_fwSize' should be initialized
  const unsigned int m_fwSize;
                     ^~~~~~~~
c:\Users\timot\Desktop\Isiklik\Arduino\libraries\thingsboard-arduino-sdk-master\src/ThingsBoard.h: In instantiation of 'void ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::Firmware_Shared_Attribute_Received(Shared_Attribute_Data&) [with unsigned int PayloadSize = 512; unsigned int MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger; Shared_Attribute_Data = const ArduinoJson6194_F1::ObjectConstRef]':
c:\Users\timot\Desktop\Isiklik\Arduino\libraries\thingsboard-arduino-sdk-master\src/ThingsBoard.h:388:40:   required from 'ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::ThingsBoardSized(Client&, const bool&) [with unsigned int PayloadSize = 512; unsigned int MaxFieldsAmt = 8; Logger = ThingsBoardDefaultLogger]'
C:\Users\timot\AppData\Local\Temp\.arduinoIDE-unsaved2022930-24268-1uph3aq.l90d\0009-esp8266_esp32_process_OTA_MQTT\0009-esp8266_esp32_process_OTA_MQTT.ino:28:35:   required from here
c:\Users\timot\Desktop\Isiklik\Arduino\libraries\thingsboard-arduino-sdk-master\src/ThingsBoard.h:794:13: error: assignment of read-only member 'ThingsBoardSized<512>::m_fwSize'
    m_fwSize = data[FW_SIZE_KEY].as<const unsigned int>();
    ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

exit status 1

Compilation error: exit status 1

gittimotap avatar Oct 30 '22 21:10 gittimotap

Hi! I tried the same program as @AdrienAdB with a few changes:

#include <Arduino.h>

#include <WiFi.h>
#include "ThingsBoard.h"
#include "account_thermostat_v2.h"

#define CURRENT_FIRMWARE_TITLE "Termostat.v2"
#define CURRENT_FIRMWARE_VERSION "0.0.1"

// Baud rate for debug serial
#define SERIAL_DEBUG_BAUD   115200

// Initialize ThingsBoard client
WiFiClient espClient;
// Initialize ThingsBoard instance
//ThingsBoard tb(espClient);
ThingsBoardSized<512> tb(espClient); //increased size to allow read shared attributes

// the Wifi radio's status
int status = WL_IDLE_STATUS;

void InitWiFi()
{
  Serial.println("Connecting to AP ...");
  // attempt to connect to WiFi network

  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {

    delay(500);
    Serial.print(".");
  }
  Serial.println("Connected to AP");
}

void reconnect() {
  // Loop until we're reconnected
  status = WiFi.status();
  if ( status != WL_CONNECTED) {
    WiFi.begin(WIFI_SSID, WIFI_PASS);
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
    Serial.println("Connected to AP");
  }
}

void UpdatedCallback(const bool& success) {

  Serial.println("UpdatedCallback");

  if (success) {
    Serial.println("Done, Reboot now");
    esp_restart();
  } else {
    Serial.println("No new firmware");
  }
}

void setup() {
  // initialize serial for debugging
  Serial.begin(SERIAL_DEBUG_BAUD);
  Serial.println();

  Serial.println(CURRENT_FIRMWARE_TITLE);
  Serial.println(CURRENT_FIRMWARE_VERSION);
  
  InitWiFi();

  delay(1000);
}

void loop() {

  if (WiFi.status() != WL_CONNECTED) {
    reconnect();
  }

  if (!tb.connected()) {
    // Connect to the ThingsBoard
    Serial.print("Connecting to: ");
    Serial.print(THINGSBOARD_SERVER);
    Serial.print(" with token ");
    Serial.println(THINGSBOARD_TOKEN);
    if (!tb.connect(THINGSBOARD_SERVER, THINGSBOARD_TOKEN)) {
      Serial.println("Failed to connect");
      return;
    }

    Serial.println("Firwmare Update...");
    tb.Start_Firmware_Update(CURRENT_FIRMWARE_TITLE, CURRENT_FIRMWARE_VERSION, UpdatedCallback);
  }

  tb.loop();
  delay(10);
}

And got the same error.

@imbeacon, I decode the backtrace :

Termostat.v2
0.0.1
Connecting to AP ...
.Connected to AP
Connecting to: tb.andrey.guru with token XXXXXXXXXXXXXXXXX
Firwmare Update...
[TB] Requesting shared attributes transformed from (fw_checksum,fw_checksum_algorithm,fw_size,fw_title,fw_version) into json ({"sharedKeys":"fw_checksum,fw_checksum_algorithm,fw_size,fw_title,fw_version"})
[TB] Callback on_message from topic: (v1/devices/me/attributes/response/1)
[TB] Received shared attribute request
[TB] Calling subscribed callback for response id (1)
[TB] {"fw_title":"Termostat.v2","fw_version":"0.0.5","fw_size":766288,"fw_checksum_algorithm":"MD5","fw_checksum":"ff57a164812e796da67afaadc187bfba"}
[TB] =================================
[TB] A new Firmware is available:
[TB] (0.0.1) => (0.0.5)
[TB] Attempting to download over MQTT...
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x40089767  PS      : 0x00060d30  A0      : 0x800db1ce  A1      : 0x3ffb21d0
A2      : 0x00000000  A3      : 0x00000000  A4      : 0x00000006  A5      : 0x00000000
A6      : 0x3ffba9b4  A7      : 0x3ffb2150  A8      : 0x00000000  A9      : 0x00000000
A10     : 0x00000001  A11     : 0x00000053  A12     : 0x3f402654  A13     : 0x00000001
A14     : 0x00000000  A15     : 0x00001032  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x40084415  LEND    : 0x4008441d  LCOUNT  : 0x00000027


Backtrace:0x40089764:0x3ffb21d00x400db1cb:0x3ffb21f0 0x401507a9:0x3ffb23c0 0x400d3235:0x3ffb23e0 0x400d9955:0x3ffb2400 0x400d9b79:0x3ffb25f0 0x401507d5:0x3ffb2690 0x400dbfaf:0x3ffb26c0 0x400dc0dd:0x3ffb26f0 0x400da56a:0x3ffb2720 0x400e1a81:0x3ffb2820

  #0  0x40089764:0x3ffb21d0 in strncmp at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/string/strncmp.c:63
  #1  0x400db1cb:0x3ffb21f0 in ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::Firmware_Shared_Attribute_Received(ArduinoJson6194_F1::ObjectConstRef const&) at .pio/libdeps/mhetesp32devkit/ThingsBoard/src/ThingsBoard.h:900
  #2  0x401507a9:0x3ffb23c0 in void std::__invoke_impl<void, void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(ArduinoJson6194_F1::ObjectConstRef const&), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, ArduinoJson6194_F1::ObjectConstRef const&>(std::__invoke_memfun_deref, void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(ArduinoJson6194_F1::ObjectConstRef const&), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, ArduinoJson6194_F1::ObjectConstRef const&) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/invoke.h:73
      (inlined by) std::__invoke_result<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(ArduinoJson6194_F1::ObjectConstRef const&), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, ArduinoJson6194_F1::ObjectConstRef const&>::type std::__invoke<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(ArduinoJson6194_F1::ObjectConstRef const&), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, ArduinoJson6194_F1::ObjectConstRef const&>(void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(ArduinoJson6194_F1::ObjectConstRef const&), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, ArduinoJson6194_F1::ObjectConstRef const&) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/invoke.h:95
      (inlined by) void std::_Bind<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*(ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*, std::_Placeholder<1>))(ArduinoJson6194_F1::ObjectConstRef const&)>::__call<void, ArduinoJson6194_F1::ObjectConstRef const&, 0u, 1u>(std::tuple<ArduinoJson6194_F1::ObjectConstRef const&>&&, std::_Index_tuple<0u, 1u>) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0/functional:400
      (inlined by) void std::_Bind<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*(ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*, std::_Placeholder<1>))(ArduinoJson6194_F1::ObjectConstRef const&)>::operator()<ArduinoJson6194_F1::ObjectConstRef const&, void>(ArduinoJson6194_F1::ObjectConstRef const&) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0/functional:484
      (inlined by) std::_Function_handler<void (ArduinoJson6194_F1::ObjectConstRef const&), std::_Bind<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*(ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*, std::_Placeholder<1>))(ArduinoJson6194_F1::ObjectConstRef const&)> >::_M_invoke(std::_Any_data const&, ArduinoJson6194_F1::ObjectConstRef const&) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:297
  #3  0x400d3235:0x3ffb23e0 in std::function<void (ArduinoJson6194_F1::ObjectConstRef const&)>::operator()(ArduinoJson6194_F1::ObjectConstRef const&) const at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:687
  #4  0x400d9955:0x3ffb2400 in ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::process_shared_attribute_request_message(char*, unsigned char*, unsigned int) at .pio/libdeps/mhetesp32devkit/ThingsBoard/src/ThingsBoard.h:1355
  #5  0x400d9b79:0x3ffb25f0 in ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::on_message(char*, unsigned char*, unsigned int) at .pio/libdeps/mhetesp32devkit/ThingsBoard/src/ThingsBoard.h:1435
  #6  0x401507d5:0x3ffb2690 in void std::__invoke_impl<void, void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(char*, unsigned char*, unsigned int), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, char*, unsigned char*, unsigned int>(std::__invoke_memfun_deref, void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(char*, unsigned char*, unsigned int), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, char*&&, unsigned char*&&, unsigned int&&) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/invoke.h:73
      (inlined by) std::__invoke_result<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(char*, unsigned char*, unsigned int), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, char*, unsigned char*, unsigned int>::type std::__invoke<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(char*, unsigned char*, unsigned int), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, char*, unsigned char*, unsigned int>(void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(char*, unsigned char*, unsigned int), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, char*&&, unsigned char*&&, unsigned int&&) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/invoke.h:95
      (inlined by) void std::_Bind<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*(ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(char*, unsigned char*, unsigned int)>::__call<void, char*&&, unsigned char*&&, unsigned int&&, 0u, 1u, 2u, 3u>(std::tuple<char*&&, unsigned char*&&, unsigned int&&>&&, std::_Index_tuple<0u, 1u, 2u, 3u>) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0/functional:400
      (inlined by) void std::_Bind<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*(ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(char*, unsigned char*, unsigned int)>::operator()<char*, unsigned char*, unsigned int, void>(char*&&, unsigned char*&&, unsigned int&&) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0/functional:484
      (inlined by) std::_Function_handler<void (char*, unsigned char*, unsigned int), std::_Bind<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*(ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(char*, unsigned char*, unsigned int)> >::_M_invoke(std::_Any_data const&, char*&&, unsigned char*&&, unsigned int&&) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:297
  #7  0x400dbfaf:0x3ffb26c0 in std::function<void (char*, unsigned char*, unsigned int)>::operator()(char*, unsigned char*, unsigned int) const at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:687
  #8  0x400dc0dd:0x3ffb26f0 in PubSubClient::loop() at .pio/libdeps/mhetesp32devkit/PubSubClient/src/PubSubClient.cpp:416
  #9  0x400da56a:0x3ffb2720 in ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::loop() at .pio/libdeps/mhetesp32devkit/ThingsBoard/src/ThingsBoard.h:469
      (inlined by) loop() at src/main.cpp:95
  #10 0x400e1a81:0x3ffb2820 in loopTask(void*) at C:/Users/andre/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:50




ELF file SHA256: 0000000000000000

Rebooting...

farmerkz avatar Nov 03 '22 16:11 farmerkz

@JfloresIoTF , I did as you except:

uint16_t m_fwSize; ---> const unsigned int m_fwSize;

but:

uint16_t m_fwSize; ---> unsigned int m_fwSize;

The result is the same:

Termostat.v2
0.0.1
Connecting to AP ...
.Connected to AP
Connecting to: tb.andrey.guru with token XXXXXXXXXXXXXXXXXXXXXX
Firwmare Update...
[TB] Requesting shared attributes transformed from (fw_checksum,fw_checksum_algorithm,fw_size,fw_title,fw_version) into json ({"sharedKeys":"fw_checksum,fw_checksum_algorithm,fw_size,fw_title,fw_version"})
[TB] Callback on_message from topic: (v1/devices/me/attributes/response/1)
[TB] Received shared attribute request
[TB] Calling subscribed callback for response id (1)
[TB] {"fw_title":"Termostat.v2","fw_version":"0.0.5","fw_size":766288,"fw_checksum_algorithm":"MD5","fw_checksum":"ff57a164812e796da67afaadc187bfba"}
[TB] =================================
[TB] A new Firmware is available:
[TB] (0.0.1) => (0.0.5)
[TB] Attempting to download over MQTT...
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x40089767  PS      : 0x00060d30  A0      : 0x800db15d  A1      : 0x3ffb21b0
A2      : 0x00000000  A3      : 0x00000000  A4      : 0x0000000a  A5      : 0x00000005
A6      : 0x00000030  A7      : 0x3ffb2150  A8      : 0x00000000  A9      : 0x00000000
A10     : 0x00000005  A11     : 0x00000044  A12     : 0x3f402480  A13     : 0x00000001
A14     : 0x00000005  A15     : 0x00000090  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x40084415  LEND    : 0x4008441d  LCOUNT  : 0x00000027


Backtrace:0x40089764:0x3ffb21b00x400db15a:0x3ffb21d0 0x4015078d:0x3ffb23c0 0x400d3241:0x3ffb23e0 0x400d9909:0x3ffb2400 0x400d9b2d:0x3ffb25f0 0x401507b9:0x3ffb2690 0x400dbf93:0x3ffb26c0 0x400dc0c1:0x3ffb26f0 0x400da52a:0x3ffb2720 0x400e1a65:0x3ffb2820

  #0  0x40089764:0x3ffb21b0 in strncmp at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/string/strncmp.c:63
  #1  0x400db15a:0x3ffb21d0 in ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::Firmware_Shared_Attribute_Received(ArduinoJson6194_F1::ObjectConstRef const&) at .pio/libdeps/mhetesp32devkit/ThingsBoard/src/ThingsBoard.h:864
  #2  0x4015078d:0x3ffb23c0 in void std::__invoke_impl<void, void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(ArduinoJson6194_F1::ObjectConstRef const&), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, ArduinoJson6194_F1::ObjectConstRef const&>(std::__invoke_memfun_deref, void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(ArduinoJson6194_F1::ObjectConstRef const&), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, ArduinoJson6194_F1::ObjectConstRef const&) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/invoke.h:73
      (inlined by) std::__invoke_result<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(ArduinoJson6194_F1::ObjectConstRef const&), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, ArduinoJson6194_F1::ObjectConstRef const&>::type std::__invoke<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(ArduinoJson6194_F1::ObjectConstRef const&), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, ArduinoJson6194_F1::ObjectConstRef const&>(void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(ArduinoJson6194_F1::ObjectConstRef const&), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, ArduinoJson6194_F1::ObjectConstRef const&) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/invoke.h:95
      (inlined by) void std::_Bind<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*(ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*, std::_Placeholder<1>))(ArduinoJson6194_F1::ObjectConstRef const&)>::__call<void, ArduinoJson6194_F1::ObjectConstRef const&, 0u, 1u>(std::tuple<ArduinoJson6194_F1::ObjectConstRef const&>&&, std::_Index_tuple<0u, 1u>) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0/functional:400
      (inlined by) void std::_Bind<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*(ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*, std::_Placeholder<1>))(ArduinoJson6194_F1::ObjectConstRef const&)>::operator()<ArduinoJson6194_F1::ObjectConstRef const&, void>(ArduinoJson6194_F1::ObjectConstRef const&) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0/functional:484
      (inlined by) std::_Function_handler<void (ArduinoJson6194_F1::ObjectConstRef const&), std::_Bind<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*(ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*, std::_Placeholder<1>))(ArduinoJson6194_F1::ObjectConstRef const&)> >::_M_invoke(std::_Any_data const&, ArduinoJson6194_F1::ObjectConstRef const&) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:297
  #3  0x400d3241:0x3ffb23e0 in std::function<void (ArduinoJson6194_F1::ObjectConstRef const&)>::operator()(ArduinoJson6194_F1::ObjectConstRef const&) const at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:687
  #4  0x400d9909:0x3ffb2400 in ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::process_shared_attribute_request_message(char*, unsigned char*, unsigned int) at .pio/libdeps/mhetesp32devkit/ThingsBoard/src/ThingsBoard.h:1357
  #5  0x400d9b2d:0x3ffb25f0 in ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::on_message(char*, unsigned char*, unsigned int) at .pio/libdeps/mhetesp32devkit/ThingsBoard/src/ThingsBoard.h:1437
  #6  0x401507b9:0x3ffb2690 in void std::__invoke_impl<void, void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(char*, unsigned char*, unsigned int), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, char*, unsigned char*, unsigned int>(std::__invoke_memfun_deref, void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(char*, unsigned char*, unsigned int), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, char*&&, unsigned char*&&, unsigned int&&) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/invoke.h:73
      (inlined by) std::__invoke_result<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(char*, unsigned char*, unsigned int), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, char*, unsigned char*, unsigned int>::type std::__invoke<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(char*, unsigned char*, unsigned int), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, char*, unsigned char*, unsigned int>(void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*&)(char*, unsigned char*, unsigned int), ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*&, char*&&, unsigned char*&&, unsigned int&&) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/invoke.h:95
      (inlined by) void std::_Bind<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*(ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(char*, unsigned char*, unsigned int)>::__call<void, char*&&, unsigned char*&&, unsigned int&&, 0u, 1u, 2u, 3u>(std::tuple<char*&&, unsigned char*&&, unsigned int&&>&&, std::_Index_tuple<0u, 1u, 2u, 3u>) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0/functional:400
      (inlined by) void std::_Bind<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*(ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(char*, unsigned char*, unsigned int)>::operator()<char*, unsigned char*, unsigned int, void>(char*&&, unsigned char*&&, unsigned int&&) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0/functional:484
      (inlined by) std::_Function_handler<void (char*, unsigned char*, unsigned int), std::_Bind<void (ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::*(ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>*, std::_Placeholder<1>, std::_Placeholder<2>, std::_Placeholder<3>))(char*, unsigned char*, unsigned int)> >::_M_invoke(std::_Any_data const&, char*&&, unsigned char*&&, unsigned int&&) at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:297
  #7  0x400dbf93:0x3ffb26c0 in std::function<void (char*, unsigned char*, unsigned int)>::operator()(char*, unsigned char*, unsigned int) const at c:\users\andre\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:687
  #8  0x400dc0c1:0x3ffb26f0 in PubSubClient::loop() at .pio/libdeps/mhetesp32devkit/PubSubClient/src/PubSubClient.cpp:416
  #9  0x400da52a:0x3ffb2720 in ThingsBoardSized<512u, 8u, ThingsBoardDefaultLogger>::loop() at .pio/libdeps/mhetesp32devkit/ThingsBoard/src/ThingsBoard.h:469
      (inlined by) loop() at src/main.cpp:95
  #10 0x400e1a65:0x3ffb2820 in loopTask(void*) at C:/Users/andre/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:50




ELF file SHA256: 0000000000000000

Rebooting...

farmerkz avatar Nov 03 '22 17:11 farmerkz

I tried to add

m_fwState = FW_STATE_DOWNLOADING;

after

// Update state
Firmware_Send_State(FW_STATE_DOWNLOADING);

and the firmware loaded successfully, but when checking the MD5 I got an error because the m_fwChecksum is corrupted:

[TB] MD5 actual checksum: (ff57a164812e796da67afaadc187bfba)
[TB] MD5 expected checksum: (4��?��J�����[ ���?8Pp�)
[TB] Checksum verification failed

farmerkz avatar Nov 06 '22 18:11 farmerkz

m_fwChecksum is corrupted after call m_client.publish(TELEMETRY_TOPIC, json, m_qos) in inline const bool sendTelemetryJson(const char *json) {}

farmerkz avatar Nov 07 '22 18:11 farmerkz

Hi! I tried the same program as @farmerkz

m_fwState = FW_STATE_DOWNLOADING; uint16_t m_fwSize; ---> unsigned int m_fwSize;

But it didn't detect the MD5 error like him The result is the same:

Firwmare Update... [TB] Requesting shared attributes transformed from (fw_checksum,fw_checksum_algorithm,fw_size,fw_title,fw_version) into json ({"sharedKeys":"fw_checksum,fw_checksum_algorithm,fw_size,fw_title,fw_version"}) [TB] Callback on_message from topic: (v1/devices/me/attributes/response/1) [TB] Received shared attribute request [TB] Calling subscribed callback for response id (1) [TB] {"fw_checksum":"27baa30d3ae0ac6a7348d1d3f8eb3ee3","fw_size":731296,"fw_title":"ESP32","fw_checksum_algorithm":"MD5","fw_version":"0.0.2"} [TB] ================================= [TB] A new Firmware is available: [TB] (0.0.1) => (0.0.2) [TB] Attempting to download over MQTT... Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled. Core 1 register dump: PC : 0x4000c61c PS : 0x00060a30 A0 : 0x800d2104 A1 : 0x3ffb1b80
A2 : 0x00000000 A3 : 0x00000000 A4 : 0x0000000b A5 : 0x00000001
A6 : 0x00000004 A7 : 0xff000000 A8 : 0x3f400762 A9 : 0x00000044
A10 : 0x00000000 A11 : 0x00000000 A12 : 0x3ffc17b4 A13 : 0x00005800
A14 : 0x00000000 A15 : 0x00000022 SAR : 0x0000000a EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff

ELF file SHA256: 0000000000000000

Backtrace: 0x4000c61c:0x3ffb1b80 0x400d2101:0x3ffb1ba0 0x40145d8a:0x3ffb1cd0 0x400d1357:0x3ffb1cf0 0x400d3bc9:0x3ffb1d10 0x400d3d56:0x3ffb1e80 0x40145db1:0x3ffb1ef0 0x400d5d22:0x3ffb1f10 0x400d2875:0x3ffb1f50 0x400d790d:0x3ffb1fb0 0x40089a12:0x3ffb1fd0

Rebooting...

@farmerkz Do you change anything else ?

NgocThinhNTP18 avatar Nov 11 '22 09:11 NgocThinhNTP18

@NgocThinhNTP18, I did everything that was in @JfloresIoTF post, but in point 2 I removed the const on the right side of the expressions.

And I changed

// Update state
Firmware_Send_State(FW_STATE_DOWNLOADING);

to

// Update state
Firmware_Send_State(FW_STATE_DOWNLOADING);
m_fwState = FW_STATE_DOWNLOADING;

It's all

farmerkz avatar Nov 11 '22 13:11 farmerkz

A small magical workaround, I don’t think it radically solves the problem, but OTA works at the same time:

inline void Firmware_Shared_Attribute_Received(const Shared_Attribute_Data &data)
{
.....
    Logger::log(buffer);
    char _md5SumTmp[33];
....
    if (m_fwChecksum != nullptr)
    {
      strcpy(_md5SumTmp, m_fwChecksum);
    }

    // Update state
    Firmware_Send_State(FW_STATE_DOWNLOADING);
    m_fwState = FW_STATE_DOWNLOADING;

    if (m_fwChecksum != nullptr)
    {
      m_fwChecksum = _md5SumTmp;
    }
....
}

farmerkz avatar Nov 11 '22 18:11 farmerkz

@farmerkz I got it working, but ran into something else. In https://github.com/thingsboard/thingsboard/issues/5366 they say that you can't use MQTT for the download and I would guess this is why I get this:

11:55:50.490 -> OTA
11:55:50.490 -> 1.0.0
11:55:50.490 -> Connecting to AP ...
11:55:51.108 -> .....Connected to AP
11:55:54.102 -> Connecting to: xxx with token xxxx
11:55:54.181 -> Firwmare Update...
11:55:54.181 -> [TB] Requesting shared attributes transformed from (fw_checksum,fw_checksum_algorithm,fw_size,fw_title,fw_version) into json ({"sharedKeys":"fw_checksum,fw_checksum_algorithm,fw_size,fw_title,fw_version"})
11:55:56.919 -> [TB] Callback on_message from topic: (v1/devices/me/attributes/response/1)
11:55:56.919 -> [TB] Received shared attribute request
11:55:56.979 -> [TB] Calling subscribed callback for response id (1)
11:55:56.979 -> [TB] {"fw_title":"OTA","fw_version":"1.0.1","fw_size":842512,"fw_checksum_algorithm":"MD5","fw_checksum":"914c9f3d462a56edea5e5d70ca5716ee"}
11:55:56.979 -> [TB] =================================
11:55:56.979 -> [TB] A new Firmware is available:
11:55:56.979 -> [TB] (1.0.0) => (1.0.1)
11:55:56.979 -> [TB] Attempting to download over MQTT...
11:55:56.996 -> [TB] Unable to write firmware
11:55:56.996 -> UpdatedCallback
11:55:56.996 -> No new firmware

How did you get the OTA working? In the device profile I can only specify Default or the other non-http protocols, as per https://thingsboard.io/docs/user-guide/device-profiles/#default-transport-type. But the Thingsboard source code implicitly says it's using MQTT: ThingsBoard.h - Library API for sending data to the ThingsBoard Based on PubSub MQTT library.

What am I missing?

gittimotap avatar Nov 14 '22 11:11 gittimotap

Hi i have the same problem [TB] Unable to write firmware UpdatedCallback No new firmware

Someone can fixed? Or update the firmware ok esp32?

Regards!

camiloconcha avatar Nov 15 '22 01:11 camiloconcha

@farmerkz Thanks for your answer. I fixed the code like you and it works quite well

Firwmare Update...
[TB] Requesting shared attributes transformed from (fw_checksum,fw_checksum_algorithm,fw_size,fw_title,fw_version) into json ({"sharedKeys":"fw_checksum,fw_checksum_algorithm,fw_size,fw_title,fw_version"})
[TB] Callback on_message from topic: (v1/devices/me/attributes/response/1)
[TB] Received shared attribute request
[TB] Calling subscribed callback for response id (1)
[TB] {"fw_checksum":"6e44779c9cdd120bf5b8fe69fb272754","fw_size":1048768,"fw_title":"ESP32","fw_checksum_algorithm":"MD5","fw_version":"0.0.4"}
[TB] =================================
[TB] A new Firmware is available:
[TB] (0.0.1) => (0.0.4)
[TB] Attempting to download over MQTT...
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/1)
[TB] Receive chunk (1), with size (4096) bytes
[TB] Error during Update.begin
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/0)
[TB] Receive chunk (0), with size (4096) bytes
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/1)
[TB] Receive chunk (1), with size (4096) bytes
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/2)
.........
[TB] Receive chunk (253), with size (4096) bytes
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/254)
[TB] Receive chunk (254), with size (4096) bytes
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/255)
[TB] Receive chunk (255), with size (4096) bytes
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/256)
[TB] Receive chunk (256), with size (192) bytes
[TB] MD5 actual checksum: (6e44779c9cdd120bf5b8fe69fb272754)
[TB] MD5 expected checksum: (6e44779c9cdd120bf5b8fe69fb272754)
[TB] Checksum is the same as expected
[TB] Update success
UpdatedCallback
Done, Reboot now

But sometimes still some errors appear like this. It seems that there must be some condition for it to work well such as: size of code, timeout,....or OTA works at the same time like you say. Can you tell me what is the problem? how to fix it?

........
[TB] Receive chunk (173), with size (4096) bytes
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/174)
[TB] Receive chunk (174), with size (4096) bytes
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/175)
[TB] Receive chunk (175), with size (4096) bytes
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/176)
[TB] Receive chunk (176), with size (4096) bytes
[TB] Error during Update.begin
[TB] Unable to write firmware
UpdatedCallback
No new firmware

NgocThinhNTP18 avatar Nov 15 '22 04:11 NgocThinhNTP18

Hi @NgocThinhNTP18 i do the same of @JfloresIoTF and @farmerkz but it the same problem [TB] Requesting shared attributes transformed from (fw_checksum,fw_checksum_algorithm,fw_size,fw_title,fw_version) into json ({"sharedKeys":"fw_checksum,fw_checksum_algorithm,fw_size,fw_title,fw_version"}) [TB] Callback on_message from topic: (v1/devices/me/attributes/response/1) [TB] Received shared attribute request [TB] Calling subscribed callback for response id (1) [TB] {"fw_checksum":"4b46ba174ef57bdcfc484ad536be28fb","fw_checksum_algorithm":"MD5","fw_size":869824,"fw_title":"TEST","fw_version":"1.0.4"} [TB] ================================= [TB] A new Firmware is available: [TB] (1.0.0) => (1.0.4) [TB] Attempting to download over MQTT... [TB] Unable to write firmware UpdatedCallback No new firmware

how did you make the .bin file? what is your code of the program? Thank everyone for your help here!!

kmilokeepex avatar Nov 15 '22 12:11 kmilokeepex

H! Hmmm..... With the adjustments that I described above, I have practically no problems with OTA:

[TB] Callback on_message from topic: (v1/devices/me/attributes)
[TB] Received shared attribute update
[TB] Shared attribute update callback id: (0)
[TB] No keys subscribed. Calling subscribed callback for any updated attributes (assumed to be subscribed to every possible key)
[TB] Requesting shared attributes transformed from (fw_checksum,fw_checksum_algorithm,fw_size,fw_title,fw_version) into json ({"sharedKeys":"fw_checksum,fw_checksum_algorithm,fw_size,fw_title,fw_version"})
[TB] Callback on_message from topic: (v1/devices/me/attributes)
[TB] Received shared attribute update
[TB] Shared attribute update callback id: (0)
[TB] No keys subscribed. Calling subscribed callback for any updated attributes (assumed to be subscribed to every possible key)
[TB] Callback on_message from topic: (v1/devices/me/attributes/response/2)
[TB] Received shared attribute request
[TB] Calling subscribed callback for response id (2)
[TB] {"fw_title":"Termostat.v2","fw_version":"0.0.2","fw_size":822912,"fw_checksum_algorithm":"MD5","fw_checksum":"60bcb682bf4cd9cd5c17654ca78c69a9"}
[TB] =================================
[TB] A new Firmware is available:
[TB] (0.0.1) => (0.0.2)
[TB] Attempting to download over MQTT...
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/1)
[TB] Receive chunk (1), with size (4096) bytes
[TB] Error during Update.begin
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/0)
[TB] Receive chunk (0), with size (4096) bytes
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/1)
[TB] Receive chunk (1), with size (4096) bytes
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/2)
[TB] Receive chunk (2), with size (4096) bytes
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/3)
[TB] Receive chunk (3), with size (4096) bytes
.......
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/195)
[TB] Receive chunk (195), with size (4096) bytes
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/196)
[TB] Receive chunk (196), with size (4096) bytes
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/197)
[TB] Receive chunk (197), with size (4096) bytes
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/198)
[TB] Receive chunk (198), with size (4096) bytes
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/199)
[TB] Receive chunk (199), with size (4096) bytes
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/200)
[TB] Receive chunk (200), with size (3712) bytes
[TB] MD5 actual checksum: (60bcb682bf4cd9cd5c17654ca78c69a9)
[TB] MD5 expected checksum: (60bcb682bf4cd9cd5c17654ca78c69a9)
[TB] Checksum is the same as expected
[TB] Update success


===================================
     Firmware updated, reboot
===================================

[305461][E][WiFiSTA.cpp:253] begin(): disconnect failed!
SYSTEM_EVENT_STA_DISCONNECTED
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13132
load:0x40080400,len:3036
entry 0x400805e4

According to this snippet:

[TB] Attempting to download over MQTT...
[TB] Callback on_message from topic: (v2/fw/response/0/chunk/1)
[TB] Receive chunk (1), with size (4096) bytes
[TB] Error during Update.begin

zero chunk is lost, and this happens every time, but the transfer is restored. I haven't found the reason yet.

All work with ThingsBoard is locked in a separate task. When an update is available, I initiate it in this task like this:

      if ((_eventBits & NEW_FIRMWARE) != 0)
      {
        disableLoopWDT();
        xSemaphoreTake(tbMutex, portMAX_DELAY);
        _result = tb.Start_Firmware_Update(CURRENT_FIRMWARE_TITLE, CURRENT_FIRMWARE_VERSION, UpdateCallback);
        xSemaphoreGive(tbMutex);
        if (!_result)
          continue;
        while (1)
        {
          xSemaphoreTake(tbMutex, portMAX_DELAY);
          tb.loop();
	  xSemaphoreGive(tbMutex);
          delay(500);
        }
      }

In the callback routine, I check the result of the update, send the update completion status to ThingsBoard, and then I reload the ESP (regardless of the success or failure of the update)

farmerkz avatar Nov 15 '22 13:11 farmerkz

Perhaps this is due to the board? I'm using a Firebeetle board, https://wiki.dfrobot.com/FireBeetle_Board_ESP32_E_SKU_DFR0654. Out of interest, have you checked from TB logs if the download is done via MQTT or HTTP ? This line is actually hardcoded to TB source: [TB] Attempting to download over MQTT... I'm guessing it's because the only supported mechanism from PubSub is MQTT and there was no reason to add it as a variable. But still it's weird, how it's working for you over MQTT and a number of us have issues with it?

gittimotap avatar Nov 15 '22 13:11 gittimotap

Perhaps this is due to the board? I'm using a Firebeetle board, https://wiki.dfrobot.com/FireBeetle_Board_ESP32_E_SKU_DFR0654.

I'm using a board I designed myself based on the ESP32-WROOM, VSCode and PlatformIO with platformio.ini:

[env]
platform = espressif32
board = mhetesp32devkit
framework = arduino
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
lib_deps =
    https://github.com/milesburton/Arduino-Temperature-Control-Library
    https://github.com/PaulStoffregen/OneWire
    ; https://github.com/thingsboard/thingsboard-arduino-sdk
    https://github.com/farmerkz/thingsboard-arduino-sdk
    https://github.com/knolleary/pubsubclient
    https://github.com/bblanchon/ArduinoJson
    https://github.com/adafruit/RTClib

[env:release]
build_flags = -D RELEASE -D WIFI_IOT -I"$PROJECT_DIR/../../include" 

[env:debug]
build_type = debug
build_flags = -D DEBUG -D WIFI_IOT -I"$PROJECT_DIR/../../include"

I made a fork of the library and made all the corrections

Out of interest, have you checked from TB logs if the download is done via MQTT or HTTP ?

Yes, of course, via MQTT, In this library, OTA is only possible via MQTT, see ThingsBoard.h:

    //----------------------------------------------------------------------------
    // Firmware OTA API

#if defined(ESP8266) || defined(ESP32)

farmerkz avatar Nov 15 '22 15:11 farmerkz

@kmilokeepex I don't know what is software you use ?. But if you use Arduino software, you will do the following

  Sketch -> Export Compiled Binary

My code is example 0009 of Thingsboard

NgocThinhNTP18 avatar Nov 17 '22 02:11 NgocThinhNTP18

Perhaps this is due to the board? I'm using a Firebeetle board, https://wiki.dfrobot.com/FireBeetle_Board_ESP32_E_SKU_DFR0654.

I'm using a board I designed myself based on the ESP32-WROOM, VSCode and PlatformIO with platformio.ini:

[env]
platform = espressif32
board = mhetesp32devkit
framework = arduino
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
lib_deps =
    https://github.com/milesburton/Arduino-Temperature-Control-Library
    https://github.com/PaulStoffregen/OneWire
    ; https://github.com/thingsboard/thingsboard-arduino-sdk
    https://github.com/farmerkz/thingsboard-arduino-sdk
    https://github.com/knolleary/pubsubclient
    https://github.com/bblanchon/ArduinoJson
    https://github.com/adafruit/RTClib

[env:release]
build_flags = -D RELEASE -D WIFI_IOT -I"$PROJECT_DIR/../../include" 

[env:debug]
build_type = debug
build_flags = -D DEBUG -D WIFI_IOT -I"$PROJECT_DIR/../../include"

I made a fork of the library and made all the corrections

Out of interest, have you checked from TB logs if the download is done via MQTT or HTTP ?

Yes, of course, via MQTT, In this library, OTA is only possible via MQTT, see ThingsBoard.h:

    //----------------------------------------------------------------------------
    // Firmware OTA API

#if defined(ESP8266) || defined(ESP32)

@farmerkz i use yours library with all the corrections and its work perfect!!

thank you very much!

kmilokeepex avatar Nov 17 '22 15:11 kmilokeepex

During the test code when I give

Thingsboardsized <128> TB (Espclient);

I found that the OTA update process did not work, I knew that we had to increase Thingsboardsized to OTA work

Thingsboardsized <512> TB (Espclient);

Does anyone can tell me how much is the Thingsboardsized in the programs? How to calculate it?

Thank you!

NgocThinhNTP18 avatar Nov 21 '22 02:11 NgocThinhNTP18

The library cannot know the number of how many variables you are going to send, so it establishes as an example that if many variables are required, the declaration of the instance must be different, and it establishes the data of 128, as an example, if the size is not enough it is necessary to increase from 128 to 256 or 512 etc

JfloresIoTF avatar Nov 24 '22 23:11 JfloresIoTF

@imbeacon I think this issue can be closed, the OTA update has been fixed a while ago and works perfectly.

MathewHDYT avatar Mar 13 '23 12:03 MathewHDYT