MKR GSM Issue - Keeps crashing

Hi everyone,

I am really stuck with trying to get a MKR GSM 1400 to connect to Arduino IOT cloud with a Giffgaff sim.

Current setup is:

MKR GSM 1400 powered by 3.7v LiPo battery (fully charged)
USB cable into the MKR GSM for serial port monitoring
Giffgaff sim card

I am just trying to upload the default IOT cloud sketch with one bool variable called "led".

I have used the details specified by giffgaff for connection which is as follows:
APN - giffgaff.com
Pin - They say leave it blank but arduino requires it so I have used 5555
Username - gg
Password - p

With a blank sketch pushed to it, the MKR GSM sits there nicely. As soon as I try and program it with the IOT sketch it takes the program, output the device ID to the serial monitor, outputs "MQTT Broker: mqtts-sa.iot.arduino.cc:8883" an then disconnects from the PC and restarts. Connects itself again, outputs the same device ID and MQTT message and restarts continuously.

At fist I thought it was my board so I bought a new one. Then, when this did the same I tried having additional power (LiPo & power from PC usb) and this still doesn't work.

I have googled for weeks but can't seem to throw any further light on what could be wrong. Is anyone able to help me please?

I have also tried running the following code to see how far it gets and for some reason it always seems to crash after doing 5 or 6 "loops"

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled 2"
  https://create.arduino.cc/cloud/things/7076ff59-09a7-4559-bf35-632285519f6a 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  CloudLocation coordinates;
  bool status;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(5000); 

  // Defined in thingProperties.h
  initProperties();
  Serial.println("Intialised Properties");
  delay(1000);

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  delay(1000);
  Serial.println("Started Arduino Cloud");
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(4);
  delay(1000);
  Serial.println("Set Debug Level");
  delay(1000);
  ArduinoCloud.printDebugInfo();
  delay(1000);
  Serial.println("Debugged");
  delay(2000);
}

void loop() {
  Serial.println("into the loop");
  // Your code here 
  //coordinates = Location(78.517541210126, 36.236772410127);
  delay(2000);
  Serial.println("Finished Loop");
  //ArduinoCloud.update();
}

/*
  Since Status is READ_WRITE variable, onStatusChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onStatusChange()  {
  // Add your code here to act upon Status change
}

It is like it on both boards.

Hi @newone96

It sounds like the microcontroller's watchdog timer (WDT) is resetting the board. I believe the ArduinoCloud sets the WDT timeout to 16 seconds.

Have you tried uncommenting the ArduinoCloud.update() function?

That is an interesting thought as when I run a sketch that isn't on the IOT cloud. i.e a basic sketch with a few serial commands and leds it works fine. I don't have the board with me at the moment but will try as soon as I do.

Am I right in thinking that the WDT will only kick in if there is a fault in the hardware / software that has caused it to hang? Could it be an issue with the compatibility of the inbuilt libraries for IOT on the MKR GSM board? It just seems really strange that I have had exactly the same issue on two brand new boards.

Really appreciate your response, as you can see I am firmly at the "clutching-at-straws" stage!

Hi @newone96

Yes, that's right. If the WDT isn't reset before its expiration time, it will reset the microcontroller.

It's possible to test if the watchdog has reset your board, by testing the WDT bit in the SAMD21's RCAUSE register in the setup() portion of your sketch:

Serial.println(PM->RCAUSE.bit.WDT);  // Test if the watchdog caused the reset

It outputs a 1 if the watchdog was the cause, otherwise 0.

The reason why I mentioned it, is because another forum member also recently had an issue with their board resetting when using the ArduinoCloud, (although the reason for their board resetting was different):

Evening,

I would be interested to hear what came of this?

I am having the exact same issue, I can upload a blink sketch no problem...

But if I upload the IoT cloud generated sketch the board (MKR 1500 NB) goes into a reset loop.

It does seem to reset more frequently than 16 seconds though and at random intervals.

Would be very appreciative of an update/guidance.

Thank you very much for your reply @MartinL. I am away at the moment but will be back home over the weekend and will try this out and let you know the outcome. Really do appreciate your help.

@bigdingo Stay tuned.

Hi @bigdingo

This appears to be a reoccuring problem recently.

I'm not familiar with using the Arduino IoT Cloud, but I suspect that either IoT code is hanging causing the watchdog to generate a reset, or the 5 to 6ms blocking synchronization delay when updating the watchdog's CLEAR register is affecting timing elsewhere in the loop() function.

Access to the watchdog's CLEAR register takes 5 to 6ms because the WDT module is clocked using a 1.024kHz clock, rather than the main 48MHz CPU clock. Register synchronization takes 5 to 6 clock cycles, because 1.024kHz = 1ms period, 1ms * 6 = 6ms.

The 5 to 6ms blocking synchronization delay occurs because the Arduino IoT uses the Adafruit Sleepydog library. This code blocks, waiting for the register to become available:

while (WDT->STATUS.bit.SYNCBUSY);      // Wait for synchronization
WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY;  // Update the watchdog CLEAR register

...rather than allowing the code to continue unhindered:

if (WDT->STATUS.bit.SYNCBUSY == false)    // Check that the register is not being synchronized
{
   WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY;  // Update the watchdog CLEAR register
}

Apparently it's possible to turn off the watchdog by setting the second parameter of the ArduinoCloud.begin() function to false:

ArduinoCloud.begin(ArduinoIoTPreferredConnection, false)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.