mobizt / Firebase-ESP8266

[DEPRECATED] 🔥 Firebase RTDB Arduino Library for ESP8266 and RP2040 Pico. The complete, fast, secured and reliable Firebase Arduino client library that supports CRUD (create, read, update, delete) and Stream operations.
MIT License
410 stars 111 forks source link

Soft WDT reset - Firebase ESP8266 Client #208

Closed AlvaroVelloso closed 3 years ago

AlvaroVelloso commented 3 years ago

Hello, I'm trying so hard to get rid of this error, could you please help me? My application reads parameters from Firebase once a minute, takes temperatures from sensors, appends it, updates DB, and sends notifications (FCM). Randomly, from 20 to 120 minutes, I get a "Soft WDT reset" error.

I have Firebase ESP8266 Client 3.2.3 Library installed.

Thank you so much in advance!

This is the Stack Decoded:

0x402295c2: optimistic_yield(uint32_t) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266/core_esp8266_features.h line 66 0x402295c2: optimistic_yield(uint32_t) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266/core_esp8266_features.h line 66 0x4023462b: BearSSL::WiFiClientSecureCtx::_run_until(unsigned int, bool) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266/PolledTimeout.h line 260 0x40258e28: br_ssl_hs_client_init_main at src/ssl/ssl_hs_client.c line 907 0x40258e78: br_ssl_hs_client_run at src/ssl/ssl_hs_client.c line 960 0x40258466: br_ssl_engine_hs_reset at src/ssl/ssl_engine.c line 1319 0x40234753: BearSSL::WiFiClientSecureCtx::_wait_for_handshake() at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\libraries\ESP8266WiFi\src\WiFiClientSecureBearSSL.cpp line 585 0x40234963: BearSSL::WiFiClientSecureCtx::_connectSSL(char const) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\libraries\ESP8266WiFi\src\WiFiClientSecureBearSSL.cpp line 1164 0x402294f0: __esp_yield() at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\core_esp8266_main.cpp line 116 0x40229e96: __delay(unsigned long) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\core_esp8266_wiring.cpp line 54 0x40205f5a: WiFiClient::connect(IPAddress, unsigned short) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\libraries\ESP8266WiFi\src/include/ClientContext.h line 148 0x40234a09: BearSSL::WiFiClientSecureCtx::connect(char const, unsigned short) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\libraries\ESP8266WiFi\src\WiFiClientSecureBearSSL.cpp line 231 0x4023baf6: BearSSL::WiFiClientSecure::connect(char const, unsigned short) at c:\users\avelloso\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.0-newlib4.0.0-gnu23-48f7b08\xtensa-lx106-elf\include\c++\10.2.0\bits/shared_ptr_base.h line 1324 0x40205220: ESP8266WiFiSTAClass::status() at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp line 527 0x40221583: FB_HTTPClient::connect() at c:\users\avelloso\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.0-newlib4.0.0-gnu23-48f7b08\xtensa-lx106-elf\include\c++\10.2.0\bits/basic_string.h line 2301 0x402215ca: FB_HTTPClient::send(char const, char const) at C:\Users\Avelloso\AppData\LocalGoogle\Documents\Arduino\libraries\Firebase_ESP8266_Client\src\wcs\esp8266\FB_HTTPClient.cpp line 95 0x4021847c: FB_RTDB::sendRequest(FirebaseData, fb_esp_rtdb_request_info_t) at c:\users\avelloso\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.0-newlib4.0.0-gnu23-48f7b08\xtensa-lx106-elf\include\c++\10.2.0\bits/basic_string.h line 2301 0x40100434: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\core_esp8266_main.cpp line 181 0x402292f1: operator new(unsigned int) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\abi.cpp line 40 0x4024853b: std::cxx11::basic_string , std::allocator >::_M_create(unsigned int&, unsigned int) at /workdir/arena.x86_64/gcc-gnu/xtensa-lx106-elf/libstdc++-v3/include/ext/new_allocator.h line 103 0x40100f8e: malloc(size_t) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\umm_malloc\umm_malloc.cpp line 821 0x402485bc: std::cxx11::basic_string , std::allocator >::_S_copy(char, char const, unsigned int) at /workdir/arena.x86_64/gcc-gnu/xtensa-lx106-elf/libstdc++-v3/include/bits/char_traits.h line 322 0x40248614: std::__cxx11::basic_string , std::allocator >::_S_copy_chars(char, char, char) at /workdir/arena.x86_64/gcc-gnu/xtensa-lx106-elf/libstdc++-v3/include/bits/basic_string.h line 394 0x40100c37: umm_free_core(umm_heap_context_t, void) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\umm_malloc\umm_malloc.cpp line 549 0x40100f4e: free(void) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\umm_malloc\umm_malloc.cpp line 595 0x40248558: std::__cxx11::basic_string , std::allocator >::_M_dispose() at /workdir/arena.x86_64/gcc-gnu/xtensa-lx106-elf/libstdc++-v3/include/ext/new_allocator.h line 120 0x4021bd41: FirebaseData::validRequest(std::__cxx11::basic_string , std::allocator > const&) at c:\users\avelloso\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.0-newlib4.0.0-gnu23-48f7b08\xtensa-lx106-elf\include\c++\10.2.0\ext/new_allocator.h line 89 0x40205220: ESP8266WiFiSTAClass::status() at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp line 527 0x40221287: Firebase_Signer::checkToken() at C:\Users\Avelloso\AppData\LocalGoogle\Documents\Arduino\libraries\Firebase_ESP8266_Client\src\signer\Signer.cpp line 1809 0x402212cc: Firebase_Signer::tokenReady() at C:\Users\Avelloso\AppData\LocalGoogle\Documents\Arduino\libraries\Firebase_ESP8266_Client\src\signer\Signer.cpp line 1819 0x4021a23c: FB_RTDB::handleRequest(FirebaseData, fb_esp_rtdb_request_info_t) at C:\Users\Avelloso\AppData\LocalGoogle\Documents\Arduino\libraries\Firebase_ESP8266_Client\src\rtdb\FB_RTDB.cpp line 3778 0x402212cc: Firebase_Signer::tokenReady() at C:\Users\Avelloso\AppData\LocalGoogle\Documents\Arduino\libraries\Firebase_ESP8266_Client\src\signer\Signer.cpp line 1819 0x4021a42b: FB_RTDB::processRequest(FirebaseData, fb_esp_rtdb_request_info_t) at C:\Users\Avelloso\AppData\LocalGoogle\Documents\Arduino\libraries\Firebase_ESP8266_Client\src\rtdb\FB_RTDB.cpp line 3606 0x4024853b: std::cxx11::basic_string , std::allocator >::_M_create(unsigned int&, unsigned int) at /workdir/arena.x86_64/gcc-gnu/xtensa-lx106-elf/libstdc++-v3/include/ext/new_allocator.h line 103 0x40100f8e: malloc(size_t) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\umm_malloc\umm_malloc.cpp line 821 0x402292f7: operator new(unsigned int) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\abi.cpp line 41 0x402485bc: std::cxx11::basic_string , std::allocator >::_S_copy(char, char const, unsigned int) at /workdir/arena.x86_64/gcc-gnu/xtensa-lx106-elf/libstdc++-v3/include/bits/char_traits.h line 322 0x4024870e: std::__cxx11::basic_string , std::allocator >::_M_mutate(unsigned int, unsigned int, char const, unsigned int) at /workdir/arena.x86_64/gcc-gnu/xtensa-lx106-elf/libstdc++-v3/include/bits/basic_string.h line 180 0x40100f4e: free(void) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\umm_malloc\umm_malloc.cpp line 595 0x402489e4: std::__cxx11::basic_string , std::allocator >::_M_replace(unsigned int, unsigned int, char const, unsigned int) at /workdir/arena.x86_64/gcc-gnu/xtensa-lx106-elf/libstdc++-v3/include/bits/basic_string.h line 216 0x4021b8f8: FirebaseData::reconnect(unsigned long) at C:\Users\Avelloso\AppData\LocalGoogle\Documents\Arduino\libraries\Firebase_ESP8266_Client\src\session\FB_Session.cpp line 600 0x4021a73c: FB_RTDB::processRequest(FirebaseData, fb_esp_rtdb_request_info_t) at C:\Users\Avelloso\AppData\LocalGoogle\Documents\Arduino\libraries\Firebase_ESP8266_Client\src\rtdb\FB_RTDB.cpp line 3562 0x4021ab05: FB_RTDB::int_pushJSON(FirebaseData, char const, FirebaseJson, char const, bool) at C:\Users\Avelloso\AppData\LocalGoogle\Documents\Arduino\libraries\Firebase_ESP8266_Client\src\rtdb\FB_RTDB.cpp line 860 0x40211078: std::_Sp_counted_ptr ::_M_destroy() at c:\users\avelloso\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.0-newlib4.0.0-gnu23-48f7b08\xtensa-lx106-elf\include\c++\10.2.0\bits/shared_ptr_base.h line 383 0x40100fc8: realloc(void, size_t) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\umm_malloc\umm_malloc.cpp line 853 0x40248e00: std::__cxx11::basic_string , std::allocator >::_M_construct (char const, char const, std::forward_iterator_tag) at /workdir/arena.x86_64/gcc-gnu/xtensa-lx106-elf/libstdc++-v3/include/bits/basic_string.h line 188 0x40100c00: umm_free_core(umm_heap_context_t, void) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\umm_malloc\umm_malloc.cpp line 520 0x40228609: String::concat(char const, unsigned int) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\WString.cpp line 309 0x40228609: String::concat(char const, unsigned int) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\WString.cpp line 309 0x402286bc: String::concat(String const&) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266/WString.h line 277 0x4021ab63: FB_RTDB::pushJSON(FirebaseData, char const, FirebaseJson) at C:\Users\Avelloso\AppData\LocalGoogle\Documents\Arduino\libraries\Firebase_ESP8266_Client\src\rtdb\FB_RTDB.cpp line 821 0x4021062a: FirebaseESP8266::pushJSON(FirebaseData&, String const&, FirebaseJson&) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266/WString.h line 277 0x4020424e: Firebase_Append_Temperature() at E:\@Alvaro\Eletronica\@Aquario\eAqua\eCacau011/eCacau011.ino line 393 0x40100400: ets_intr_unlock() at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\core_esp8266_main.cpp line 167 0x4024853b: std::cxx11::basic_string , std::allocator >::_M_create(unsigned int&, unsigned int) at /workdir/arena.x86_64/gcc-gnu/xtensa-lx106-elf/libstdc++-v3/include/ext/new_allocator.h line 103 0x40100f8e: malloc(size_t) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\umm_malloc\umm_malloc.cpp line 821 0x402485bc: std::cxx11::basic_string , std::allocator >::_S_copy(char, char const, unsigned int) at /workdir/arena.x86_64/gcc-gnu/xtensa-lx106-elf/libstdc++-v3/include/bits/char_traits.h line 322 0x40248614: std::__cxx11::basic_string , std::allocator >::_S_copy_chars(char, char, char) at /workdir/arena.x86_64/gcc-gnu/xtensa-lx106-elf/libstdc++-v3/include/bits/basic_string.h line 394 0x40100c37: umm_free_core(umm_heap_context_t, void*) at C:\Users\Avelloso\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\umm_malloc\umm_malloc.cpp line 549

