Problems during ota/deep sleep after including blynk in my project

• esp32 (lolin d32 pro + STH31 + lolin EPD) i work with wifi i cconnect on blynk servers
• i use android blnyk app
• i use last version of all (i use platform io)

before including BLYNK my ota update it’s easy to get (i set the wait time = 610 sec)
i reach arduino between 20 minutes and i can update ( i cant access phisically on my hardware in the final porject)

after i include Arduino blynk update, my project had 2 problems:

-sometimes my esp32 doasent boot up after deep sleep
-ota update are broke


#include <Arduino.h>
#include <ArduinoOTA.h>
#include <LOLIN_EPD.h>
#include <Adafruit_GFX.h>
#include <Wire.h>           // SHTSensor
#include "SHTSensor.h"      // SHT Sensor
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <ESPmDNS.h>
#include <esp_wifi.h>
#include <WiFiUdp.h>
#define BLYNK_PRINT Serial

#define uS_TO_S_FACTOR 1000000  /* Conversion factor for micro seconds to s */
#define TIME_TO_SLEEP  600   /* DEFAULT Time ESP32 will go to sleep (in seconds) */


WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);

WidgetTerminal terminal(V40);

char auth[] = "abuabauabauabauabauabauabauabau";
char ssid[] = "pspspspspspspspsps";
char pass[] = "pspwpspwpspwpspwps";

String udp_day;
String udp_time;

String rsii_perc;
const int RSSI_MAX =-50;// define maximum strength of signal in dBm
const int RSSI_MIN =-100;// define minimum strength of signal in dBm

int ADC_VALUE = 0; //battery

float temp;
float humi;

/*D32 Pro EPD*/
#define EPD_CS 14
#define EPD_DC 27
#define EPD_RST 33     // can set to -1 and share with microcontroller Reset!
#define EPD_BUSY -1    // can set to -1 to not use a pin (will wait a fixed delay)

LOLIN_IL3897 EPD(250, 122, EPD_DC, EPD_RST, EPD_CS, EPD_BUSY); //hardware SPI
// int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY
SHTSensor sht;    // Temperatursensor or sht(SHTSensor::SHT3X);




void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  ArduinoOTA.begin();
  ArduinoOTA.setPort(3232);
  ArduinoOTA.setHostname("ESP32_EPD");
  timeClient.begin();
  timeClient.setTimeOffset(3600);
  Wire.begin();
  terminal.println(" _ _ _ _ _ ");
  terminal.println("|B|O|N|A|Z|");
  terminal.println(" ¯ ¯ ¯ ¯ ¯ ");
  terminal.println("V2.1.2");
  terminal.println("gotothechoppha");
  terminal.println("[ACPI] BOOT NOW!");
  terminal.flush();
  delay(100);
  if (sht.init()) {
      terminal.println("[SHT] Sensor initialized");
      terminal.flush();
  } else {
      terminal.println("[SHT] Sensor initialization failed");
      terminal.println("[KEN] Reboot in 2 sec.");
      EPD.clearBuffer();
      EPD.clearDisplay();
      EPD.setTextSize(2);
      EPD.setTextColor(EPD_BLACK);
      EPD.setCursor(10, 25);    // 10 to the right and 18 down 
      EPD.print("[SHT] REBOOT DUE A SENSOR ERROR");
      EPD.display();
      delay(1000);
      ESP.restart();
  }
  sht.setAccuracy(SHTSensor::SHT_ACCURACY_MEDIUM); // only supported by SHT3x

  EPD.begin();
  EPD.clearBuffer();
//  EPD.setTextWrap(true);
  EPD.setTextSize(3);
  EPD.setTextColor(EPD_BLACK);
  EPD.setCursor(10, 18);    // 10 to the right and 18 down 
  EPD.print(">>>BOOTING<<<");
  EPD.setTextSize(2);
  EPD.setCursor(25, 58);    // 10 to the right and 58 down 
  EPD.print("please hold on...");
  EPD.setTextSize(1);
  EPD.setCursor(1,1);
  EPD.print(WiFi.localIP());
  EPD.display();
  delay(100);
}

int dBmtoPercentage(int dBm) //funzione che converte i decibel max/min in numero intero 0-100
{
  int quality;
    if(dBm <= RSSI_MIN){
        quality = 0;
    }
    else if(dBm >= RSSI_MAX){  
        quality = 100;
    }
    else{
        quality = 2 * (dBm + 100);
    }

     return quality;
}

