• 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();
}