Firebase Cloud Function Post Request From ESP8266
Posted: Tue Jan 12, 2021 10:21 am
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 all
void 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");
}