void loop()
{
  long rssi = WiFi.RSSI(); //rsii in db
  rsii_perc = dBmtoPercentage(rssi); //converto i db in percentuale
  terminal.println("<<<<[PLEASE LOADING]>>>");
  terminal.flush();

  ArduinoOTA.handle();
   while(!timeClient.update()) {
    timeClient.forceUpdate();
  }
 try
 {
    udp_time = timeClient.getFormattedTime();
 }
 catch(const std::exception& e)
 {
   terminal.print("[KENR] Error on UDP Time and Date");
   terminal.flush(); 
 }
 
  if (sht.readSample()) {
      EPD.clearBuffer();
      temp = sht.getTemperature();
      terminal.print(udp_time +" >T:  ");
      terminal.println(temp, 2);   
      terminal.flush();

      humi = sht.getHumidity();
      terminal.print(udp_day + udp_time + " >H:  ");
      terminal.println(humi, 2);
      terminal.flush();
      
  } else {
      terminal.println(udp_time +"[KENR] Something went wrong");
      terminal.flush();
      delay(1000);
      ESP.restart();

  }
  int ADC_VALUE = analogRead(35);
  int adc_percentage = int(100 * ADC_VALUE / 4095);
  terminal.println("[BATT] Perc = " + String(adc_percentage) + "%");
  terminal.println("[BATT] Voltage = " + String(ADC_VALUE));
  terminal.flush();
  Blynk.run();
  delay(3000);
  Blynk.virtualWrite(V0, WiFi.RSSI());
  Blynk.virtualWrite(V5, temp);
  Blynk.virtualWrite(V6, humi);
  Blynk.virtualWrite(V8, WiFi.localIP());
  Blynk.virtualWrite(V95, analogRead(35));
  Blynk.virtualWrite(V98,adc_percentage);

  delay(1000);

  if ( ! Blynk.connected() ){
  EPD.clearDisplay();
  EPD.setTextSize(2);
  EPD.setTextColor(EPD_BLACK);
  EPD.setCursor(10, 12);    // 10 to the right and 18 down 
  EPD.print(">REBOOT DUE A NETLINK ERROR<");
  EPD.display();
  delay(4000);
  ESP.restart();
  }

  EPD.clearBuffer();
//  EPD.setTextWrap(true);
  EPD.clearDisplay();
  EPD.setTextSize(2);
  EPD.setTextColor(EPD_BLACK);
  EPD.setCursor(10, 12);    // 10 to the right and 18 down 
  EPD.print("TEMP:" + String(temp) + "C");
  EPD.setCursor(10, 30);    // 10 to the right and 58 down 
  EPD.print("HUMI:" + String(humi) + "%");
  EPD.setCursor(10, 55);    // 10 to the right and 58 down 
  EPD.print("BATT:" + String(adc_percentage) + "% ("+ (String(ADC_VALUE) +"mV)"));
  EPD.setCursor(10, 75);    // 10 to the right and 58 down 
  EPD.print("WIFI:" + String(WiFi.RSSI())+"db (" + String(rsii_perc) + "%)");
  EPD.setCursor(10, 95);    // 10 to the right and 58 down 
  EPD.print("SFARTZ-GOTOTHECHOPPA");
  EPD.setTextSize(1);
  EPD.setCursor(1,1);
  EPD.print(WiFi.localIP());
  EPD.setCursor(130,1);
  EPD.print("UPD TIME:" +String (TIME_TO_SLEEP) +" sec");
  EPD.display();
  delay(100);

  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  terminal.println("[KERN] see you after: " + String(TIME_TO_SLEEP) +" Seconds");
  terminal.println("ZZzz...");
  terminal.flush();
  delay(1000);
  esp_deep_sleep_start();
}

i rebuild my code
the escaper from conn or disconn wifi now it’s working, but ora still broke

/*by Bon Ni

coronavirus coding time 7 mag 2020

*/

#include <Arduino.h>

#include <ArduinoOTA.h>

#include <ESPmDNS.h>

#include <NTPClient.h>

#include <WiFiUdp.h>

#include “WiFi.h”

#include <BluetoothSerial.h>

