Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...