Firebase push crashing

Hi, folks.

I am updating a firmware for the Anavi Thermometer that works perfectly. The idea is to save temperature and humity in json format to Firebase Real Time DB.

So I added this lines to the existing code:

#define FIREBASE_HOST "******.firebaseio.com"
#define FIREBASE_AUTH "*********************"
//Define Firebase Data object
FirebaseData firebaseData;

void printResult(FirebaseData &data);
void setup_firebase();
void updateDatabaseRules(FirebaseData &dataObj);
void firebase_push(const char* path, FirebaseJson json);

Inside void setup():

 Serial.println("------------------------------------");
  Serial.println("Starting Firebase connection...");
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

  //Set the size of WiFi rx/tx buffers in the case where we want to work with large data.
  //firebaseData.setBSSLBufferSize(1024, 1024);

  //Set the size of HTTP response buffers in the case where we want to work with large data.
  //firebaseData.setResponseSize(1024);
  Serial.println("------------------------------------");

The method called in loop() to push the data to Firebase:

void firebase_push(const char* path, FirebaseJson json){
       
    Serial.println("------------------------------------");
    Serial.println("Pushing JSON data...");
  
    //Also can use Firebase.push instead of Firebase.pushJSON
    //JSON string does not support in v 2.6.0 and later, only FirebaseJson object is supported.
    //TRACE();
    if (Firebase.pushJSON(firebaseData, path, json))
    {
      Serial.println("PASSED");
      Serial.println("PATH: " + firebaseData.dataPath());
      Serial.print("PUSH NAME: ");
      Serial.println(firebaseData.pushName());
      Serial.println("------------------------------------");
      Serial.println();
      //String jsonStr;
      //json.toString(jsonStr, true);
      //Serial.println("PAYLOAD: " + jsonStr);
    }
    else
    {
      Serial.println("FAILED");
      Serial.println("REASON: " + firebaseData.errorReason());
      Serial.println("------------------------------------");
      Serial.println();
    }
}

And finally, the segment that is crashing in void loop(). I removed the “TRACE()” to paste here to improve readability:

   if (sensorInterval <= (currentMillis - sensorPreviousMillis))
    {
         
         -- TRUNCATED --

        if (!isnan(humidity) && !isnan(temp))
        {
           // //TRACE();
            mqtt_online(MQTT_DHT22);

            // Adjust temperature depending on the calibration coefficient
            temp = temp*temperatureCoef;

           // //TRACE();
            dhtTemperature = temp;
            dhtHumidity = humidity;
            publishSensorData(MQTT_DHT22, "air/temperature", "temperature",
                              convertTemperature(temp));
            publishSensorData(MQTT_DHT22, "air/humidity", "humidity", humidity);

            // Calculate heat index
            float dhtHeatIndex = dht.computeHeatIndex(dhtTemperature, dhtHumidity, false);
            publishSensorData(MQTT_DHT22, "air/heatindex", "heatindex",
                              convertTemperature(dhtHeatIndex));
            Serial.println("DHT Heat Index: " + formatTemperature(dhtHeatIndex));

            FirebaseJson firebaseJsonData;
 
            firebaseJsonData.set("Temp",static_cast<double>(dhtTemperature));
            
            firebaseJsonData.set("Humid",static_cast<double>(dhtHumidity));
            
            firebase_push("air/", firebaseJsonData);
            
            firebaseJsonData.clear();

        }
        else
        {
            
            mqtt_status(MQTT_DHT22)->offline();
        }
        
        TRACE();
        setDefaultSensorLines();

From the serial output, I can confirm it’s running fine until firebaseJsonData.clear() and then it crashes, burns and resets :’( :

DHT Heat Index: 23.5°C
custom_anavi-thermometer-sw_1.3.ino:2423: void loop()
custom_anavi-thermometer-sw_1.3.ino:2428: void loop()
custom_anavi-thermometer-sw_1.3.ino:2430: void loop()
------------------------------------
Pushing JSON data…
PASSED
PATH: air/
PUSH NAME: -MB_Qww4mjd2A1RDwUrO
------------------------------------
custom_anavi-thermometer-sw_1.3.ino:2432: void loop()
custom_anavi-thermometer-sw_1.3.ino:2434: void loop()
Exception (3):
epc1=0x401009e1 epc2=0x00000000 epc3=0x00000000 excvaddr=0x40032a68 depc=0x00000000
>>>stack>>>
ctx: cont
sp: 3fff1e40 end: 3fff2340 offset: 0190
*3fff1fd0: 64696f76 6f6f6c20 00292870 40224e45 *
*3fff1fe0: 000005d8 000000bb 000000bb 40100ae4 *

– TRUNCATED –

*3fff2320: 3fffdad0 00000000 3fff0d68 40227714 *
*3fff2330: feefeffe feefeffe 3ffe86a8 40101045 *
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(3,7)
load 0x4010f000, len 3456, room 16
tail 0
chksum 0x84
csum 0x84
va5432625
~ld

And this is the output from Exception Decoder:

Exception 3: LoadStoreError: Processor internal physical address or data error during load or store
PC: 0x401009e1: umm_assimilate_up(unsigned short) at C:\Users\Felipe\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\umm_malloc\umm_malloc.cpp line 183
EXCVADDR: 0x40032a68
Decoding stack results
0x40224f01: Print::print(__FlashStringHelper const*) at C:\Users\Felipe\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\Print.cpp line 114
0x40100ae4: umm_free_core(void*) at C:\Users\Felipe\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\umm_malloc\umm_malloc.cpp line 316
0x40100d83: free(void*) at C:\Users\Felipe\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\umm_malloc\umm_malloc.cpp line 362
0x40100d83: free(void*) at C:\Users\Felipe\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\umm_malloc\umm_malloc.cpp line 362
0x4023de81: operator delete(void*) at /workdir/repo/gcc/libstdc+±v3/libsupc++/del_op.cc line 48
0x4023de6c: operator delete at /workdir/repo/gcc/libstdc+±v3/libsupc++/del_opv.cc line 33
0x40210521: FirebaseJson::_delPtr(char*) at C:\Users\Felipe\Documents\Arduino\libraries\Firebase_ESP8266_Client\src\FirebaseJson.cpp line 2468
0x4021053d: FirebaseJson::_finalize() at C:\Users\Felipe\Documents\Arduino\libraries\Firebase_ESP8266_Client\src\FirebaseJson.cpp line 95
0x40100604: delayMicroseconds(unsigned int) at C:\Users\Felipe\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\core_esp8266_wiring.cpp line 210
0x40211772: FirebaseJson::~FirebaseJson() at c:\users\felipe\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\bits/shared_ptr_base.h line 781
0x40209309: loop() at C:\Users\Felipe\Documents\Arduino\libraries\ArduinoTrace/ArduinoTrace.h line 118
0x40100100: std::function ::operator()() const at c:\users\felipe\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2/functional line 2459
0x40100218: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\Felipe\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\core_esp8266_main.cpp line 177
0x402277d0: loop_wrapper() at C:\Users\Felipe\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.1\cores\esp8266\core_esp8266_main.cpp line 197

Things I’ve noticed:

  • Whatever method that comes after firebaseJsonData.clear(); is shown on Exception Decoder: line 118 in loop() corresponds to TRACE()
  • If I remove TRACE() it will stop at setDefaultSensorLines(); and so on…
  • Code works fine when I remove the code firebaseJsonData.set from loop()

I am pretty sure it’s a beginner’s mistake, but I am failing to see it.

Any ideas?

Thanks!