I am using an ESP32 to capture some data and then sending it over using ArduinoJson. However, sometimes, the firmware gets stuck at the line where it is transmitting data at obj.printTo(client). I have the logs for the same. Do you have any idea as to what might be making it freeze? And any way to avoid it in the future.
Logs:
12:28:00.584 -> [V][ssl_client.cpp:276] send_ssl_data(): Writing HTTP request...
12:28:00.584 -> [V][ssl_client.cpp:276] send_ssl_data(): Writing HTTP request...
12:47:11.229 -> [E][ssl_client.cpp:33] handle_error(): UNKNOWN ERROR CODE (004E) 12:47:11.229 -> [E][ssl_client.cpp:35] handle_error(): MbedTLS message code:-78
12:47:11.229 -> [V][ssl_client.cpp:245] stop_ssl_socket(): Cleaning SSL connection.
12:47:11.229 -> request sent
12:47:12.217 -> esp32/Arduino CI has failed
12:47:12.217 -> reply was:
12:47:12.217-> ==========
12:47:12.217 ->
12:47:12.217 -> ==========
12:47:12.217 -> closing connection
The send code:
jsonBuffer.clear();
JsonObject &rootObject = jsonBuffer.createObject();
JsonObject &dataObject = rootObject.createNestedObject("data");
JsonArray &X1dataObject = dataObject.createNestedArray("X1");
JsonArray &Y1dataObject = dataObject.createNestedArray("Y1");
JsonArray &Z1dataObject = dataObject.createNestedArray("Z1");
JsonArray &T1dataObject = dataObject.createNestedArray("T1");
vTaskDelay(10);
if (send_flag) {
digitalWrite(2,0);
send_flag = false;
int connection_iterator = 0;
int connection_iterator2 = 0;
for (int iterator = 0; iterator < SAMPLE_SIZE; iterator++) {
X1dataObject.add(X1dataArray[iterator]);
Y1dataObject.add(Y1dataArray[iterator]);
Z1dataObject.add(Z1dataArray[iterator]);
}
T1dataObject.add((float)(analogRead(NTC)*0.0244));
rootObject["coreid"] = String(low, HEX) + String(high, HEX);
//rootObject["coreid_high"] = String(high, HEX);
rootObject["sample_time"] = int(time_taken);
rootObject["firmware_version"] = FIRMWARE_UPDATE_VERSION;
rootObject.prettyPrintTo(Serial);
Serial.print("connecting to ");
Serial.println(host);
while ((!client.connect(host, httpsPort)) && !setup_mode) {
connection_iterator++;
Serial.println("connection failed! Retrying..");
delay(5000);
if (connection_iterator >= 10)
ESP.restart();
}
if (client.verify(fingerprint, host)) {
Serial.println("certificate matches");
} else {
Serial.println("certificate doesn't match");
}
digitalWrite(LED_BUILTIN, HIGH);
Serial.print("requesting URL: ");
Serial.println(url);
client.println(String("POST ") + url + " HTTP/1.0");
client.println(String("Host: ") + host);
client.println("Cache-Control: no-cache");
client.println("Content-Type: application/json");
client.print("Content-Length: ");
client.println(rootObject.measureLength());
client.println();
rootObject.printTo(client);
Serial.println("NUMBER OF INTERRUPTS:");
Serial.println(interruptCounter);
Serial.println("request sent");
while ((client.connected()) && !setup_mode) {
connection_iterator2++;
String line = client.readStringUntil('\n');
if (line == "\r") {
Serial.println("headers received");
break;
}
Serial.println("Waiting for response");
delay(500);
if (connection_iterator2 >= 40)
break;
}
String line = client.readStringUntil('\n');
if (line.startsWith("{")) {
Serial.println("esp32/Arduino CI successfull!");
} else {
Serial.println("esp32/Arduino CI has failed");
}
Serial.println("reply was:");
Serial.println("==========");
Serial.println(line);
Serial.println("==========");
Serial.println("closing connection");
digitalWrite(LED_BUILTIN, LOW);
// readRegister(INT_SOURCE, 1, &dummy_read);
}