Arduino doesn't work offline

Board: Arduino Mega 2560
Connection : ESP8266 WIFI Shield
Blynk: for Android


I made a simple code for light up and turn off the LED by using real button, I also have button in the Blynk app for switching the same diode.

My problem is that arduino does not react on “real” button until connecting to wifi is already done, it takes about 10 seconds. I mean this:

    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.4 on Arduino Mega

[599] Connecting to lol
[3648] AT version: 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.
Jun 13 2016 11:29:20
[4733] Failed to enable MUX
[9778] +CIFSR:STAIP,""
[9786] Connected to WiFi
[20222] Ready (ping: 12ms).

Second problem is, when I power up or reset arduino and hotspot is currently not available. Of course I get report :

[13758] Failed to connect WiFi

but after unsuccessfull conection I still can’t work offline by using real push button. Procces is somewhere stopped and waiting for a wifi connection.

My code:

#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = "***";
char ssid[] = "***";
char pass[] = "***";
#define EspSerial Serial1
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);
BlynkTimer timer;
void myTimerEvent()
   Blynk.virtualWrite(V5, millis() / 1000);

int button;
int led;
void setup()
  pinMode(50, INPUT);
  pinMode(22, OUTPUT);
  digitalWrite (22, LOW);

  // Set ESP8266 baud rate

  Blynk.begin(auth, wifi, ssid, pass);
  timer.setInterval(1000L, myTimerEvent);

void loop()
  button = digitalRead(50);
  led = digitalRead(22);
  if (button == LOW) {
    if (led == LOW ) {
      led = HIGH;
    else {
      led = LOW;
    digitalWrite(22, led);
    while (digitalRead(50) == LOW) {
      delay (50);
  };; // Initiates BlynkTimer

So i want switching diod with real push button and Blynk button (it works). And using real button, when wifi is not connected ( doesn’t work). And if it is possible using real button when arduino with esp-01 is just connecting to wifi hotspot ( doesn’t work).

The solution will probably be very simple, but i am beginner in arduino programming and programming at all :smiley:

Thanks for your ideas…

When I put in void loop:


I can see loop really doesn’t run before wifi is connected.

[9786] Connected to WiFi
[20189] Ready (ping: 12ms).

and when hotspot is offline loop doesn’t even start.

[13759] Failed to connect WiFi

This is heavily discussed topic on the forum that would have been found with a little searching first (as is also recommended throughout this forum) :stuck_out_tongue_winking_eye:

Blynk.begin() is a blocking command… no server connection no further processing… setup your wifi independently and use Blynk.config() if you wish network independent operation.

1 Like