Hi I have a simple Arduino Sketch displaying Temperature, Humidity and a switch on. the Arduino Cloud and these are mapped to graphs in a Dashboard
It connects fine, authenticates and sends data and interacts with the switch
but after a while it disconnects and reboots.
And keeps trying with this error message(which I can find no reference to)
the first line appears it ios getting the TiMe from the ArduinoCloud so some connection ios going through
It keeps giving this error
TimeServiceClass::sync done. Drift: -12 RTC value: 1739817171
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to iot.arduino.cc:8885 Error: -2
Since this is Arduino Library code I would expect that they could tell what this error is but -2 appears as if its incomplete error handling
The only method to reconnect it seems to be if I delete the device - re-add it (same Sketc same parameters) then it will connect for a "random" while.
It looks like your Arduino IoT device is having trouble maintaining a stable MQTT connection. The error Error: -2
generally indicates a connection failure, often due to network issues or authentication problems.
Here are a few things you can try to troubleshoot:
- Check Your Network Stability
- Ensure your internet connection is stable.
- If using WiFi, check for interference or weak signals.
- Verify Arduino IoT Cloud Credentials
- Make sure your device's credentials (Thing ID, Secret Key) are correct.
- Try generating new credentials and updating them in your sketch.
- Increase MQTT Keep-Alive Interval
- If the connection is timing out, try increasing the keep-alive time in your code.
- Check Device Memory Usage
- If your Arduino runs out of memory, it may crash and restart.
- Consider reducing the number of variables or using a board with more RAM.
- Firmware and Library Updates
- Ensure you're using the latest version of the Arduino IoT Cloud library.
- Update your board’s firmware via the Arduino IDE.
- Check MQTT Broker Status
- Arduino Cloud services might be experiencing temporary issues. You can check Arduino's status page for any outages.
Since deleting and re-adding the device temporarily fixes it, this suggests an authentication or session issue. You might also try using a different network or board to see if the issue persists.
Hi @10hosein thanks
So I have discovered I can reboot the router and the reboot the MKR/Opla and they work again for a while without deleting the thing and re-adding.
This suggests that it is a network issue involving the router which is strange since really the only thing that changes is the IP address (of the WAN port of the Router) on reboot
I have confirmed this twice now - and I am going to move the device to a completely different network (that would involve redoing the wifi credentials) and re-compiling which is unfortunate - but if it occurs there as well then the issue could be MKR board & OPLA/software / memory as suggested.
I had the exact same problem. In my case, it seemed that when the transmitted data exceeded a certain size, the cloud server would block it. I was sending strings, and while short strings were transmitted without issues, sending longer ones triggered the same error message. After that, even rebooting didn't help—I was permanently unable to reconnect. However, if I registered a new device, it would work fine, but only when sending short strings.
Because of this issue, I really don’t want to use Arduino Cloud. However, I haven’t found a single reliable way to connect my Arduino MKR NB 1500 to another server. It’s absolutely frustrating.