BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Deep Sleep Door lock

History

prathamesh_bakliwal just now

Hello,
I want to use deep sleep with esp 8266 attached to my door lock.
When I press the button on the blynk app it should open and after some time it should go to deep sleep and when again I press the unlock button it should directly reboot and the board after getting started should unlock the door.
Can anyone help me with this please?

Code-

#include <BlynkSimpleEsp8266.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <EEPROM.h>
#include <Servo.h>

Servo myservo;

char auth[] = “BNzkxxxxxxxxxxxxxxxFxEpXwxxxxxxR”;

void setup()
{
EEPROM.begin(512);
Serial.begin(115200);
myservo.attach(0);
myservo.write(180);
WiFiManager wifiManager;
wifiManager.autoConnect(“NodeMCU”);
Serial.println(“connected…:)”);
pinMode(LED_BUILTIN, OUTPUT);
Blynk.begin(auth, WiFi.SSID().c_str(), WiFi.psk().c_str());
}

BLYNK_WRITE(V2)
{
int pinValue = param.asInt();
Serial.print("V1 Slider value is: ");
Serial.println(pinValue);
Blynk.virtualWrite(V0, “Door State”);
if(pinValue)
{
Blynk.virtualWrite(V1, “Open”);
servo();

}else
{
Blynk.virtualWrite(V1, “Closed”);
myservo.write(180);
}

}

void loop()
{
Blynk.run();

}```

I’ve moved this to a new topic.

Deep Sleep on the ESP8266 and Blynk don’t mix well, unless your project is designed to wake-up occasionally, take some readings and upload them to the Blynk server, then go back to sleep.
Your BLYNK_WRITE(V2) callback function will never be called while the device is sleeping, because the device isn’t connected to the Blynk server and therefore will be unaware that the button in the app has been pressed.

Pete.

Is it not possible to make nodemcu to go to deepsleep and wake up when A button is pressed in the Blynk app, then I will Connect to the Server and check if there is any changes since it went to sleep ??
Also I have updated my Code to sync to last state after power failure, in this case it will work when it goes to deepsleep and wakeup.

Thanks.

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <SPI.h>
#include <BlynkSimpleEsp8266.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>         
#include <EEPROM.h>
#include <Servo.h>

Servo myservo;

char auth[] = "xxxx";
BLYNK_CONNECTED() {
  // Request Blynk server to re-send latest values for all pins
  Blynk.syncAll();

  // You can also update individual virtual pins like this:
  //Blynk.syncVirtual(V0, V2);

  // Let's write your hardware uptime to Virtual Pin 2
  int value = millis() / 1000;
  Blynk.virtualWrite(V2, value);
}

BLYNK_WRITE(V0)
{
  // Use of syncAll() will cause this function to be called
  // Parameter holds last slider value
  int sliderValue0 = param.asInt();
}

BLYNK_WRITE(V2)
{
  // You'll get uptime value here as result of syncAll()
  int uptime = param.asInt();
}


void setup()
{
  EEPROM.begin(512);
  Serial.begin(115200);
  myservo.attach(2);
  myservo.write(180);
  WiFiManager wifiManager;
  wifiManager.autoConnect("Door");
  Serial.println("connected...:)");
  pinMode(LED_BUILTIN, OUTPUT);
  Blynk.begin(auth, WiFi.SSID().c_str(), WiFi.psk().c_str());
  
}

BLYNK_WRITE(V5)
{
  int pinValue = param.asInt();
  Serial.print("V4 Slider value is: ");
  Serial.println(pinValue);
  Blynk.virtualWrite(V3, "Door State");
  if(pinValue)
  {
    Blynk.virtualWrite(V4, "Open");
    servo();
    
  }else 
  {
    Blynk.virtualWrite(V4, "Closed");
    myservo.write(180);
  }
  
}

void loop()
{
  Blynk.run();

}

void servo()
{
  myservo.write(90);
}

No it is not.
The NodeMCU is unaware that the button on the Blynk app has been pressed, because it is not connected to the Blynk server, because it is in Deep Sleep mode.
In Deep Sleep mode the NodeMCU has WiFi turned off.
You can wake the NodeMCU from Deep Sleep via a physical button connected to the board, but not via Blynk.

Pete.

With 8 months between OP posts, this could turn out to be a topic functioning in deep sleep itself :sleeping: :laughing:

2 Likes

This could turn out to be a topic as long as the wait for Blynk 2.0 . . . . . :wink:
cul
billd

2 Likes

@PeteKnight Thanks for the Information.
Will try to find another way to achieve this.
@GTT I know I have replied to this topic too late as I am doing study and as an hobby working on this sort of projects. :innocent::innocent:
@Bill_Donnelly yess, we all are waiting for Blynk 2.0… Fingers crossed :crossed_fingers: that I will launch Soon…

What is the need for deep sleep? One would guess that between needing to be in WiFi range as well as a power source capable of controlling the door lock, you should have sufficient power availability to keep the device running all the time.

1 Like

Actually I am trying to run it using battery, so I am trying to work around deepsleep so that the battery will last longer.