#include <string.h>

#include <LOLIN_EPD.h>

#include <Adafruit_GFX.h>

#include <fonts/FreeMonoBold9pt7b.h>

#include <Wire.h> // SHTSensor

#include <WEMOS_SHT3X.h> // SHT Sensor

#include <BlynkSimpleEsp32.h> //blynk library

#include “qrcode.h” //unused

#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */

#define TIME_TO_SLEEP 1800 /* Time ESP32 will go to sleep (in seconds) */

char auth[] = “xxxxxxxxxxxxxxxxxxxxx”;

char ssid[] = “TISxxxxxx3”;

char pass[] = “xxxxxxxxx”;

char apnm[] = “SHT30 SETUP”;

char temp_ssid[32];

char temp_pass[32];

char temp_auth[32];

WidgetTerminal terminal(V40);

BluetoothSerial SerialBT;

static volatile bool wifi_connected = false;

float temp;

float humi;

int ADC_VALUE;

int adc_percentage;

float voltage_value;

WiFiUDP ntpUDP;

NTPClient timeClient(ntpUDP);

String formattedDate;

String dayStamp;

String timeStamp;

/D32 Pro epaper display/

#define EPD_CS 14

#define EPD_DC 27

#define EPD_RST 33

#define EPD_BUSY -1

LOLIN_IL3897 EPD(250, 122, EPD_DC, EPD_RST, EPD_CS, EPD_BUSY); //hardware SPI

// int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY

SHT3X sht30(0x45); // Temperatursensor or sht(SHTSensor::SHT3X);

void wifiOnConnect(){

Serial.println("STA Connected");

Serial.print("STA SSID: ");

Serial.println(WiFi.SSID());

Serial.print("STA IPv4: ");

Serial.println(WiFi.localIP());

Serial.print("STA IPv6: ");

Serial.println(WiFi.localIPv6());

}

//when wifi disconnects

void wifiOnDisconnect(){

Serial.println("STA Disconnected");

delay(1000);

WiFi.begin(ssid, pass);

}

void WiFiEvent(WiFiEvent_t event){

switch(event) {

    case SYSTEM_EVENT_AP_START:

        //can set ap hostname here

        WiFi.softAPsetHostname(apnm);

        //enable ap ipv6 here

        WiFi.softAPenableIpV6();

        break;

    case SYSTEM_EVENT_STA_START:

        //set sta hostname here

        WiFi.setHostname(apnm);

        break;

    case SYSTEM_EVENT_STA_CONNECTED:

        //enable sta ipv6 here

        WiFi.enableIpV6();

        break;

    case SYSTEM_EVENT_AP_STA_GOT_IP6:

        //both interfaces get the same event

        Serial.print("STA IPv6: ");

        Serial.println(WiFi.localIPv6());

        Serial.print("AP IPv6: ");

        Serial.println(WiFi.softAPIPv6());

        break;

   case SYSTEM_EVENT_STA_GOT_IP:

        wifiOnConnect();

        wifi_connected = true;

        break;

    case SYSTEM_EVENT_STA_DISCONNECTED:

        wifi_connected = false;

        wifiOnDisconnect();

        break;

    default:

        break;

}

}

void checksht30(){ //helloSht30AreYouThere?

if(sht30.get()==0){

delay(100);

temp = (sht30.cTemp);

delay(100);

humi = (sht30.humidity);

delay(100);

} else {

delay(500);

int batt_volt = analogRead(35);

EPD.begin();

EPD.clearBuffer();

EPD.clearDisplay();

EPD.setTextSize(3);

EPD.setTextColor(EPD_BLACK);

//EPD.setFont()

EPD.setCursor(10, 18);    // 10 to the right and 18 down 

EPD.print("SHT30 ERROR");

EPD.setTextSize(2);

EPD.setCursor(3, 58);    // 10 to the right and 58 down 

EPD.print("low battery("+ String(batt_volt)+")mV");

EPD.setCursor(3, 78);

EPD.print("good battery voltage may be 2300mV");

EPD.setTextSize(1);

EPD.setCursor(1,1);

EPD.print("BY BONAZ");

EPD.display();

delay(2000);

ESP.restart();

}

}

