MQTT.js
MQTT.js copied to clipboard
When the network is disconnected abnormally, the disconnection event is not triggered in time
The "offline" event will be triggered in a few seconds client.on('offline', (error) => { console.log('offline:', error) }) offline This event triggered too slowly What event can I call back in time to disconnect?
I believe what you need is that keepalive
value when you initialize the client.
MQTT client detects the disconnection via a packet called pingreq
, it will send a pingreq
packet for every keepalive
duration, if it does not receive the ack message from the broker, it will consider the connection is lost. The default value of keepAlive
is 60 seconds based on the documentation, it means you can only detect the disconnection after a minute or so.
If you would like to detect the disconnection sooner, just reduce the keepalive
value.
This is an automated message to let you know that this issue has gone 365 days without any activity. In order to ensure that we work on issues that still matter, this issue will be closed in 14 days.
If this issue is still important, you can simply comment with a "bump" to keep it open.
Thank you for your contribution.
This issue was automatically closed due to inactivity.