timherreijgers / Domotics-base

Project containing base code for domotics projects
MIT License
0 stars 0 forks source link

Mqtt keeps disconnecting #44

Closed timherreijgers closed 1 year ago

timherreijgers commented 1 year ago

When using either WiFi or Ethernet the MQTT middleware keeps disconnecting randomly. From an investigation from Wireshark, this is caused by disconnects, followed by out-of-sequence messages. This is probably caused by the function connect function in the MQTT middleware. This function also initializes the connection to the internet card and should be called when a disconnect with the broker occurs.

When a disconnect occurs (for example caused by dropped packets) the connection with the internet will be recreated, and thus, the TCP packet sequence will be reset. TCP guarantees that all packets arrive, and will resend the old dropped packets, which will arrive out-of-sequence with the new TCP connection. The network card might not be able to fully handle this and thus disconnects again causing net packets to be dropped again and keeping this circle going.