void checkbatt(){

ADC_VALUE = analogRead(35);

adc_percentage = int(100 * ADC_VALUE / 4095);

//delay(1000);

adc_percentage = int(100 * ADC_VALUE / 2357);

voltage_value = (ADC_VALUE * 3.3 ) / (4095);

}

void checktime(){

timeClient.begin();

// Set offset time in seconds to adjust for your timezone, for example:

// GMT +1 = 3600

// GMT +8 = 28800

// GMT -1 = -3600

// GMT 0 = 0

timeClient.setTimeOffset(3600*2);

timeClient.forceUpdate();

formattedDate = String(timeClient.getFormattedTime());

dayStamp = String(timeClient.getDay());

timeStamp = String(timeClient.getEpochTime());

}

void epd_boot(){

EPD.begin();

delay(500);

EPD.clearBuffer();

//const GFXfont *f = &FreeMono9pt7b;

EPD.setFont(&FreeMonoBold9pt7b);

EPD.clearDisplay();

EPD.setTextSize(1);

EPD.setTextColor(EPD_BLACK);

int color = EPD_BLACK;

int t;

int w = EPD.width()/2;

int x = EPD.height()-1;

int y = 80;

int z = EPD.width();

for(t = 0 ; t <= 15; t++) {

    EPD.drawTriangle(w, y, y, x, z, x, color);

    x-=4;

    y+=4;

    z-=4;

    if(t == 8) color = EPD_WHITE;

}

EPD.setCursor(20,40);    // xx to the right and xx down

EPD.setTextSize(2); 

EPD.print(">BOOTING<");

EPD.setTextSize(1);

EPD.setCursor(40, 58); 

EPD.print("please hold on...");

EPD.setTextSize(1);

EPD.setCursor(1,10);

EPD.print("MADE BY BONAZ");

EPD.drawCircle(30,30,50,EPD_DARK);

EPD.display();

delay(1000);

}

void checkota(){

ArduinoOTA

.onStart([]() {

  String type;

  if (ArduinoOTA.getCommand() == U_FLASH)

    type = "sketch";

  else // U_SPIFFS

    type = "filesystem";

  // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()

  Serial.println("Start updating " + type);

})

.onEnd([]() {

    Serial.println("\nEnd");

    EPD.begin();

    delay(500);

    EPD.clearBuffer();

    //const GFXfont *f = &FreeMono9pt7b;

    EPD.setFont(&FreeMonoBold9pt7b);

    EPD.clearDisplay();

    EPD.setTextSize(1);

    EPD.setTextColor(EPD_BLACK);

    int color = EPD_BLACK;

    int t;

    int w = EPD.width()/2;

    int x = EPD.height()-1;

    int y = 80;

    int z = EPD.width();

    for(t = 0 ; t <= 15; t++) {

    EPD.drawTriangle(w, y, y, x, z, x, color);

    x-=4;

    y+=4;

    z-=4;

    if(t == 8) color = EPD_WHITE;

    }

    EPD.setCursor(10,40);    // xx to the right and xx down

    EPD.setTextSize(2); 

    EPD.print(">UPDATE OK!<");

    EPD.setTextSize(1);

    EPD.setCursor(40, 58); 

    EPD.print("rebooting...");

    EPD.setTextSize(1);

    EPD.setCursor(1,10);

    EPD.print("BY BONAZ");

    EPD.drawCircle(30,30,50,EPD_DARK);

    EPD.display();

    delay(5000);

})

.onProgress([](unsigned int progress, unsigned int total) {

  Serial.printf("Progress: %u%%\r", (progress / (total / 100)));

  EPD.clearBuffer();

  EPD.setFont(&FreeMonoBold9pt7b);

  EPD.clearDisplay();

  EPD.setTextSize(1);

  EPD.setTextColor(EPD_BLACK);

  EPD.setCursor(20,10);

  EPD.print("PROGRESS:");

  EPD.drawFastHLine(20,50,progress,EPD_BLACK);

})

.onError([](ota_error_t error) {

  Serial.printf("Error[%u]: ", error);

  if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");

  else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");

  else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");

  else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");

  else if (error == OTA_END_ERROR) Serial.println("End Failed");

});

}

///////////////////////////////////////////////////////////////////////////// SETUP

