Closed wjdready closed 3 years ago
Thanks for reporting, we will look into.
Mqtt broker is a Vert.x MQTT implemented in Java.
@wjdready Could you please share the debug log from your board and possibly some log from the server side, as well? And possibly also a wireshark capture of the disconnection event, which is happening every 10 minutes?
I've tested your code (on v4.2
-- c40f2590bf759ff60ef122afa79b4ec04e7633d2) with vertx-mqtt
broker running on my PC and seen no disconnections.
@wjdready Thanks for reporting, would you please help share if any updates for the issue? Thanks.
@Alvin1Zhang It has been solved. It is my own vertx-mqtt problem. Vertx-mqtt disconnects the device without heartbeat. It's ok after I join the heartbeat. Thank you for your answers.
@wjdready Thanks for sharing updates.
Hi I'm having same issue with ESP32 but in my case device always disconnects on time after 10 seconds of connecting to the Mqtt server, then reconnects within seconds, and then disconnects after 10 seconds of reconnection. I'm using nodeMCU (https://nodemcu.readthedocs.io/en/dev-esp32/modules/mqtt/). I can't identify issue myself(whether it is related to server or device) Here my code..
local client_id,user_id,password,host_id,port="House1","temp1","temp2","198.xx.xx.xxx",18xx topics={"iot/ANUD45/HAll","iot/ADR1/KITCH","iot/ADR5/BED"} m = mqtt.Client(client_id, 0,user_id,password) m:lwt("/lwt", "offline", 0, 0) m:on("connect", function(client) print ("connection estblished") end) m:on("offline", function(client) print ("offline") do_mqtt_connect end) m:on("message", function(client, topic, data) if data ~= nil then data=string.sub(data,2,#data-1) print('mqtt',data) end end) function handle_mqtt_error(client, reason) tmr.create():alarm(10 * 1000, tmr.ALARM_SINGLE, do_mqtt_connect) end function do_mqtt_connect() m:connect(host_id, port, 0) m:subscribe(topics[3], 0, function(client_3) print("subscribe success_9") end) m:subscribe(topics[1], 0, function(client_1) print("subscribe success_1") end) m:subscribe(topics[2], 0, function(client_2) print("subscribe success_4") end) end do_mqtt_connect()
here is my error.. [0;31mE (492351) MQTT_CLIENT: mqtt_message_receive: transport_read() error: errno=128[0m [0;31mE (492351) MQTT_CLIENT: mqtt_process_receive: mqtt_message_receive() returned -1[0m [0;33mW (492351) MQTT_CLIENT: Client asked to stop, but was not started[0m offline
I have the same problem with connection to local MQTT broker, although other clients connects properly.
The logs are
[I][mqtt_messaging.cpp:249] mqtt_event_handler(): MQTT_EVENT_DISCONNECTED
[I][mqtt_messaging.cpp:462] mqtt_event_handler(): Other event id:7
E (164519) MQTT_CLIENT: mqtt_message_receive: transport_read() error: errno=128
[I][mqtt_messaging.cpp:459] mqtt_event_handler(): MQTT_EVENT_ERROR
E (164521) MQTT_CLIENT: esp_mqtt_connect: mqtt_message_receive() returned -1
E (164528) MQTT_CLIENT: MQTT connect failed
[I][mqtt_messaging.cpp:249] mqtt_event_handler(): MQTT_EVENT_DISCONNECTED
[I][mqtt_messaging.cpp:462] mqtt_event_handler(): Other event id:7
E (174563) MQTT_CLIENT: mqtt_message_receive: transport_read() error: errno=128
[I][mqtt_messaging.cpp:459] mqtt_event_handler(): MQTT_EVENT_ERROR
E (174566) MQTT_CLIENT: esp_mqtt_connect: mqtt_message_receive() returned -1
E (174573) MQTT_CLIENT: MQTT connect failed
I tried to tweak MQTT version, change host or server address format (it's IP-address), with config, delay between connect with WiFi and connect to MQTT but it didn't make any effect. But once per 100 it can connect to MQTT. ESP-IDF version is v3.3.5-1-g85c43024c, used from ESP32-Arduino
I had a similar behavior which was caused by a subscribe to a topic which contained invalid characters: topic=þÿÿÿp)\b>@#<\r<6>mytopic/commands/reported
Log at esp32:
[0;32mI (3699) MQTT: Other event id:7[0m
[0;32mI (3819) MQTT: MQTT_EVENT_CONNECTED[0m
[0;32mI (8839) MQTT: Handling motor info update[0m
[0;32mI (8849) MQTT: subscribing to mqtt command topic, topic=þÿÿÿp)<\b>@#<\r><6>mytopic/commands/reported[0m
[0;32mI (8859) MQTT: sent subscribe successful, msg_id=47155[0m
[0;31mE (8899) MQTT_CLIENT: mqtt_message_receive: transport_read() error: errno=128[0m
[0;32mI (8899) MQTT: MQTT_EVENT_ERROR[0m
[0;31mE (8899) MQTT_CLIENT: mqtt_process_receive: mqtt_message_receive() returned -1[0m
[0;32mI (8909) MQTT: MQTT_EVENT_DISCONNECTED[0m
[0;33mW (17839) MQTT_CLIENT: Publish: Losing qos0 data when client not connected[0m
[0;33mW (21839) MQTT_CLIENT: Publish: Losing qos0 data when client not connected[0m
[0;32mI (23909) MQTT: Other event id:7[0m
[0;32mI (23979) MQTT: MQTT_EVENT_CONNECTED[0m
[0;31mE (25009) MQTT_CLIENT: mqtt_message_receive: transport_read() error: errno=128[0m
[0;32mI (25019) MQTT: MQTT_EVENT_ERROR[0m
[0;31mE (25019) MQTT_CLIENT: mqtt_process_receive: mqtt_message_receive() returned -1[0m
[0;32mI (25029) MQTT: MQTT_EVENT_DISCONNECTED[0m
[0;33mW (25839) MQTT_CLIENT: Publish: Losing qos0 data when client not connected[0m
[0;33mW (29839) MQTT_CLIENT: Publish: Losing qos0 data when client not connected[0m
[0;33mW (33839) MQTT_CLIENT: Publish: Losing qos0 data when client not connected[0m
[0;33mW (37839) MQTT_CLIENT: Publish: Losing qos0 data when client not connected[0m
[0;32mI (40029) MQTT: Other event id:7[0m
[0;32mI (40159) MQTT: MQTT_EVENT_CONNECTED[0m
Broker was Mosquitto 2.0.14
I am not sure if the problem is the invalid topic or the timing to the CONNACK request from the server. After several connection retries the connection is working:
To get this detail output you should set mosquitto to more verbose logging.
You could try to disable the subscribe request in the esp software to check if the situation gets better.
Hello I also facing same problem when I try to connect with Azure IoT hub please help me Guys.. My log messages are as follows: (14:42:20.717) [0;32mI (2081) Azure_IoT: STARTING MQTT (14:42:20.717) [0m (14:42:20.717) [0;32mI (2081) Azure_IoT: Other event id:7[0m (14:42:20.843) [0;31mE (2221) MQTT_CLIENT: mqtt_message_receive: transport_read() error: errno=128[0m (14:42:20.875) [0;32mI (2221) Azure_IoT: MQTT_EVENT_ERROR (14:42:20.875) [0m (14:42:20.875) [0;31mE (2231) MQTT_CLIENT: esp_mqtt_connect: mqtt_message_receive() returned -1[0m (14:42:20.875) [0;31mE (2231) MQTT_CLIENT: MQTT connect failed[0m (14:42:20.875) [0;32mI (2241) Azure_IoT: MQTT_EVENT_DISCONNECTED
Please help me Guys
For anyone wondering, usually this tipe of errors:
E (6912) esp-tls-mbedtls: read error :-0x004C:
E (6912) transport_base: esp_tls_conn_read error, errno=Socket is not connected
E (6912) mqtt_client: esp_mqtt_handle_transport_read_error: transport_read() error: errno=128
Occurs when the MQTT broker, closes the conection, meaning that maybe your code is not wrong, (certificate problems are addressed in other form).
In my case, it was that the Policy on AWS IoT Core was blocking the device, check the Policy of the Cloud you are using, or your broker related firewall and make a less strict policy (for amazon aws is arn:aws:iot:eu-west-1:XXXXXXXXXXXX:*) (WARNING: This is not the safest way of creating a policy, but maybe it helps with the testing) witch helped me figuring out what was the problem.
Hope it helps someone, it was the only post i found.
Environment
Problem Description
When I connect to a remote Mqtt server, the Mqtt client of Esp32 is always disconnected regularly. It always disconnects on time after 10 minutes of connecting to the Mqtt server, then reconnects within seconds, and then disconnects after 10 minutes of reconnection. There are two possibilities for this problem, one is that there is a problem with the server, and the other is that there is a problem with Esp32 If there is a problem with the server, there is no problem when I use the paho.mqtt.client library under python to connect to the remote server. If there is a problem with Esp32, there is no problem when I use Esp32 to connect to mqtt://mqtt.eclipse.org. So what's the problem? Please help me.
Expected Behavior
I need to keep Esp32 mqtt stable enough to communicate with my server.
Actual Behavior
It always disconnects in 10 minutes.
Steps to reproduce
Code to reproduce this issue
Debug Logs