This is the Error:

Soft WDT reset

stack>>>

ctx: cont sp: 3ffff4a0 end: bb67ae85 offset: 01a0 3ffff640: 002304e7 3ffff670 3fff7644 402295c2
3ffff650: 00000000 40107934 3fff29fc 402295c2
3ffff660: 00000000 0005cdd9 3fff29fc 4023462b
3ffff670: 000000f5 f99811a6 8c8d42d9 a7aad7ac
3ffff680: 00000008 00000001 0022f913 00000000
3ffff690: 40258e28 40258e78 3fff7644 40258466
3ffff6a0: 3fff7b44 3fff518c 3fff7644 3fff518c
3ffff6b0: 00000000 00000001 3fff29fc 40234753
3ffff6c0: 00000000 00000001 3fff29fc 40234963
3ffff6d0: 00000006 3fff18ac 00000001 402294f0
3ffff6e0: 00000000 00000000 00000000 40229e96
3ffff6f0: 00000000 3fff51bc 3fff29fc 40205f5a
3ffff700: 3fff58dc 00000399 00000399 3fff6ea4
3ffff710: 000001bb 3fff518c 3fff29fc 3fff6ea4
3ffff720: 000001bb 3fff518c 3fff29fc 40234a09
3ffff730: 4023d430 5561c923 4023d430 5561c923
3ffff740: 3fff5874 00000000 3ffefba8 4023baf6
3ffff750: 3fff5f54 40205220 3ffefba8 40221583
3ffff760: 3fff09a8 3ffefba8 0000005e 402215ca
3ffff770: 3fff63b4 00000000 3fff63b4 3ffefba8
3ffff780: 3ffffa10 3ffff888 00000000 4021847c
3ffff790: 00000000 00000000 0000000a 00000000
3ffff7a0: 00000000 00000000 0000000a 00000000
3ffff7b0: 00010000 3fff0601 ffffffff 3fff0628
3ffff7c0: 3ffff8ba a0000000 00000000 0000001c
3ffff7d0: 0000000c 00000000 00000020 40100434
3ffff7e0: 00000001 00000005 0000000c 401024c0
3ffff7f0: 3ffe9f8c 40101e0a 04000000 0000000d
3ffff800: 00000001 00000004 402292f1 00000000
3ffff810: 8899cc60 00000000 000f4240 3ffffa10
3ffff820: 3fff558d 4024853b 00000020 40100f8e
3ffff830: 3fff4d5c 3fff4d5c 0000039a 402485bc
3ffff840: 00000000 3fff51f4 3ffff8c8 40248614
3ffff850: 000008c6 000008c6 3ffe8650 40100c37
3ffff860: 00000399 00000030 00000018 3ffffa10
3ffff870: 3ffefba8 00000020 3fff6734 40100f4e
3ffff880: 00009cbf 3fff1638 3fff6ea4 000004aa
3ffff890: 0000078a 3fff0020 00000003 40248558
3ffff8a0: 3fff5874 0000005e 0000005e 4021bd41
3ffff8b0: 4028814a 3ffefba8 00000000 00000001
3ffff8c0: 4028932f 00000001 3fff10c8 00000399
3ffff8d0: 00000399 40205220 3fff1638 40221287
3ffff8e0: 3ffff8e8 00000000 00000000 402212cc
3ffff8f0: 000007a0 3ffefba8 3ffefba8 3ffffa10
3ffff900: 3fff08a8 00000000 3ffefba8 4021a23c
3ffff910: 3fff10c8 3fff07a8 3fff09a8 402212cc
3ffff920: 00000000 3ffefba8 3ffffa10 3fff10c8
3ffff930: 3ffefba8 00000001 3ffffa10 4021a42b
3ffff940: 0000005e 4024853b 00000020 40100f8e
3ffff950: 3ffffd00 0000005e 0000005f 402292f7
3ffff960: 00000000 3ffffa58 3ffffa58 402485bc
3ffff970: 0000085b 0000085b 3ffe8650 4024870e
3ffff980: 0000005e 0000005d 3fff63dc 00000001
3ffff990: 00000000 00000000 3fff5ddc 40100f4e
3ffff9a0: 4028814a 3ffefba8 00000000 00000001
3ffff9b0: 4028932f 3ffffa58 00000000 402489e4
3ffff9c0: 3fff08a8 00000000 00000001 00000000
3ffff9d0: 00000001 00000020 3fff63dc 4021b8f8
3ffff9e0: 00000000 00000000 3fff66ac 3ffefba8
3ffff9f0: 3ffffa10 3fff10c8 3ffefba8 4021a73c
3ffffa00: 3fff10c8 3ffe9457 00000000 4021ab05
3ffffa10: 3fff571c 0000001c 0000001e 40211078
3ffffa20: 00000001 00000020 00000002 00000007
3ffffa30: 00000000 00000000 00000000 00000000
3ffffa40: 00000000 00000000 00000000 00000000
3ffffa50: 00000000 00000000 3fff5e9c 0000005e
3ffffa60: 0000005e 00000000 00000000 00000000
3ffffa70: 3ffffa78 00000000 3ffe8600 0000000a
3ffffa80: 00000000 00000020 3ffffa90 00000000 < 3ffffa90: 3ffffb00 00000020 3ffffb40 40100fc8
3ffffaa0: 3fff0000 3ffffaac 00000000 40248e00
3ffffab0: 0000085b 0000085b 3ffe8650 40100c00
3ffffac0: 3ffffd2c 00000001 3ffffb40 40228609
3ffffad0: 3fff638c 3fff5134 3fff5ddc 0000005e
3ffffae0: 000000ba 00000001 3ffffb40 40228609
3ffffaf0: 3fff638c 00000000 3ffffb40 402286bc
3ffffb00: 3ffe8aef 3ffffee4 3ffffb40 60ccfec9
3ffffb10: 3ffe8b1a 3fff10c8 3ffefba8 4021ab63
3ffffb20: 3ffe8b1a 3ffef604 3ffef600 4021062a
3ffffb30: 41d80000 3ffef604 3ffef600 4020424e
3ffffb40: 00000000 001c001f 00000000 00000000
3ffffb50: 00000000 00000000 40282dcb 00000001
3ffffb60: 00000000 3ffffb6c 00000000 40100400
3ffffb70: 40282e1a 3ffed6f0 00000001 3fff63dc
3ffffb80: 00000001 ffffffff 00000007 ffffffff
3ffffb90: 888ae510 00000000 000f4240 3ffffd90
3ffffba0: 3fff558d 4024853b 00000020 40100f8e
3ffffbb0: 0000000d 00000000 0000039a 402485bc
3ffffbc0: 00000000 3fff51f4 3ffffc48 40248614
3ffffbd0: 000008c6 000008c6 3ffe8650 40100c37
3ffffbe0: 3ffffbe8 00000000 55434d00 6c6f4720
3ffffbf0: 226e6564 00000000 3ffffc00 00000000 < 3ffffc00: 00000100 3fff4c74 3ffefba8 3ffefba8
3ffffc10: 3ffefba8 3fff29d4 00000000 3fff10c8
3ffffc20: 00000000 00000000 00000000 3fff4d5c
3ffffc30: 00000000 00000000 00000404 00000001

