If you still have a disconnection issue with this bare code then, clearly the problem i not with your code. That is for sure.
So, you absolutely need to do what @pennam asked you to do in post #2 so he can try to understand what's happening and help you.
What I proposed in post #3 is just a turnaround the problem. In the past I have had also problems with disconnection and not connecting again so I implemented this code. But, since last month I never had any disconnection at all. I think the IOT team solved this problem. But I am using ESP32.
Hi @jarriaga and @pennam and anyone else that can assist?
I have set up a dedicated laptop and a MKR 1500 NB running the basic code above with just two boolean variables so I can check for connection from the dashboard.
So far the board has been able to reconnect, I would like to know why it is disconnecting though?
***** Arduino IoT Cloud - configuration info *****
Device ID: 3aba0056-3d37-4579-ae6c-b6a1d4483053
MQTT Broker: mqtts-sa.iot.arduino.cc:8883
SIM card ok
Connected to GPRS Network
Connected to Arduino IoT Cloud
Thing ID: 69664eea-2fca-42e8-88a5-66cb51a2f1d3
ArduinoIoTCloudTCP::handle_Disconnect MQTT client connection lost
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to mqtts-sa.iot.arduino.cc:8883
ArduinoIoTCloudTCP::handle_ConnectMqttBroker 1 connection attempt at tick time 19385315
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to mqtts-sa.iot.arduino.cc:8883
ArduinoIoTCloudTCP::handle_ConnectMqttBroker 2 connection attempt at tick time 19395429
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to mqtts-sa.iot.arduino.cc:8883
ArduinoIoTCloudTCP::handle_ConnectMqttBroker 3 connection attempt at tick time 19410021
Disconnected from Arduino IoT Cloud
Connected to Arduino IoT Cloud
Thing ID: 69664eea-2fca-42e8-88a5-66cb51a2f1d3
ArduinoIoTCloudTCP::handle_Disconnect MQTT client connection lost
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to mqtts-sa.iot.arduino.cc:8883
ArduinoIoTCloudTCP::handle_ConnectMqttBroker 1 connection attempt at tick time 20107078
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to mqtts-sa.iot.arduino.cc:8883
ArduinoIoTCloudTCP::handle_ConnectMqttBroker 2 connection attempt at tick time 20117757
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to mqtts-sa.iot.arduino.cc:8883
ArduinoIoTCloudTCP::handle_ConnectMqttBroker 3 connection attempt at tick time 20131853
Disconnected from Arduino IoT Cloud
Connected to Arduino IoT Cloud
Thing ID: 69664eea-2fca-42e8-88a5-66cb51a2f1d3
Is it possible that being connected to the laptop and the serial monitor is assisting the board to be able to connect?
The time it takes for the board to get to a point that it can not reconnect is variable, so it may take a few days to get a failure in normal circumstances anyhow.
Are the reconnection attempts limited? For example if it can not re-connect after 3 attempts does it stop trying?
Any advice or ideas greatly appreciated.
M
Morning @jarriaga @pennam et al.
The laptop that I was running the test on decided to do a windows update and I lost several days of serial monitor log, however, I don't believe the board failed to reconnect in that time.
I connected another brand new board with updated firmware to v216, and installed a brand new SIM card, the board connected to Arduino fine then I received this, this is the complete log from boot, connected fine, stayed connected for several hours then disconnected.
SIM card ok
Connected to GPRS Network
Connected to Arduino IoT Cloud
Thing ID: c26ee65a-dbd6-4851-9b0d-2776985aead7
ArduinoIoTCloudTCP::handle_Disconnect MQTT client connection lost
Disconnected from cellular network
SIM not present or wrong PIN
Any advice will be greatly appreciated, I have put hundreds of hours into trying to achieve stability with these boards and it is very frustrating.
M
Have just run the NB scanner sketch from the MKRNB tools folder,
Here is the result if this gives any insight.
NB IoT/LTE Cat M1 networks scanner
Modem IMEI: 352753097914319
Current carrier: One NZ DATA ONLY
Signal Strength: 20 [0-31]
Scanning available networks. May take some seconds.
> 530 05
> One NZ
> 530 05
Thank you,
M
Some further information @jarriaga and @pennam...
I think I have identified some code that causes some instability, when I add this code often the controller reboots before connecting to the cloud, when I remove it it connects first time.
Color aCurrentColour=Color(aColour.getValue().hue, aColour.getValue().sat, aColour.getValue().bri);
aCurrentColour.getRGB(aRValue, aGValue, aBValue);
Color bCurrentColour=Color(bColour.getValue().hue, bColour.getValue().sat, bColour.getValue().bri);
bCurrentColour.getRGB(bRValue, bGValue, bBValue);
Color cCurrentColour=Color(cColour.getValue().hue, cColour.getValue().sat, cColour.getValue().bri);
cCurrentColour.getRGB(cRValue, cGValue, cBValue);
This code is for converting HSI values from the colour widget and returns RGB values for use with RGB Led's etc.
Thank you,
M
Additionally it turns out adding this causes instability,
if (hbSched.isActive()) {
heartbeat = true;
digitalWrite(hbPin, HIGH);
digitalWrite(statusA, HIGH);
}
else {
heartbeat = false;
digitalWrite(hbPin, LOW);
digitalWrite(statusA, LOW);
}
With this added to the code I get... with - setDebugMessageLevel(4);
***** Arduino IoT Cloud - configuration info *****
Device ID: fcee724c-8656-4f82-a15a-439438c3dc72
MQTT Broker: mqtts-sa.iot.arduino.cc:8883
SIM card ok
GPRS.attachGPRS(): 4
Connected to GPRS Network
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to mqtts-sa.iot.arduino.cc:8883
ArduinoIoTCloudTCP::handle_ConnectMqttBroker 1 connection attempt at tick time 25579
GPRS.isAccessAlive(): 1
Connected to Cellular Network
Connected to Arduino IoT Cloud
Thing ID: 0d76444a-fa51-4045-8079-9ec884405eac
The board then resets itself.
Without this if routine checking for the status of a cloud variable I get this...
SIM card ok
GPRS.attachGPRS(): 4
Connected to GPRS Network
Connected to Arduino IoT Cloud
Thing ID: 0d76444a-fa51-4045-8079-9ec884405eac
ArduinoIoTCloudTCP::setTimeZoneData tz_offset: [46800]
ArduinoIoTCloudTCP::setTimeZoneData tz_dst_unitl: [1680357600l]
It connects perfectly and is stable,
Why would it be that adding any code makes it unstable?
Should I put all my code (except ArduinoCloud.update();) in a 'blink without delay' style millis() delay to allow the board some time to retrieve the variables from the cloud?
Further information - It appears that if I add any code that tries to retrieve or send variables to the cloud affects the connection speed and the stability
Best,
M
I don't think so, trying to reconnect once disconnected is the default behaviour of the ConnectionHandler and there is no relationship whith the serial monitor
No the board will try to connect indefinitely, but the retry interval increases each time.
This print comes from the ConnectionHandler: each loop is checking if connection is alive calling this function
This is meaning the modem has replied either:
0: not registered, the MT is not currently searching an operator to register to
2: not registered, but the MT is currently trying to attach or searching an operator to register to
3: registration denied
4: unknown (e.g. out of E-UTRAN coverage)
since the modem was not able to detect the board anymore i suspect it has something to do with SIM contacts...
This could be a RAM issue, but need to investigate this further: commenting out that code, the compiler is optimizing (not including in the build) your properties leaving more RAM available avoiding heap and stack collision.
Could you please try to add only and int property and check if connection is stable? Than add another int property re-check and so on...
Thank you @pennam,
I will do this test as soon as I am back to the office, however I can not understand how just one variable is causing a RAM collision?
Best,
M
Hi @bigdingo did you had the chance to do the tests?
Hi @pennam,
I have done the tests and identified that managing my memory usage defo helped with stability,
I have put everything I can in functions() to manage memory usage.
I am still having stability issues, they are very hard (for me anyway) to diagnose, because in order for the issues to arise, I really need to have the MKR connected to all the sensors, and when it is connected, I am unable to use the serial monitor.
Is there any chance you could run my code your end and see what you think?
I also feel as if I may have been having a brownout issue which was complicating things, when I was connected to USB it was fine, when it was installed it was resetting.
Is there any advice on diagnosing brownout or memory issues in real time?
Best,
M
I noticed this LED behaviour on one board that became unresponsive today.
Why did the WDT not reset this?
What do the LEDs mean?
Thank you,
M
Hi @bigdingo
you can share it here on the forum but can't ensure i find out the time to debug it
I would use the debugger or you can put in the code some prints about the runtime available memory using this library
Looks like the board is in bootloader mode: BUILTIN LED looping fadein fadeout.
Thank you. What would cause the board to go into bootloader mode?
Shouldnât the WDT reset the MCU?
Best,
M
Additionally,
The charge LED is also flashing, what does this mean?
If I manually put the board into bootloader, this does not happen.
M
hi @bigdingo sorry for the big delay
Yes the watchdog will reset the MCU.
Do you have a battery connected to the board?
If not and the charge LED is flashing this is a symptom of some issue on the I2C bus. The bootloader is stuck in some i2c transaction and can't boot user sketch.
Do you have anything connected to the i2c bus?
Hi @pennam
No not connected to a battery but yes there is a temperature and humidity sensor connected to the I2C bus. Although with all the other issues I am having there is no code to use it, could this be the issue?
The sketch does load as it works for a while then goes into bootloader where it gets stuck indefinitely.
Best,
M
I should add that I now have a Atmel ICE so can run the debugger but am unsure what I am looking for.
Best,
M