I set up an ESP32 Webserver based on the example "restful server" of the ESP32-IDF. I also created a small webpage that sends a get request every 1 seconds to get some sensordata. Everything is working fine, however after some time (I think after 40 to 50 minutes) I get some error massages and the server or wifi crashes.
I added the debug in the attachments.
It seems like, that the connections or the sockets are not closed in a correct way.
Does anyone have an idea, what this cause
s the troubles?
Thank you for you help.
Best regards
Lukas
That is the setup for httpd_uri_t:
Code: Select all
httpd_uri_t sensorvalue_get = {
.uri = "/sensorX",
.method = HTTP_GET,
.handler = sensorvalue_json_handler, // sensorvalue_handler,
.user_ctx = NULL};
Code: Select all
esp_err_t sensorvalue_json_handler(httpd_req_t *req)
{
// ESP_LOGI(TAG, "sensorvalue_json_handler");
httpd_resp_set_type(req, "application/json");
char json_string[300];
create_json_from_sensordata(json_string, sensors.sensor1, sensors.sensor2, sensors.sensor3, sensors.timestamp);
// ESP_LOGI(TAG, "%s", json_string);
// httpd_resp_send(req, json_string, HTTPD_RESP_USE_STRLEN);
httpd_resp_sendstr(req, json_string);
httpd_resp_sendstr(req, NULL);
return ESP_OK;
}
Code: Select all
setInterval(function () {
var xhttp = new XMLHttpRequest();
console.log("still running");
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
//nums = this.responseText.split('+');
obj = JSON.parse(this.responseText);
document.getElementById('s1').innerHTML = obj.sensor1;
document.getElementById('s2').innerHTML = obj.sensor2;
document.getElementById('s3').innerHTML = obj.sensor3;
}
};
console.log("send get");
xhttp.open("GET", "/sensorX", true);
xhttp.send();
}, 1000);