This is the Source Code

//------------------------------------------------- // Software //------------------------------------------------- //Processor:LOLIN(WEMOS)D1 mini Pro //Processor LilliGo :WEMOS D1 R1 //https://escapequotes.net/wemos-d1-mini-pro/

String Product = "Product1"; String deviceVersion = "0.02";

//------------------------------------------------- // Libraries //-------------------------------------------------

// WiFi **** //

include

include //Local WebServer used to serve the configuration portal

include //Local DNS Server used for redirecting all requests to the configuration portal ( https://github.com/zhouhan0126/DNSServer---esp32 )

include //WiFi Configuration Magic ( https://github.com/zhouhan0126/WIFIMANAGER-ESP32 ) >> https://github.com/tzapu/WiFiManager (ORIGINAL)

// Web Time Clock *** //

include

include

WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP);

// HTTP Client *** // //#include

include

include

//ESP8266WiFiMulti WiFiMulti;

// OTA *** //

include

include

// Timer //

include

include

const int TimerWiFiPeriod = 1 1000; //WiFi LED const int TimerSensorPeriod = 60 1000; //Time between reads const int TimerMsgPeriod = 560 1000; //Enable New Message every each x minutes

auto TimerWiFi = timer_create_default(); // Get WiFi Status auto TimerSensor = timer_create_default(); // create a timer with default settings auto TimerMessage = timer_create_default(); //Enables Message avery x minutes bool gNotifyEnable = true; bool gToastEnable = true;

