remote var now work

This commit is contained in:
reaw 2024-02-12 03:23:25 +07:00
parent 742027acf0
commit 34eeca14e0
6 changed files with 145 additions and 91 deletions

View file

@ -12,7 +12,7 @@
platform = espressif32 platform = espressif32
board = wt32-eth01 board = wt32-eth01
framework = arduino framework = arduino
lib_deps = siwats/ESPMegaPROR3@^2.2.4 lib_deps = siwats/ESPMegaPROR3@^2.2.5
monitor_speed = 115200 monitor_speed = 115200
build_flags = -DCORE_DEBUG_LEVEL=5 build_flags = -DCORE_DEBUG_LEVEL=5
upload_port = COM28 upload_port = COM28

View file

@ -33,9 +33,9 @@ object id:
5 s_pm_toggle 5 s_pm_toggle
6 s_time (txt) -> date 6 s_time (txt) -> date
7 s_date (txt) -> time 7 s_date (txt) -> time
8 s_outside_temp (txt) -> outside_temp 8 s_outside_temp (txt) -> temp_outside
9 idle_timer (timer) // wait one min for inactivity then dim screen 9 idle_timer (timer) // wait one min for inactivity then dim screen
10 s_weather_icon (pic) 10 weather_icon (pic)
picture id: picture id:

View file

