I’m trying to prototype a controller for a machine I’m building. Losant keeps kicking me off with disconnect reason: connection closed. This reason is NOT helpful.
I’ve also hired two companies try to get a Nimbelink modem to work without success.
Please help.
Hey @Lyndon_Walker,
Yes, that is indeed one of the least helpful disconnect reasons. It’s because it’s the one with the least amount of information available.
“Connection closed” means the connection was uncleanly terminated by the device or by something between the device and Losant. We see this most often when the device power cycles. The connection gets terminated, but not cleanly, meaning the device did not have a chance to send a proper MQTT or TCP disconnect packet.
A power cycle can occur for many reasons. Maybe you’re sleeping the device and not giving it enough time to send a proper disconnect message. Another reason could be a fault or watchdog timer (if using something like FreeRTOS) causing the device to restart.
There is also a lot of networking hops and equipment between your device and Losant. Anywhere in those layers can terminate a connection outside of either of our control. These issues are fairly rare. The culprit is almost always something odd happening on the device side or in the device firmware.
So in this case, it’s not that Losant is kicking the device off. Losant simply sees the TCP connection suddenly end without receiving any proper disconnect packets.
It’s not a power cycle or watchdog issue. I don’t lose the internet connection. It seems to me that Losant is kicking the device. Can you give me any other information from your end?
Unfortunately, for this type of disconnect, there are no additional details available. What Losant sees is a sudden, unclean, disconnection of the TCP socket. The disconnect is not initiated by Losant. Things like upgrades to our MQTT broker will force devices to disconnect, but those have specific messages in the connection log to indicate the reason for the disconnect.
Do you have suggestions as to what to do from here?
It’s tough with cellular because it’s hard to monitor the network traffic. The first thing I would attempt is to remove TLS from the equation by connecting the device to port 1883 (unencrypted). We’ve seen plenty of issues related to embedded TLS libraries causing connection instability (some libraries use a shared send/receive buffer that’s totally not designed for MQTT’s asynchronous communication).
The next thing I’d attempt is to eliminate Losant from the equation to narrow down the issue (cloud vs. device). I would install the Mosquitto MQTT broker on a cheap cloud VM (something like Digital Ocean) and point the device at that. Let it run for a while and inspect the broker logs for disconnects. This gives you a controlled environment to continue testing.