Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

arduino - Firebase Cloud Function Post Request From ESP8266

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

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");   
  
 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The Arduino HTTP client requires a fingerprint/hash of the server's certificate when using the HTTPS protocol.

This can be setup with:

client.setFingerprint("81:dc:88:59:f1:fd:3b:f2:4a:27:c6:ba:39:44:3c:1c:16:4f:9c:ae");
http.begin(client, "https://us-central1-firedetectionapi.cloudfunctions.net/status");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...