@ -112,7 +112,6 @@ void ISEDisplay::handleTouch(uint8_t page, uint8_t component, uint8_t touch_type
else if (page == PAGE_DASHBOARD) else if (page == PAGE_DASHBOARD)
{ {
switch (component) switch (component)
{ {
case COMPONENT_LIGHT_MASTER_BUTTON: case COMPONENT_LIGHT_MASTER_BUTTON:
@ -326,6 +325,10 @@ void ISEDisplay::updateWeather(char *weather_string)
{ {
weather_code = 63; weather_code = 63;
} }
else if (strcmp(weather_string, "sunny") == 0)
{
weather_code = 63;
}
else if (strcmp(weather_string, "fair_night") == 0) else if (strcmp(weather_string, "fair_night") == 0)
{ {
weather_code = 64; weather_code = 64;
@ -334,11 +337,11 @@ void ISEDisplay::updateWeather(char *weather_string)
{ {
weather_code = 65; weather_code = 65;
} }
else if (strcmp(weather_string, "clearsky_day") == 0) else if (strcmp(weather_string, "clear-day") == 0)
{ {
weather_code = 66; weather_code = 66;
} }
else if (strcmp(weather_string, "clearsky_night") == 0) else if (strcmp(weather_string, "clear-night") == 0)
{ {
weather_code = 67; weather_code = 67;
} }
@ -346,6 +349,10 @@ void ISEDisplay::updateWeather(char *weather_string)
{ {
weather_code = 68; weather_code = 68;
} }
else if (strcmp(weather_string, "partlycloudy") == 0)
{
weather_code = 68;
}
else if (strcmp(weather_string, "partlycloudy_night") == 0) else if (strcmp(weather_string, "partlycloudy_night") == 0)
{ {
weather_code = 69; weather_code = 69;
@ -366,6 +373,10 @@ void ISEDisplay::updateWeather(char *weather_string)
{ {
weather_code = 73; weather_code = 73;
} }
else if (strcmp(weather_string, "rainy") == 0)
{
weather_code = 73;
}
else if (strcmp(weather_string, "lightrain") == 0) else if (strcmp(weather_string, "lightrain") == 0)
{ {
weather_code = 74; weather_code = 74;
@ -378,9 +389,11 @@ void ISEDisplay::updateWeather(char *weather_string)
{ {
weather_code = 68; weather_code = 68;
} }
ESP_LOGI("ISEDisplay", "Updating weather to: %s (%d)", weather_string, weather_code);
this->takeSerialMutex(); if (!this->takeSerialMutex())
this->displayAdapter->printf("weather_icon.pic=%s", weather_code); return;
this->displayAdapter->printf("weather_icon.pic=%d", weather_code);
this->sendStopBytes(); this->sendStopBytes();
this->giveSerialMutex(); this->giveSerialMutex();
} }
@ -390,22 +403,37 @@ void ISEDisplay::updateTempOutside(float temp_outside)
// change temp_outside to int then display // change temp_outside to int then display
u_int8_t temp_outside_int = (u_int8_t)temp_outside; u_int8_t temp_outside_int = (u_int8_t)temp_outside;
ESP_LOGI("ISEDisplay", "Updating temperature outside to: %d", temp_outside_int);
this->takeSerialMutex(); this->takeSerialMutex();
this->displayAdapter->printf("temp_outside.txt=%d", temp_outside_int); this->displayAdapter->printf("outside_temp.txt=\"%d\"", temp_outside_int);
this->sendStopBytes(); this->sendStopBytes();
this->giveSerialMutex(); this->giveSerialMutex();
} }
void ISEDisplay::updatePMoutside(u_int16_t pm25_outside) void ISEDisplay::updatePMoutside(u_int16_t pm25_outside)
{
ESP_LOGI("ISEDisplay", "Updating PM2.5 outside to: %d", pm25_outside);
u_int16_t curPage = this->currentPage;
if (curPage == 2)
{ {
this->takeSerialMutex(); this->takeSerialMutex();
this->displayAdapter->printf("pm_outside.txt=%d", pm25_outside); this->displayAdapter->printf("pm_out.txt=\"%d\"", pm25_outside);
this->sendStopBytes(); this->sendStopBytes();
this->giveSerialMutex(); this->giveSerialMutex();
}
// TODO : use remotevar to get PM2.5 data from appdaemon and update the display // TODO : use remotevar to get PM2.5 data from appdaemon and update the display
} }
void ISEDisplay::updatePMinside(u_int8_t pm25_inside) void ISEDisplay::updatePMinside(u_int16_t pm25_inside)
{ {
// TODO : get data from HA's Xiaomi air purifier sensor // TODO : get data from HA's Xiaomi air purifier sensor
ESP_LOGI("ISEDisplay", "Updating PM2.5 inside to: %d", pm25_inside);
u_int16_t curPage = this->currentPage;
if (curPage == 2)
{
this->takeSerialMutex();
this->displayAdapter->printf("pm_in.txt=\"%d\"", pm25_inside);
this->sendStopBytes();
this->giveSerialMutex();
}
} }
void ISEDisplay::setPMstate(bool is_pm_on, uint8_t pm_fan_speed) void ISEDisplay::setPMstate(bool is_pm_on, uint8_t pm_fan_speed)
@ -417,7 +445,6 @@ void ISEDisplay::setACstate(uint8_t ac_fan_speed, uint8_t ac_mode, uint8_t ac_te
{ {
ESP_LOGI("ISEDisplay", "Setting AC state: = fan speed: %d, mode: %d, temperature: %d", ac_fan_speed, ac_mode, ac_temperature); ESP_LOGI("ISEDisplay", "Setting AC state: = fan speed: %d, mode: %d, temperature: %d", ac_fan_speed, ac_mode, ac_temperature);
this->climateCard->setFanSpeed(ac_fan_speed); this->climateCard->setFanSpeed(ac_fan_speed);
ESP_LOGI("ISEDisplay", "AC fan speed set to: %d", ac_fan_speed); ESP_LOGI("ISEDisplay", "AC fan speed set to: %d", ac_fan_speed);
this->climateCard->setMode(ac_mode); this->climateCard->setMode(ac_mode);

View file

@ -29,7 +29,7 @@ class ISEDisplay : public ESPMegaDisplay {
void updateWeather(char *weather_string); void updateWeather(char *weather_string);
void updateTempOutside(float temp_outside); void updateTempOutside(float temp_outside);
void updatePMoutside(u_int16_t pm25_outside); void updatePMoutside(u_int16_t pm25_outside);
void updatePMinside(u_int8_t pm25_inside); void updatePMinside(u_int16_t pm25_inside);
void loop(); void loop();

View file

@ -1,8 +1,9 @@
#include <main.hpp> #include <main.hpp>
// RemoteVariable pm25_out = RemoteVariable(); RemoteVariable pm25_out = RemoteVariable();
// RemoteVariable temp_out = RemoteVariable(); RemoteVariable temp_out = RemoteVariable();
// RemoteVariable weather = RemoteVariable(); RemoteVariable weather = RemoteVariable();
RemoteVariable pm25_in = RemoteVariable();
const char *mode_names[] = {"off", "fan_only", "cool"}; const char *mode_names[] = {"off", "fan_only", "cool"};
const char *fan_speed_names[] = {"auto", "high", "medium", "low"}; const char *fan_speed_names[] = {"auto", "high", "medium", "low"};
@ -108,11 +109,13 @@ void setup()
// PM2.5 PPM Remote Variable // PM2.5 PPM Remote Variable
// 12 bytes remote variable, 11 characters + null terminator // 12 bytes remote variable, 11 characters + null terminator
// Enable value request at /iqair/pm25_request // Enable value request at /iqair/pm25_request
// pm25_out.begin(6, "/aqi/value", espmega.iot, true, "/aqi/value_request"); pm25_out.begin(6, "/aqi/value", espmega.iot, true, "/aqi/request_value");
// // Temperature Remote Variable // Temperature Remote Variable
// temp_out.begin(6, "/temp/value", espmega.iot, true, "/weather/temp_request"); temp_out.begin(6, "/temp/value", espmega.iot, true, "/temp/request_value");
// // Weather Remote Variable // Weather Remote Variable
// weather.begin(45, "/weather", espmega.iot, true, "/weather_request"); weather.begin(45, "/weather/value", espmega.iot, true, "/weather/request_value");
// PM2.5 PPM Remote Variable
pm25_in.begin(6, "/pm/value", espmega.iot, true, "/pm/request_value");
} }
void loop() void loop()
@ -142,50 +145,71 @@ void loop()
iseDisplay.updateDateTimeText(time); iseDisplay.updateDateTimeText(time);
last_time_updated = millis(); last_time_updated = millis();
} }
// Update the PM2.5 PPM value every 5 minutes //Update the PM2.5 PPM value every 15 seconds
// static uint32_t last_pm25_out_update = 0; static uint32_t last_pm25_out_update = 0;
// if (millis() - last_pm25_out_update > 300000) if (millis() - last_pm25_out_update > 15000)
// { {
// uint16_t pm25_out_value = get_pm25_out(); uint16_t pm25_out_value = get_pm25_out();
// iseDisplay.updatePMoutside(pm25_out_value); //ESP_LOGI("loopPM2.5","updating PM2.5 from MQTT inside loop: %d", pm25_out_value);
// last_pm25_out_update = millis(); 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; // Update the PM2.5 PPM value every 15 seconds
// if (millis() - last_temp_out_update > 300000) static uint32_t last_pm25_in_update = 0;
// { if (millis() - last_pm25_in_update > 15000)
// float temp_out_value = get_temp_out(); {
// iseDisplay.updateTempOutside(temp_out_value); uint8_t pm25_in_value = get_pm25_in();
// last_temp_out_update = millis(); iseDisplay.updatePMinside(pm25_in_value);
// } last_pm25_in_update = millis();
// // Update the weather value every 5 minutes }
// static uint32_t last_weather_update = 0; // Update the temperature value every 15 seconds
// if (millis() - last_weather_update > 300000) static uint32_t last_temp_out_update = 0;
// { if (millis() - last_temp_out_update > 15000)
// char *weather_value = weather.getValue(); {
// iseDisplay.updateWeather(weather_value); float temp_out_value = get_temp_out();
// last_weather_update = millis(); iseDisplay.updateTempOutside(temp_out_value);
// } last_temp_out_update = millis();
}
// Update the weather value every 15 seconds
static uint32_t last_weather_update = 0;
if (millis() - last_weather_update > 15000)
{
char *weather_value = weather.getValue();
iseDisplay.updateWeather(weather_value);
last_weather_update = millis();
}
} }
void on_pin_change(uint8_t pin, uint8_t value) void on_pin_change(uint8_t pin, uint8_t value)
{ {
} }
// uint16_t get_pm25_out() uint16_t get_pm25_out()
// { {
// uint16_t pm25_out_value = 0; uint16_t pm25_out_value = 0;
// // Read PM2.5 PPM from sensor // Read PM2.5 PPM from sensor
// pm25_out_value = atoi(pm25_out.getValue()); pm25_out_value = atoi(pm25_out.getValue());
// return pm25_out_value; ESP_LOGI("PM2.5", "getting PM2.5 PPM from MQTT: %d", pm25_out_value);
// } return pm25_out_value;
// float get_temp_out() }
// {
// float temp_out_value = 0; uint16_t get_pm25_in()
// // Read temperature from sensor {
// temp_out_value = atof(temp_out.getValue()); uint16_t pm25_in_value = 0;
// return temp_out_value; // Read PM2.5 PPM from sensor
// } pm25_in_value = atoi(pm25_in.getValue());
ESP_LOGI("PM2.5", "getting PM2.5 PPM from MQTT: %d", pm25_in_value);
return pm25_in_value;
}
float get_temp_out()
{
float temp_out_value = 0;
// Read temperature from sensor
temp_out_value = atof(temp_out.getValue());
ESP_LOGI("Temperature", "getting Temperature from MQTT: %f", temp_out_value);
return temp_out_value;
}
void handlePageChange(uint8_t page) void handlePageChange(uint8_t page)
{ {
@ -210,9 +234,11 @@ void handlePageChange(uint8_t page)
} }
// iseDisplay.updatePMinside(); // iseDisplay.updatePMinside();
/* iseDisplay.updatePMoutside(get_pm25_out()); iseDisplay.updatePMoutside(get_pm25_out());
iseDisplay.updatePMinside(get_pm25_in());
iseDisplay.updateWeather(weather.getValue()); iseDisplay.updateWeather(weather.getValue());
iseDisplay.updateTempOutside(get_temp_out()); */ iseDisplay.updateTempOutside(get_temp_out());
/* iseDisplay.updateACState(); /* iseDisplay.updateACState();
iseDisplay.updateAirPurifierState(); iseDisplay.updateAirPurifierState();
iseDisplay.updateLightGroupStatePageStandby(); iseDisplay.updateLightGroupStatePageStandby();

View file

@ -35,4 +35,5 @@ void loop();
void on_pin_change(uint8_t pin, uint8_t value); void on_pin_change(uint8_t pin, uint8_t value);
uint16_t get_pm25_out(); uint16_t get_pm25_out();
uint16_t get_pm25_in();
float get_temp_out(); float get_temp_out();