-->
Page 1 of 1

Firebase Cloud Function Post Request From ESP8266

PostPosted: Tue Jan 12, 2021 10:21 am
by Saifkhan
I am trying to call firebase cloud function from ESP8266, it is working fine from postman but I am getting http response Code -1 in esp. below is the code, can anyone help me to find my mistake. Thanks

Code: Select allvoid loop() {
 
 if(WiFi.status()== WL_CONNECTED){   //Check WiFi connection status
  Serial.println("Still Connected !");
   WiFiClientSecure client;
   HTTPClient http;   
 
   http.begin(client, "https://us-central1-firedetectionapi.cloudfunctions.net/status");  //Specify destination for HTTP request
 
   http.addHeader("Content-Type", "application/json");             //Specify content-type header
 
   int httpResponseCode = http.POST("{\"F\":\"T\"}");   //Send the actual POST request
 
   if(httpResponseCode>0){
 
 
    Serial.println("API Called");   //Print return code
   
 
   }else{
 
    Serial.print("Error on sending POST: ");
    Serial.println(httpResponseCode);
 
   }
 
   http.end();  //Free resources
 
 }else{
 
    Serial.println("Error in WiFi connection");   
 
 }

Re: Firebase Cloud Function Post Request From ESP8266

PostPosted: Tue Jan 12, 2021 11:05 am
by Bonzo
You are trying to connect to a secure server and I assume -1 is a connection refused error. It is not a standard http error code.

Have you a non https server you can try it on?