SSL error on subsequent connections
Posted: Tue Nov 10, 2020 8:00 pm
I have an Olimex ESP32-EVB board with several sensors talking to a webserver.
The first time through, the board sends the data fine:
However, with the second and subsequent connections, I see an SSL error pop up ... [E][ssl_client.cpp:33] _handle_error(): [data_to_read():270]: (-80) UNKNOWN ERROR CODE (0050)
Note that the subsequent connections do have the SSL error, but are successful with a 200 result code.
Beyond the httpClient.end() and client.stop(), what else should I use to fully close this connection and reset the SSL?
Any pointers would be appreciated. I don't want to ignore this if I can fix it.
The first time through, the board sends the data fine:
connecting to 172.16.0.172 - connected to: https://172.16.0.172/api/device/update
{"device_uuid":"692cc64f-c824-4d11-9252-b824f2dd18c4","last_mac":"BC:DD:C2:F1:72:F8","last_ip":"172.16.0.181","inputs":{"1":{"input_uuid":"5253c650-8b99-48f2-8bea-e581aa40fdac","value":2355,"unit":"C","scalefactor":100},"2":{"input_uuid":"9b754ac7-c5b0-4d2c-977c-7635ae7fa978","value":1950,"unit":"%","scalefactor":100},"3":{"input_uuid":"c96efdc5-9aee-406b-b755-140a87611442","value":85227,"unit":"hPa","scalefactor":1},"4":{"input_uuid":"9feefc89-9800-4c88-9524-a533810e0485","value":0,"unit":"oz","scalefactor":1}}}
HTTP Response code: (200)
closing connection
However, with the second and subsequent connections, I see an SSL error pop up ... [E][ssl_client.cpp:33] _handle_error(): [data_to_read():270]: (-80) UNKNOWN ERROR CODE (0050)
My guess is that I'm not closing a connection somewhere in my code:connecting to 172.16.0.172 - connected to: https://172.16.0.172/api/device/update
[E][ssl_client.cpp:33] _handle_error(): [data_to_read():270]: (-80) UNKNOWN ERROR CODE (0050)
{"device_uuid":"692cc64f-c824-4d11-9252-b824f2dd18c4","last_mac":"BC:DD:C2:F1:72:F8","last_ip":"172.16.0.181","inputs":{"1":{"input_uuid":"5253c650-8b99-48f2-8bea-e581aa40fdac","value":2352,"unit":"C","scalefactor":100},"2":{"input_uuid":"9b754ac7-c5b0-4d2c-977c-7635ae7fa978","value":1942,"unit":"%","scalefactor":100},"3":{"input_uuid":"c96efdc5-9aee-406b-b755-140a87611442","value":85226,"unit":"hPa","scalefactor":1},"4":{"input_uuid":"9feefc89-9800-4c88-9524-a533810e0485","value":0,"unit":"oz","scalefactor":1}}}
HTTP Response code: (200)
closing connection
Code: Select all
void updateServer()
{
Serial.print("\nconnecting to ");
Serial.print(SERVER_HOST);
WiFiClient client;
if (!client.connect(SERVER_HOST, SERVER_PORT)) {
Serial.println(" - connection failed");
return;
}
Serial.println(" - connected to: " + SERVER_URL);
// set http timeout after connected - default is 5 seconds, increase to 30
httpClient.setTimeout(30 * 1000);
// Domain name with URL path or IP address with FULL path
httpClient.begin(SERVER_URL);
// Specify content-type header
httpClient.addHeader("X-API-AUTH", String(api_token));
// HTTP request with a content type: application/json
httpClient.addHeader("Content-Type", "application/json");
// build the JSON object - NOTE: make sure to delimit all internal double-quotes
String json = "{"
"\"device_uuid\":\"" + String(device_uuid) + "\","
"\"last_mac\":\"" + String(ethMacAddress) + "\","
"\"last_ip\":\"" + String(ethIpAddress) + "\","
"\"inputs\":{"
"\"1\":{"
"\"input_uuid\":\"" + String(input_1_uuid) + "\","
"\"value\":" + input_1_data + ","
"\"unit\":\"" + String(input_1_unit) + "\","
"\"scalefactor\":" + input_1_sf +
"},"
"\"2\":{"
"\"input_uuid\":\"" + String(input_2_uuid) + "\","
"\"value\":" + input_2_data + ","
"\"unit\":\"" + String(input_2_unit) + "\","
"\"scalefactor\":" + input_2_sf +
"},"
"\"3\":{"
"\"input_uuid\":\"" + String(input_3_uuid) + "\","
"\"value\":" + input_3_data + ","
"\"unit\":\"" + String(input_3_unit) + "\","
"\"scalefactor\":" + input_3_sf +
"},"
"\"4\":{"
"\"input_uuid\":\"" + String(input_4_uuid) + "\","
"\"value\":" + input_4_data + ","
"\"unit\":\"" + String(input_4_unit) + "\","
"\"scalefactor\":" + input_4_sf +
"}"
"}"
"}";
Serial.println(json);
int httpResponseCode = httpClient.POST(json);
Serial.print("HTTP Response code: (");
Serial.print(httpResponseCode);
Serial.print(") ");
Serial.println(httpClient.errorToString(httpResponseCode));
// Free resources
httpClient.end();
client.stop();
Serial.println("closing connection\n");
}
Note that the subsequent connections do have the SSL error, but are successful with a 200 result code.
Beyond the httpClient.end() and client.stop(), what else should I use to fully close this connection and reset the SSL?
Any pointers would be appreciated. I don't want to ignore this if I can fix it.