I want Esp8266 Module will not give any output if it is disconnected from wifi network

Suppose I have programmed my esp8266 module to control LED light (On/Off control) via Blynk .

It will work perfectly while connected to Blynk via WiFi. But the problem starts when ESP8266 is disconnected from WiFi, it continues writing the last data it received from Blynk app or website. If I turn the LED on and disconnect ESP8266 from wifi, the LED kept turned on by ESP8266. Now I want, if I disconnect ESP8266 from wifi, it will do nothing to the LED. Means ESp8266 will be like “shut down” if it is disconnected from internet.

Even, if you can able to write a code, that will tell ESP8266 to reset(turn off, then turn on again) it self when disconnected from wifi, Will be helpful for me.

Thank you so much Sir, for your valuable time…

You would use a timer to run a function which checks if Blynk.connected() = false.

If it is false then you know that your device is no longer connected to the Blynk server and you can take the appropriate action.

It actually takes around 18 seconds from the Blynk connection being dropped to Blynk.connected() to change from true to false.

If you want a speedier response when the disconnection is caused by WiFi or internet failure then you could check if you are connected to WiFi using the WiFi.status() != WL_CONNECTED test, but this alone won’t handle situations where the Blynk server can’t be reached.

Of course, you’ll probably want your sketch to try to reconnect to Blynk at some point, and how you do that would depend on how you’ve written your sketch, how you manage your Blynk connection, and whether you want to add any physical buttons to your device to give manual control.

Pete.

1 Like

Sir, My sketch is:

#define BLYNK_TEMPLATE_ID “xxxxxxx”
#define BLYNK_DEVICE_NAME “Rc Receiver”
#define BLYNK_AUTH_TOKEN “xxxxxxx”
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

#include <Servo.h>

Servo servo1;

char auth[] = “xxxxxx”;

char ssid[] = “Virus”;

char pass[] = “415362892472”;

void setup()

{

Serial.begin(9600);

Blynk.begin(auth, ssid, pass);

servo1.attach(15); // NodeMCU D8 pin

}

void loop()

{

Blynk.run();

}

BLYNK_WRITE(V1)

{

servo1.write(param.asInt());

}

I want that, the ESP8266 will no run If wifi connection drops or Blynk server connection does not work, then .

@Ibn_Binte Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

1 Like

Any reason why you didn’t edit post #3 as requested?

Pete.

1 Like

OHHH…okay…now i am editing…actually i thought that, it will be more easier for you to understand if i type only the code…so that i did not edit post #3 …but i am doing it now as your wish sir…

.
.
.
  timer.setInterval(500L, CarStream);

  .
  .
  .
  .
BLYNK_WRITE(V12)
  { block_driv = 0;
  }
  .
  .
  .
  void CarStream() 
{
  .
  .
   { block_driv++;
   if (block_driv > 3) // if delivery is missed more than 3 times, we stop car
    {
      digitalWrite(AIN1, LOW);      
      digitalWrite(AIN2, LOW);
    }
   if (block_driv > 120) // if delivery over communication channel is missed for more than a minute 
    { ESP.deepSleep (30e6); // we go to sleep for 30 seconds, then we start as standard                  
    }
   if (block_driv < 6) // continue if channel is healthy or loss is <6, otherwise we will overflow buffer with sends
    { Blynk.virtualWrite(V12, 0); // BLYNK automatic, if "0" comes from car and after "1" comes, then
      Blynk.virtualWrite(V12, 1); // BLYNK sends message to V12 to reset "block_driv"
    }

I drive cars by video in another city and if the connection is lost, it stops after 2 seconds. Works 2 years. Automation is configured as a sensor and control.