Hi. Today I received my nodemcu board. I bilded my first project with Blynk. Everything was OK. But this sould be a devise that is always pluged in to the wall. So the energy consuming shuld be minimal. S decided to edit my code that the board updates ad than goes in a deep sleep mode for a minute and than it should be updated again a so for a loop. I tried a few deep sleep configurations but it hasnt worked. Anyways thank’s for the help and sorry for my bad english.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "my code";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xx";
char pass[] = "xx";
BlynkTimer timer;
// V3 LED Widget represents the physical button state
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
if(analogRead(0)>400){
Blynk.virtualWrite(3, 1023);
}else{
Blynk.virtualWrite(3, 0);
}
Blynk.run();
timer.run();
here it shoul sleep for a minute and than update again.
}
Ok I found a good deep sleep guide and anything woked well. But the Blynk service work’s quite strange for example if you preess the button or slider or anything else on your smartphone it goes through the Blynk server and tan gives to the Nodemcu or any device the command to do something. But if the devise was offline and you changed the position of the button from 0 to 1 and than the board gets online it wouldn’t receive this. So my question is: is there a functuin that check’s the status that is right now. For example I pressed a button and now it’s in 1 position but the board was offline. Than in a few seconds it becomes online and ask’s the server:
Device: Hey server is there some data for me?
Server: Yes here is some data. The button is now 1.
If not that will be really bad for devices that are powered by a battery or are parts of a smart home becouse the energy consuming if 100mah or 0.5w/h isn’t really effective…
Thank you very much. Bu there is a new problem with the program.
Now i tried to activate an LED for the future sleep mode by button activation mode
by a button on a virtual pin and now using the oficial code examples nothing even woks
here is a code where the led attaced to pin 0 sould bo ON if the button is pressed and OFF if it’s not `
#define BLYNK_PRINT Serial
include "ESP8266WiFi.h"
include "BlynkSimpleEsp8266.h"
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "8204b80f3exxxxxxxxxxxxxdccf77312874";
int pinData = 0;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "TP-LINK_dll";
char pass[] = "210379dima";
BlynkTimer timer;
boolean button = 0;
// V3 LED Widget represents the physical button state
BLYNK_WRITE(V1)
{
if (param.asInt()){
button = 1;
} else {
button = 0;
}
// process received value
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop(){
if(button==1){
digitalWrite(0, HIGH);
}else{
digitalWrite(0, LOW);
}
if(analogRead(0)>400){
Blynk.virtualWrite(3, 1023);
}else{
Blynk.virtualWrite(3, 0);
}
Blynk.run();
timer.run();
}
Well I am not sure what you are looking for then. I basically just took your code, made it work with BLYNK, and added the deepsleep function. I fixed the error, I forgot a bracket.
Please post your working code so I can see what you were trying to accomplish.
Hi today I am finaly redy with my project. It is a Wi-Fi relay module. I made it to have access to my computer from anywhere. I added an auto deep sleep and an option to stop the sleep from my phone.
Here is the source code
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "8204b80f3exxxxxxxxxxdccf77312874";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "my name";
char pass[] = "my pass";
boolean sleep = 0;
BlynkTimer timer;
WidgetLED led1(V3); // Virtual LED on Virtual Pin 3
WidgetLED led2(V2); // Virtual LED on Virtual Pin 3
BLYNK_CONNECTED() {
Blynk.syncAll(); // Request Blynk server to re-send latest values for all pins
}
void analogCheck(){
if(analogRead(0) > 400){
led1.on(); //Turn ON LED
led1.setValue(255); //set brightness of LED to 100%.
}
else{
led1.off(); // Turn OFF LED
}
}
void goToSleep(){
if(digitalRead(12)!=1){
led2.off();
ESP.deepSleep(60 * 1000000);
}else{
led2.on(); //Turn ON LED
led2.setValue(255); //set brightness of LED to 100%.
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, analogCheck); //Check Analog Pin Every 1 second
timer.setInterval(5000L, goToSleep); goToSleep; //trigger deep sleep command after 30 seconds
}
void loop()
{
Blynk.run();
timer.run();
}
When posting code, please format it properly with the three backticks at the front and end of code, as described here. so that is is properly viewable.
And recommended that you block out your auth code
I have already edited your above post, please look back at how it was done.
Please edit your code using the pencil icon at the bottom and add triple backticks at the beginning and end of your code.
Triple backticks look like this:
```