//unsigned long GlobalEpcoh = 0; int GMT = 0; String gDeviceAlias = "";

// Temperature Sensor //

include

include

// FireBase //

include

define FIREBASE_HOST "ecacau-1b2d4-default-rtdb.firebaseio.com"

define API_KEY "AIzaSyCpqo4ajI4dUyHfqVIRWKecmEoTJ858-Ns"

define USER_EMAIL "devices@ecacau.com.br"

define USER_PASSWORD "17d1f82573edee6052975b9e027fff49"

define FIREBASE_AUTH "zel1cuPLwCoTstil9XAtaKj5Rrp9tVkpuHPMJiJo" //"DATABASE_SECRET"

FirebaseData fbdo; FirebaseConfig config; FirebaseAuth auth;

//------------------------------------------------- // Globais //-------------------------------------------------

// WiFi Connected Global bool WiFiReady = false;

// Pinout //

define CATODO_COMUM_PIN 4 //D2, Terra Virtual, atendendo aos dos LEDs

define CONECTADO_A_PIN 5 //D1, modo conectado

define WIFIMAN_A_PIN 0 //D3, modo de configuração da rede

//#define BAT_PIN A0 //Analog para versão com bateria

define TEMP_PIN 13 //D7, One Wire

define TEMP_GND_PIN 12 //D6, Terra virtual

