I’m using a nodemcu and 4 Channel Relay to control my bedroom lights and fan.
But every time the power goes out the relay turns off all the connected appliances and never turns them back on automatically. I read somewhere that blynksyncall can help solve this problem. If this is so can someone please help me integrate this into my existing code.
I don’t know anything about coding so couldn’t do it myself.
I’m pasting my existing code, can someone please help me integrate blynksyncall() into this so everything turns back on as it was before the power went out.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "AuthCode"; // the auth code that you got on your gmail
char ssid[] = "ssid"; // username or ssid of your WI-FI
char pass[] = "password"; // password of your Wi-Fi
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(D1,OUTPUT); //extend these to D8 if you are using a 8 pin relay
pinMode(D2,OUTPUT);
pinMode(D3,OUTPUT);
pinMode(D4,OUTPUT);
digitalWrite(D1,HIGH); // Make it low if you want everything to go off
digitalWrite(D2,HIGH); // in case of a power cut
digitalWrite(D3,HIGH);
digitalWrite(D4,HIGH);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}
Many other users (including some of us regulars) have bent to the task of learning how to code enough to be useful in our projects… I suspect you can do it as well Particularly as what you are asking us to do is simply copy/paste for you… how hard can that be for you to do?
EDIT, that above recommended function is just that… a stand alone function… simply paste it in somewhere between the void setup() and void loop() functions
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "AuthCode"; // the auth code that you got on your gmail
char ssid[] = "ssid"; // username or ssid of your WI-FI
char pass[] = "password"; // password of your Wi-Fi
BLYNK_CONNECTED() {
// Request Blynk server to re-send latest values for all pins
Blynk.syncAll();
}
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(D1,OUTPUT); //extend these to D8 if you are using a 8 pin relay
pinMode(D2,OUTPUT);
pinMode(D3,OUTPUT);
pinMode(D4,OUTPUT);
digitalWrite(D1,HIGH); // Make it low if you want everything to go off
digitalWrite(D2,HIGH); // in case of a power cut
digitalWrite(D3,HIGH);
digitalWrite(D4,HIGH);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}
The concept of “between” is not rocket surgery or brain science Here are a couple of user functions “between” the void setup() and the void loop() functions (NOTE, they will generally run almost anywhere, before, after, all of the above… but this is subjectively better programming form).
void setup() {
// Setup stuff here, runs once at boot
}
void MyFunction() {
// Random function stuff here that runs when it gets called by the command MyFunction();
// Your code is built up of many of these, named and doing different things as needed
}
BLYNK_CONNECTED() {
// Stuff that runs once upon server connection... like Blynk.syncAll()
}
BLYNK_WRITE(V0) {
// Do stuff here whenever the state changes on the widget applied to vPin 0
}
void Loop() {
// Main loop stuff here - avoid clutter and delay() as this runs (loops) thousands of times a second
}
So you just couldn’t copy paste a simple few lines code instead you started yammering and typed like a page worth of stuff that’s not useful to me?
Boy I’m 76 years old. I don’t need to learn new stuff now. I just needed a little help in my project and all I asked was for you to merge 2 codes written above together in a way that it’ll work for me without any issues.
Is that too much to ask?
This wise(ish) old fart says… Give a man code and you pacify him for a day. Teach a man to think and he should be a little less of a grumpier old fart and learn a thing or two
Since you apparently haven’t read much in this forum, you probably are not aware of this forum fact… we try our best to help people learn… we do NOT respond well to being asked to be someones code monkey.
Apparently you’re always on this forum to troll guys asking for help. I’m guessing you don’t have a job son. Maybe you should get off your butt and get a job instead of doing this all day long.
So far the only troll here had been yourself… and to paraphrase… in the time it has taken you to argue about my providing valued suggestions and information to both yourself and anyone else keen enough to read and learn… you could have copy pasted your simple few lines and moved onto whatever “not learning” you do all day