implement remote variable
This commit is contained in:
parent
d8c57b4a22
commit
cac235a536
4 changed files with 130 additions and 9 deletions
|
|
@ -7,7 +7,6 @@ ISEDisplay::ISEDisplay(HardwareSerial *adapter) : ESPMegaDisplay(adapter, 115200
|
||||||
// debug to work
|
// debug to work
|
||||||
// appdeamon send data / receive data
|
// appdeamon send data / receive data
|
||||||
|
|
||||||
|
|
||||||
void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCard, ClimateCard *climateCard)
|
void ISEDisplay::begin(DigitalInputCard *inputCard, DigitalOutputCard *outputCard, ClimateCard *climateCard)
|
||||||
{
|
{
|
||||||
this->inputCard = inputCard;
|
this->inputCard = inputCard;
|
||||||
|
|
@ -274,15 +273,93 @@ void ISEDisplay::updateDateTimeText(rtctime_t time)
|
||||||
// TODO : Implement
|
// TODO : Implement
|
||||||
// user remote var
|
// user remote var
|
||||||
// appdeamon
|
// 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
|
// 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
|
// 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
|
// TODO : get data from HA's Xiaomi air purifier sensor
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,10 @@ class ISEDisplay : public ESPMegaDisplay {
|
||||||
void begin(DigitalInputCard* inputCard, DigitalOutputCard* outputCard, ClimateCard* climateCard);
|
void begin(DigitalInputCard* inputCard, DigitalOutputCard* outputCard, ClimateCard* climateCard);
|
||||||
|
|
||||||
void updateDateTimeText(rtctime_t time);
|
void updateDateTimeText(rtctime_t time);
|
||||||
void updateWeather(uint8_t weather_code, float outside_temp);
|
void updateWeather(char *weather_string);
|
||||||
void updatePMoutside(float pm25_outside);
|
void updateTempOutside(float temp_outside);
|
||||||
void updatePMinside(float pm25_inside);
|
void updatePMoutside(u_int16_t pm25_outside);
|
||||||
|
void updatePMinside(u_int8_t pm25_inside);
|
||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
41
src/main.cpp
41
src/main.cpp
|
|
@ -1,6 +1,9 @@
|
||||||
#include <main.hpp>
|
#include <main.hpp>
|
||||||
|
|
||||||
|
|
||||||
RemoteVariable pm25_out = RemoteVariable();
|
RemoteVariable pm25_out = RemoteVariable();
|
||||||
|
RemoteVariable temp_out = RemoteVariable();
|
||||||
|
RemoteVariable weather = 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"};
|
||||||
|
|
@ -107,7 +110,11 @@ 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(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()
|
void loop()
|
||||||
|
|
@ -123,6 +130,31 @@ 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
|
||||||
|
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)
|
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
|
// Read PM2.5 PPM from sensor
|
||||||
pm25_out_value = atoi(pm25_out.getValue());
|
pm25_out_value = atoi(pm25_out.getValue());
|
||||||
return pm25_out_value;
|
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;
|
||||||
}
|
}
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <ESPMegaProOS.hpp>
|
#include <ESPMegaProOS.hpp>
|
||||||
|
SET_LOOP_TASK_STACK_SIZE(32*1024);
|
||||||
#include <ise_display.hpp>
|
#include <ise_display.hpp>
|
||||||
#include <ir_codes.hpp>
|
#include <ir_codes.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***********************************************
|
/***********************************************
|
||||||
* Begin Configuration *
|
* Begin Configuration *
|
||||||
************************************************/
|
************************************************/
|
||||||
|
|
@ -30,4 +33,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();
|
||||||
|
float get_temp_out();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue