Check connection status in loop and reconect

@ Costas
Wonderful !!
Any suggestion for my TP Link 3G router M5250 with internal battery?

@Gianca mine are all TP Link 3G routers but not battery powered. Have you tried to telnet into the router?

I am more of a software guy than a hardware type.

Maybe @psoro, @Lichtsignaal or others could advise a hardware solution to restart this http://www.tp-link.com/en/products/details/M5250.html battery powered router when it crashes?

@Costas actually I don’t know how to telnet inside the router thru an ESP 8266. Consider that my network is composed only by an AT mega 328, an ESP 8266 and this router, because it is a monitoring system implemented for a remote site

https://petestechprojects.wordpress.com/2014/11/30/simple-communication-through-esp8266-wifi-module/ this Blog mentions a Telnet server on the ESP, but it could be a start. I’m not sure how much Blynk will be “fubar” if you start running your own AT commands while blynk is running, but its worth trying in a local setup I guess.

@Lichtsignaal Thanks, I’ll try !! :slight_smile:

What state is the router in when it “stops working”?
Is the 3G failing but the router still running perhaps?
Your manual indicates telnet access is available. In theory a simple shell script could be put on the router and called at intervals with crontab to reboot it if fails to ping google DNS. Obviously this would only work if some parts of the router are still functioning correctly.

@Xandr has just posted a link to a script that would do the job for you.

@Costas Hi Costas, sorry for the delay in my answer but in this period I stay on holidays :sunglasses:
I don’t remember which is the connection status of the router when the issue occours, anyway I strongly believe that the problem is relevant to the SIM Card because changing the type of SIM Card the frequency of the issue varies.
As regards the router, it is still working because it is enough to press the power switch for 1 second to restabilish the connection (when the router is completely down it is necessary to press the power button for 5 seconds).
Anyway the systen that I’ve implemented is very effective but the problem is the wire bonding on the terminals of the power switch that are located on a tiny flexible connector. For this reason I’m still interested to a software solution.
I have had a look at Xandr’s script but I don’t know how to launch it because I don’t have a PC within the system. The system is composed only by an AT Mega 328, an ESP 8266 and this 3G router. Nothing else. The script should be inserted in the sketch of the AT Mega as:
if (!Blynk.connected())
{
script code …
}

But I don’t know how to do it (I’m more an hardware guy than a software person). Could you help??
Ciao,
Giancarlo

@Gianca my TPLink routers only have Telnet up until the first bootup and then it is disabled but I believe your router may have a permanent Telnet connection. With Gargoyle I am supposed to be able to enable Telnet permanently but it didn’t work when I tried.

I have tried a Telnet session from the ESP to my Pi and a Telnet server in the US (scn.org) but with limited success. I am struggling with the correct parameters to send from the ESP but it should be doable.

Similarly you should be able to do it via http from the ESP to 192.168.0.1 with admin username and admin password (unless you have changed them) and then to the reboot url. I haven’t tried this yet with my router and I again I am a bit ropey with the commands I need to send from the ESP.

Presumably you have a Smartphone, is it Android or iOS?

On my Android Smartphone I have this simple Telnet Client https://play.google.com/store/apps/details?id=jackpal.androidterm

Can you try to Telnet into your router from your Smartphone:

Just type telnet 192.168.0.1 in the Smartphone console and then it should ask for username and password. If we know Telnet is available then we should be able to give you a simple script to put on the router until we are able to give you and ESP Telnet / http fix.

My routers are all unlocked with the Gargoyle firmware but it might be that you can’t write anything to your filesystem even when you make a Telnet connection. That said it if allows Telnet then maybe you can.

@Costas Thanks indeed for your attention !!

@Gianca you can also try to SSH from your Smartphone to the router. I’m using this app https://play.google.com/store/apps/details?id=org.connectbot as I can’t activate Telnet on my router.

@Costas Uhmm !! I’ll try !! Thanks

hello,
i own an uno and an esp8266 connected via softserial. all works great with blynk except when the connection drops either to blynk server either to the router or to the internet. in that case the blynk function just retries to connect to server no matter if the wifi connection is down. so i would like the code that is descriped in this tthread writen for my hardware (uno+esp8266 via softserial). thats because i think that my hardware does not support MyWifi function just AT commands.
Thanks in advance and sorry for my English.
!

@liq you want your Uno to continue running if the internet is down, right?

