Closed hongtoushizi closed 9 years ago
That error means a connection was truncated, which can happen if you CTRL-C your client. I think it might be normal or not, depending on your application. So, I cannot help you without more details.
As a side note, you might want to improve the way you report issues. I think there are a lot of guides on how to do that, which mainly consist:
{"name":"mosca","hostname":"Zhangs-MacBook-Pro.local","pid":6720,"client":"18FE349FBD19","level":40,"err":{"message":"read ECONNRESET","name":"Error","stack":"Error: read ECONNRESET\n at errnoException (net.js:905:11)\n at TCP.onread (net.js:559:19)","code":"ECONNRESET"},"msg":"read ECONNRESET","time":"2015-03-19T03:26:36.635Z","v":0}
same here
the client is a wifi chip esp8266 which use mqtt-client from tuanpmt(link below) that running by a nodemcu firmware, and all mqtt client functions are using on lua interpreter which is a c module.
nodemcu mqtt part based on tuanpmt mqtt client lib https://github.com/nodemcu/nodemcu-firmware
mqtt client https://github.com/tuanpmt/esp_mqtt
The client code that i'm running which is basic client connect to mosca broker then subscribe a topic and send & receive message between those two.
i've set 1sec to send a "hello world" from esp8266 client through uart port, the broker received message but the esp8266 crashes and reboot sometimes then it will produce below error randomly.
i think it might be caused by mqtt-client lib or nodemcu.
That error happen because the device crashed, it is a perfectly legit error condition. You should debug your devices.
Will the last will message be sent if this happened?
@JokerQyou : Yes. will messages are stored (on broker) at the time of client connecting to broker. so in case of any abnormally disconnect event, broker will send this will message on topic specified in will option.
But no, the will message did not get delivered if this happened. I was using Paho MQTT client for python, and what my client do is just connect to the broker, set the last will, and subscribe a topic. While the client is doing its network loop, I hit Ctrl-C
and quit the terminal, and Mosca did not send the last will. I saw no delivering last will
message as I expected. (This message will show up every time I close a webpage on which a WebSockets client is running. All I got is as follows:
{"name":"mosca","hostname":"85c0f86860aa","pid":11,"client":"zopen-users.admin-bhjRx6pE80Dt-4928e4a60625da560e35f85ff90713ff","level":30,"msg":"client connected","time":"2015-07-02T06:41:46.402Z","v":0}
{"name":"mosca","hostname":"85c0f86860aa","pid":11,"client":"zopen-users.admin-bhjRx6pE80Dt-4928e4a60625da560e35f85ff90713ff","level":30,"topic":"zopen-default-users.admin-64ce64658ffde2440f172dc3bd9ab293","qos":1,"msg":"subscribed to topic","time":"2015-07-02T06:41:46.419Z","v":0}
{"name":"mosca","hostname":"85c0f86860aa","pid":11,"client":"zopen-users.admin-bhjRx6pE80Dt-4928e4a60625da560e35f85ff90713ff","level":40,"err":{"message":"read ECONNRESET","name":"Error","stack":"Error: read ECONNRESET\n at exports._errnoException (util.js:746:11)\n at TCP.onread (net.js:559:26)","code":"ECONNRESET"},"msg":"read ECONNRESET","time":"2015-07-02T06:42:03.020Z","v":0}
{"name":"mosca","hostname":"85c0f86860aa","pid":11,"client":"zopen-users.admin-bhjRx6pE80Dt-4928e4a60625da560e35f85ff90713ff","level":30,"msg":"closed","time":"2015-07-02T06:42:03.021Z","v":0}
In addition, I think I can confirm that the last will has been set right after the connection was established. The code is as follows:
def on_connect(client, userdata, flags, return_code):
# 订阅自己的 topic
print 'connected: ', return_code, flags
client.will_set(topic=str(userdata['ref'].sys_topic),
payload=json.dumps(userdata['ref'].gen_connection_msg(userdata, False)),
qos=MSG_QOS, retain=False)
print 'last will set'
for topic in userdata['topics'].values():
print 'subscribing ', topic
client.subscribe(str(topic), qos=MSG_QOS)
@PritamUpadhyay I know how it's described in the spec, but I'm having problem with the will message. I've updated details.
Alright, I misunderstood part of the documentation, as at the time of client connecting to broker, so you have to set the will before connecting to the broker, otherwise the will message is not set.
@JokerQyou : Exactly.
You can probably try adding client.loop() after every subscription in your client code. Worked for us. We are using pubsubclient for esp8366 (https://github.com/knolleary/pubsubclient). ISSUE: https://github.com/marvinroger/homie-esp8266/issues/11
{"name":"mosca","hostname":"dev0003","pid":14618,"client":"push/4409b077adf1f29","level":40,"err":{"message":"read ECONNRESET","name":"Error","stack":"Error: read ECONNRESET\n at errnoException (net.js:904:11)\n at TCP.onread (net.js:558:19)","code":"ECONNRESET"},"msg":"read ECONNRESET","time":"2015-03-12T03:15:26.368Z","v":0}
why this happen? thanks!