define LED_BUITIN_PIN 2 //GPIO 2 / D4 / LED_BUILTIN

//Message Mode const int MESSAGE_LOG =0; const int MESSAGE_TOAST =1; const int MESSAGE_POPUP =2; const int MESSAGE_NOTIFY=3;

// Temperature Sensors // OneWire oneWire(TEMP_PIN); // One Wire Protocol DallasTemperature sensors(&oneWire); // DeviceAddress ds18;

float T0 = 0; //Topo float T1 = 0; //Meio float T2 = 0; //Fundo

//bool PowerSave = false; //------------------------------------------------- // SETUP //------------------------------------------------- void setup() {

// Serial // Serial.begin(9600);

pinMode(TEMP_PIN, INPUT);

pinMode(CATODO_COMUM_PIN, OUTPUT); pinMode(CONECTADO_A_PIN, OUTPUT); pinMode(WIFIMAN_A_PIN, OUTPUT); pinMode(TEMP_GND_PIN, OUTPUT); pinMode(LED_BUITIN_PIN, OUTPUT);

digitalWrite(CATODO_COMUM_PIN,LOW); digitalWrite(CONECTADO_A_PIN,LOW); digitalWrite(WIFIMAN_A_PIN,LOW); digitalWrite(TEMP_GND_PIN,LOW); //digitalWrite(LED_BUITIN_PIN,LOW);

// Web Time Clock // timeClient.begin();

// Timers // TimerWiFi.every(TimerWiFiPeriod, WiFi_Ready); TimerSensor.every(TimerSensorPeriod, ReadSensors); TimerMessage.every(TimerMsgPeriod, EnableMsg);

// Temperature Sensor // sensors.begin(); sensors.setResolution(12);

