Esp8266 and Blynk project with sleep mode

Hi dear Blynkers,
I’m new here and I need help for my project.
I use ESP8266 as a weather and control station for my plants, which actually works quite well.
The ESP8266 will later be battery operated and would add a sleep mode in the following zenario:
1- Between 06:00 and 22:00 o’clock he should send values ​​to blynk every hour and then go into deep sleep mode.
2- between 22:00 and 06:00 o’clock he should go deep sleep mode the whole time
Thank you

Here my code


#define BLYNK_PRINT Serial  
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include "DHT.h"

#define DHTPIN D3 
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE); 

#define soilMoisterPin A0
#define soilMoisterVcc D8

SimpleTimer timer;

char auth[] = "auth"; //
char ssid[] = "ssid";
char pass[] = "pass";

void setup()
{
  Serial.begin(115200);
  pinMode(soilMoisterVcc, OUTPUT);   
  digitalWrite (soilMoisterVcc, LOW);
  
  Blynk.begin(auth, ssid, pass, IPAddress());
  
  timer.setInterval(2000, getDHT);
  timer.setInterval(2000, getSoilMoister);
}

void getDHT(void)
{
  float airTemp = dht.readTemperature();
  float airHum = dht.readHumidity();
  if (isnan(airHum) || isnan(airTemp))   // Check if any reads failed and exit early (to try again).
  {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Blynk.virtualWrite(1, airTemp); //
  Blynk.virtualWrite(2, airHum); // 
}

void getSoilMoister(void)
{
  int soilMoister = 0;
  digitalWrite (soilMoisterVcc, HIGH);
  delay (500);
  int N = 3;
  for(int i = 0; i < N; i++) // read sensor "N" times and get the average
  {
    soilMoister += analogRead(soilMoisterPin);   
    delay(150);
  }
  digitalWrite (soilMoisterVcc, LOW);
  soilMoister = soilMoister/N; 
  soilMoister = map(soilMoister, 1024, 520, 0, 100); 

  Blynk.virtualWrite(3, soilMoister);
  
}

void loop()
{
  Blynk.run();
  timer.run();
}

What have you tried so far?

I’m a beginner in programming with ESP8266/Arduino and i was hoping you can give me a tip to solve the problem !?

You don’t have a problem yet as you haven’t tried it.

But I’d suggest studying the RTC widget and the Time library. Sync time and put your device to sleep.

First of all you’ll need to wire GPIO16 to the RST pin as this pin is used to wake up the ESP. Now, the problem is, that the ESP can go into deep sleep for a max of ~71 minutes so you’ll need to take that into account. Than you can use ESP.deepSleep(20e6);
where 20e6 means 20s as you need to enter the time in us (micro seconds). Try some reading on the topic, than test this and only if it works upgrade the code with blynk or you’ll get lost very soon :grinning:

The new core release can make esp8266 sleep longer https://github.com/esp8266/Arduino/pull/4627