Blynk have made changes recently regarding the connection process but in loop() you should be ok with:

  if (Blynk.connected()) { // Blynk.run() is only called if connected to the server
    Blynk.run();
  }

Costas , thanks for the reply. i think that something is wrong with the Blynk.begin function.
i dont Know how to post my entire sketch, anyway
when Blynk.begin (auth,ssid,psw) is called in void setup if the wifi is not available at this moment this function goes into an infinite loop and the code does not advance further. Here is what esp sends to uno when (Blynk.begin(auth, wifi, ssid, pass, “139.59.206.133”):wink: when wifi not found:

ATE0
AT+GMR
AT+CIPMUX=1
AT+CWMODE?
AT+CWJAP=“XXXXX”,“XXXXXX”
AT+CIPCLOSE=1
AT+CIPCLOSE=1
AT+CIPSTART=1,“TCP”,“139.59.206.133”,8442
AT+CIPCLOSE=1
AT+CIPSTART=1,“TCP”,“139.59.206.133”,8442
AT+CIPCLOSE=1
AT+CIPCLOSE=1
AT+CIPSTART=1,“TCP”,“139.59.206.133”,8442
AT+CIPCLOSE=1

etc…
so the code hangs there…
as soon as wifi becomes available it does not unstuck because the “AT+CWJAP=“XXXXX”,“XXXXXX”” is need in order to connect to wifi and then the
“AT+CIPSTART=1,“TCP”,“139.59.206.133”,8442” inorder to connect to blynk cloud
that is the no1 bug that i spotted
i could run blynk.begin in a timed loop but the “at+cipstart…” continues forever so the code hungs.
no2 is that sometimes the “AT+CIPSTART=1,“TCP”,“139.59.206.133”,8442” command is send but because “mux=0” , the command fails. (i ll write details in future post)

i find blynk a very cool , unique , powerful and simplified project that if some stability isues were resolved it would be the best available out there.
thanks in advance

In my opinion it already is :slight_smile:

In the last week or so Blynk introduced a blocking routine for Blynk.begin() and generally most users will benefit form it. Without the blocking some of the code directly after Blynk.begin() wasn’t being processed correctly.

As you have found the blocking can also be a problem but there are ways to overcome it.

Even though I have used AT commands for around 30 years it’s something I try to avoid i.e. I have ESP’s that can be used as a shield for my Arduino’s but I almost never use them as working with ESP’s in standalone mode is my preferred set up.

What you need to do is make a WiFi connection with the regular Arduino functions before connecting to Blynk. Then instead of using Blynk.begin() you use Blynk.config() which circumnavigates the new blocking routine.

@Liq as an aside I stumbled across “mux” in some code I was looking at a few days ago. The code was “AT based” and I was looking to convert it to “ESP standalone format”. Are you familiar with “mux”?

when i use Blynk.config(auth); function “BlynkSimpleShieldEsp8266.h:160:10: note: void BlynkWifi::config(ESP8266&, const char*, const char*, uint16_t)” so no solution… :frowning:
When i say mux=0 i mean esp is running in single connection mode
see: “AT+CIPMUX - Enable multiple connections or not”
as you can see i am new to all this and i don’t know if i can help you somehow
anyway i ve order new wemos boards so if there is no solution for my hardware i ll move on…

@Liq thanks, I’ll dig into “mux” when I have a minute.

Notice an error in my last post. It should have said was make an ethernet, not WiFi connection.

The compiler error is telling you that you now need 2 variables for the Blynk.config() function. I think it was just the token variable previously. Let me check here if Blynk.config() will work with ENC.

I am going mad!!! In your case it is WiFi not Ethernet and nothing to do with ENC (that is the ENC28J60 thread).

For the second variable in Blynk.config() after token just try “blynk-cloud.com” (assuming you are using Blynk’s cloud server).

Blynk.config(auth,“blynk-cloud.com”);

no known conversion for argument 1 from ‘char [33]’ to ‘ESP8266&’
BlynkSimpleShieldEsp8266.h:160:10: note: void BlynkWifi::config(ESP8266&, const char*, const char*, uint16_t)
void config(ESP8266& esp8266,
^
exit status 1
no matching function for call to ‘BlynkWifi::config(char [33], const char [16])’

try to relax i am newbie to all these. maybe i am making an rookie mistake such as “turn the power switch on”…