void setup(){

Serial.begin(115200);

Serial.println("********************");

WiFi.onEvent(WiFiEvent);

WiFi.mode(WIFI_MODE_APSTA);

WiFi.softAP(apnm);

delay(10000);

WiFi.begin(ssid, pass);

Serial.println("AP Started");

Serial.print("AP SSID: ");

Serial.println(apnm);

Serial.print("AP IPv4: ");

Serial.println(WiFi.softAPIP());

epd_boot();   

}

//while wifi is connected

void wifiConnectedLoop(){

Serial.println("wifiConnectedLoop()");

Serial.print("RSSI: ");

Serial.println(WiFi.RSSI());

Serial.println("START TO OTA CHECK");

checkota();

ArduinoOTA.begin();

ArduinoOTA.setPort(3232);

ArduinoOTA.setPassword("admin");

ArduinoOTA.handle();

delay(1000);

Serial.println("OTA CHECKED");

checkbatt();

checktime(); //online

checksht30(); //REBOOT IF ERROR

EPD.clearBuffer();

EPD.clearDisplay();

EPD.setTextSize(1);

EPD.setCursor(2,10);

EPD.print("WIFI OK ");

EPD.setCursor(100,10);

EPD.print("LAST:" + String(formattedDate));

EPD.setTextColor(EPD_BLACK);

EPD.setCursor(2, 30);    // xx to the right and xx down 

EPD.print("T:" + String(temp)+"^C   " + "H:" + String(humi) +"rH%");

EPD.setCursor(160, 115);

EPD.print("BATT:" + String(adc_percentage) +"%");

EPD.setCursor(2, 115);

EPD.println(WiFi.localIP());

EPD.display();

delay(1000);

Serial.println("EPD PRINTED!");

//////////////////////////////BLYNK SPAM

Blynk.config(auth);

Blynk.connect(3333);

delay(100);

Blynk.virtualWrite(V0, WiFi.RSSI());

Blynk.virtualWrite(V5, temp);

Blynk.virtualWrite(V6, humi);

Blynk.virtualWrite(V8, WiFi.localIP());

Blynk.virtualWrite(V95, analogRead(35));

Blynk.virtualWrite(V98,adc_percentage);

terminal.println("");

terminal.println("");

terminal.println("");

terminal.println("");

terminal.println("°º¤ø,¸¸,ø¤º°`°º¤ø,¸,");

terminal.println(" - BONAZ-SILENT -  ");

terminal.println("°º¤ø,¸¸,ø¤º°`°º¤ø,¸,");

terminal.println("v0.4 beta (no-OTA)");

terminal.println(WiFi.localIP());

terminal.println("TEMP:" + String(temp));

terminal.println("HUMI:" + String(humi));

terminal.println("VALIDATE ON: " + String(formattedDate));

terminal.println("NOW I SLEEP FOR:" +  String (TIME_TO_SLEEP));

terminal.flush();

Serial.println(temp);

Serial.println(humi);

Serial.println("DONE! IM GOING TO SLEEP .. ZZZzz.."); 

esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);

delay(2000);

esp_deep_sleep_start();

}

//while wifi is not connected

void wifiDisconnectedLoop(){

Serial.println("wifiDisconnectedLoop()");

checksht30(); //REBOOT IF ERROR

checkbatt();

EPD.clearBuffer();

EPD.clearDisplay();

EPD.setTextSize(1);

EPD.setCursor(2,10);

EPD.print("WIFI DISCONNECTED ");

EPD.setTextColor(EPD_BLACK);

EPD.setCursor(2, 30);    // xx to the right and xx down 

EPD.print("T:" + String(temp)+"^C   " + "H:" + String(humi) +"rH%");

EPD.setCursor(160, 115);

EPD.print("BATT:" + String(adc_percentage) +"%");

EPD.display();

delay(1000);

Serial.println("EPD PRINTED!");

esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);

delay(2000);

esp_deep_sleep_start();

}

void loop(){

if(wifi_connected){

    wifiConnectedLoop();

    ArduinoOTA.handle();

} else {

    wifiDisconnectedLoop();

}

}

@ardu_pro please edit your code (using the pencil icon at the bottom), and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

hi Pete,

i can’t find any oen im sorry,
i see only the 3 point of menu and only a trashcan

Tap the three dots (points) and the pencil icon should appear.

Pete.

This topic was automatically closed after 9 hours. New replies are no longer allowed.