I am piecing together a program that calls a http endpoint every hour, adjusting the RTC and reads energy meter with modbus. (NBClient, GPRS, NBAccess RTCZero, ArduinoModbus and ArduinoRS485)
Posting the values back at next request.
I could use some advice on how to achieve maximal continuous operation.
Should I try to do a timed program restart every so often, or should the Arduino be able to run for months/years without breaking down.
Is the NB-IoT modem the Achilles heel? So should I monitor requests and advise the end user when no request has been made for a couple of hours, making hard reset only option.
The Achillies heel ist the connection / TCP socket. The mobile network can kick you out, the TCP socket can die, the modem can become unresponsive (My experience: Even after a hard reset)
I would try to open LTE-M, check, open TCP connection, check, push the data in the socket, check and then close everything vice versa, wait 1 hour and repeat, trying to keep the AT console alive.
The modem is it's own computer with memory, os and so on, you can only communicate over the AT console. If there is just a ERROR or no response you can do nothing.
The problem is IMHO not the board reset but the modem who, as an independent "computer" is not reseted then because it has it's own power supply. If you check the wiring, the reset and the power on controlled with your code are not cutting the power, so if the modem is unproductive, no way to do smth. Write stable code, thats my hint.
When testing the sample code on An MKR 1500 - i looks like it works, and restarts, but the serial monitor stops writing after first run, do you know what I am missing?
#include <WDTZero.h>
WDTZero MyWatchDoggy; // Define WDT
void setup()
{
int t = 20; // Initialize serial and wait for port to open, max 10 seconds
Serial.begin(9600);
while (!Serial)
{
delay(500);
if ((t--) == 0)
break;
}
Serial.print("\nWDTZero-Demo : Setup Soft Watchdog at 32S interval");
MyWatchDoggy.attachShutdown(myshutdown);
MyWatchDoggy.setup(WDT_SOFTCYCLE32S); // initialize WDT-softcounter refesh cycle on 32sec interval
}
void loop()
{
unsigned int t = 0;
Serial.print("\nWatchdog Test1 - run 60 seconds with a WDT.clear()\n");
for (t = 1; t < 60; ++t)
{
MyWatchDoggy.clear(); // refresh wdt - before it loops
delay(950);
Serial.print(t);
Serial.print(".");
}
Serial.print("\n\nWatchdog Test2 - Free run wait for reset @32s\n");
for (t = 1; t > 0; ++t)
{
delay(950);
Serial.print(t);
Serial.print(".");
}
Serial.print("\nYou will never read this line");
}
void myshutdown()
{
Serial.print("\nWe gonna shut down ! ...");
}
My program with the watchdog implemented, ran for about 1 month.
Then it was stuck in this
boolean connected = false;
// After starting the modem with NB.begin()
// attach to the GPRS network with the APN, login and password
while (!connected)
{
Serial.println("while (!connected)");
if ((nbAccess.begin(PINNUMBER, APN) == NB_READY) &&
(gprs.attachGPRS() == GPRS_READY))
{
Serial.println("GPRS_READY");
connected = true;
}
else
{
Serial.println("Not connected");
delay(1000);
}
}
And burning a new program didn't help, but disconnection the power worked.
Is there any method to do a modem reset from code?
Or
Can I use a small electronic circuit to monitor my watchdog and reset the power to the board if the watchdog doesn't reach its checkpoint? Can I use a relay or MOSFET with a timed delay to achieve this function?
ChatGBT said:
if (nbAccess.getSignalStrength() == 0) {
nbAccess.restart();
}
But then you have to repeat all the AT commands to re-establish the mobile connection, tcp sockets etc. after a reboot grace time.
Maybe you can try to reset the modem with the code above and then reset the mkr (and your code) within the hooked "myshutdown": MyWatchDoggy.attachShutdown(myshutdown);
“One good test is worth a thousand expert opinions.” - Wernher von Braun
Just initialize with nb.access(true); and check the serial monitor the see the AT commands. This is the interface between your sketch and the modem
Some say yes, this can harm the modem
If you reset the modem, you have to start the whole process of establishing the network etc. The modem is a second independent fully computer which can be controled ONLY of that AT interface. Now imagine a cold, hard boot on the modem-computer side.