mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
systemCheck() now calls read functions
This commit is contained in:
@@ -187,9 +187,10 @@ The Boiler (ID 0x08) will send out these broadcast telegrams regularly:
|
||||
|
||||
And a thermostat (ID 0x17 for a RC20) would broadcast these messages regularly:
|
||||
|
||||
| Type | Description |
|
||||
| ---- | ----------- | undefined |undefined |undefined |undefined |undefined |undefined |undefined |undefined |undefined |undefined |undefined |undefined |undefined |undefined |undefined |undefined |undefined |undefined |
|
||||
| 0x06 | time on thermostat Y,M,H,D,M,S,wd |
|
||||
| Type | Description | Frequency |
|
||||
| ---- | ------------------------------------------------- | ------------ |
|
||||
| 0x06 | RC20Time - time on thermostat Y M H D M S weekday | every minute |
|
||||
| 0x91 | RC20StatusMessage - | every minute |
|
||||
|
||||
Refer to the code in `ems.cpp` for further explanation on how to parse these message types and also reference the EMS Wiki.
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ Ticker systemCheckTimer;
|
||||
Ticker heartbeatTimer;
|
||||
Ticker showerResetTimer;
|
||||
#define publishValuesTime 300 // every 5 mins post HA values
|
||||
#define systemCheckTime 10 // every 10 seconds check if Boiler is online
|
||||
#define systemCheckTime 30 // every 30 seconds check if Boiler is online and execute other requests
|
||||
#define heartbeatTime 1 // every second blink heartbeat LED
|
||||
|
||||
// hostname is also used as the MQTT topic identifier (home/<hostname>)
|
||||
@@ -89,6 +89,7 @@ const uint8_t SHOWER_BURNPOWER_MIN = 80;
|
||||
typedef struct {
|
||||
bool wifi_connected;
|
||||
bool boiler_online;
|
||||
bool thermostat_enabled;
|
||||
bool shower_enabled; // true if we want to report back on shower times
|
||||
bool shower_timer; // true if we want the cold water reminder
|
||||
} _Boiler_Status;
|
||||
@@ -227,7 +228,7 @@ void showInfo() {
|
||||
EMS_Boiler.heatWorkMin % 60);
|
||||
|
||||
// Thermostat stats
|
||||
if (EMS_Sys_Status.emsThermostatEnabled) {
|
||||
if (Boiler_Status.thermostat_enabled) {
|
||||
myDebug("Thermostat stats:\n Thermostat time is %02d:%02d:%02d %d/%d/%d\n",
|
||||
EMS_Thermostat.hour,
|
||||
EMS_Thermostat.minute,
|
||||
@@ -342,6 +343,7 @@ void myDebugCallback() {
|
||||
case 'T': // toggle Thermostat
|
||||
b = !ems_getThermostatEnabled();
|
||||
ems_setThermostatEnabled(b);
|
||||
Boiler_Status.thermostat_enabled = b;
|
||||
break;
|
||||
case 'S': // toggle Shower timer support
|
||||
Boiler_Status.shower_enabled = !Boiler_Status.shower_enabled;
|
||||
@@ -397,9 +399,10 @@ void WIFIcallback() {
|
||||
// Initialize the boiler settings
|
||||
void _initBoiler() {
|
||||
// default settings
|
||||
ems_setThermostatEnabled(BOILER_THERMOSTAT_ENABLED);
|
||||
Boiler_Status.shower_enabled = BOILER_SHOWER_ENABLED;
|
||||
Boiler_Status.shower_timer = BOILER_SHOWER_TIMER;
|
||||
Boiler_Status.shower_enabled = BOILER_SHOWER_ENABLED;
|
||||
Boiler_Status.shower_timer = BOILER_SHOWER_TIMER;
|
||||
Boiler_Status.thermostat_enabled = BOILER_THERMOSTAT_ENABLED;
|
||||
ems_setThermostatEnabled(Boiler_Status.thermostat_enabled);
|
||||
|
||||
// init boiler
|
||||
Boiler_Status.wifi_connected = false;
|
||||
@@ -427,9 +430,9 @@ void setup() {
|
||||
digitalWrite(LED_ERR, HIGH);
|
||||
|
||||
// Timers
|
||||
publishValuesTimer.attach(publishValuesTime, publishValues); // every 5 mins (300000) post HA values
|
||||
systemCheckTimer.attach(systemCheckTime, systemCheck); // every 10 seconds check if Boiler is online
|
||||
heartbeatTimer.attach(heartbeatTime, heartbeat); // every second blink heartbeat LED
|
||||
publishValuesTimer.attach(publishValuesTime, publishValues); // post HA values
|
||||
systemCheckTimer.attach(systemCheckTime, systemCheck); // check if Boiler is online
|
||||
heartbeatTimer.attach(heartbeatTime, heartbeat); // blink heartbeat LED
|
||||
|
||||
// set up Wifi, MQTT, Telnet
|
||||
myESP.setWifiCallback(WIFIcallback);
|
||||
@@ -484,11 +487,17 @@ void heartbeat() {
|
||||
}
|
||||
|
||||
// do a healthcheck every now and then to see if we connections
|
||||
// also this is place to send requests to the EMS
|
||||
void systemCheck() {
|
||||
Boiler_Status.boiler_online = ((timestamp - EMS_Sys_Status.emsLastPoll) < POLL_TIMEOUT_ERR);
|
||||
if (!Boiler_Status.boiler_online) {
|
||||
myDebug("Error! Boiler unreachable. Please check connection. Retrying in 10 seconds.\n");
|
||||
}
|
||||
|
||||
// send any custom requests here
|
||||
if (Boiler_Status.thermostat_enabled) {
|
||||
ems_doReadCommand(EMS_TYPE_RC20Temperature); // get the thermostat mode
|
||||
}
|
||||
}
|
||||
|
||||
// turn off hot water to send a shot of cold
|
||||
|
||||
72
src/ems.cpp
72
src/ems.cpp
@@ -15,34 +15,6 @@
|
||||
_EMS_Sys_Status EMS_Sys_Status; // EMS Status
|
||||
_EMS_TxTelegram EMS_TxTelegram; // Empty buffer for sending telegrams
|
||||
|
||||
// define here the Thermostat type
|
||||
#define EMS_ID_THERMOSTAT 0x17 // x17=RC20, x10=RC30 (Moduline 300)
|
||||
|
||||
// define here the EMS telegram types you need
|
||||
// Boiler...
|
||||
#define EMS_TYPE_UBAMonitorFast 0x18 // is an automatic monitor broadcast
|
||||
#define EMS_TYPE_UBAMonitorSlow 0x19 // is an automatic monitor broadcast
|
||||
#define EMS_TYPE_UBAMonitorWWMessage 0x34 // is an automatic monitor broadcast
|
||||
#define EMS_TYPE_UBAMaintenanceStatusMessage 0x1c // is an automatic monitor broadcast
|
||||
#define EMS_TYPE_UBAParameterWW 0x33
|
||||
|
||||
#define EMS_TYPE_UBATotalUptimeMessage 0x14
|
||||
#define EMS_TYPE_UBAMaintenanceSettingsMessage 0x15
|
||||
#define EMS_TYPE_UBAParametersMessage 0x16
|
||||
|
||||
// Thermostat...
|
||||
#define EMS_TYPE_RC20StatusMessage 0x91
|
||||
#define EMS_TYPE_RC20Time 0x06 // is an automatic monitor broadcast
|
||||
#define EMS_TYPE_RC20Temperature 0xA8
|
||||
#define EMS_TYPE_RCOutdoorTempMessage 0xa3 // we can ignore
|
||||
#define EMS_TYPE_Version 0x02 // version of the controller
|
||||
|
||||
// Offsets for specific values in a telegram, per type, used for validation
|
||||
#define EMS_OFFSET_RC20Temperature_temp 0x1C // thermostat set temp
|
||||
#define EMS_OFFSET_RC20Temperature_mode 0x17 // thermostat mode
|
||||
#define EMS_OFFSET_UBAParameterWW_wwtemp 0x02 // WW Temperature
|
||||
#define EMS_OFFSET_UBAParameterWW_wwactivated 0x01 // WW Activated
|
||||
|
||||
// and call backs
|
||||
#define MAX_TYPECALLBACK 12 // make sure it matches the #types you have
|
||||
// callbacks per type
|
||||
@@ -65,7 +37,7 @@ const _EMS_Types EMS_Types[MAX_TYPECALLBACK] =
|
||||
{EMS_ID_BOILER, EMS_TYPE_UBAParametersMessage, "UBAParametersMessage", 30, NULL},
|
||||
{EMS_ID_BOILER, EMS_TYPE_UBAMaintenanceStatusMessage, "UBAMaintenanceStatusMessage", 30, NULL},
|
||||
|
||||
{EMS_ID_THERMOSTAT, EMS_TYPE_RC20StatusMessage, "RC20StatusMessage", 3, _process_RC20StatusMessage},
|
||||
{EMS_ID_THERMOSTAT, EMS_TYPE_RC20StatusMessage, "RC20StatusMessage", 19, _process_RC20StatusMessage},
|
||||
{EMS_ID_THERMOSTAT, EMS_TYPE_RC20Time, "RC20Time", 20, _process_RC20Time},
|
||||
{EMS_ID_THERMOSTAT, EMS_TYPE_RC20Temperature, "RC20Temperature", 27, _process_RC20Temperature},
|
||||
{EMS_ID_THERMOSTAT, EMS_TYPE_Version, "Version", 2, _process_Version}};
|
||||
@@ -586,8 +558,8 @@ bool _process_RC20Temperature(uint8_t * data, uint8_t length) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Version - type 0x02 - get the version of the Thermostat firmware
|
||||
*/
|
||||
* Version - type 0x02 - get the version of the Thermostat firmware
|
||||
*/
|
||||
bool _process_Version(uint8_t * data, uint8_t length) {
|
||||
uint8_t major = data[1];
|
||||
uint8_t minor = data[2];
|
||||
@@ -598,8 +570,8 @@ bool _process_Version(uint8_t * data, uint8_t length) {
|
||||
}
|
||||
|
||||
/*
|
||||
* process_RC20Time - type 0x06 - date and time from the RC20 thermostat (0x17) - 14 bytes long
|
||||
*/
|
||||
* process_RC20Time - type 0x06 - date and time from the RC20 thermostat (0x17) - 14 bytes long
|
||||
*/
|
||||
bool _process_RC20Time(uint8_t * data, uint8_t length) {
|
||||
EMS_Thermostat.hour = data[2];
|
||||
EMS_Thermostat.minute = data[4];
|
||||
@@ -620,8 +592,8 @@ bool _process_RC20Time(uint8_t * data, uint8_t length) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Build the telegram, which includes a single byte followed by the CRC at the end
|
||||
*/
|
||||
* Build the telegram, which includes a single byte followed by the CRC at the end
|
||||
*/
|
||||
void _buildTxTelegram(uint8_t data_value) {
|
||||
// header
|
||||
EMS_TxTelegram.data[0] = EMS_ID_ME; // src
|
||||
@@ -640,10 +612,10 @@ void _buildTxTelegram(uint8_t data_value) {
|
||||
|
||||
|
||||
/*
|
||||
* Send a command to Tx to Read from another device
|
||||
* Read commands when sent must to responded too by the destination (target) immediately
|
||||
* usually within a 10ms window
|
||||
*/
|
||||
* Send a command to Tx to Read from another device
|
||||
* Read commands when sent must to responded too by the destination (target) immediately
|
||||
* usually within a 10ms window
|
||||
*/
|
||||
void ems_doReadCommand(uint8_t type) {
|
||||
if (type == EMS_TYPE_NONE)
|
||||
return; // not a valid type, quit
|
||||
@@ -686,8 +658,8 @@ void ems_doReadCommand(uint8_t type) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the temperature of the thermostat
|
||||
*/
|
||||
* Set the temperature of the thermostat
|
||||
*/
|
||||
void ems_setThermostatTemp(float temperature) {
|
||||
if (_checkWriteQueueFull())
|
||||
return; // check if there is already something in the queue
|
||||
@@ -708,8 +680,8 @@ void ems_setThermostatTemp(float temperature) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the thermostat working mode (0=low, 1=manual, 2=clock/auto)
|
||||
*/
|
||||
* Set the thermostat working mode (0=low, 1=manual, 2=clock/auto)
|
||||
*/
|
||||
void ems_setThermostatMode(uint8_t mode) {
|
||||
if (_checkWriteQueueFull())
|
||||
return; // check if there is already something in the queue
|
||||
@@ -729,8 +701,8 @@ void ems_setThermostatMode(uint8_t mode) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the warm water temperature
|
||||
*/
|
||||
* Set the warm water temperature
|
||||
*/
|
||||
void ems_setWarmWaterTemp(uint8_t temperature) {
|
||||
if (_checkWriteQueueFull())
|
||||
return; // check if there is already something in the queue
|
||||
@@ -749,9 +721,9 @@ void ems_setWarmWaterTemp(uint8_t temperature) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Activate / De-activate the Warm Water
|
||||
* true = on, false = off
|
||||
*/
|
||||
* Activate / De-activate the Warm Water
|
||||
* true = on, false = off
|
||||
*/
|
||||
void ems_setWarmWaterActivated(bool activated) {
|
||||
if (_checkWriteQueueFull())
|
||||
return; // check if there is already something in the queue
|
||||
@@ -772,8 +744,8 @@ void ems_setWarmWaterActivated(bool activated) {
|
||||
|
||||
|
||||
/*
|
||||
* Helper functions for formatting and converting floats
|
||||
*/
|
||||
* Helper functions for formatting and converting floats
|
||||
*/
|
||||
|
||||
// function to turn a telegram int (2 bytes) to a float
|
||||
float _toFloat(uint8_t i, uint8_t * data) {
|
||||
|
||||
27
src/ems.h
27
src/ems.h
@@ -21,6 +21,33 @@
|
||||
|
||||
#define EMS_TX_MAXBUFFERSIZE 128 // max size of the buffer. packets are 32 bits
|
||||
|
||||
// define here the Thermostat type
|
||||
#define EMS_ID_THERMOSTAT 0x17 // x17=RC20 (Moduline300), x10=RC30/RC35 (Moduline 400)
|
||||
|
||||
// define here the EMS telegram types you need
|
||||
// Boiler...
|
||||
#define EMS_TYPE_UBAMonitorFast 0x18 // is an automatic monitor broadcast
|
||||
#define EMS_TYPE_UBAMonitorSlow 0x19 // is an automatic monitor broadcast
|
||||
#define EMS_TYPE_UBAMonitorWWMessage 0x34 // is an automatic monitor broadcast
|
||||
#define EMS_TYPE_UBAMaintenanceStatusMessage 0x1C // is an automatic monitor broadcast
|
||||
#define EMS_TYPE_UBAParameterWW 0x33
|
||||
#define EMS_TYPE_UBATotalUptimeMessage 0x14
|
||||
#define EMS_TYPE_UBAMaintenanceSettingsMessage 0x15
|
||||
#define EMS_TYPE_UBAParametersMessage 0x16
|
||||
|
||||
// Thermostat...
|
||||
#define EMS_TYPE_RC20StatusMessage 0x91 // is an automatic thermostat broadcast
|
||||
#define EMS_TYPE_RC20Time 0x06 // is an automatic thermostat broadcast
|
||||
#define EMS_TYPE_RC20Temperature 0xA8
|
||||
#define EMS_TYPE_RCOutdoorTempMessage 0xA3
|
||||
#define EMS_TYPE_Version 0x02 // version of the controller
|
||||
|
||||
// Offsets for specific values in a telegram, per type, used for validation
|
||||
#define EMS_OFFSET_RC20Temperature_temp 0x1C // thermostat set temp
|
||||
#define EMS_OFFSET_RC20Temperature_mode 0x17 // thermostat mode
|
||||
#define EMS_OFFSET_UBAParameterWW_wwtemp 0x02 // WW Temperature
|
||||
#define EMS_OFFSET_UBAParameterWW_wwactivated 0x01 // WW Activated
|
||||
|
||||
/* EMS UART transfer status */
|
||||
typedef enum {
|
||||
EMS_RX_IDLE,
|
||||
|
||||
Reference in New Issue
Block a user