mobizt/ESP-Signer

ESP12E keeps throwing exceptions whenever Token needs to be refreshed

AlHasanSameh opened this issue · 9 comments

Hi Mobizt,
now I am using oauth2.0 tokens with google analytics 4 API, it seems that the token never gets refreshed successfully, whenever it expires it keeps throwing -4 error connection lost repeatedly until the ESP crashes, sometimes it's OOM exception this time it's exception 29 which is storeprohibitedcause.

I use the token every 30mins, I relied earlier on the fact that it's refreshed automatically but it gave me errors, then added a call to the refresh token function but still the same problem

Am I not having enough memory for my ESP12E?, does the library require anything I am not aware of ?
my code is attached, Arduino IDE
Board: Node MCU V1.0 ( ESP12E )
Core: latest

Please help asap
Serial monitor output
Code.txt

Library works normally which it was intensively tested long enough over months. This library also used in my other library project without error.

You should debug your code for memory leaks and use ESP exception decoder to decode the stack traces.

For SSL Client usage, you should update your esp8266 core to v3.x.x and set the MMU option in Arduino IDE to gain more heap.

MMU option 3, 16KB cache + 48KB IRAM and 2nd Heap (shared).

The error "connection lost" is about no WiFi connection. Library will check for WiFi status before sending the request to googleapis server to exchange the auth token. When WiFi was disconnected, library will be trying to reconnect the WiFi by calling WiFi.disconnect() and WiFi.reconnect() and do it in the next 10 seconds if WiFi still lost.

No memory involved for the network checking process during refreshing the token because it calls the callback for reporting the status and exit.

Calling WiFi.disconnect() and WiFi.reconnect() in the token refreshing process may cause the wdt reset due to low free heap and system tasks may fail to work.

Then you should find why your device free heap is too low and should make sure that you choose MMU option 3 already.

The error "connection lost" is about no WiFi connection. Library will check for WiFi status before sending the request to googleapis server to exchange the auth token. When WiFi was disconnected, library will be trying to reconnect the WiFi by calling WiFi.disconnect() and WiFi.reconnect() and do it in the next 10 seconds if WiFi still lost.

No memory involved for the network checking process during refreshing the token because it calls the callback for reporting the status and exit.

Calling WiFi.disconnect() and WiFi.reconnect() in the token refreshing process may cause the wdt reset due to low free heap and system tasks may fail to work.

Then you should find why your device free heap is too low and should make sure that you choose MMU option 3 already.

Ok, thanks a lot for your reply
I didn't know I should be choosing MMU option 3, you didn't mention it in the library's main page unlike your Firebase Client library, so if you can add it in there will be a big help
Regarding WiFi connection, what you're saying is basically I don't need to manage that myself as the repeated calling causes the wdt resets, is there an option in the library to disable WiFi management ?

There is no option for WiFi reconnection disable and it has no conflicts with WiFiManager library.

If you want to stop library to work when you want, just ignore or skip to execute Signer.tokenReady().

Changing the MMU option solved it for me, amazing library, please add the instructions to choose the shared option in the main page as you only talk about enabling PSRAM there

It's not about the PSRAM in this case but internal memory which sheared between the stack and heap.

This MMU configuration is available in ESP8266 since core v3.0.x which user should verify the different free heap when updates from v2.x.x to v3.0.x. Did you never check this?

Why this MMU option mentioned in my other Firebase and ESP Google Sheet client libraries documentation and does not mention in this library?

It is because changing MMU option from default to option 3 is not required by the library as it has enough free heap for JWT creation, signing and sending auth token exchanging to googleapis server.

My other libraries involved the SSL and TCP session that may be needed to keep open and large memory reserved all the time then I have to write this MMU option in documentation for ESP8266.

There is no option for WiFi reconnection disable and it has no conflicts with WiFiManager library.

If you want to stop library to work when you want, just ignore or skip to execute Signer.tokenReady().

Awesome, will keep that in mind if I ever need to use this library with my own WiFi Manager library

It's not about the PSRAM in this case but internal memory which sheared between the stack and heap.

This MMU configuration is available in ESP8266 since core v3.0.x which user should verify the different free heap when updates from v2.x.x to v3.0.x. Did you never check this?

Why this MMU option mentioned in my other Firebase and ESP Google Sheet client libraries documentation and does not mention in this library?

It is because changing MMU option from default to option 3 is not required by the library as it has enough free heap for JWT creation, signing and sending auth token exchanging to googleapis server.

My other libraries involved the SSL and TCP session that may be needed to keep open and large memory reserved all the time then I have to write this MMU option in documentation for ESP8266.

Great insights, thanks for sharing, your work came in clutch for me as always I really appreciate those libraries, thanks