0

I have data on firebase rtdb, which i want to listen in my nodemcu. I know there are libraries available like this one which provides listeners, but i want to do it using REST API streaming as mentioned in firebase documentation for rest api streaming. So far i have successfully tested with curl on cmd as shown

My curl command is:

curl -v https://<name of rtdb>.firebaseio.com/SD0001/Up.json -H "Accept:text/event-stream"

I want to do the same thing on ESP8266 using ESP8266HTTPClient library. The firebase documentation states "Set the client's Accept header to text/event-stream" (which i added in header), "Respect HTTP Redirects, in particular HTTP status code 307" (which i am still struggling).

So far, my code is somewhat like this

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
const uint8_t fingerprint[20] = {<<<<fingerprint of rtdb database>>>>};
HTTPClient https;
std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
void setup()
{
 Serial.begin(115200);
 WiFi.begin("SSID", "PASSWORD");
 while (WiFi.status() != WL_CONNECTED)
 {
 delay(500);
 Serial.print(".");
 }
 Serial.println("");
 Serial.println("WiFi connected");
 Serial.println("IP address: ");
 Serial.println(WiFi.localIP()); // successful Connection of ESP8266,
 client->setFingerprint(fingerprint);
 if (https.begin(*client, "https://<name of rtdb>.firebaseio.com/SD0001/Up.json"))
 {
 https.addHeader("Accept", "text/event-stream", false, true);
 https.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS);
 int httpCode = https.GET();
 Serial.println(httpCode);
 Serial.println(https.getString()); 
 // Serial.println(https.getLocation());
 // Serial.println(https.header("Location"));
 //https.end();
 }
}
void loop()
{
 // Serial.println(https.getStream());
 // Serial.println(https.getString());
 // Serial.println(https.getLocation());
 // delay(1000);
}

My code GETs the respone with 200 code, but there is no "Location" to redirect in the response header (at least i can't find any). Should i do http GET in the loop everytime? If so, where will i get my redirection url? It would be really helpful if any solution is provided or any documentation to guide me in the right way.

Edit: I have put the text versions of curl command and the code in the post alongwith the screenshots. This is my first post here, so please bear with me.

asked Jul 15, 2022 at 3:14
2
  • 1
    please remove the screenshot of the code and replace it with the code text ... do the same with the first screenshot also Commented Jul 15, 2022 at 3:26
  • 1
    @jsotola i have put the actual code in text form. Please look into it. any help is appreciated as i am completely at sea here Commented Jul 16, 2022 at 1:52

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.