Hi,
I am using the tutorial code on a NodeMCU ESP8266 12F to listen for changes on the RTDB and update GPIO pins. I find that after a few hours the user authority is revoked and updates are no longer picked up by the call back function.
I have set up a counter to indicate 1min intervals and below is a typical serial output showing the auth_revoked event. Immediately before this, we see the hourly token refresh being recorded.
Counter: 236
Token info: type = id token, status = on refreshing
Token info: type = id token, status = ready
Counter: 237
stream path, /Tablet1/Line/
event path, /12
data type,
event type, auth_revoked
Received stream payload size: 57 (Max. 68)
Database change!
Counter: 238
Counter: 239
Does anyone have any ideas on what is going one here and even better, how to prevent it so that the callback function continues to operate?
Regards,
Peter
Hi Peter.
Tell me what’s the exact example you’re trying to run, the library you’re using and the version.
Did you change something on the code?
Regards,
Sara
Hi Sara,
which libraries are you asking about? The Arduino core or the PlatformIO extensions?
Regards,
Peter
Hi Sara, I’m using mobizt/Firebase Arduino Client Library for ESP8266 and ESP32@4.0.0 – do you think I should revert back to an earlier release? Surely later releases are backwards compatible with earlier ones or are there breaking changes that we should be aware of?
Regards,
Peter
Hi Peter.
I’m sorry for taking so long to get back to you.
To be honest, I’m not sure… You can try using an earlier version to check if it solves the problem.
I need to test our projects with the new version of the library and check if there’s something we need to change.
I’ll try to do that this next week.
Regards,
Sara
Thanks Sarah,
I’m re-posting my comments from the Project “Firebase: Control NodeMCU GPIO Pins from Anywhere” page so that they are seen by the wider community. Hopefully you can find out why the re-issue of the Firebase token every hour causes the NodeMCU to crash.
“Hi Sara,
From monitoring on the serial port, it seems that every 57 or 58 minutes the Firebase token is reissued/ refreshed and this causes the ESP8266 to crash and reboot due to ‘OOM’ error (Out of Memory)? Does the refreshed token or the updated database stream contain so much data that it uses up all the available RAM when trying to process it? This is the error report that I get on the serial port.
PATH: /********/Battery
PATH: /********Runtime
12v DC Supply Volts = 1.69
Minutes run = 57
FAILED
REASON: send request failed
PATH: /********/Runtime
12v DC Supply Volts = 1.78
Minutes run = 58
Token info: type = id token, status = on refreshing
User exception (panic/abort/assert)
————— CUT HERE FOR EXCEPTION DECODER —————
Unhandled C++ exception: OOM
stack>>>
Contents
<<<stack<<<
last failed alloc call: 40232473(1496)
————— CUT HERE FOR EXCEPTION DECODER —————
last failed alloc caller: 0x40232473
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v000cd4e0
~ld
Connecting to WiFi ..
….Connected to Wi-Fi sucessfully.
I also noticed this comment on the instructions for the ESP Firebase Library
// 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
I wondered if this is perhaps causing the out of memory restarts? You have set this value at 4096 but perhaps it needs to be adjusted?
Hope this might be of some interest/value to you.”
Perhaps an update to the TokenHelper.h library is required to overcome this issue?
Peter
Hi Sarah,
Also re-posted from the Projects page….
Thinking more about this, initially I was only using the streamCallback function to listen with the FirebaseData stream object and that’s when I was being disconnected every few hours. When I added in the writing function to my code, using the FirebaseData fbdo object, that’s when the NodeMCU started crashing every hour, so I think this is also perhaps significant for this issue.
Peter
Hi Sarah,
Using a NodeMCU Lua Lolin V3 board, with ESP8266MOD 12-F chip, from AZ-Delivery.
NodeMCU Lua Lolin V3 Module ESP8266 ESP-12F WIFI Wifi Development Board mit CH340
Peter
I was referring to the ESP8266 installation. Tools > Boards > Boards Manager > ESP8266.
Hi Sara,
I’m using VS Studio Code, so its as follows:
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
lib_deps =
me-no-dev/ESPAsyncTCP@^1.2.2
ayushsharma82/AsyncElegantOTA@^2.2.7
me-no-dev/ESP Async WebServer@^1.2.3
mobizt/Firebase Arduino Client Library for ESP8266 and ESP32@4.0.0
monitor_speed = 115200
(I’ve installed the ElegantOTA libraries also for convenience).
Try using ESP8266 boards version 3.0.1
platform = espressif8266@3.0.1
Let me know if this changes anything.
Regards,
Sara
Hi Sarah, I don’t see that option on VS Code Platform for Expressif 8266 – only 3.0.0. and 3.1.0? If I try 3.0.1 it is not found.
Platform Manager: Installing espressif8266 @ 3.0.1
Error: Could not find the package with ‘espressif8266 @ 3.0.1’ requirements for your system ‘windows_amd64’
Peter
Hi Sara, for what it’s worth, these are the various references to ESP8266 Platforms / Frameworks / Libraries that are logged when the VS Code builder operates. I’m confused as they all have different version numbers, so not sure which one you are suggesting that I should use.
CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/nodemcuv2.html
PLATFORM: Espressif 8266 (4.0.1) > NodeMCU 1.0 (ESP-12E Module)
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES:
– framework-arduinoespressif8266 @ 3.30002.0 (3.0.2)
– tool-esptool @ 1.413.0 (4.13)
– tool-esptoolpy @ 1.30000.201119 (3.0.0)
– toolchain-xtensa @ 2.100300.210717 (10.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 40 compatible libraries
Scanning dependencies…
Dependency Graph
|– ESPAsyncTCP @ 1.2.2
|– AsyncElegantOTA @ 2.2.7
| |– ESP8266WiFi @ 1.0
| |– ESPAsyncTCP @ 1.2.2
| |– ESP Async WebServer @ 1.2.3
| | |– ESPAsyncTCP @ 1.2.2
| | |– Hash @ 1.0
| | |– ESP8266WiFi @ 1.0
|– ESP Async WebServer @ 1.2.3
| |– ESPAsyncTCP @ 1.2.2
| |– Hash @ 1.0
| |– ESP8266WiFi @ 1.0
|– Firebase Arduino Client Library for ESP8266 and ESP32 @ 4.0.0
| |– SD @ 2.0.0
| | |– SDFS @ 0.1.0
| | | |– ESP8266SdFat @ 2.0.2
| | | | |– SPI @ 1.0
| | | |– SPI @ 1.0
| |– ESP8266SdFat @ 2.0.2
| | |– SPI @ 1.0
| |– SPI @ 1.0
| |– ESP8266WiFi @ 1.0
| |– lwIP_enc28j60 @ 1
| | |– SPI @ 1.0
| |– lwIP_w5500 @ 1
| | |– SPI @ 1.0
| |– lwIP_w5500 @ 1
| | |– SPI @ 1.0
|– ESP8266WiFi @ 1.0
Peter
Hi.
I’m sorry for taking so long to get back to you.
I was trying to understand what was going on.
Your library versions seem fine.
At first, I thought you needed to add something like this in the loop():
if firebase.ready()
return
But after testing, nothing changed.
This issue didn’t happen in another project I’ve built on the Firebase ebook that listens for changes at the same time that it publishes data. So, I’ve added some code to publish a random number while listening for database changes.
But, that didn’t solve the issue.
I’m not sure why this happens. A workaround is to reset the ESP8266 after a defined period of time. But, it’s just a workaround, not the solution.
Have you found something?
Have you tried with an ESP32 board?
Regards,
Sara
Hi Sara, my turn to apologise for late response!
I have tried to monitor the memory useage on the NodeMCU ESP8266 board using ESP.getFreeHeap() and this does confirm that when both listening and writing to Firebase the memory useage is increased quite a bit. I also installed an ESP Stack Exception monitor in the Platformio.ini Config file, using monitor_filters = esp8266_exception_decoder, and whilst this does decode the stack exception contents in the monitor window, the output means nothing to me!, so I don’t know which program line is causing the ESP8266 to crash when the token is refreshed. Could you take a look at the stack exception analysis?
In the meantime, I have used the ESP soft reset, ESP.reset() to reset the board every 58 minutes, before the token refresh from Firebase occurs. This workaround seems to prevent the ESP crashing.
I have also tried to compile the code onto an ESP32, but came up against the compile error that others have reported here. This was solved by changing the platformio.ini platform entry to platform = espressif32@3.5.0. However, I now get another compile error message stating not enough memory on the ESP32, which I don’t understand. The ESP32 has more memory than the ESP8266, so maybe I have something wrong in my Platformio project configuration?
Any further thoughts would be most welcome.
Peter
Hi.
One of our readers suggested the following to refresh the token:
”
Hi, I solved this problem by putting this code in loop, I think maybe there’s a better solution but that works for now, it is because the tokan is expired and nothing is called after than to refresh it
if(Firebase.isTokenExpired())
Firebase.refreshToken(&FirebaseConfigObj);
”
As for the ESP32 issue, there must be something wrong with your board or configurations. I never had a memory problem with those examples…
Try to “format” your ESP32. Search for “ESP32 erase flash”. You can also take a look at this discussion to see how to erase flash: https://rntlab.com/question/how-perform-reset-factory-esp32/
Regards,
Sara
Hi Sara,
I tried the workaround posted above, but this error message from the compiler in VS Code: error: ‘class Firebase_ESP_Client’ has no member named ‘refreshToken’. Any thoughts about this – do I need a different Firebase Library?
Regards,
Peter
Make sure you update the library to the latest version.
Version 4.1.0.
It may also be useful to check out this example: https://github.com/mobizt/Firebase-ESP-Client/blob/00d3f1d9cc643a37ed5cb98cf8ed9bd55903c3aa/examples/Authentications/SignInWithRefreshIDToken/SignInWithRefreshIDToken.ino
Regards,
Sara
Hi Sara,
Thanks – updated to library version 4.1.0 and all good. The hourly ESP8266 crashes are now avoided by this workaround.
Regards,
Peter
Great!
So, everything is working fine now?
I think I’ll add those lines to the project to avoid issues related to the token.
Regards,
Sara
Everything is working fine – for now! If you are going to use the code in your projects, I think it would be:
if(Firebase.isTokenExpired())
Firebase.refreshToken(&config);