following a sketch I’m working on (there are still some stability problems) to drive an Esp8266 pin and put it in deep sleep mode for a while to safe battery.
I hope this will be useful. Of course any comment and suggestions will be appreciated.
The Blynk app includes a label for espVCC readings, two led Widget, one switch to drive the led and one button to put ESP8266 in deep mode.
> include ESP8266WiFi.h
> include BlynkSimpleEsp8266.h
> include SimpleTimer.h
> ADC_MODE(ADC_VCC);
> int Led = 5 ;
> char auth[] = "";
> WidgetLED led1(V2);
> WidgetLED led2(V5);
> SimpleTimer timer;
> // Keep this flag not to re-sync on every reconnection
> bool isFirstConnect = true;
> // This function will run every time Blynk connection is established
> BLYNK_CONNECTED() {
> if (isFirstConnect) {
> Blynk.syncAll();
> isFirstConnect = false;
> }
> led1.off();
> led2.off();
> }
> void setup() {
>
> led2.off();
>
> pinMode (Led, OUTPUT) ;
> digitalWrite (Led, LOW);
> Blynk.begin(auth);
> }
>
>
> void loop() {
> Blynk.run();
> }
> BLYNK_READ(V1)
> {
> Blynk.virtualWrite(V1, ESP.getVcc());
> }
> BLYNK_WRITE(V3)
> {
> int pinValue = param.asInt();
> if (pinValue==1)
> {
> digitalWrite (Led, HIGH);
> led1.on();
> } else {
> digitalWrite (Led, LOW);
> led1.off();
> }
> }
> BLYNK_WRITE(V4)
> {
> int pinValue = param.asInt();
> if (pinValue==1)
> {
> led2.on();
> ESP.deepSleep(60000000);
> } else {
> led2.off();
> }
> }
// ESP8266-07 Standalone
//
// Esp voltage reading to Blynk
// Pin physical drive on ESP8266
// Low voltage setting for Deep Sleep
//
// Deep sleep for 600 sec (GPIO16 connected to RST)
//
// Arduino IDE parameters :
// - NodeMCU 0.9 (ESP-12 Module)
// - 80 MHz
// - Serial
// - 115200
// - 4M (3M SPIFFS)
//
// Virtual PIN
// V1 : EspVCC readings
// V2 : Led physical pin status On/Off
// V3 : Slide button for physical pin
// V5 : Led for deep sleep mode status
// V4 : Slider for deep sleep Vcc low limit value setting
// #define BLYNK_PRINT Serial
include ESP8266WiFi.h>
include BlynkSimpleEsp8266.h>
include SimpleTimer.h>
ADC_MODE(ADC_VCC);
int Led = 5 ;
int SliderValue;
char auth[] = "";
WidgetLED led1(V2);
WidgetLED led2(V5);
SimpleTimer timer;
// Keep this flag not to re-sync on every reconnection
bool isFirstConnect = true;
// This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
if (isFirstConnect) {
Blynk.syncAll();
isFirstConnect = false;
}
led1.off();
led2.off();
}
void setup() {
led2.off();
// Serial.begin(115200);
pinMode (Led, OUTPUT) ;
digitalWrite (Led, LOW);
Blynk.begin(auth, "");
timer.setInterval(5000L, ReadSensor);
Blynk.notify("ESP8266-BLYNK Ready");
}
void loop() {
Blynk.run();
timer.run();
}
//Function to read Esp voltage and check deep sleep low voltage value (to safe battery!!)
void ReadSensor() {
Blynk.virtualWrite(V1, ESP.getVcc());
// Serial.println(ESP.getVcc());
// Serial.println(SliderValue);
if (ESP.getVcc() < SliderValue)
{
led2.on();
Blynk.notify("Deep Sleep");
ESP.deepSleep(600000000);
delay(100);
}
}
//Switch button to drive the physical pin
BLYNK_WRITE(V3)
{
int pinValue = param.asInt();
if (pinValue==1)
{
digitalWrite (Led, HIGH);
led1.on();
} else {
digitalWrite (Led, LOW);
led1.off();
}
}
//Slider change values from 3000 to 3700 from Widget Slider
BLYNK_WRITE(V4)
{
SliderValue = map(param.asInt(), 0, 1023, 3000, 3700);
}
@zetalif led2.off() in setup() is not much good before you have connected to Blynk. To be honest I have never really been a fan of ledx.on() format and prefer just virtualWrite’s to the pin.
This is one of the exceptions that a delay() might be useful in Blynk. Normally it is an absolute no, no but when entering deepSleep Blynk dies anyway.
So try delay(1000) before and after the deepSleep command.
Ensure any frequency based widgets are set to PUSH in the app as they default to time based.
For testing purposes you could mod the slider map routine.
Thank you for your suggestions. I’ve moved led.off() after connection and increase delay time before and after deep sleep. Now in monitoring…
But there is a problem with slider widget. When I use the project with IPad and Samsung pone at the same time there is a mismatch between the slider values in the two device (i.e. 3500 on iOS and 3750 on Android).
It seems I can use the project only on one device.
Yes in my project i set the mapping on in widget slider : 3000 - 4000. This because i read the widget value and compare it with EspVcc value to set the minimum voltage value to sleep Esp. My be there is a better way…
You have a virtual pin and you’ve set min max values in widget settings. So you don’t need mapping in your code. just:
BLYNK_WRITE(V4)
{
SliderValue = param.asInt();
}
Also, I believe you may have mapping set in widget settings, which ruins your iOS - Android sync. Mapping should be turned off (like on my screenshot):
Any ideas about sending various sleep timer value through Blynk to ESP8266.
The challenge i have is that once i installed the kit i would not reach it, so, instead i think if i can rest the timer through wi-fi (definitely the kit would wake-up so i send it to deep mode again with new value), is it possible? and recommendations.