Continue code if Register in network failed

So I couldn’t find a solution.
I have an arduino mega using a sim800l to connect to blynk.
I control the sim800l power with a mosfet, so i can turn it off to save power.
I want to be able to continue with the code even if the sim800 can’t connect to the network.


The problem with GSM connection is that the code in library forces reboot on MCU if it cannot init the modem. In such a case it is not that straightforward to continue without connection. In case of proper modem initialisation but interrupted GPRS communication it is much easier to handle. I can post my solution to review, if needed.

Please do, I would appreciate it!
What i need is to understand if it could connect to the network, ex: if i’m in a location where i don’t have any signal. and if not, to continue with the code and try later.

Tried using config(), managed to connect but if i don’t have any gprs connection, it just reboots. There is no confirmation of a connect or a disconnect. The code just stops there, and I want it to continue instead.

Exactly the way it is. And currently I did nothing with that. You can modify a library to not trigger reboot, but in my case it is the correct behaviour. What I did, is a periodic GPRS connection check and reconnect attempt. But currently I’m on the mobile only and have not access to the computer.

Since I use this circuit on a battery, in case it doesn’t connect, i want it to turn off GSM and go to sleep for a while and try again later. If it keeps rebooting it continues to drain battery. Could you point me to where in the library i can change it? or share your solution when possible ofc.

Thank you!

I know nothing on this GSM issue… but I recommend searching…

1 Like

Here is the way I handle the connection:
(irrelevant parts stripped)


CustomConsole lcdConsole;

#define BLYNK_PRINT lcdConsole
#define SerialAT Serial1
#include <TinyGsmClient.h>
#include <BlynkSimpleSIM800.h>

TinyGsm modem(SerialAT);
BlynkTimer timer;

void GPRScheck() {
  if (!modem.isGprsConnected()) {
    Blynk.config(modem, auth, server);
    if (Blynk.connectNetwork(apn, user, pass)) {
      lcd.setCursor(1, 0);
      lcd.print(F("               "));
      lcd.setCursor(1, 0);
      String COP = modem.getOperator();
      lcd.setCursor(18, 0);
  int csq = modem.getSignalQuality();
  char _buff[3];
  if (csq != 99) {
    csq = map(csq, 0, 31, 0, 99);
    sprintf(_buff, "%2d", csq);
  else {
    strcpy(_buff, "--");
  lcd.setCursor(37, 0);

void setup()

  //trigger GSM modem POWER pin
  pinMode(20, OUTPUT);
  digitalWrite(20, HIGH);
  digitalWrite(20, LOW);

  GPRScheck();  //check and initialize GPRS/Blynk connection
  timer.setInterval (60000L, GPRScheck);

void loop()

As it comes to library mod, I traced the BLYNK_FATAL definition located in BlynkDebug.h.:

#define BLYNK_FATAL(msg) { BLYNK_LOG1(msg); BlynkFatal(); }
Where BlynkFatal() part causes the delayed (10sec) reboot

BLYNK_FATAL is called each time an unrecoverable (?) error occurs. In BlynkGsmClient.h file you will find it (among others) in bool connectNetwork() in line #43

SO, perhaps simple changing the BLYNK_FATAL to BLYNK_LOG1 in places, where you want to continue instead of reboot will help. BUT this solution is untested by me

1 Like

10 posts were split to a new topic: My project sometimes hang with the modem not connecting