Firebase .getInt() fails after Internet is reconnected - ESP8266 #22996
-
Hi. I’m working on a project where I need to read data from my Firebase database frequently. I use a NodeMCU (ESP8266-12) to connect to a WiFi network and read data from the Firebase. If the Internet is available initially, everything works perfect. I get proper data from Firebase. But if I disconnect the Internet (NOT WiFi), and reconnect it again, then Firebase.getInt() would still return 0, and not the value stored in my database. I checked Firebase.success() function and it also returns 0 after Internet is reconnected. But the odd thing is, Firebase.setInt() works. ie, data is written into Firebase properly even after reconnection. This is the code: #include <ESP8266WiFi.h> // Set these to run example. void setup() { Serial.begin(9600); // connect to wifi. Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); } void loop() { Serial.println(Firebase.getInt(“manual”)); |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
I wouldn’t know why this happens, but why don’t you just reconnect to the WiFi network after you’ve detected the internet is lost (= just calling setup() again)? PS: Next time could you please put your code in a code block? Using the </> icon in the toolbar? |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply. I was thinking the same thing too, but in a different way. I thought about using an ESP.restart() once internet is reconnected. I tried it a couple of hours ago and looks like it worked. Restarting the whole system seemed to have fixed the issue. But still it’s weird that it fails to read from firebase even when internet is connected. By the way, is there any way I could send an unsigned long data to firebase using Arduino library functions (Like Firebase.setInt()… I couldn’t find one for “long” ) ? |
Beta Was this translation helpful? Give feedback.
-
For the first part, glad it worked fine! For the second part of your new question: I really don’t know enough about Firebase to really comment on that, but a quick Google search turned up this: https://stackoverflow.com/questions/31930406/storing-long-type-in-firebase - it might be of use. Otherwise I would recommend asking a new question on this forum, both so everything stays organized but also to make sure your new question gets the attention it deservers (because this one is already marked as solved, not many people will look at it anymore). |
Beta Was this translation helpful? Give feedback.
-
I have the same problem. Also, sometime I’ve got Firebase .getInt() failed when power on. So I use ESP.restart() everytime when an Firebase.failed() I don’t know why this happens but this trick works for me |
Beta Was this translation helpful? Give feedback.
-
you can use ArduinoJson and embedd the long var inside json object https://arduinojson.org/v5/example/ |
Beta Was this translation helpful? Give feedback.
-
In my case, fix Firebase.cpp AND fix FirebaseArduino.cpp of firebasearduino libs and worked perfectly
To:
To:
You can change all get function to: return -1 for your code |
Beta Was this translation helpful? Give feedback.
-
No need to reconnect the device to wifi. Just try to add some value to the firebase before checking the connection. This line will helps you. void loop() { Firebase.setInt(“a”,0); if(Firebase.failed()) { … } |
Beta Was this translation helpful? Give feedback.
I wouldn’t know why this happens, but why don’t you just reconnect to the WiFi network after you’ve detected the internet is lost (= just calling setup() again)?
PS: Next time could you please put your code in a code block? Using the </> icon in the toolbar?