0

**我的 esp32 通过 WIFI 连接到互联网。我想通过https向服务器发送一些数据。但随机我得到了http返回码-1。当硬重置 esp32 时,它可以在 200 响应下正常工作。由于这个问题,我面临数据丢失。我不知道原因,我什至找不到任何解决方案。帮我.. **

String DTurl=(String)BASE_URL+"getdevicedatanew";
String playload= "apidata="+code+"/"+PASSWORD+"/"+(String)data;
if(WiFi.status() == WL_CONNECTED)
  {
    HTTPClient http;
    http.begin(DTurl);
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
    http.setTimeout(45000);
    DEBUG_SERIAL.println("Sending data to server: "+ playload);
    int httpCode = http.POST(playload);
    DEBUG_SERIAL.println("httpcode:"+(String)httpCode);
    last_data_sent_time = millis();
    if(httpCode == HTTP_CODE_OK)
    {
      String response = http.getString();
      DEBUG_SERIAL.println("Http response success: "+ response);
      return true;
    }
   
    else
    {
      return false;
    }
    
  }
  else
  {
    return false;
  }
4

0 回答 0