remote var now work
This commit is contained in:
parent
742027acf0
commit
34eeca14e0
6 changed files with 145 additions and 91 deletions
122
src/main.cpp
122
src/main.cpp
|
|
@ -1,8 +1,9 @@
|
|||
#include <main.hpp>
|
||||
|
||||
// RemoteVariable pm25_out = RemoteVariable();
|
||||
// RemoteVariable temp_out = RemoteVariable();
|
||||
// RemoteVariable weather = RemoteVariable();
|
||||
RemoteVariable pm25_out = RemoteVariable();
|
||||
RemoteVariable temp_out = RemoteVariable();
|
||||
RemoteVariable weather = RemoteVariable();
|
||||
RemoteVariable pm25_in = RemoteVariable();
|
||||
|
||||
const char *mode_names[] = {"off", "fan_only", "cool"};
|
||||
const char *fan_speed_names[] = {"auto", "high", "medium", "low"};
|
||||
|
|
@ -108,11 +109,13 @@ 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(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");
|
||||
pm25_out.begin(6, "/aqi/value", espmega.iot, true, "/aqi/request_value");
|
||||
// Temperature Remote Variable
|
||||
temp_out.begin(6, "/temp/value", espmega.iot, true, "/temp/request_value");
|
||||
// Weather Remote Variable
|
||||
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()
|
||||
|
|
@ -142,50 +145,71 @@ 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();
|
||||
// }
|
||||
//Update the PM2.5 PPM value every 15 seconds
|
||||
static uint32_t last_pm25_out_update = 0;
|
||||
if (millis() - last_pm25_out_update > 15000)
|
||||
{
|
||||
uint16_t pm25_out_value = get_pm25_out();
|
||||
//ESP_LOGI("loopPM2.5","updating PM2.5 from MQTT inside loop: %d", pm25_out_value);
|
||||
iseDisplay.updatePMoutside(pm25_out_value);
|
||||
last_pm25_out_update = millis();
|
||||
}
|
||||
// Update the PM2.5 PPM value every 15 seconds
|
||||
static uint32_t last_pm25_in_update = 0;
|
||||
if (millis() - last_pm25_in_update > 15000)
|
||||
{
|
||||
uint8_t pm25_in_value = get_pm25_in();
|
||||
iseDisplay.updatePMinside(pm25_in_value);
|
||||
last_pm25_in_update = millis();
|
||||
}
|
||||
// Update the temperature value every 15 seconds
|
||||
static uint32_t last_temp_out_update = 0;
|
||||
if (millis() - last_temp_out_update > 15000)
|
||||
{
|
||||
float temp_out_value = get_temp_out();
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
// uint16_t get_pm25_out()
|
||||
// {
|
||||
// uint16_t pm25_out_value = 0;
|
||||
// // 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;
|
||||
// }
|
||||
uint16_t get_pm25_out()
|
||||
{
|
||||
uint16_t pm25_out_value = 0;
|
||||
// Read PM2.5 PPM from sensor
|
||||
pm25_out_value = atoi(pm25_out.getValue());
|
||||
ESP_LOGI("PM2.5", "getting PM2.5 PPM from MQTT: %d", pm25_out_value);
|
||||
return pm25_out_value;
|
||||
}
|
||||
|
||||
uint16_t get_pm25_in()
|
||||
{
|
||||
uint16_t pm25_in_value = 0;
|
||||
// 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)
|
||||
{
|
||||
|
|
@ -210,9 +234,11 @@ void handlePageChange(uint8_t page)
|
|||
}
|
||||
|
||||
// iseDisplay.updatePMinside();
|
||||
/* iseDisplay.updatePMoutside(get_pm25_out());
|
||||
iseDisplay.updatePMoutside(get_pm25_out());
|
||||
iseDisplay.updatePMinside(get_pm25_in());
|
||||
iseDisplay.updateWeather(weather.getValue());
|
||||
iseDisplay.updateTempOutside(get_temp_out()); */
|
||||
iseDisplay.updateTempOutside(get_temp_out());
|
||||
|
||||
/* iseDisplay.updateACState();
|
||||
iseDisplay.updateAirPurifierState();
|
||||
iseDisplay.updateLightGroupStatePageStandby();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue