-
I am trying to on and off a led connected with Arduino using firebase and voiceflow. I am giving a http post request in voiceflow to change the data like This command is successfully running and updated the value of the firebase rt database but data is not received by the Arduino (firebase library) I think the issue is related to the api ,Can you please tell the reason for the same ,I tried using get function and stream to get the data from firebase but its not getting the data changed using http post/put/patch request. Is there any alternative to do the same? Should getJson function be a good idea to fix this ?? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
You should use Discussions for question. Make sure you update the library to latest version. You must spend more time to try and making understand the Firebase RTDB REST API when you're going to use it. I can't help because you did not follow the issue template and post the part of your code that you have tried. |
Beta Was this translation helpful? Give feedback.
-
The examples provide enough use cases that you can test. The debug information from fbdo.errorReason will tell you the error which you should always use it during test. |
Beta Was this translation helpful? Give feedback.
-
I tried using fbdo.errorReason to know whats the reason. CODE: #include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>
#include "FirebaseESP8266.h"
#include <ESP8266WiFi.h>
#define FIREBASE_HOST "x-x-x-"
#define FIREBASE_AUTH "x-x-x"
#define WIFI_SSID "x-x-"
#define WIFI_PASSWORD "xx-x-"
IRrecv irrec(4);
decode_results results;
FirebaseData firebaseData;
bool bstate1;
void setup()
{
irrec.enableIRIn();
//pin modes
pinMode(5,OUTPUT);
//IR sensor
pinMode(4,INPUT);
//serial monitor config
Serial.begin(115200);
//Wifi config
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
//Firebase config
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.setInt(firebaseData,"/Devices/Nodemcu 1",0);
//buttons state
bstate1=false;
Firebase.reconnectWiFi(true);
}
void loop()
{
if(Firebase.getInt(firebaseData,"/Devices/Nodemcu 1/status"))
{
if(firebaseData.intData()==1 && bstate1==false)
{
Serial.printf("Led is On\n");
digitalWrite(5,HIGH);
bstate1=true;
}
else if(firebaseData.intData()==0 && bstate1==true)
{
Serial.printf("Led is Off\n");
digitalWrite(5,LOW);
bstate1==false;
}
}
else
Serial.printf(firebaseData.errorReason().c_str());
Serial.printf("\n");
IRcodeSensor();
}
void IRcodeSensor()
{
if (irrec.decode(&results)) {
const uint16_t ircode = results.value;
if(ircode==1)
{
if(bstate1==false)
{
bstate1=true;
if(Firebase.setInt(firebaseData,"/Devices/Nodemcu 1/status",1))
Serial.printf("Done\n");
else
firebaseData.errorReason().c_str();
digitalWrite(5,HIGH);
}
else
{
digitalWrite(5,LOW);
if(Firebase.setInt(firebaseData,"/Devices/Nodemcu 1/status",0))
Serial.printf("Done\n");
else
firebaseData.errorReason().c_str();
bstate1=false;
}
}
irrec.resume(); // Receive the next value
}
} OUTPUT:When i first boot up the arduino ,Data mismatch error comes for about 3-4 times and after that it work fine . |
Beta Was this translation helpful? Give feedback.
-
That is inappropriate and inefficient to use library to
You should use stream instead to avoid those issues and more effective. Any of your code for third party sensor lib used in loop can be delayed as it need to wait hardware to be ready. |
Beta Was this translation helpful? Give feedback.
-
I also update the comment in basic examples to warn users to avoid these use cases Firebase-ESP8266/examples/Basic/Basic.ino Lines 151 to 184 in abcf739 |
Beta Was this translation helpful? Give feedback.
-
ok got that what you are saying but in this code i am using function without using a delay or millis but it still working with no lag at all whereas replacing stream with get function introduces delay and type mismatch error.Also Sensor library is not blocking the code this time. IRrecv irrec(4); //IR sensor //serial monitor config //Wifi config //Firebase config } void IRcodeSensor() if(ircode==1) } OUTPUT :No error in recieving data and setting data ,works fine |
Beta Was this translation helpful? Give feedback.
-
Did you understand "close and reopen session" I mentioned and why this happens and the effect of this in SSL connection. Are you sure the IRremote lib does not block? How you prove that. |
Beta Was this translation helpful? Give feedback.
-
Normally the TCP session was kept open (server is always connected or keep alive) for the next request to speed up data transfer, this is how the session was reuse. If the next request has different HTTP method e.g. the previous request is GET (from get function) while the next request is POST request (from push function) which its method is different from the previous one, the TCP session need to be closed (server disconnected) and establish the new connection. Every time secure TCP session was new established, the SSL handshake is need to be performed and it takes time about 1-2 seconds to be done. The above case is for single FirebaseData object which multiple sockets per TCP client instance is not implemented as it is not suitable for limited memory device which works in secure connection which required huge memory for SSL resource for each socket connection. One FirebaseData object per one socket connection at a time. In non-secure connection, multiple sockets connection is possible as it requires less memory. |
Beta Was this translation helpful? Give feedback.
Normally the TCP session was kept open (server is always connected or keep alive) for the next request to speed up data transfer, this is how the session was reuse.
If the next request has different HTTP method e.g. the previous request is GET (from get function) while the next request is POST request (from push function) which its method is different from the previous one, the TCP session need to be closed (server disconnected) and establish the new connection.
Every time secure TCP session was new established, the SSL handshake is need to be performed and it takes time about 1-2 seconds to be done.
The above case is for single FirebaseData object which multiple sockets per TCP client in…