WiFiSpi icon indicating copy to clipboard operation
WiFiSpi copied to clipboard

Not able to connect secure server

Open codev123 opened this issue 7 months ago • 1 comments

thank you sir for amazing work. I am using your library to send data to my https secure server, using POST method but it can not connect to https server.

Serial.println("Send weight to server :" + String(finalWeight));
  Serial.print("Starting connection to server...");
  Serial.println(centralServer);
  // if you get a connection, report back via serial:
  if (secureClient.connectSSL(centralServer, centralServerPort)) {
    Serial.println("connected to server");
    // Prepare the POST request
    String path = "/api/iotdata.php";
    String postData = "{\"device\":" + String(deviceID) + ",\"weight\":" + String(finalWeight, 2) + ",\"timestamp\":\"" + currentDateTime + "\"}";
    //final https request
    String request = String("POST ") + path + " HTTP/1.1\r\n" + "Host: " + String(centralServer) + "\r\n" + "User-Agent: Arduino/1.0\r\n" + "Connection: keep-alive\r\n" + "Content-Type: application/json\r\n" + "Content-Length: " + postData.length() + "\r\n" + "\r\n" + postData;
    //Serial.print("Http post request :");
    //Serial.println(request);
    // Convert String to char array
    char charRequest[request.length() + 1];
    request.toCharArray(charRequest, request.length() + 1);
    // Send the request
    secureClient.write(charRequest);
  }

while when i simply use

if (secureClient.connect(centralServer, centralServerPort)) {
    Serial.println("connected to server"); }

i am able to connect to server and send data to serevr. i an supply correct fingerprint and setting fingerprint too using WiFiSpi.setSSLFingerprint(fingerprint); please help me resolve this issue.

codev123 avatar Jul 20 '24 09:07 codev123