Suport for many OWM monitoring

This commit is contained in:
choelzl 2022-04-08 20:46:49 +02:00
parent 3e858fa48e
commit 46734d537f
Signed by: sora
GPG Key ID: A362EA0491E2EEA0
2 changed files with 41 additions and 21 deletions

View File

@ -27,7 +27,7 @@
typedef enum {
VIEW_MAIN = 0,
VIEW_WEATHER, VIEW_WEATHER_ALT,
VIEW_WEATHER_0, VIEW_WEATHER_1, VIEW_WEATHER_2, VIEW_WEATHER_3,
VIEW_TEMP, VIEW_AIR,
VIEW_CUSTOM,
@ -38,7 +38,7 @@ static const uint8_t view_count = 5;
static uint8_t view_curr;
static const views_t view_tab[view_count] = {
VIEW_MAIN,
VIEW_WEATHER,VIEW_WEATHER_ALT,
VIEW_WEATHER_0,VIEW_WEATHER_1,
VIEW_TEMP,VIEW_AIR
};
@ -47,10 +47,11 @@ static TwoWire I2C = TwoWire(0);
static strDateTime dateTime = {0};
static Sensor* sensor = new Sensor(&I2C);
static GT1151* touch = new GT1151(&I2C);
static OWM* owm = new OWM(LOCATION, OPENWEATHER_API);
static OWM* owm_alt = new OWM(LOCATION_ALT, OPENWEATHER_API);
static OWM* owm[6] = {new OWM(LOCATION_0, OPENWEATHER_API),
new OWM(LOCATION_1, OPENWEATHER_API),
new OWM(LOCATION_2, OPENWEATHER_API), 0,0,0};
static Influx* iflx = new Influx(NULL, owm, owm_alt);//add sensor
static Influx* iflx = new Influx(NULL, owm);//add sensor
static NTPtime NTPch(NTP_URL);
static bool time_update = false,
@ -154,7 +155,7 @@ void setup_TOUCH() {
void setup_WIFI(){
uint8_t tries = 3;
WIFI_REGISTER_AP(wifiMulti);
while (wifiMulti.run() == WL_CONNECTED && tries-- >0) delay(500);
while(wifiMulti.run() != WL_CONNECTED && tries-- >0) delay(500);
}
void setup_TIMER(){
@ -198,9 +199,12 @@ void updateWeather(){
if (!weather_update) return;
if (wifiMulti.run() != WL_CONNECTED) return;
if(owm!= NULL && !owm->update()) return;
if(owm_alt!= NULL && !owm_alt->update()) return;
weather_update = false;
uint8_t i = 0, success = true;
while(owm && owm[i]){
success &= owm[i]-> update();
++i;
}
if(success) weather_update = false;
}
void updateTime(){
@ -246,8 +250,17 @@ void refreshDisplay(){
Paint_SelectImage(BlackImage);
}
OWM* viewToOWM(views_t view){
switch(view){
case VIEW_WEATHER_0: return owm[0];
case VIEW_WEATHER_1: return owm[1];
case VIEW_WEATHER_2: return owm[2];
case VIEW_WEATHER_3: return owm[3];
default: return NULL;
}
}
void updateDisplay(){
// forceRefresh();
if (!view_update) return;
if (view_refresh) refreshDisplay();
Paint_ClearWindows(0, 0, EPD_2IN13_V2_HEIGHT, EPD_2IN13_V2_WIDTH - Font24.Height, WHITE);
@ -258,11 +271,13 @@ void updateDisplay(){
Paint_DrawString_EN(60,0,"MAIN", &Font24, WHITE, BLACK);
Paint_DrawIntUnit(0,30, 69,"", &Font24, BLACK, WHITE);
break;
case VIEW_WEATHER_ALT:
case VIEW_WEATHER:
case VIEW_WEATHER_0:
case VIEW_WEATHER_1:
case VIEW_WEATHER_2:
case VIEW_WEATHER_3:
{
OWM* cowm = (view_tab[view_curr]==VIEW_WEATHER)?owm:owm_alt;
if(!cowm->valid_weather) break;
OWM* cowm = viewToOWM(view_tab[view_curr]);
if(cowm == NULL || !cowm->valid_weather) break;
JsonObject weather_0 = cowm->weather["weather"][0];
JsonObject weather_main = cowm->weather["main"];
JsonObject weather_wind = cowm->weather["wind"];

View File

@ -47,7 +47,7 @@ emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=\n\
class Influx {
public:
Influx(Sensor* _sensor, OWM* _owm0, OWM* _owm1): sensor(_sensor), owm0(_owm0), owm1(_owm1) {}
Influx(Sensor* _sensor, OWM* _owm[]): sensor(_sensor), owm(_owm) {}
void check(){
if (client.validateConnection()) {
@ -60,14 +60,20 @@ class Influx {
}
void record(){
if(owm0) record_weather(owm0);
if(owm1) record_weather(owm1);
uint8_t i = 0;
while(owm && owm[i] != NULL){
record_weather(owm[i]);
++i;
}
if(sensor) record_local();
}
void record(bool w, bool s){
if(owm0 && w) record_weather(owm0);
if(owm1 && w) record_weather(owm1);
uint8_t i = 0;
while(w && owm && owm[i] != NULL){
record_weather(owm[i]);
++i;
}
if(sensor && s) record_local();
}
@ -155,8 +161,7 @@ class Influx {
private:
OWM* owm0;
OWM* owm1;
OWM** owm;
Sensor* sensor;
InfluxDBClient client = InfluxDBClient(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, cert);