diff --git a/src/ise_display.cpp b/src/ise_display.cpp index a9f6503..af60c80 100644 --- a/src/ise_display.cpp +++ b/src/ise_display.cpp @@ -7,7 +7,6 @@ ISEDisplay::ISEDisplay(HardwareSerial *adapter) : ESPMegaDisplay(adapter, 115200 // debug to work // appdeamon send data / receive data - void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCard, ClimateCard *climateCard) { this->inputCard = inputCard; @@ -274,15 +273,93 @@ void ISEDisplay::updateDateTimeText(rtctime_t time) // TODO : Implement // user remote var // appdeamon -void ISEDisplay::updateWeather(uint8_t weather_code, float outside_temp) +void ISEDisplay::updateWeather(char *weather_string) { // TODO : use remotevar to get weather data from appdaemon and update the display + u_int8_t weather_code = 68; + + if (strcmp(weather_string, "fair_day") == 0) + { + weather_code = 63; + } + else if (strcmp(weather_string, "fair_night") == 0) + { + weather_code = 64; + } + else if (strcmp(weather_string, "cloudy") == 0) + { + weather_code = 65; + } + else if (strcmp(weather_string, "clearsky_day") == 0) + { + weather_code = 66; + } + else if (strcmp(weather_string, "clearsky_night") == 0) + { + weather_code = 67; + } + else if (strcmp(weather_string, "partlycloudy_day") == 0) + { + weather_code = 68; + } + else if (strcmp(weather_string, "partlycloudy_night") == 0) + { + weather_code = 69; + } + else if (strcmp(weather_string, "heavyrain") == 0) + { + weather_code = 70; + } + else if (strcmp(weather_string, "heavyrainandthunder") == 0) + { + weather_code = 71; + } + else if (strcmp(weather_string, "rainandthunder") == 0) + { + weather_code = 72; + } + else if (strcmp(weather_string, "rain") == 0) + { + weather_code = 73; + } + else if (strcmp(weather_string, "lightrain") == 0) + { + weather_code = 74; + } + else if (strcmp(weather_string, "fog") == 0) + { + weather_code = 75; + } + else + { + weather_code = 68; + } + + this->takeSerialMutex(); + this->displayAdapter->printf("weather_icon.pic=%s", weather_code); + this->sendStopBytes(); + this->giveSerialMutex(); } -void ISEDisplay::updatePMoutside(float pm25_outside) +void ISEDisplay::updateTempOutside(float temp_outside) { // TODO : use remotevar to get PM2.5 data from appdaemon and update the display + + //change temp_outside to int then display + u_int8_t temp_outside_int = (u_int8_t)temp_outside; + this->takeSerialMutex(); + this->displayAdapter->printf("temp_outside.txt=%d", temp_outside_int); + this->sendStopBytes(); + this->giveSerialMutex(); } -void ISEDisplay::updatePMinside(float pm25_inside) +void ISEDisplay::updatePMoutside(u_int16_t pm25_outside) +{ + this->takeSerialMutex(); + this->displayAdapter->printf("pm_outside.txt=%d", pm25_outside); + this->sendStopBytes(); + this->giveSerialMutex(); + // TODO : use remotevar to get PM2.5 data from appdaemon and update the display +} +void ISEDisplay::updatePMinside(u_int8_t pm25_inside) { // TODO : get data from HA's Xiaomi air purifier sensor } diff --git a/src/ise_display.hpp b/src/ise_display.hpp index 8830bcf..5dbe09f 100644 --- a/src/ise_display.hpp +++ b/src/ise_display.hpp @@ -23,9 +23,10 @@ class ISEDisplay : public ESPMegaDisplay { void begin(DigitalInputCard* inputCard, DigitalOutputCard* outputCard, ClimateCard* climateCard); void updateDateTimeText(rtctime_t time); - void updateWeather(uint8_t weather_code, float outside_temp); - void updatePMoutside(float pm25_outside); - void updatePMinside(float pm25_inside); + void updateWeather(char *weather_string); + void updateTempOutside(float temp_outside); + void updatePMoutside(u_int16_t pm25_outside); + void updatePMinside(u_int8_t pm25_inside); void loop(); private: diff --git a/src/main.cpp b/src/main.cpp index e1015f4..8ff0f28 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,9 @@ #include + RemoteVariable pm25_out = RemoteVariable(); +RemoteVariable temp_out = RemoteVariable(); +RemoteVariable weather = RemoteVariable(); const char *mode_names[] = {"off", "fan_only", "cool"}; const char *fan_speed_names[] = {"auto", "high", "medium", "low"}; @@ -107,7 +110,11 @@ void setup() // PM2.5 PPM Remote Variable // 12 bytes remote variable, 11 characters + null terminator // Enable value request at /iqair/pm25_request - pm25_out.begin(12, "/iqair/pm25_ppm", espmega.iot, true, "/iqair/pm25_request"); + pm25_out.begin(6, "/aqi/value", espmega.iot, true, "/aqi/value_request"); + // Temperature Remote Variable + temp_out.begin(6, "/temp/value", espmega.iot, true, "/weather/temp_request"); + // Weather Remote Variable + weather.begin(45, "/weather", espmega.iot, true, "/weather_request"); } void loop() @@ -123,6 +130,31 @@ void loop() iseDisplay.updateDateTimeText(time); last_time_updated = millis(); } + // Update the PM2.5 PPM value every 5 minutes + static uint32_t last_pm25_out_update = 0; + if (millis() - last_pm25_out_update > 300000) + { + uint16_t pm25_out_value = get_pm25_out(); + iseDisplay.updatePMoutside(pm25_out_value); + last_pm25_out_update = millis(); + } + // Update the temperature value every 5 minutes + static uint32_t last_temp_out_update = 0; + if (millis() - last_temp_out_update > 300000) + { + float temp_out_value = get_temp_out(); + iseDisplay.updateTempOutside(temp_out_value); + last_temp_out_update = millis(); + } + // Update the weather value every 5 minutes + static uint32_t last_weather_update = 0; + if (millis() - last_weather_update > 300000) + { + char *weather_value = weather.getValue(); + iseDisplay.updateWeather(weather_value); + last_weather_update = millis(); + } + } void on_pin_change(uint8_t pin, uint8_t value) @@ -136,4 +168,11 @@ uint16_t get_pm25_out() // Read PM2.5 PPM from sensor pm25_out_value = atoi(pm25_out.getValue()); return pm25_out_value; +} +float get_temp_out() +{ + float temp_out_value = 0; + // Read temperature from sensor + temp_out_value = atof(temp_out.getValue()); + return temp_out_value; } \ No newline at end of file diff --git a/src/main.hpp b/src/main.hpp index 55489ef..df1e403 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -1,8 +1,11 @@ #pragma once #include +SET_LOOP_TASK_STACK_SIZE(32*1024); #include #include + + /*********************************************** * Begin Configuration * ************************************************/ @@ -30,4 +33,5 @@ void loop(); void on_pin_change(uint8_t pin, uint8_t value); -uint16_t get_pm25_out(); \ No newline at end of file +uint16_t get_pm25_out(); +float get_temp_out();