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();
}
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.
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?
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:
```