How to let device working without WIFI connection?

I have the sketch its work fine now, and I try to combine it with Blynk and it also work fine now while WIFI connected.
but I need to let its continue work even my WIFI router is down.
I’v try to search and try to

 while (Blynk.connect() == false) { 
     if((millis() / 1000) > mytimeout + 8){  // try for less than 9 seconds
       break;

still not work.

 #define BLYNK_PRINT Serial
 #include <ESP8266_Lib.h>
 #include <BlynkSimpleShieldEsp8266.h>
 
 // You should get Auth Token in the Blynk App.
 // Go to the Project Settings (nut icon).
 char auth[] = "xxxx";
 
 // Your WiFi credentials.
 // Set password to "" for open networks.
 char ssid[] = "xxxx";
 char pass[] = "xxxx";
 
 // Hardware Serial on Mega, Leonardo, Micro...
 #define EspSerial Serial
 
 // or Software Serial on Uno, Nano...
 //#include <SoftwareSerial.h>
 //SoftwareSerial EspSerial(2, 3); // RX, TX
 
 // Your ESP8266 baud rate:
 #define ESP8266_BAUD 115200
 
 ESP8266 wifi(&EspSerial);
   long previousMillis = 0;
   long rept=36000;
   long interval=9000;
 void setup()
 {
 pinMode(2, OUTPUT);
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(5, OUTPUT);
   // Debug console
   Serial.begin(9600);
   //int Le1 =12;
   // Set ESP8266 baud rate
   EspSerial.begin(ESP8266_BAUD);
   delay(10);
   Blynk.begin(auth, wifi, ssid, pass);
   // You can also specify server:
   //Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 8442);
   //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8442);
 
  }
 
 void loop()
 {
 unsigned long currentMillis = millis();
   if(currentMillis - previousMillis > rept) 
   {
     digitalWrite(2, HIGH);
     if(currentMillis - previousMillis > rept+interval)
     {
       digitalWrite(2, LOW);
       digitalWrite(3, HIGH);
       if(currentMillis - previousMillis > rept+interval+interval)
       {
         digitalWrite(3, LOW);
         digitalWrite(4, HIGH);
           if(currentMillis - previousMillis > rept+interval+interval+interval)
           {
             digitalWrite(4, LOW);
             digitalWrite(5, HIGH);
              if(currentMillis - previousMillis > rept+interval+interval+interval+interval)
               {
               digitalWrite(5, LOW);
               previousMillis = currentMillis; 
               }
           }
        }  
     }
   }
 Blynk.run();
 }

Thanks in advance

You need to integrate BlynkTimer, move much of your running code into a timed loop instead of in the void loop() and then add in the connection management commands… search this forum for keywords like connection management for more examples.

http://docs.blynk.cc/#blynk-firmware-blynktimer

http://help.blynk.cc/

1 Like

@Gunner did I see a library hack on the forum recently for connection management of ESP shield’s?

Yes… I finally found it :slight_smile: However it was more a “reset if not connected”, then a “keep running code when not connected” thing.

I have tried to search connection management

 #define BLYNK_PRINT Serial
 
 
 #include <ESP8266_Lib.h>
 #include <BlynkSimpleShieldEsp8266.h>
 BlynkTimer timer;
   long previousMillis = 0;
   long rept=36000;
   long interval=9000;
 #define EspSerial Serial
 
 // or Software Serial on Uno, Nano...
 //#include <SoftwareSerial.h>
 //SoftwareSerial EspSerial(2, 3); // RX, TX
 
 // Your ESP8266 baud rate:
 #define ESP8266_BAUD 115200
 
 ESP8266 wifi(&EspSerial);
 
 void setup()
 {
 pinMode(2, OUTPUT);
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT);
   // Debug console
   Serial.begin(9600);
 
   delay(10);
 
   // Set ESP8266 baud rate
 }
 
 void loop()
 {
   timer.run();
   Blynk.run();
   unsigned long currentMillis = millis();
   if(currentMillis - previousMillis > rept) 
   {
     digitalWrite(2, HIGH);
     if(currentMillis - previousMillis > rept+interval)
     {
       digitalWrite(2, LOW);
       digitalWrite(3, HIGH);
       if(currentMillis - previousMillis > rept+interval+interval)
       {
         digitalWrite(3, LOW);
         digitalWrite(4, HIGH);
           if(currentMillis - previousMillis > rept+interval+interval+interval)
           {
             digitalWrite(4, LOW);
             digitalWrite(5, HIGH);
              if(currentMillis - previousMillis > rept+interval+interval+interval+interval)
               {
               digitalWrite(5, LOW);
               previousMillis = currentMillis; 
 
               }
           }
        }  
     }
   }
 if (Blynk.connected()==false)
 {
 char auth[] = "xxxxxx";
   char ssid[] = "xxxxxx";
   char pass[] = "xxxx";
     EspSerial.begin(ESP8266_BAUD);
     delay(10);
     int mytimeout = millis() / 1000;
     Blynk.begin(auth, wifi, ssid, pass);
     while (Blynk.connect() == false) { 
     if((millis() / 1000) > mytimeout + 8){  // try for less than 9 seconds
       break;
     }
   }
 
 }
 }

look like,
Its need a first time to connected WIFI for make my program succeed.
If no first time WIFI connected its do nothing.

I think

struck in loop Blynk.begin(auth, wifi, ssid, pass); of #include <BlynkSimpleShieldEsp8266.h>

How to seperrate this function of BlynkSimpleShieldEsp8266.h Library to

  1. wifi connecting and 2.blynk connecting

limited connecting time of Blynk.begin

sorry for my bad English

Then you missed the part about using Blynk.config() instead of Blynk.begin()

Opps… just noticed (again) that you seem to be using Arduino with ESP as a shield…

OK, many of the connection management methods don’t work properly with the shield library. Probably because they require to be running ON an ESP… but when used as a shield, the ESP is just a separate Serial to WiFi adapter and all code runs ON the Arduino.

Hello Blynkers,. I’m a beginer and I have the project and I’m using Ethernet shield and Arduíno Mega, I did the routine If (Blynk.connected()){Blynk.run} and the reconnection routine too, and now, when dont have internet the code with physical buttons Works well, but, Just we had a fisrt internet connection,… When I energized arduíno without internet the code dosent Works .
How Can I solve this problem?

Thanks

Can you clarify exactly what this statement means please?
It would also be useful if you posted your code, correctly formatted with triple backticks at the beginning and end.
Triple backticks look like this:
```

Pete.