ESP32 mqtt client ws_read() failure
Posted: Fri Sep 25, 2020 2:57 pm
ws_read_payload() is failing on:
Adding some diagnostics:
Yields:
The background is that I have created an MQTT QoS0 server. The server is attached to my HTTP server (port 80) on uri /mqtt.
I have tested the server with HiveMq and the HiveMq browser client seems quite happy, can connect, subscribe, receieves subscriptions and may publish.
The MQTT server is cross platform and protocol agnostic. The transmit function ends up as (because sometime the server must send disconnect outside the context of an incomming packet).
I have now added the ESP32 MQTT client to the application. The client PUBLISHes to the MQTT server and so feeds a number of local web application stations. PUBLISH works fine. I have connected multiple HiveMq browsers the browsers SUBSCRIBE and receives the ESP32 MQTT client's data.
The ESP32 application must accept web application commands and so SUBSCRIBEs to server topics using an ESP32 MQTT client.
The SUBSCRIPTION generates the above error.
It is interresting that during the CONNECT process the ws_read_payload() timeout is reported as '1000' but is '0' during SUBSCRIBE (i.e. differences between grabbing CONACK and SUBACK).
It is also interesting that the MQTT server works well on its own. The ESP32 MQTT client is failing. Could this be because of the combination of websocket server (used in MQTT server) and websocket client?
Any suggestion for logging etc. I have tried with IDF MASTER and same result.
Code: Select all
if (bytes_to_read != 0 && (rlen = esp_transport_read(ws->parent, buffer, bytes_to_read, timeout_ms)) <= 0)
Code: Select all
static int ws_read_payload(esp_transport_handle_t t, char *buffer, int len, int timeout_ms)
{
transport_ws_t *ws = esp_transport_get_context_data(t);
int bytes_to_read;
int rlen = 0;
ESP_LOGI(TAG, "%p: ws_read_payload: len: %d, bytes_remaining: %d, timeout: %d", t, len, ws->frame_state.bytes_remaining, timeout_ms);
if (ws->frame_state.bytes_remaining > len) {
ESP_LOGD(TAG, "Actual data to receive (%d) are longer than ws buffer (%d)", ws->frame_state.bytes_remaining, len);
bytes_to_read = len;
} else {
bytes_to_read = ws->frame_state.bytes_remaining;
}
// Receive and process payload
if (bytes_to_read != 0 && (rlen = esp_transport_read(ws->parent, buffer, bytes_to_read, timeout_ms)) <= 0) {
ESP_LOGE(TAG, "(1) Error read data: bytes:%d, rlen %d", bytes_to_read, rlen);
ESP_LOGI(TAG, "ws_read_payload() end");
return rlen;
}
Code: Select all
I (29692) TRANSPORT_WS: 0x3ffc2d08: ws_read_payload: len: 1, bytes_remaining: 5, timeout: 0
E (29702) TRANSPORT_WS: (1) Error read data: bytes:1, rlen 0
I have tested the server with HiveMq and the HiveMq browser client seems quite happy, can connect, subscribe, receieves subscriptions and may publish.
The MQTT server is cross platform and protocol agnostic. The transmit function ends up as
Code: Select all
httpd_ws_send_frame_async()
I have now added the ESP32 MQTT client to the application. The client PUBLISHes to the MQTT server and so feeds a number of local web application stations. PUBLISH works fine. I have connected multiple HiveMq browsers the browsers SUBSCRIBE and receives the ESP32 MQTT client's data.
The ESP32 application must accept web application commands and so SUBSCRIBEs to server topics using an ESP32 MQTT client.
The SUBSCRIPTION generates the above error.
It is interresting that during the CONNECT process the ws_read_payload() timeout is reported as '1000' but is '0' during SUBSCRIBE (i.e. differences between grabbing CONACK and SUBACK).
It is also interesting that the MQTT server works well on its own. The ESP32 MQTT client is failing. Could this be because of the combination of websocket server (used in MQTT server) and websocket client?
Any suggestion for logging etc. I have tried with IDF MASTER and same result.