I have been using the Web IDE and testing four MKR 1500 boards with different antennas and sim chip vendors. I am new to Arduino but experienced programmer on other non-micro systems. I am frustrated with the inability to get good diagnostic messages and difficulties retaining the entire serial monitor log (sometimes clears itself). I am including (below) my sketch for monitoring the connection progress. It does require the Modulino Pixels (and QWIIC connection) so that status can be reported via 8 RGB leds. There is a built in reset if the connection is not achieved in 120 seconds. But I have found that sometimes the only way to get the modem to connect is to do a full power cycle of the board--most annoying since I have not found a programmatic way to do this. Thinking about adding an external watchdog circuit. If anyone has a tip for power reset, I am all ears. Meanwhile, I will follow up with things I have learned from this testing. This sketch uses the Arduino Cloud to help me log uptime and outages during my tests.
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled 2"
https://create.arduino.cc/cloud/things/cd7704c6-7046-425f-bc0f-5be66e6d1b84
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
String compFile;
String compTime;
String devTime;
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"
#include <Modulino.h>
#define SP(a) Serial.print(a)
#define SP2(a,b) Serial.print(a);Serial.print(b)
#define SPLN(a) Serial.println(a)
const String compile_time = __DATE__" " __TIME__ ;
const String compile_file = __FILE__ ;
// devTime String READ ... defined in thing
char timeString[30]="",timeStringPrev[30];
// Create a ModulinoPixels object for the LED array
ModulinoPixels leds;
// Define a custom color for turning off LEDs
ModulinoColor POFF(0, 0, 0);
ModulinoColor YELLOW(200, 100, 0);
long int commBlinkRate=100, commBlink=commBlinkRate; bool commLed=0;
long int msCommTime=millis(), resetComm=120*1000; bool goodComm=0;
/* use modulino pixels for real-time monitoring of connection
led 0 = card identity (when testing many boards at same time)
led 2 = waiting for connection yellow blinker, loop count / 100
led 3 = connection status, green good
led 4 = violet: setup and first time through loop indicator
led 5 = strobe: white when not stuck waiting for ArduinoCloud function
led 7 = indicate which APN value I am currently testing with (multiple sims)
*/
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // ONBOARD LED
digitalWrite(LED_BUILTIN, 0);
// 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(15000);
Serial.println("------------------------------------------------------------1");
// Defined in thingProperties.h
initProperties();
// Initialize Modulino I2C communication
Modulino.begin();
// Detect and connect to knob module
// knob.begin();
// Detect and connect to buzzer module
// buzzer.begin();
// Detect and connect to pixels module
leds.begin();
leds.set(4, VIOLET, 20); leds.show(); // setup and first full loop
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
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);
ArduinoCloud.printDebugInfo();
compTime=compile_time; compFile=compile_file;
Serial.print(" APN=");Serial.println(GPRS_APN);
delay(500);
Serial.println("------------------------------------------------------------2");
// the following lets me know that the sketch has restarted.
// this can be caused by my 2 minute connection timeout or by modem doing its own reset
for (int i = 0; i < 8; i++) { leds.set(i, BLUE, 20); leds.show(); delay(50); }
for (int i = 0; i < 8; i++) { leds.set(i, GREEN, 20); leds.show(); delay(50); }
for (int i = 0; i < 8; i++) { leds.set(i, POFF, 0); leds.show(); delay(50); }
leds.set(4, VIOLET, 20); leds.show(); // setup and first full loop
if (strncmp(GPRS_APN,"cmhk",1)==0){leds.set(7, VIOLET,22); leds.show();}
if (strncmp(GPRS_APN,"",1)==0){leds.set(7, BLUE,22); leds.show();}
if (strncmp(PINNUMBER,"",1)==0){} else {leds.set(6,RED,11); leds.show();}
}
void loop() {
leds.set(0, BLUE, 20); leds.show(); // BLUE ... use a diff color for each card being tested ... helps with note taking
// 2 yellow blink loop/100
if(!goodComm && commBlink++>commBlinkRate) {
commBlink=0;
if (commLed^=1) {
leds.set(2, YELLOW, 10);
SP2("waiting for comm secs=",(millis()-msCommTime)/1000);SPLN();
} else {
commBlink=0; leds.set(2, POFF, 30);
}
leds.show(); //commLed=!commLed;
}
// cloud update or hang
leds.set(5, POFF, 0); leds.show(); // STROBE
ArduinoCloud.update();
// Your code here
digitalWrite(LED_BUILTIN, ArduinoCloud.connected());
leds.set(5, WHITE, 5); leds.show(); // STROBE
// comm state change
if (ArduinoCloud.connected() != goodComm) {
msCommTime=millis(); goodComm^=1;
SP2("Comm ms=",msCommTime);SP2(" flag=",goodComm);SPLN();
}
// failed to connect in reasonable time
if (!goodComm){if (millis()-msCommTime>=resetComm) {
Serial.println("Resetting due to long failure to connect.");
for (int i = 0; i < 8; i++) { leds.set(i, RED, 20); leds.show(); delay(50); }
NVIC_SystemReset();
}}
// cloud watch ... use this to monitor uptime from ArduinoCloud dashboard
if (goodComm){
time_t currentTime = ArduinoCloud.getLocalTime();
strcpy(timeStringPrev,timeString);
strftime(timeString, sizeof(timeString), "%Y-%m-%d %H:%M", localtime(¤tTime));
if (strcmp(timeString,timeStringPrev)!=0){
devTime=timeString;
} }
// reached loop bottom
leds.set(4, POFF, 0); leds.show(); // setup and first full loop -- DONE
if (ArduinoCloud.connected()) {
leds.set(2, GREEN, 20); leds.set(3, GREEN, 20);
} else {
leds.set(3, RED, 30);
} leds.show();
}