Hi There,
I’m tying to use horizontal slider to set the deep sleep time in minutes.
But every time wemos wakes up the value of the silder jumps to ZERO/default.
Now i know that this is normal beheviour but i just can’t seem to fix it in my code.
Tried a lot of things but nothing seems to work.
What i have read it should be possible to first sync the last saves value of the slider and then go in to the rest of the code?
Hope someone can help.
This is my code. It still in development…
#define BLYNK_PRINT Serial
#include <Wire.h>
#include <SPI.h>
#include <SSD_13XX.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <SimpleTimer.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 bme; // I2C
#define SEALEVELPRESSURE_HPA (1013.25)
//*********************OLED SCREEN********************
//****************************************************
#define _cs 15 // goes to TFT CS
#define _dc 2 // goes to TFT DC
#define _mosi 13 // goes to TFT MOSI
#define _sclk 14 // goes to TFT SCK/CLK
#define _rst 0 // ESP RST to TFT RESET
#define _miso // Not connected
SSD_13XX tft = SSD_13XX(_cs, _dc);
//*********************WIFI CONNECTION****************
char auth[] = "************";
char ssid[] = "*******";
char pass[] = "******";
BlynkTimer timer;
WidgetRTC rtc;
#define BLYNK_PRINT Serial
int pressure;
char tension12[5];
//Live time to allow blynk.run to run multiple times
unsigned long livetime = 10000;
const int numReadings = 20;
float readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
float total = 0; // the running total
float average = 0;
int updatetime; // minutes
int val; // batterij
int Battery;
float fmap(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
//************************************************************************************************
void setup() {
Serial.begin(115200);
Blynk.syncVirtual(V0);
// long unsigned debug_start = millis();
// while (!Serial && ((millis() - debug_start) <= 5000));
tft.begin(false);
delay(30);
tft.setRotation(0);
tft.setCursor(0, 0);
tft.setTextScale(1.5);
tft.print("Opstarten....");
delay(1000);
tft.setTextColor(GREEN);
tft.println("OK");
tft.setTextColor(WHITE);
delay(1000);
tft.setCursor(0, 15);
tft.print("Aanmelden WIFI....");
Blynk.begin(auth, ssid, pass);
setSyncInterval(10 * 60); // Sync interval in seconds (10 minutes)
delay(500);
tft.setTextColor(GREEN);
tft.println("OK");
delay(1000);
timer.setInterval(1000L, myTimerEvent);
//***********************INITIATE SENSOR**********************
//************************************************************
tft.setCursor(0, 30);
tft.setTextColor(WHITE);
tft.print("Zoeken sensor....");
bool status;
status = bme.begin(0x76);
if (!status) {
tft.println("Geen sensor");
while (1);
}
delay(500);
tft.setTextColor(GREEN);
tft.println("OK");
delay(1000);
}
//************************************************************************************************
BLYNK_WRITE(V0)
{
updatetime = param.asInt(); // assigning incoming value from pin V1 to a variable
//hibernation_time_min = param.asInt()
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
Serial.print("V1 Slider value is: ");
Serial.println(updatetime);
}
void myTimerEvent() {
//***********************************************************
// SMOOTHING THE TEMP READINGS
//***********************************************************
while (readIndex != numReadings) {
total = total - readings[readIndex];
readings[readIndex] = (bme.readTemperature());
total = total + readings[readIndex];
readIndex = readIndex + 1;
if (readIndex >= numReadings) {
readIndex = 0;
break;
}
}
average = (total / numReadings); //- 1.0;
//Serial.println(average);
//***********************************************************
// READING THE BATTERY
//***********************************************************
//int raw = analogRead(A0);
// val = fmap(raw, 300, 1023, 0.0, 100);
//***********************************************************
//
//***********************************************************
dtostrf(average, 5, 1, tension12);
float temp_rounded = round(average * 10) / 10.0;
float Humudity = round(bme.readHumidity() * 10) / 10.0;
int HumidityChart = round(bme.readHumidity() * 10) / 10.0;
pressure = (bme.readPressure() / 100);
val = analogRead(A0);
Battery = round(val);
Blynk.virtualWrite(V3, tension12);
Blynk.virtualWrite(V4, temp_rounded);// superchart
Blynk.virtualWrite(V5, 23);//max
Blynk.virtualWrite(V6, 20);//min
Blynk.virtualWrite(V8, pressure);
Blynk.virtualWrite(V7, Humudity);
Blynk.virtualWrite(V9, HumidityChart);
Blynk.virtualWrite(V10, 60);//max
Blynk.virtualWrite(V11, 45);//min
Blynk.virtualWrite(V12, Battery);
Blynk.virtualWrite(V13, updatetime);
//ESP.deepSleep(pinValue * 60 * 1000000);
//delay(100);
}
//************************************************************************************************
void loop()
{
while (livetime > millis()) {
Blynk.run();
}
timer.run();
//***********************************************************
// WRITE TO OLED SCREEN
//***********************************************************
String currentTime = String(hour()) + ":" + minute() + ":" + second();
String currentDate = String(day()) + "/" + month() + "/" + year();
tft.clearScreen();
tft.setCursor(0, 0);
tft.setTextColor(WHITE);
tft.print(currentTime);
tft.print(" ");
tft.println(currentDate);
tft.setTextScale(2);
tft.setCursor(0, 25);
tft.print("Temp: ");
tft.setTextColor(YELLOW);
tft.print(average, 1);
tft.setTextColor(WHITE);
tft.setTextScale(1);
tft.println(" °C");
tft.setTextScale(2);
tft.setCursor(0, 50);
tft.setTextColor(WHITE);
tft.print("LuchtV: ");
tft.setTextColor(YELLOW);
tft.print(bme.readHumidity(), 1);
tft.setTextColor(WHITE);
tft.setTextScale(1);
tft.println(" %");
tft.setTextScale(2);
tft.setCursor(0, 75);
tft.setTextColor(WHITE);
tft.print("Druk: ");
tft.setTextColor(YELLOW);
tft.print(pressure);
tft.setTextColor(WHITE);
tft.setTextScale(1);
tft.println(" hPa");
}
//************************************************************************************************
BLYNK_CONNECTED() {
//Synchronize time on connection
rtc.begin();
}