Nodemcu deep sleep and auto wake up

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.
  
}

@dimin21590 have you tried searching this site and the wider internet with a search engine like Google?

Suggest “ESP deepSleep” as a search term. Loads of info available.

Yes I tried but I couldn’t find this information. And also the nodemcu did not responded after starting the sleep process.It just stuck!

ESP sleep mode is not a Blynk specific issue.

https://www.google.com/search?q=ESP+deepSleep&oq=ESP+deepSleep&aqs=chrome..69i57j69i60l3&sourceid=chrome&ie=UTF-8#newwindow=1&q=esp+deepsleep

This finds many topics… which one are you not “finding”?

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();
}
#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[] = "8204b80f3xxxxxxxxxxxxxxccf77312874";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "TP-LINK_dll";
char pass[] = "210379dima";

BlynkTimer timer;

WidgetLED led1(V3); // Virtual LED on Virtual Pin 3

BLYNK_CONNECTED() {     
    Blynk.syncAll(); // Request Blynk server to re-send latest values for all pins
}


BLYNK_WRITE(V1) // Button Widget Attached to Virtual Pin 1
{

if (param.asInt()){
 digitalWrite(0, HIGH);
} 
else {
digitalWrite(0, LOW);
}

}

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(){

ESP.deepSleep(5 * 60 * 1000000); //sleep for 5 minutes

}


void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);

pinMode(0, OUTPUT); //
digitalWrite(0, LOW); // Set GPIO 0 LOW

 timer.setInterval(1000L, analogCheck); //Check Analog Pin Every 1 second
 timer.setInterval(5000L, goToSleep); //trigger deep sleep command after 5 seconds

}

void loop()
}
Blynk.run();
timer.run();
}
1 Like

Thank you for te code first it isnt the code i wanten but newer mind and secund it returns me an error

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.

1 Like

@dimin21590, Still awaiting your code. I am curious as to what you were actually trying to accomplish.

I am realy sorry but in my town for the last 2 days I have no electricity. If I will be ready i will definetly post it there.

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();
}

and the circuit

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 :wink:

I have already edited your above post, please look back at how it was done.

Thank you.

First off please format the code with triple back ticks. ```

Your code doesn’t include deep sleep. Please search the forum and if you still have questions ask on the functions that don’t make sense…

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:
```

Pete.

A post was split to a new topic: Deep Sleep Door lock