#define BLYNK_TEMPLATE_ID "TMPL4_o61dOV4"
#define BLYNK_TEMPLATE_NAME "IOT"
#define BLYNK_AUTH_TOKEN "7V4fyAAt0eWdO_Xr37gBOn-G9vnbqwij"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST"; // Your WiFi SSID
char pass[] = ""; // Your WiFi Password
int fuse , plug;
const int relay = 13;
const int relayPlug = 12;
#define VIRTUAL_FUSE V0
#define VIRTUAL_PLUG V1
BlynkTimer timer;
void setup() {
Serial.begin(115200);
pinMode(relay, OUTPUT); // Set the pin as output
pinMode(relayPlug, OUTPUT);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, sendStatus);
}
void loop() {
Blynk.run();
timer.run();
// Read the state of the push button
fuse = digitalRead(relay);
plug = digitalRead(relayPlug);
// Update the Blynk app with the switch state
delay(1000);
}
void sendStatus(){
Blynk.virtualWrite(VIRTUAL_FUSE, fuse);
Blynk.virtualWrite(VIRTUAL_PLUG, plug);
}
BLYNK_WRITE(VIRTUAL_FUSE)
{
int state = param.asInt(); // Get the state of the switch from the Blynk app
digitalWrite(relay, state); // Set the state of the pin
digitalWrite(relayPlug, 0);
}
BLYNK_WRITE(VIRTUAL_PLUG)
{
int state = param.asInt();
int fuseState = digitalRead(relay);
//Serial.println(fuseState);
if (fuseState == HIGH ){
digitalWrite(relayPlug, state);
}
}