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

Arduino doesn't work offline

esp8266
#1

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

Hello,

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:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.
Jun 13 2016 11:29:20
OK
[4733] Failed to enable MUX
[9778] +CIFSR:STAIP,"192.168.43.75"
+CIFSR:STAMAC,"84:f3:eb:b1:29:f8"
[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);
  Serial.begin(9600);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

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

void loop()
{
  button = digitalRead(50);
  led = digitalRead(22);
  //Serial.print(button);
  if (button == LOW) {
    if (led == LOW ) {
      led = HIGH;
    }
    else {
      led = LOW;
    }
    digitalWrite(22, led);
    while (digitalRead(50) == LOW) {
      delay (50);
    }
  }
  Blynk.run();
  timer.run(); // 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…

0 Likes

#2

When I put in void loop:

Serial.print(button);

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

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

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

[13759] Failed to connect WiFi
0 Likes

#3

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.

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

http://docs.blynk.cc/#blynk-firmware-connection-management

1 Like