Suport for many OWM monitoring
This commit is contained in:
		
							
								
								
									
										43
									
								
								metesp.ino
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								metesp.ino
									
									
									
									
									
								
							@@ -27,7 +27,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
typedef enum {
 | 
					typedef enum {
 | 
				
			||||||
  VIEW_MAIN = 0,
 | 
					  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_TEMP, VIEW_AIR, 
 | 
				
			||||||
  VIEW_CUSTOM,
 | 
					  VIEW_CUSTOM,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -38,7 +38,7 @@ static const uint8_t view_count = 5;
 | 
				
			|||||||
static uint8_t view_curr;
 | 
					static uint8_t view_curr;
 | 
				
			||||||
static const views_t view_tab[view_count] = {
 | 
					static const views_t view_tab[view_count] = {
 | 
				
			||||||
  VIEW_MAIN, 
 | 
					  VIEW_MAIN, 
 | 
				
			||||||
  VIEW_WEATHER,VIEW_WEATHER_ALT,
 | 
					  VIEW_WEATHER_0,VIEW_WEATHER_1,
 | 
				
			||||||
  VIEW_TEMP,VIEW_AIR
 | 
					  VIEW_TEMP,VIEW_AIR
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -47,10 +47,11 @@ static TwoWire I2C = TwoWire(0);
 | 
				
			|||||||
static strDateTime dateTime = {0};
 | 
					static strDateTime dateTime = {0};
 | 
				
			||||||
static Sensor* sensor = new Sensor(&I2C);
 | 
					static Sensor* sensor = new Sensor(&I2C);
 | 
				
			||||||
static GT1151* touch = new GT1151(&I2C);
 | 
					static GT1151* touch = new GT1151(&I2C);
 | 
				
			||||||
static OWM* owm = new OWM(LOCATION, OPENWEATHER_API);
 | 
					static OWM* owm[6] = {new OWM(LOCATION_0, OPENWEATHER_API), 
 | 
				
			||||||
static OWM* owm_alt = new OWM(LOCATION_ALT, 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 NTPtime NTPch(NTP_URL);
 | 
				
			||||||
static bool time_update = false, 
 | 
					static bool time_update = false, 
 | 
				
			||||||
@@ -154,7 +155,7 @@ void setup_TOUCH() {
 | 
				
			|||||||
void setup_WIFI(){
 | 
					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);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void setup_TIMER(){
 | 
					void setup_TIMER(){
 | 
				
			||||||
@@ -198,9 +199,12 @@ void updateWeather(){
 | 
				
			|||||||
  if (!weather_update) return;
 | 
					  if (!weather_update) return;
 | 
				
			||||||
  if (wifiMulti.run() != WL_CONNECTED) return;
 | 
					  if (wifiMulti.run() != WL_CONNECTED) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if(owm!= NULL && !owm->update()) return;
 | 
					  uint8_t i = 0, success = true;
 | 
				
			||||||
  if(owm_alt!= NULL && !owm_alt->update()) return;
 | 
					  while(owm && owm[i]){
 | 
				
			||||||
  weather_update = false;
 | 
					    success &= owm[i]-> update();
 | 
				
			||||||
 | 
					    ++i;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if(success) weather_update = false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void updateTime(){
 | 
					void updateTime(){
 | 
				
			||||||
@@ -246,8 +250,17 @@ void refreshDisplay(){
 | 
				
			|||||||
  Paint_SelectImage(BlackImage);
 | 
					  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(){
 | 
					void updateDisplay(){
 | 
				
			||||||
  // forceRefresh();
 | 
					 | 
				
			||||||
  if (!view_update) return;
 | 
					  if (!view_update) return;
 | 
				
			||||||
  if (view_refresh) refreshDisplay();
 | 
					  if (view_refresh) refreshDisplay();
 | 
				
			||||||
  Paint_ClearWindows(0, 0, EPD_2IN13_V2_HEIGHT, EPD_2IN13_V2_WIDTH - Font24.Height, WHITE);
 | 
					  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_DrawString_EN(60,0,"MAIN", &Font24, WHITE, BLACK);
 | 
				
			||||||
      Paint_DrawIntUnit(0,30, 69,"", &Font24, BLACK, WHITE);
 | 
					      Paint_DrawIntUnit(0,30, 69,"", &Font24, BLACK, WHITE);
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
    case VIEW_WEATHER_ALT:
 | 
					    case VIEW_WEATHER_0: 
 | 
				
			||||||
    case VIEW_WEATHER:
 | 
					    case VIEW_WEATHER_1: 
 | 
				
			||||||
 | 
					    case VIEW_WEATHER_2: 
 | 
				
			||||||
 | 
					    case VIEW_WEATHER_3:
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        OWM* cowm = (view_tab[view_curr]==VIEW_WEATHER)?owm:owm_alt;
 | 
					        OWM* cowm = viewToOWM(view_tab[view_curr]);
 | 
				
			||||||
        if(!cowm->valid_weather) break;
 | 
					        if(cowm == NULL || !cowm->valid_weather) break;
 | 
				
			||||||
        JsonObject weather_0 = cowm->weather["weather"][0];
 | 
					        JsonObject weather_0 = cowm->weather["weather"][0];
 | 
				
			||||||
        JsonObject weather_main = cowm->weather["main"];
 | 
					        JsonObject weather_main = cowm->weather["main"];
 | 
				
			||||||
        JsonObject weather_wind = cowm->weather["wind"];
 | 
					        JsonObject weather_wind = cowm->weather["wind"];
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,7 +47,7 @@ emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=\n\
 | 
				
			|||||||
class Influx {
 | 
					class Influx {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public:
 | 
					    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(){
 | 
					        void check(){
 | 
				
			||||||
            if (client.validateConnection()) {
 | 
					            if (client.validateConnection()) {
 | 
				
			||||||
@@ -60,14 +60,20 @@ class Influx {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        void record(){
 | 
					        void record(){
 | 
				
			||||||
            if(owm0) record_weather(owm0);
 | 
					            uint8_t i = 0;
 | 
				
			||||||
            if(owm1) record_weather(owm1);
 | 
					            while(owm && owm[i] != NULL){
 | 
				
			||||||
 | 
					                record_weather(owm[i]);
 | 
				
			||||||
 | 
					                ++i;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            if(sensor) record_local();
 | 
					            if(sensor) record_local();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        void record(bool w, bool s){
 | 
					        void record(bool w, bool s){
 | 
				
			||||||
            if(owm0 && w) record_weather(owm0);
 | 
					            uint8_t i = 0;
 | 
				
			||||||
            if(owm1 && w) record_weather(owm1);
 | 
					            while(w && owm && owm[i] != NULL){
 | 
				
			||||||
 | 
					                record_weather(owm[i]);
 | 
				
			||||||
 | 
					                ++i;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            if(sensor && s) record_local();
 | 
					            if(sensor && s) record_local();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -155,8 +161,7 @@ class Influx {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private:
 | 
					    private:
 | 
				
			||||||
        OWM* owm0; 
 | 
					        OWM** owm;
 | 
				
			||||||
        OWM* owm1;
 | 
					 | 
				
			||||||
        Sensor* sensor;
 | 
					        Sensor* sensor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        InfluxDBClient  client = InfluxDBClient(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, cert);
 | 
					        InfluxDBClient  client = InfluxDBClient(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, cert);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user