// **** Firebase https://github.com/mobizt/Firebase-ESP-Client String var = "$user"; String val = "(auth.uid === $user)";

//Firebase Header------------------ fbdo.setResponseSize(4096); config.host = FIREBASE_HOST; config.api_key = API_KEY; auth.user.email = USER_EMAIL; auth.user.password = USER_PASSWORD; Firebase.begin(&config, &auth); Firebase.reconnectWiFi(true); //Firebase Header------------------

fbdo.fcm.begin("AAAAHP_PHSU:APA91bGF4myi-ra9Vpssv_lDN5_b_Zr2ptmv21JsDsL9DTv8UmVlwzONzY1oENdkixTD96y2GqaSiFhlhJcJg78DXl446D9_cJtU9agBOYxRBsBDsGBU-UXfn-YvrEL41aOhtLVLJjt8"); fbdo.fcm.setPriority("normal"); fbdo.fcm.setTimeToLive(1000);

//Optional, set number of error retry //Firebase.RTDB.setMaxRetry(&fbdo, 3); Firebase.RTDB.setMaxRetry(&fbdo, 1);

//Optional, set number of error resumable queues //Firebase.RTDB.setMaxErrorQueue(&fbdo, 30); Firebase.RTDB.setMaxErrorQueue(&fbdo, 1);

//Optional, use classic HTTP GET and POST requests. //This option allows get and delete functions (PUT and DELETE HTTP requests) works for //device connected behind the Firewall that allows only GET and POST requests. Firebase.RTDB.enableClassicRequest(&fbdo, true);

//#if defined(ESP8266) //Optional, set the size of BearSSL WiFi to receive and transmit buffers //Firebase may not support the data transfer fragmentation, you may need to reserve the buffer to match //the data to transport. fbdo.setBSSLBufferSize(1024, 1024); //minimum size is 512 bytes, maximum size is 16384 bytes //#endif

//Optional, set the size of HTTP response buffer //Prevent out of memory for large payload but data may be truncated and can't determine its type. fbdo.setResponseSize(1024); //minimum size is 1024 bytes //The reserved SSL Rx/Tx buffer size in ESP8266 can be set through the function .setBSSLBufferSize, e.g. fbdo.setBSSLBufferSize(2048, 2048);

// WiFi Manager // WiFi_Config();

}

//------------------------------------------------- // LOOP //------------------------------------------------- void loop() {

OTA();
TimerWiFi.tick(); TimerSensor.tick(); TimerMessage.tick();

}

//------------------------------------------------- // Timers //------------------------------------------------- bool ReadSensors(void *) {

Serial.print("."); if (!WiFiReady) return (true);

Firebase_Reads();

// Temperature // float tTemp = 0; sensors.requestTemperatures();

sensors.getAddress(ds18, 0); //T0 tTemp = sensors.getTempC(ds18); if (tTemp >= 0) T0 = tTemp;

sensors.getAddress(ds18, 1); //T1 tTemp = sensors.getTempC(ds18); if (tTemp >= 0) T1 = tTemp;

sensors.getAddress(ds18, 2); //T1 tTemp = sensors.getTempC(ds18); if (tTemp >= 0) T2 = tTemp;

Firebase_Append_Temperature();

return (true); }

//------------------------------------------------- // WiFi Reset to WiFi Manager //------------------------------------------------- void WiFi_Config() {

//Turn LED Configuration ON LED_Alert(2);

digitalWrite(WIFIMAN_A_PIN,HIGH);

delay(3000);

WiFiManager wifiManager; wifiManager.setConfigPortalTimeout(60);

char WiFiConfig_SSID[50]; String WM_SSID = Product + " (" + String(WiFi.macAddress()+ ")"); WM_SSID.toCharArray(WiFiConfig_SSID, 50);

if(!wifiManager.startConfigPortal(WiFiConfig_SSID)) { wifiManager.autoConnect(); delay(1000); }

//Turn LED Configuration OFF digitalWrite(WIFIMAN_A_PIN,LOW); LED_Alert(2);

return; }

//------------------------------------------------- // WiFi Reset to WiFi Manager //------------------------------------------------- void LED_Alert(int Times) {

int t = 300;

delay(t);

for (int i = 0; i < Times; i++) { digitalWrite(LED_BUILTIN, LOW); delay(t); digitalWrite(LED_BUILTIN, HIGH); delay(t); } return; }

//------------------------------------------------- // OTA //------------------------------------------------- void OTA()

{

static bool ConnectedBefore = false;

if (!WiFiReady) return; ArduinoOTA.handle();

if (ConnectedBefore) return;

String MACr = gDeviceAlias;

MACr = Product + "(" + MACr + ")" ;

char HostName[50]; MACr.toCharArray(HostName, 50);

ArduinoOTA.setHostname(HostName); ArduinoOTA.begin();

ConnectedBefore = true; }

