Hello. In my application, I need to connect to the blynk server, send data once to the blynk app and then go to sleep. After 10 seconds, wake up, second data and go to sleep again.
I have implemented the code but the only issue is that the blynk app simply does not update, I think it has to do something with the way Blynk.run() is being called. Normally the Blynk.run() must be called in the void.loop(). But since I am using esp32 Deep sleep, void loop is never executed hence I must called blynk.run() elsewhere.
My code:
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp32.h>
#include "adc.h"
#include "deepsleep.h"
#include "wifi_wrapper.h"
char auth[] = "LdYGyhQrFV28vBAl-CxNZi_-vO_Q2IAP";
BlynkTimer timer;
uint16_t adc1_value=0;
uint16_t adc2_value=0;
uint16_t adc3_value=0;
double current1=0;
double current2=0;
double current3=0;
RTC_DATA_ATTR int bootCount = 0;
void setup()
{
//timer.setInterval(1000L, myTimerEvent);
Serial.begin(115200);
setupWifi();
Blynk.config(auth);
delay(1000); //Take some time to open up the Serial Monitor
++bootCount;
Serial.println("Boot number: " + String(bootCount));
print_wakeup_reason();
Serial.println("sending data");
adc1_value = ADC_read(pin_adc1);
adc2_value = ADC_read(pin_adc2);
adc3_value = ADC_read(pin_adc3);
current1 = double(adc1_value / 1241.0f) *30.0f;
current2 = double(adc2_value / 1241.0f) *30.0f;
current3 = double(adc3_value / 1241.0f) *30.0f;
Serial.println(current1);
Blynk.virtualWrite(V4, current1); //sending to Blynk
Blynk.virtualWrite(V5, current2); //sending to Blynk
Blynk.virtualWrite(V6, current3); //sending to Blynk
Blynk.run();
WiFi.disconnect();
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) +
" Seconds");
deepSleep();
}
void loop()
{
}
rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
.Connected :192.168.43.135
[1077]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v1.0.0 on ESP32
Boot number: 3
Wakeup caused by timer
sending data
98.99
[2083] Connecting to blynk-cloud.com:80
Setup ESP32 to sleep for every 10 Seconds
Going to sleep now
ets Jun 8 2016 00:22:57
rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
..Connected :192.168.43.135
[2077]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v1.0.0 on ESP32
Boot number: 4
Wakeup caused by timer
sending data
98.99
[3083] Connecting to blynk-cloud.com:80
Setup ESP32 to sleep for every 10 Seconds
Going to sleep now
As you can see from the serial monitor, I am printing a value before sending to blynk and the value printed is 98,99, but on my blink app it just says 0.0000000. I have tested without the deep sleep just a normal blynk example from the arduino library example and it works fine.