BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Continue code if Register in network failed

#1

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.

Thanks!

0 Likes

#2

http://docs.blynk.cc/#blynk-firmware-configuration-blynkconfig

http://docs.blynk.cc/#blynk-firmware-connection-management

https://community.blynk.cc/search?q=run%20Blynk%20without%20internet

0 Likes

#3

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.

0 Likes

#4

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.

0 Likes

#6

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.

0 Likes

#7

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.

0 Likes

#8

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!

0 Likes

#9

https://community.blynk.cc/search?expanded=true&q=GSM%20%40marvin7%20order%3Alatest

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

1 Like

#10

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

#define TINY_GSM_MODEM_SIM800

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()) {
    modem.restart();
    modem.simUnlock("1111");
    Blynk.config(modem, auth, server);
    if (Blynk.connectNetwork(apn, user, pass)) {
      lcd.setCursor(1, 0);
      lcd.print(F("               "));
      lcd.setCursor(1, 0);
      lcd.print(modem.getLocalIP());
      String COP = modem.getOperator();
      COP.remove(15);
      lcd.setCursor(18, 0);
      lcd.print(COP);
      Blynk.connect();
    }
  }
  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);
  lcd.print(_buff);
}


void setup()
{
//...
  Serial.begin(9600);

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

  pinMode (LED_BUILTIN, OUTPUT);
  SerialAT.begin(115200);
  delay(3000);
//...
  GPRScheck();  //check and initialize GPRS/Blynk connection
  //help();
  timer.setInterval (60000L, GPRScheck);
}


void loop()
{
  Blynk.run();
  timer.run();
}

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

split this topic #11

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

0 Likes

closed #12
0 Likes