I’m working on a project using an ESP8266 module with Blynk to connect to WiFi. However, I’m facing an issue: if there’s a power cut and the WiFi disconnects, I need a way to receive notifications. Additionally, I want the ESP8266 to automatically reconnect to Blynk once the power is restored.
Has anyone here tackled a similar problem or have any suggestions on how to achieve this? Any advice or code snippets would be greatly appreciated!
Thanks in advance!
code here
#define BLYNK_TEMPLATE_ID "TMPL63XbV8BX7"
#define BLYNK_TEMPLATE_NAME "HOME"
#define BLYNK_AUTH_TOKEN "------------"
#define BLYNK_PRINT Serial
#include "MapFloat.h"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
int led1=14;
int led2=15;
int value=A0;
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Test"; //your hotspot name
char pass[] = "123456789"; //your hotspot password name
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(value, INPUT);
delay(10);
}
void loop() {
Blynk.run();
float voltagevalue = analogRead(value);
Serial.print("A0 value: ");
Serial.println(voltagevalue);
if (voltagevalue <30){
voltagevalue = 0;
}
else
voltagevalue = mapFloat(voltagevalue, 0, 1024, 0, 15.8);
Blynk.virtualWrite(V0, voltagevalue);
Serial.print("voltage value: ");
Serial.println(voltagevalue,4);
delay(1000);
}
BLYNK_WRITE(V1){
int pinValue = param.asInt(); // assigning incoming value from pin V0 to a variable
digitalWrite(led1,pinValue);
}
BLYNK_WRITE(V2){
int pinValue = param.asInt(); // assigning incoming value from pin V0 to a variable
digitalWrite(led2,pinValue);
}
@Nithurshan 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.
@Nithurshan please edit your post and replace the screenshot with the text copied from your serial monitor, and use triple backticks at tge ebgin8ng and end when you paste it into your post, as I said here…
Your serial output shows the device connecting correctly to Blynk, so I’m not really sure why you’ve posted it. I’d expected you to post serial output of the device failing to re-connect to Blynk after a power outage.