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

SIM800 wont reconnect; how to reconnect to gprs network when blynk only keeps trying to reconnect to my server?

Hello; everything works fine with my Arduino Leonardo with SIM800 included. But if somehow, it disconnect to the gprs network, arduino keeps trying to reconnect to my server over and over; i need it to detect its a grps issue and try to reconnect to network. Yes, i check and my server is running; When i reboot it, everything comes to normal again. But if this happens again, we can’t be rebooting device.

[76867568] Connecting to 128.122.181:8080
2027 <- Counter i print on BlynkArduinoClient.h to know how retries we have…
[76872569] Connecting to 128.122.181:8080
2028
[76877571] Connecting to 128.122.181:8080

How can he denotare a gsm reconnect in some timeout. We see the gprs led not blinking fast so we know we are offline the gprs network. Any idea? thanks.

Inside BlynkArdiunoClient.h:

bool connect() {
    if (domain) {
        BLYNK_LOG4(BLYNK_F("Connecting to "), domain, ':', port);
        t++;   Serial.println(t);   ///  HERE'S WERE WE'RE PRINTING THE RETRY COUNTER!!
                                            /// We want to reconnect to gprs network (not the blynk server over and 
                                            /// over, if we lost the grps network connection
        isConn = (1 == client->connect(domain, port));
        return isConn;
    } else { //if (uint32_t(addr) != 0) {
        BLYNK_LOG_IP("Connecting to ", addr);
        isConn = (1 == client->connect(addr, port));
        return isConn;
    }
    return false;
}

I think i solved it (need to wait for tests).
In my main code, i created a timer and each minute i check if blynk.connected()
Then i trigger the reconnect instruction again: Blynk.begin(auth, modem, apn, “”, “”, “xxx.xxx.xxx.xxx”,8080); If someone has a better idea, its great to share it. I’ll test two days of connection meanwhile im logging the gsm signal strenght, etc.

i have the same function that check WiFi and blynk connection every 120 sec with two rec counters.
only blynk rec count increase, so WiFi connection is stable.
give it a try and take me informed.

1 Like

Thanks a lot. I’ll start the wifi version project and im sure i’ll do the same thing you did.
I never thought wifi connection wont be auto-reconnected by default with blynk libraries.
Thanks for the reply.

1 Like

To my knowledge, it does - It is nested inside Blynk.run(). But you have more control, if done manually.

1 Like

Thanks for you reply. I dont know what else to do. I know you’re working with wifi, but on gsm this is keep happening. Everything works like a charm, i love it but someone, sometimes it stop working; sometimes the grps led is off, so i have a timer to check and reconnect. But sometimes, it dosent and it keeps retrying to connect to my server over and over. If i reset device, everything works ok. The main problem is that i dont know whats the REAL cause of this. If this is a mobile provider issue, if this a grps issue, if something’s wrong with my server (i dont think so, wifi devices are working for months). Sometimes the terminal dosent shows anything like it was stuck, even with the gprs blinking. I dont know what else to try.

hmmm…maybe you could try to check the connection with modem.isGprsConnected() which is implemented in TinyGsm library? Then, if received false (it returns boolean), just reset the modem (with hardware pin) AND the MCU, just to start “from scratch”. I haven’t checked however how isGprsConnected() works and IF it will be able to detect your specific issue.
I think, this might be your operator disconnects you, which isn’t (wasn’t?) rare. In PL in the past every cellular connection needed to be reset (to summarize data usage? Or whatever reason…). Now it doesn’t seem the case, but I’m not absolutely sure.

1 Like

But if somehow, it disconnect to the gprs network, arduino keeps trying to reconnect to my server over and over; i need it to detect its a grps issue and try to reconnect to network.

Need to use wdt. In the program, you need to reset the wdt counter, but if the program hangs here: [76867568] Connecting to 128.122.181: 8080
2027 <- Counter i print on BlynkArduinoClient.h to know how retries we have …
[76872569] Connecting to 128.122.181: 8080
2028
[76877571] Connecting to 128.122.181: 8080
there will be a general reset and the program will start from the very beginning.

Também estou com problema similar amigo!
GSM conectado porém Blynk não conectado.

I’m also having similar problem friend!
GSM connected but Blynk not connected.

Blynk already has connection management options… You need to use whatever 3rd party interface code is reguired to link your devcie with your WiFi/GSM/Ethernet/Telegraph/Smoke signal… followed by Blynk.connect().

Then add in some connection check and logic routines in the void loop() to “disengage” Blynk while keeping the rest of the sketch running when there is no server connection

And finally, periodically attempt to reconnect as desired, instead of constantly every loop cycle.

One example…