//------------------------------------------------- // FireBase Append Temperature //------------------------------------------------- void Firebase_Append_Temperature() {

if (!WiFiReady) return;

String IdDispositivo = String(WiFi.macAddress());

int Epoch = EpochTime(); if (Epoch == 0 ) return;

float TMed = round((T0 + T1 + T2) / 3);

//** Medições CO2 Append FirebaseJson json; json.set("timestamp", Epoch); json.set("tTopo", T0); json.set("tMeio", T1); json.set("tFundo", T2); json.set("tMedia", TMed);

int InterpolationIndex = Interpolation_Index(); json.set("interpolationIndex",InterpolationIndex);

String base_path = "/medicoes/" + IdDispositivo + "/"; if (!Firebase.pushJSON(fbdo, base_path, json)) Serial.println(fbdo.errorReason());

base_path = "/medicoes_backup/" + IdDispositivo + "/"; if (!Firebase.pushJSON(fbdo, base_path, json)) Serial.println(fbdo.errorReason());

if (InterpolationIndex >= 24) { base_path = "/medicoes_high/" + IdDispositivo + "/"; if (!Firebase.pushJSON(fbdo, base_path, json)) Serial.println(fbdo.errorReason());

base_path = "/medicoes_high_backup/" + IdDispositivo + "/";
if (!Firebase.pushJSON(fbdo, base_path, json))
  Serial.println(fbdo.errorReason());
}

//** Dispositivo Update FirebaseJson updateData; updateData.set("IP",WiFi.localIP().toString()); updateData.set("SSID",String(WiFi.SSID())); updateData.set("deviceVersion",deviceVersion); updateData.set("dtUltInicializacao",Epoch);

if (!Firebase.updateNode(fbdo, "/dispositivos/" +IdDispositivo, updateData)) Serial.println(fbdo.errorReason());

LED_Alert(1);

return; }

//------------------------------------------------- // Interpolation Index //------------------------------------------------- int Interpolation_Index() { //Serial.println("***** INTERPOLATION INDEX");
static int Cont = 0; const int MaxCont = 336;

int Index = 1; if ((Cont%3) == 0) Index = 3; if ((Cont%12) == 0) Index = 12; if ((Cont%24) == 0) Index = 24; if ((Cont%72) == 0) Index = 72; if ((Cont%168) == 0) Index = 168; if ((Cont%336) == 0) Index = 336;

Cont++; if (Cont >= MaxCont) Cont = 1; //overflow

//Serial.println("Index: " + String(Index));

return(Index); }

//------------------------------------------------- // FireBase Read Token //------------------------------------------------- String Firebase_Read_Token() { //Serial.println("***** FIREBASE READ TOKEN");
String path = "/dispositivos/" + String(WiFi.macAddress())+ "/" + "fcmToken";
//Serial.println("path:" + path);

String Ret = ""; String msg = "";

if (!Firebase.getString(fbdo, path))
{ msg = "Token inválido, notificação perdida: " + msg + " Error Reason: " + String(fbdo.errorReason()); } else Ret = fbdo.stringData();

return(Ret);

}

//------------------------------------------------- // WiFi Connection //------------------------------------------------- bool WiFi_Ready(void *) {

if (WiFi.status() == WL_CONNECTED) { WiFiReady = true;
digitalWrite(CONECTADO_A_PIN,HIGH); digitalWrite(LED_BUITIN_PIN,LOW); } else { WiFiReady = false; digitalWrite(CONECTADO_A_PIN,LOW); digitalWrite(LED_BUITIN_PIN,HIGH); }

if (!WiFiReady) return (true);

static bool msgDone = false;

int Epoch = EpochTime(); if (Epoch == 0) return (false);

if (!msgDone) { FireBase_Message("Dispositivo iniciado na rede " + String(WiFi.SSID()),MESSAGE_LOG);
msgDone = true; }

return(true); } //------------------------------------------------- // FireBase Read Parameters //------------------------------------------------- float Firebase_Read_Par(String Par, float PreviousValue) {

if (!WiFiReady) return (PreviousValue);

String path = "/dispositivos/" + String(WiFi.macAddress())+ "/" + Par;
float Ret = -1; String msg = ""; int ErrorSize = 0;

if (!Firebase.getFloat(fbdo, path))
{ msg = "Read PAr";

//Criação do parametro, se não existe  
ErrorSize = msg.length();
if (ErrorSize == 0)
 {
 Firebase.setFloat(fbdo, path, 0);
 msg = "Parametro criado: " + Par;
 }
else
 msg = "Erro leitura FireBase. Parâmetro: " + Par + " - " + msg + " - Tamanho: " + String(ErrorSize);  

return(PreviousValue);
}

