I'm struggling with this since 2 days and I don't find what is wrong. I'm making an example with an epaper touch and LVGL (I'm making a PR to add parallel epaper drivers using EPDiy as a component soon)
This is the code and the lines that connect to the mesh light are here:
https://github.com/martinberlin/lv_port ... ht.cpp#L89
Note: Is the right IP, tested with Postman sending a post to the root light, and following JSON:
{
"request": "set_status",
"characteristics": [
{"cid": 1,
"value": 277
}
]}
And is all good it changes the cid:1 that is the HUE and everything works.
Now when I do the request from the ESP32 I get the following:
I (11654) epaper: EVENT_ON_CONNECTED
I (11674) epaper: HEADER_SENT
E (11684) TRANSPORT_BASE: ssl_poll_write select error 104, errno = Connection reset by peer, fd = 54
W (11684) TRANSPORT_BASE: Poll timeout or error, errno=Connection already in progress, fd=54, timeout_ms=500
E (11694) epaper:
POST failed:ESP_FAIL
It connects, sends the Headers, but get's cut somehow by the lamp without ending the request. Is like if the Mesh light does not like something in the request. I've seen it change colors only 2 times, then it hangs, could not repeat it.
When it does work I see this:
I (13644) epaper: EVENT_ON_CONNECTED
I (13654) epaper: HEADER_SENT
I (13744) epaper: ON_HEADER
I (13744) epaper: ON_HEADER
I (13744) epaper: ON_HEADER
I (13754) epaper: ON_DATA, len=39
{"status_msg":"MDF_OK","status_code":0}
I (13754) epaper: ON_FINISH
Any ideas what I'm doing wrong here?
Relevant part of the code to do the HTTP request:#
Code: Select all
esp_err_t light_request(uint8_t cid, uint16_t value) {
char json_request[100];
esp_http_client_config_t config = {
.url = MESH_LAMP_REQUEST_URL,
.method = HTTP_METHOD_POST,
.timeout_ms = 500,
.event_handler = _http_event_handler,
.buffer_size = HTTP_RECEIVE_BUFFER_SIZE
};
esp_http_client_handle_t client = esp_http_client_init(&config);
// Build POST
sprintf(json_request, "{\"request\":\"set_status\",\"characteristics\":[{\"cid\":%d,\"value\":%d}]}",
cid, value);
esp_http_client_set_header(client, "Mesh-Node-Mac", "3c71bf9d6980");
esp_http_client_set_header(client, "Content-Type", "application/json");
esp_http_client_set_post_field(client, json_request, strlen(json_request));
esp_err_t err = esp_http_client_perform(client);
if (err == ESP_OK) {
// Disable after debugging
ESP_LOGI(TAG, "Status=%d, content_length=%d",
esp_http_client_get_status_code(client),
esp_http_client_get_content_length(client));
}else{
ESP_LOGE(TAG, "\nPOST failed:%s", esp_err_to_name(err));
}
return err;
}
Code: Select all
http.begin("http://192.168.0.75/device_request");
http.addHeader("Content-Type", "application/json");
http.addHeader("Mesh-Node-Mac", "3c71bf9d6ab4,3c71bf9d6980");
String json = "{\"request\": \"set_status\",\"characteristics\": [{\"cid\": 1,\"value\": "+String(signalLevel)+"}]}";
int httpResponseCode = http.POST(json);'