[WIP] Sleep
This commit is contained in:
parent
a3f967e747
commit
97b0351761
107
metesp.ino
107
metesp.ino
@ -32,12 +32,11 @@
|
|||||||
|
|
||||||
/* Global Variables -----------------------------------------------------------*/
|
/* Global Variables -----------------------------------------------------------*/
|
||||||
|
|
||||||
RTC_DATA_ATTR int bootCount = 0;
|
|
||||||
|
|
||||||
static WiFiMulti wifiMulti;
|
static WiFiMulti wifiMulti;
|
||||||
static TwoWire I2C = TwoWire(0);
|
static TwoWire I2C = TwoWire(0);
|
||||||
TaskHandle_t task_measure;
|
TaskHandle_t task_measure;
|
||||||
TaskHandle_t task_draw;
|
TaskHandle_t task_draw;
|
||||||
|
TaskHandle_t task_touch;
|
||||||
|
|
||||||
|
|
||||||
static NTPtime* ntp = new NTPtime(NTP_URL);
|
static NTPtime* ntp = new NTPtime(NTP_URL);
|
||||||
@ -52,7 +51,7 @@ static Influx* iflx = new Influx(NULL, owm);//TODO: Add sensor
|
|||||||
|
|
||||||
static TimedFun* tf = new TimedFun();
|
static TimedFun* tf = new TimedFun();
|
||||||
|
|
||||||
static bool time_update = false, view_update = true, view_refresh = true;
|
static bool time_update = true, view_update = true, view_refresh = false;
|
||||||
static bool shutdownt = false;
|
static bool shutdownt = false;
|
||||||
static int shutdownc = 0;
|
static int shutdownc = 0;
|
||||||
|
|
||||||
@ -97,15 +96,15 @@ void IRAM_ATTR onSecondTimer() {
|
|||||||
|
|
||||||
void IRAM_ATTR onTouch(int8_t contacts, GTPoint *points) {
|
void IRAM_ATTR onTouch(int8_t contacts, GTPoint *points) {
|
||||||
if(touch->dev.holding){
|
if(touch->dev.holding){
|
||||||
Serial.printf("Draging:\n");
|
// Serial.printf("Draging:\n");
|
||||||
Serial.printf("C0: #0 %d,%d \n", touch->dev.dx, touch->dev.dy);
|
// Serial.printf("C0: #0 %d,%d \n", touch->dev.dx, touch->dev.dy);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Serial.printf("Contacts: %d\n", contacts);
|
// Serial.printf("Contacts: %d\n", contacts);
|
||||||
for (uint8_t i = 0; i < contacts; i++) {
|
// for (uint8_t i = 0; i < contacts; i++) {
|
||||||
Serial.printf("C%d: #%d %d,%d s:%d\n", i, points[i].id, points[i].x, points[i].y, points[i].a);
|
// Serial.printf("C%d: #%d %d,%d s:%d\n", i, points[i].id, points[i].x, points[i].y, points[i].a);
|
||||||
yield();
|
// yield();
|
||||||
}
|
// }
|
||||||
if(points[0].y < 125) Display::nextView();
|
if(points[0].y < 125) Display::nextView();
|
||||||
else Display::prevView();
|
else Display::prevView();
|
||||||
view_update = true;
|
view_update = true;
|
||||||
@ -122,6 +121,8 @@ void setup_WIFI(){
|
|||||||
uint8_t tries = 3;
|
uint8_t tries = 3;
|
||||||
WIFI_REGISTER_AP(wifiMulti);
|
WIFI_REGISTER_AP(wifiMulti);
|
||||||
while(wifiMulti.run() != WL_CONNECTED && tries-- >0) delay(500);
|
while(wifiMulti.run() != WL_CONNECTED && tries-- >0) delay(500);
|
||||||
|
if(wifiMulti.run() != WL_CONNECTED) Serial.println("WIFI: Not Connected");
|
||||||
|
else Serial.println("WIFI: Connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_TIMER(){
|
void setup_TIMER(){
|
||||||
@ -141,36 +142,19 @@ REGISTER_TIMEDFUN(RECORD_WEATHER_TF, iflx->record_weather());
|
|||||||
REGISTER_TIMEDFUN(NTP_TF, ntp->updateNTPtime());
|
REGISTER_TIMEDFUN(NTP_TF, ntp->updateNTPtime());
|
||||||
|
|
||||||
void setup_TIMEDFUN() {
|
void setup_TIMEDFUN() {
|
||||||
|
REGISTER_TIMEDFUN_CALL(NTP_TF, 60);
|
||||||
REGISTER_TIMEDFUN_CALL(SENSOR_MEASURE_TF,5);
|
REGISTER_TIMEDFUN_CALL(SENSOR_MEASURE_TF,5);
|
||||||
REGISTER_TIMEDFUN_CALL(OWM_MEASURE_TF,5);
|
REGISTER_TIMEDFUN_CALL(OWM_MEASURE_TF,5);
|
||||||
REGISTER_TIMEDFUN_CALL(RECORD_LOCAL_TF,5);
|
REGISTER_TIMEDFUN_CALL(RECORD_LOCAL_TF,5);
|
||||||
REGISTER_TIMEDFUN_CALL(RECORD_WEATHER_TF,5);
|
REGISTER_TIMEDFUN_CALL(RECORD_WEATHER_TF,5);
|
||||||
REGISTER_TIMEDFUN_CALL(NTP_TF, 60);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_POWER() {
|
void setup_POWER() {
|
||||||
esp_sleep_enable_ext0_wakeup(GPIO_NUM_15, 1);
|
esp_sleep_enable_gpio_wakeup();
|
||||||
esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, 1);
|
gpio_wakeup_enable(GPIO_NUM_15,GPIO_INTR_HIGH_LEVEL);
|
||||||
|
// esp_sleep_enable_ext0_wakeup(GPIO_NUM_15, 1);
|
||||||
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
|
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
|
||||||
esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO,ESP_PD_OPTION_ON);
|
esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO,ESP_PD_OPTION_ON);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void print_wakeup_reason(){
|
|
||||||
esp_sleep_wakeup_cause_t wakeup_reason;
|
|
||||||
|
|
||||||
wakeup_reason = esp_sleep_get_wakeup_cause();
|
|
||||||
|
|
||||||
switch(wakeup_reason)
|
|
||||||
{
|
|
||||||
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
|
|
||||||
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
|
|
||||||
case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
|
|
||||||
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
|
|
||||||
case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
|
|
||||||
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -179,20 +163,17 @@ void setup(){
|
|||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
I2C.begin(PIN_SDA, PIN_SCL);
|
I2C.begin(PIN_SDA, PIN_SCL);
|
||||||
I2C.setPins(PIN_SDA,PIN_SCL);
|
I2C.setPins(PIN_SDA,PIN_SCL);
|
||||||
|
setup_POWER();
|
||||||
++bootCount;
|
|
||||||
Serial.println("Boot number: " + String(bootCount));
|
|
||||||
print_wakeup_reason();
|
|
||||||
|
|
||||||
Display::setup();
|
Display::setup();
|
||||||
setup_TOUCH();
|
|
||||||
setup_WIFI();
|
setup_WIFI();
|
||||||
|
setup_TOUCH();
|
||||||
setup_TIMER();
|
setup_TIMER();
|
||||||
setup_TIMEDFUN();
|
setup_TIMEDFUN();
|
||||||
|
|
||||||
|
iflx->check();
|
||||||
Display::setViews(views,views_size);
|
Display::setViews(views,views_size);
|
||||||
|
|
||||||
iflx->check();
|
|
||||||
tf->updateForce();
|
tf->updateForce();
|
||||||
shutdownc = 0;
|
shutdownc = 0;
|
||||||
|
|
||||||
@ -204,25 +185,46 @@ void setup(){
|
|||||||
loop_DRAW, "Task LDraw",
|
loop_DRAW, "Task LDraw",
|
||||||
10000, NULL, 1, &task_draw, 1);
|
10000, NULL, 1, &task_draw, 1);
|
||||||
|
|
||||||
|
xTaskCreatePinnedToCore(
|
||||||
|
loop_TOUCH, "Task LTouch",
|
||||||
|
10000, NULL, 1, &task_touch, 1);
|
||||||
|
|
||||||
Serial.println("Completed Setup");
|
Serial.println("Completed Setup");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* The main loop -------------------------------------------------------------*/
|
/* The main loop -------------------------------------------------------------*/
|
||||||
|
void wakeup(){
|
||||||
|
view_refresh = true;
|
||||||
|
view_update = true;
|
||||||
|
time_update = true;
|
||||||
|
setup_WIFI();
|
||||||
|
ntp->updateNTPtime();
|
||||||
|
vTaskDelay(200);
|
||||||
|
shutdownc = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
delay(5000);
|
delay(500);
|
||||||
|
|
||||||
|
if(shutdownc >= 3){
|
||||||
|
EPD_2IN13_V2_Sleep();
|
||||||
|
Serial.println("Shuting down");
|
||||||
|
strDateTime odt = (ntp->dt);
|
||||||
|
vTaskDelay(2000);
|
||||||
|
// touch->Reset();
|
||||||
|
touch->update();
|
||||||
|
vTaskDelay(500);
|
||||||
|
esp_light_sleep_start();
|
||||||
|
Serial.println("Wakey Wakey");
|
||||||
|
wakeup();
|
||||||
|
tf->minuteTick(ntp->dt.minute - odt.minute);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop_DRAW(void * pvParameters ){
|
void loop_DRAW(void * pvParameters ){
|
||||||
for(;;){
|
for(;;){
|
||||||
touch->update();
|
if(shutdownc >= 2){vTaskDelay(500);continue;}
|
||||||
if(shutdownc >= 10){
|
|
||||||
Serial.println("Shuting down");
|
|
||||||
Display::refresh();
|
|
||||||
EPD_2IN13_V2_Sleep();
|
|
||||||
esp_deep_sleep_start();
|
|
||||||
}
|
|
||||||
if(!touch->dev.holding) shutdownc = 0;
|
|
||||||
|
|
||||||
if(view_refresh) Display::refresh();
|
if(view_refresh) Display::refresh();
|
||||||
if(view_update) Display::update();
|
if(view_update) Display::update();
|
||||||
@ -231,14 +233,23 @@ void loop_DRAW(void * pvParameters ){
|
|||||||
view_refresh = false;
|
view_refresh = false;
|
||||||
view_update = false;
|
view_update = false;
|
||||||
time_update = false;
|
time_update = false;
|
||||||
vTaskDelay(10);
|
vTaskDelay(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void loop_TOUCH(void * pvParameters ){
|
||||||
|
for(;;){
|
||||||
|
if(shutdownc >= 2){vTaskDelay(500);continue;}
|
||||||
|
touch->update();
|
||||||
|
if(!touch->dev.holding) shutdownc = 0;
|
||||||
|
vTaskDelay(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void loop_MEASURE(void * pvParameters ){
|
void loop_MEASURE(void * pvParameters ){
|
||||||
for(;;){
|
for(;;){
|
||||||
|
if(shutdownc >= 2){vTaskDelay(500);continue;}
|
||||||
tf->update();
|
tf->update();
|
||||||
vTaskDelay(10);
|
vTaskDelay(200);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,28 +8,31 @@ static int8_t view_count = -1;
|
|||||||
static int8_t view_curr = 0;
|
static int8_t view_curr = 0;
|
||||||
static DisplayWrapper** views = 0;
|
static DisplayWrapper** views = 0;
|
||||||
|
|
||||||
|
|
||||||
|
void DrawMain(bool v){
|
||||||
|
Paint_DrawIcon(89,36, ICON_LOGO, &FontIcon, BLACK, WHITE);
|
||||||
|
Paint_DrawString_EN(29, 0, "Helcel", &Font45, WHITE, BLACK);
|
||||||
|
if(v)
|
||||||
|
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 2 - Font16.Height,"WESP-v0.1", &Font16, WHITE, BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
void Display::setup(){
|
void Display::setup(){
|
||||||
DEV_Module_Init();
|
DEV_Module_Init();
|
||||||
EPD_2IN13_V2_Init(EPD_2IN13_V2_FULL);
|
// EPD_2IN13_V2_Init(EPD_2IN13_V2_FULL);
|
||||||
EPD_2IN13_V2_Clear();
|
// EPD_2IN13_V2_Clear();
|
||||||
delay(100);
|
|
||||||
|
|
||||||
uint16_t Imagesize = ((EPD_2IN13_V2_WIDTH % 8 == 0) ? (EPD_2IN13_V2_WIDTH / 8 ) : (EPD_2IN13_V2_WIDTH / 8 + 1)) * EPD_2IN13_V2_HEIGHT;
|
uint16_t Imagesize = ((EPD_2IN13_V2_WIDTH % 8 == 0) ? (EPD_2IN13_V2_WIDTH / 8 ) : (EPD_2IN13_V2_WIDTH / 8 + 1)) * EPD_2IN13_V2_HEIGHT;
|
||||||
if ((BlackImage = (uint8_t *)malloc(Imagesize)) == NULL) exit(1);
|
if ((BlackImage = (uint8_t *)malloc(Imagesize)) == NULL) exit(1);
|
||||||
Paint_NewImage(BlackImage, EPD_2IN13_V2_WIDTH, EPD_2IN13_V2_HEIGHT, 270, WHITE);
|
Paint_NewImage(BlackImage, EPD_2IN13_V2_WIDTH, EPD_2IN13_V2_HEIGHT, 270, WHITE);
|
||||||
Paint_SelectImage(BlackImage);
|
|
||||||
Paint_SetMirroring(MIRROR_HORIZONTAL);
|
Paint_SetMirroring(MIRROR_HORIZONTAL);
|
||||||
Paint_Clear(WHITE);
|
|
||||||
|
|
||||||
Paint_DrawIcon(89,36, ICON_LOGO, &FontIcon, BLACK, WHITE);
|
refresh();
|
||||||
Paint_DrawString_EN(29, 0, "Helcel", &Font45, WHITE, BLACK);
|
DrawMain(false);
|
||||||
Paint_SelectImage(BlackImage);
|
EPD_2IN13_V2_DisplayPart(BlackImage);
|
||||||
EPD_2IN13_V2_Display(BlackImage);
|
|
||||||
delay(100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::drawTime(strDateTime* dt){
|
void Display::drawTime(strDateTime* dt){
|
||||||
Paint_ClearWindows(170, EPD_2IN13_V2_WIDTH - Font24.Height, 170 + Font24.Width * 4.5, EPD_2IN13_V2_WIDTH, WHITE);
|
Paint_ClearWindows(170, EPD_2IN13_V2_WIDTH - Font24.Height+2, 170 + Font24.Width * 4.5, EPD_2IN13_V2_WIDTH, WHITE);
|
||||||
if (!dt->valid) return;
|
if (!dt->valid) return;
|
||||||
Paint_DrawTime(170, 98, dt, &Font24, WHITE, BLACK);
|
Paint_DrawTime(170, 98, dt, &Font24, WHITE, BLACK);
|
||||||
EPD_2IN13_V2_DisplayPart(BlackImage);
|
EPD_2IN13_V2_DisplayPart(BlackImage);
|
||||||
@ -89,7 +92,7 @@ void WeatherDisplay::drawDisplay() {
|
|||||||
JsonObject weather_sys = cowm->weather["sys"];
|
JsonObject weather_sys = cowm->weather["sys"];
|
||||||
if(!weather_0 || !weather_main || !weather_sys || !weather_wind) return;
|
if(!weather_0 || !weather_main || !weather_sys || !weather_wind) return;
|
||||||
Paint_DrawIcon(0,8, getWeatherIcon(weather_0["id"]), &FontIcon, BLACK, WHITE);
|
Paint_DrawIcon(0,8, getWeatherIcon(weather_0["id"]), &FontIcon, BLACK, WHITE);
|
||||||
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 4 - Font16.Height,weather_0["description"], &Font16, WHITE, BLACK);
|
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 2 - Font16.Height,weather_0["main"], &Font16, WHITE, BLACK);
|
||||||
Paint_DrawFltUnit(76,0,weather_main["temp"], "C", &Font24, BLACK, WHITE);
|
Paint_DrawFltUnit(76,0,weather_main["temp"], "C", &Font24, BLACK, WHITE);
|
||||||
Paint_DrawFltUnit(186,6,weather_main["feels_like"], "C", &Font12, BLACK, WHITE);
|
Paint_DrawFltUnit(186,6,weather_main["feels_like"], "C", &Font12, BLACK, WHITE);
|
||||||
Paint_DrawIntUnit(76,24,weather_main["pressure"], "hPa", &Font24, BLACK, WHITE);
|
Paint_DrawIntUnit(76,24,weather_main["pressure"], "hPa", &Font24, BLACK, WHITE);
|
||||||
@ -108,7 +111,7 @@ void TempDisplay::drawDisplay() {
|
|||||||
Paint_DrawFltUnit(76,24,sensor->pres, "hPa", &Font24, BLACK, WHITE);
|
Paint_DrawFltUnit(76,24,sensor->pres, "hPa", &Font24, BLACK, WHITE);
|
||||||
Paint_DrawFltUnit(76,48,sensor->hum, "%", &Font24, BLACK, WHITE);
|
Paint_DrawFltUnit(76,48,sensor->hum, "%", &Font24, BLACK, WHITE);
|
||||||
|
|
||||||
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 4 - Font16.Height,"nominal", &Font16, WHITE, BLACK);
|
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 2 - Font16.Height,"Nominal", &Font16, WHITE, BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AirDisplay::drawDisplay() {
|
void AirDisplay::drawDisplay() {
|
||||||
@ -131,7 +134,7 @@ void AirDisplay::drawDisplay() {
|
|||||||
// particles_50um, ///< 5.0um Particle Count
|
// particles_50um, ///< 5.0um Particle Count
|
||||||
// particles_100um; ///< 10.0um Particle Count
|
// particles_100um; ///< 10.0um Particle Count
|
||||||
|
|
||||||
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 4 - Font16.Height,"nominal", &Font16, WHITE, BLACK);
|
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 2 - Font16.Height,"Nominal", &Font16, WHITE, BLACK);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,14 +147,12 @@ void LightDisplay::drawDisplay() {
|
|||||||
Paint_DrawFltUnit(76,24*2,sensor->light, "l", &Font24, BLACK, WHITE);
|
Paint_DrawFltUnit(76,24*2,sensor->light, "l", &Font24, BLACK, WHITE);
|
||||||
Paint_DrawIntUnit(76,24*3,sensor->light_vis, "vl", &Font24, BLACK, WHITE);
|
Paint_DrawIntUnit(76,24*3,sensor->light_vis, "vl", &Font24, BLACK, WHITE);
|
||||||
|
|
||||||
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 4 - Font16.Height,"nominal", &Font16, WHITE, BLACK);
|
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 2 - Font16.Height,"Nominal", &Font16, WHITE, BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainDisplay::drawDisplay() {
|
void MainDisplay::drawDisplay() {
|
||||||
Paint_DrawIcon(89,36, ICON_LOGO, &FontIcon, BLACK, WHITE);
|
DrawMain(true);
|
||||||
Paint_DrawString_EN(29, 0, "Helcel", &Font45, WHITE, BLACK);
|
|
||||||
Paint_DrawString_EN(2,EPD_2IN13_V2_WIDTH - 4 - Font16.Height,"WESP-v0.1", &Font16, WHITE, BLACK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomDisplay::drawDisplay() {
|
void CustomDisplay::drawDisplay() {
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#define DEVICE "ESP32"
|
#define DEVICE "ESP32"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <WiFi.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include <InfluxDbClient.h>
|
#include <InfluxDbClient.h>
|
||||||
@ -61,7 +60,6 @@ class Influx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void record(){
|
void record(){
|
||||||
if(WiFi.status() != WL_CONNECTED) return;
|
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
while(owm && owm[i] != NULL){
|
while(owm && owm[i] != NULL){
|
||||||
record_weather(owm[i]);
|
record_weather(owm[i]);
|
||||||
@ -71,7 +69,6 @@ class Influx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void record(bool w, bool s){
|
void record(bool w, bool s){
|
||||||
if(WiFi.status() != WL_CONNECTED) return;
|
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
while(w && owm && owm[i] != NULL){
|
while(w && owm && owm[i] != NULL){
|
||||||
record_weather(owm[i]);
|
record_weather(owm[i]);
|
||||||
@ -83,7 +80,7 @@ class Influx {
|
|||||||
|
|
||||||
void record_local(){
|
void record_local(){
|
||||||
if(!sensor) return;
|
if(!sensor) return;
|
||||||
if(WiFi.status() != WL_CONNECTED) return;
|
Serial.println("InfluxDB: Uploading Local Data");
|
||||||
|
|
||||||
dp.clearFields();
|
dp.clearFields();
|
||||||
dp.clearTags();
|
dp.clearTags();
|
||||||
@ -121,6 +118,7 @@ class Influx {
|
|||||||
dp.addField("particles_100um", sensor->pmd.particles_100um);
|
dp.addField("particles_100um", sensor->pmd.particles_100um);
|
||||||
|
|
||||||
client.writePoint(dp);
|
client.writePoint(dp);
|
||||||
|
Serial.println("InfluxDB: OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
void record_weather(){
|
void record_weather(){
|
||||||
@ -129,8 +127,11 @@ class Influx {
|
|||||||
|
|
||||||
void record_weather(OWM* owm){
|
void record_weather(OWM* owm){
|
||||||
if(!owm) return;
|
if(!owm) return;
|
||||||
if(!owm->valid_weather) return;
|
Serial.println("InfluxDB: Uploading OWM Data");
|
||||||
if(WiFi.status() != WL_CONNECTED) return;
|
if(!owm->valid_weather) {
|
||||||
|
Serial.println("InfluxDB: Error, not valid weather");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
JsonObject weather_0 = owm->weather["weather"][0];
|
JsonObject weather_0 = owm->weather["weather"][0];
|
||||||
JsonObject weather_main = owm->weather["main"];
|
JsonObject weather_main = owm->weather["main"];
|
||||||
@ -167,6 +168,7 @@ class Influx {
|
|||||||
dp.addField("precipitation_snow_3h",weather_snow?float(weather_snow["3h"]):0.0);
|
dp.addField("precipitation_snow_3h",weather_snow?float(weather_snow["3h"]):0.0);
|
||||||
|
|
||||||
client.writePoint(dp);
|
client.writePoint(dp);
|
||||||
|
Serial.println("InfluxDB: OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -226,7 +226,6 @@ strDateTime NTPtime::getNTPtime(float _timeZone, boolean _DayLightSaving) {
|
|||||||
|
|
||||||
|
|
||||||
void NTPtime::updateNTPtime(){
|
void NTPtime::updateNTPtime(){
|
||||||
if(WiFi.status() != WL_CONNECTED) return;
|
|
||||||
strDateTime ndt = getNTPtime(1.0f, true);
|
strDateTime ndt = getNTPtime(1.0f, true);
|
||||||
if(ndt.valid) dt = ndt;
|
if(ndt.valid) dt = ndt;
|
||||||
};
|
};
|
@ -2,7 +2,6 @@
|
|||||||
#define NTPtime_h
|
#define NTPtime_h
|
||||||
|
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
#include <WiFi.h>
|
|
||||||
|
|
||||||
struct strDateTime {
|
struct strDateTime {
|
||||||
byte hour;
|
byte hour;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#ifndef OWM_H
|
#ifndef OWM_H
|
||||||
#define OWM_H
|
#define OWM_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <WiFi.h>
|
|
||||||
|
|
||||||
|
|
||||||
#define OPENWEATHER_URL(loc, api) ("https://api.openweathermap.org/data/2.5/weather?q=" + loc + "&appid=" + api + "&units=metric")
|
#define OPENWEATHER_URL(loc, api) ("https://api.openweathermap.org/data/2.5/weather?q=" + loc + "&appid=" + api + "&units=metric")
|
||||||
@ -18,20 +18,24 @@ class OWM{
|
|||||||
bool valid_weather = false;
|
bool valid_weather = false;
|
||||||
|
|
||||||
bool update(){
|
bool update(){
|
||||||
if(WiFi.status() != WL_CONNECTED) return false;
|
|
||||||
|
Serial.println("OWWM: Updating Data");
|
||||||
String response = httpGETRequest(OPENWEATHER_URL(location,key).c_str());
|
String response = httpGETRequest(OPENWEATHER_URL(location,key).c_str());
|
||||||
DeserializationError error = deserializeJson(weather, response);
|
DeserializationError error = deserializeJson(weather, response);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
Serial.println("OWWM: Error, request or response invalid");
|
||||||
valid_weather = false;
|
valid_weather = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(weather["weather"]==NULL ||weather["main"]==NULL ||
|
if(weather["weather"]==NULL ||weather["main"]==NULL ||
|
||||||
weather["wind"]==NULL || weather["sys"]==NULL ){
|
weather["wind"]==NULL || weather["sys"]==NULL ){
|
||||||
|
Serial.println("OWWM: Error, missing fields");
|
||||||
valid_weather = false;
|
valid_weather = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Serial.println("OWWM: OK");
|
||||||
valid_weather = true;
|
valid_weather = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#ifndef TG_TIMEDFUN_H
|
#ifndef TG_TIMEDFUN_H
|
||||||
#define TG_TIMEDFUN_H
|
#define TG_TIMEDFUN_H
|
||||||
|
|
||||||
#include <map>
|
#include <vector>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
@ -14,22 +14,27 @@ class TimedFun {
|
|||||||
TimedFun(){};
|
TimedFun(){};
|
||||||
|
|
||||||
void registerFun(timedfun_ptr p, uint64_t s){
|
void registerFun(timedfun_ptr p, uint64_t s){
|
||||||
funmap[p] = s;
|
funmap.push_back(std::pair<timedfun_ptr,uint64_t>(p,s));
|
||||||
};
|
};
|
||||||
|
|
||||||
void registerFunCond(timedfun_ptr p, uint64_t s){
|
void registerFunCond(timedfun_ptr p, uint64_t s){
|
||||||
funmap[p] = s;
|
funmap.push_back(std::pair<timedfun_ptr,uint64_t>(p,s));
|
||||||
};
|
};
|
||||||
|
|
||||||
void minuteTick(){
|
void minuteTick(){
|
||||||
++counter;
|
++counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void minuteTick(int64_t m){
|
||||||
|
counter += m;
|
||||||
|
}
|
||||||
|
|
||||||
void update(){
|
void update(){
|
||||||
|
uint64_t ccounter = old_counter;
|
||||||
|
old_counter = counter;
|
||||||
for (const auto &e : funmap){
|
for (const auto &e : funmap){
|
||||||
if((counter % e.second == 0) ||
|
if( ((counter % e.second == 0) && (counter != ccounter)) ||
|
||||||
((counter-old_counter) >= e.second) ||
|
((counter-ccounter) >= e.second) || ((counter%e.second) < (ccounter%e.second))){
|
||||||
((counter%e.second) < (old_counter%e.second))){
|
|
||||||
e.first();
|
e.first();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,15 +42,17 @@ class TimedFun {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void updateForce(){
|
void updateForce(){
|
||||||
|
Serial.println("TF: Force updating all");
|
||||||
for (const auto &e : funmap){
|
for (const auto &e : funmap){
|
||||||
e.first();
|
e.first();
|
||||||
}
|
}
|
||||||
|
Serial.println("TF: OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint64_t counter = 0;
|
uint64_t counter = 0;
|
||||||
uint64_t old_counter = 0;
|
uint64_t old_counter = 0;
|
||||||
std::map<timedfun_ptr,uint64_t> funmap;
|
std::vector<std::pair<timedfun_ptr,uint64_t>> funmap;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ int16_t GT1151::readInput(GTPoint* points) {
|
|||||||
|
|
||||||
|
|
||||||
void GT1151::Reset(void){
|
void GT1151::Reset(void){
|
||||||
pinMode(GT1151_INT_PIN, OUTPUT);
|
pinMode(GT1151_RESET_PIN, OUTPUT);
|
||||||
pinMode(GT1151_INT_PIN, INPUT);
|
pinMode(GT1151_INT_PIN, INPUT);
|
||||||
digitalWrite(GT1151_RESET_PIN, HIGH);
|
digitalWrite(GT1151_RESET_PIN, HIGH);
|
||||||
delay(100);
|
delay(100);
|
||||||
|
@ -49,6 +49,7 @@ class GT1151{
|
|||||||
|
|
||||||
void update(void);
|
void update(void);
|
||||||
void begin(void);
|
void begin(void);
|
||||||
|
void Reset(void);
|
||||||
void Gesture(void);
|
void Gesture(void);
|
||||||
void setHandler(void (*handler)(int8_t, GTPoint*));
|
void setHandler(void (*handler)(int8_t, GTPoint*));
|
||||||
|
|
||||||
@ -56,7 +57,6 @@ class GT1151{
|
|||||||
void (*touchHandler)(int8_t, GTPoint*);
|
void (*touchHandler)(int8_t, GTPoint*);
|
||||||
TwoWire* wire;
|
TwoWire* wire;
|
||||||
|
|
||||||
void Reset(void);
|
|
||||||
|
|
||||||
void armIRQ(void);
|
void armIRQ(void);
|
||||||
void onIRQ(void);
|
void onIRQ(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user