Ret = fbdo.floatData(); return(Ret);

}

//------------------------------------------------- // FireBase Read Parameters //------------------------------------------------- String Firebase_Read_Par_String(String Par, String PreviousValue) { if (!WiFiReady) return (PreviousValue);

String path = "/dispositivos/" + String(WiFi.macAddress())+ "/" + Par;
String Ret = ""; String msg = ""; int ErrorSize = 0;

if (!Firebase.getString(fbdo, path))
{ //msg = String(fbdo.errorReason()); msg="Par String"; //Criação do parametro, se não existe
ErrorSize = msg.length(); if (ErrorSize == 0) { Firebase.setString(fbdo, path, ""); msg = "Parametro criado: " + Par; } else msg = "Erro leitura FireBase. Parâmetro: " + Par + " - " + msg + " - Tamanho: " + String(ErrorSize);

//Serial.println(msg); //FireBase_Message(msg, MESSAGE_LOG);

return(PreviousValue);
}

Ret = fbdo.stringData(); return(Ret);

}

//------------------------------------------------- // FireBase Read Parameters //------------------------------------------------- void Firebase_Reads() { //Only if connected to internet if (!WiFiReady) return;

GMT = Firebase_Read_Par("GMT",GMT); gDeviceAlias = Firebase_Read_Par_String("nome",String(WiFi.macAddress()));

return; }

//------------------------------------------------- // Send Message //------------------------------------------------- bool EnableMsg(void *) {

gToastEnable = true; gNotifyEnable = true; return(true); }

//------------------------------------------------- // Get Epcho Time //------------------------------------------------- int EpochTime() {

if (!WiFiReady) return (0); timeClient.setTimeOffset(0); while(!timeClient.update()) timeClient.forceUpdate();

int Epoch = timeClient.getEpochTime(); if (Epoch < 1614370000) return (0);

return (Epoch);
}

//------------------------------------------------- // Send Message //------------------------------------------------- void FireBase_Message(String pMsg, int pLevel) {

//Serial.println("Mensagem: " + pMsg); // MESSAGE_LOG = 0 - Não exibir, só gravar na tabela mensagem // MESSAGE_TOAST = 1 - Exibir mensagem que desaparece // MESSAGE_POPUP = 2 - Interação com o usuário // MESSAGE_NOTIFY = 3 - Notificação para o usuário

//** Only if connected to internet if (!WiFiReady) return;

int Epoch = EpochTime(); if (Epoch == 0 ) return;

// ------------------------------- Message ---------------------------------------- if (!gToastEnable) pLevel = MESSAGE_LOG;

gToastEnable = false;

//** Appends on Message Table String idDispositivo = String(WiFi.macAddress()); String sSSID = String(WiFi.SSID()); String sIP = WiFi.localIP().toString();

String base_path = "/mensagens/"+ idDispositivo + "/";

//** Database Update FirebaseJson json; //json.set("idDispositivo", idDispositivo); json.set("IP",sIP); json.set("Mensagem", pMsg); json.set("Nivel", pLevel); json.set("SSID",sSSID); json.set("timestamp",Epoch);

if (!Firebase.pushJSON(fbdo, base_path, json)) Serial.println(fbdo.errorReason());

// ------------------------------- Notification ---------------------------------------- //** Avoid multiple messages if (!gNotifyEnable) return; gNotifyEnable = false;

//** Only for FCM (Notifications) if (pLevel != MESSAGE_NOTIFY) return;

//Provide one or more the recipient registered token or instant ID token String tokenDispositivo = Firebase_Read_Token(); if (tokenDispositivo == "") { Serial.println("Token inválido.");
return; }

fbdo.fcm.addDeviceToken(tokenDispositivo);

//Set the notification message data //Serial.println("**Message Send Notify"); String mTit = Product + " " + gDeviceAlias;

fbdo.fcm.setNotifyMessage(mTit, pMsg,"",""); //Serial.println("mTit:" + mTit + " pMsg:" + pMsg);

//Set the custom message data //fbdo.fcm.setDataMessage("{\"myData\":\"myValue\"}");

//Send message to one recipient with inddex 1 (index starts from 0) Firebase.sendMessage(fbdo, 0);

return; }

This is the IDE configuration:

image

mobizt commented 3 years ago

It's impossible to reproduce your issue with the code that include a lot of third party libraries.

Check your free heap because the error involved the out of memory situation.

The new version of this library will reduce memory usage (approx. 5-7k lesser) which allows more space to run for your code.