prepare for ems plujs updates

This commit is contained in:
proddy
2019-04-04 21:02:20 +02:00
parent f87c5a3d66
commit b31f3118d1
12 changed files with 107 additions and 75 deletions

View File

@@ -50,7 +50,7 @@ uint8_t DS18::setup(uint8_t gpio, bool parasite) {
// scan every 2 seconds
void DS18::loop() {
static unsigned long last = 0;
static uint32_t last = 0;
if (millis() - last < DS18_READ_INTERVAL)
return;
last = millis();

View File

@@ -63,8 +63,8 @@ Ticker showerColdShotStopTimer;
#define SHOWER_MAX_DURATION 420000 // in ms. 7 minutes, before trigger a shot of cold water
typedef struct {
unsigned long timestamp; // for internal timings, via millis()
uint8_t dallas_sensors; // count of dallas sensors
uint32_t timestamp; // for internal timings, via millis()
uint8_t dallas_sensors; // count of dallas sensors
// custom params
bool shower_timer; // true if we want to report back on shower times
@@ -78,11 +78,11 @@ typedef struct {
} _EMSESP_Status;
typedef struct {
bool showerOn;
unsigned long timerStart; // ms
unsigned long timerPause; // ms
unsigned long duration; // ms
bool doingColdShot; // true if we've just sent a jolt of cold water
bool showerOn;
uint32_t timerStart; // ms
uint32_t timerPause; // ms
uint32_t duration; // ms
bool doingColdShot; // true if we've just sent a jolt of cold water
} _EMSESP_Shower;
command_t PROGMEM project_cmds[] = {
@@ -312,7 +312,9 @@ void showInfo() {
}
myDebug(" LED is %s, Silent mode is %s", EMSESP_Status.led ? "on" : "off", EMSESP_Status.silent_mode ? "on" : "off");
myDebug(" %d external temperature sensor%s connected", EMSESP_Status.dallas_sensors, (EMSESP_Status.dallas_sensors > 1) ? "s" : "");
if (EMSESP_Status.dallas_sensors > 0) {
myDebug(" %d external temperature sensor%s connected", EMSESP_Status.dallas_sensors, (EMSESP_Status.dallas_sensors == 1) ? "" : "s");
}
myDebug(" Thermostat is %s, Boiler is %s, Shower Timer is %s, Shower Alert is %s",
(ems_getThermostatEnabled() ? "enabled" : "disabled"),
@@ -321,12 +323,23 @@ void showInfo() {
((EMSESP_Status.shower_alert) ? "enabled" : "disabled"));
myDebug("\n%sEMS Bus stats:%s", COLOR_BOLD_ON, COLOR_BOLD_OFF);
myDebug(" Bus Connected=%s, Tx is %s, # Rx telegrams=%d, # Tx telegrams=%d, # Crc Errors=%d",
(ems_getBusConnected() ? "yes" : "no"),
(ems_getTxCapable() ? "active" : "not active"),
EMS_Sys_Status.emsRxPgks,
EMS_Sys_Status.emsTxPkgs,
EMS_Sys_Status.emxCrcErr);
if (ems_getBusConnected()) {
myDebug(" Bus is connected");
myDebug(" Rx: Poll=%d ms, # Rx telegrams read=%d, # Crc Errors=%d",
ems_getPollFrequency(),
EMS_Sys_Status.emsRxPgks,
EMS_Sys_Status.emxCrcErr);
if (ems_getTxCapable()) {
myDebug(" Tx: available, # Tx telegrams sent=%d", EMS_Sys_Status.emsTxPkgs);
} else {
myDebug(" Tx: no signal");
}
} else {
myDebug(" No connection can be made to the EMS bus");
}
myDebug("");
myDebug("%sBoiler stats:%s", COLOR_BOLD_ON, COLOR_BOLD_OFF);
@@ -493,8 +506,8 @@ void showInfo() {
// send all dallas sensor values as a JSON package to MQTT
void publishSensorValues() {
StaticJsonDocument<MQTT_MAX_SIZE> doc;
JsonObject sensors = doc.to<JsonObject>();
StaticJsonDocument<200> doc;
JsonObject sensors = doc.to<JsonObject>();
bool hasdata = false;
char label[8] = {0};
@@ -511,7 +524,7 @@ void publishSensorValues() {
}
if (hasdata) {
char data[MQTT_MAX_SIZE] = {0};
char data[200] = {0};
serializeJson(doc, data, sizeof(data));
myESP.mqttPublish(TOPIC_EXTERNAL_SENSORS, data);
}

View File

@@ -157,9 +157,9 @@ const uint8_t ems_crc_table[] = {0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E,
0xCD, 0xCF, 0xC1, 0xC3, 0xC5, 0xC7, 0xF9, 0xFB, 0xFD, 0xFF, 0xF1, 0xF3, 0xF5, 0xF7, 0xE9, 0xEB, 0xED, 0xEF,
0xE1, 0xE3, 0xE5, 0xE7};
const uint8_t TX_WRITE_TIMEOUT_COUNT = 2; // 3 retries before timeout
const unsigned long EMS_BUS_TIMEOUT = 15000; // timeout in ms before recognizing the ems bus is offline (15 seconds)
const unsigned long EMS_POLL_TIMEOUT = 5000; // timeout in ms before recognizing the ems bus is offline (5 seconds)
const uint8_t TX_WRITE_TIMEOUT_COUNT = 2; // 3 retries before timeout
const uint32_t EMS_BUS_TIMEOUT = 15000; // timeout in ms before recognizing the ems bus is offline (15 seconds)
const uint32_t EMS_POLL_TIMEOUT = 5000; // timeout in ms before recognizing the ems bus is offline (5 seconds)
// init stats and counters and buffers
// uses -255 or 255 for values that haven't been set yet (EMS_VALUE_INT_NOTSET and EMS_VALUE_FLOAT_NOTSET)
@@ -176,7 +176,7 @@ void ems_init() {
EMS_Sys_Status.emsRxTimestamp = 0;
EMS_Sys_Status.emsTxCapable = false;
EMS_Sys_Status.emsTxDisabled = false;
EMS_Sys_Status.emsPollTimestamp = 0;
EMS_Sys_Status.emsPollFrequency = 0;
EMS_Sys_Status.txRetryCount = 0;
// thermostat
@@ -302,8 +302,12 @@ void ems_setTxDisabled(bool b) {
EMS_Sys_Status.emsTxDisabled = b;
}
uint32_t ems_getPollFrequency() {
return EMS_Sys_Status.emsPollFrequency;
}
bool ems_getTxCapable() {
if ((millis() - EMS_Sys_Status.emsPollTimestamp) > EMS_POLL_TIMEOUT) {
if ((EMS_Sys_Status.emsPollFrequency == 0) || (EMS_Sys_Status.emsPollFrequency > EMS_POLL_TIMEOUT)) {
EMS_Sys_Status.emsTxCapable = false;
}
return EMS_Sys_Status.emsTxCapable;
@@ -577,7 +581,6 @@ void _createValidate() {
EMS_TxQueue.unshift(new_EMS_TxTelegram); // add back to queue making it first to be picked up next (FIFO)
}
/*
* Entry point triggered by an interrupt in emsuart.cpp
* length is only data bytes, excluding the BRK
@@ -588,9 +591,9 @@ void ems_parseTelegram(uint8_t * telegram, uint8_t length) {
if ((length != 0) && (telegram[0] != 0x00)) {
_ems_readTelegram(telegram, length);
}
// now clear the Rx buffer just be safe and prevent duplicates
for (uint8_t i = 0; i < EMS_MAXBUFFERSIZE; telegram[i++] = 0x00)
;
// clear the Rx buffer just be safe and prevent duplicates
memset(telegram, 0, EMS_MAXBUFFERSIZE);
}
/**
@@ -600,9 +603,10 @@ void ems_parseTelegram(uint8_t * telegram, uint8_t length) {
void _ems_readTelegram(uint8_t * telegram, uint8_t length) {
// create the Rx package
static _EMS_RxTelegram EMS_RxTelegram;
EMS_RxTelegram.length = length;
EMS_RxTelegram.telegram = telegram;
EMS_RxTelegram.timestamp = millis();
static uint32_t _last_emsPollFrequency = 0;
EMS_RxTelegram.length = length;
EMS_RxTelegram.telegram = telegram;
EMS_RxTelegram.timestamp = millis();
// check if we just received a single byte
// it could well be a Poll request from the boiler for us, which will have a value of 0x8B (0x0B | 0x80)
@@ -610,10 +614,12 @@ void _ems_readTelegram(uint8_t * telegram, uint8_t length) {
if (length == 1) {
uint8_t value = telegram[0]; // 1st byte of data package
EMS_Sys_Status.emsPollFrequency = (EMS_RxTelegram.timestamp - _last_emsPollFrequency);
_last_emsPollFrequency = EMS_RxTelegram.timestamp;
// check first for a Poll for us
if (value == (EMS_ID_ME | 0x80)) {
EMS_Sys_Status.emsPollTimestamp = EMS_RxTelegram.timestamp; // store when we received a last poll
EMS_Sys_Status.emsTxCapable = true;
EMS_Sys_Status.emsTxCapable = true;
// do we have something to send thats waiting in the Tx queue?
// if so send it if the Queue is not in a wait state
@@ -1396,8 +1402,8 @@ void ems_printTxQueue() {
strlcpy(sType, "?", sizeof(sType));
}
char addedTime[15] = {0};
unsigned long upt = EMS_TxTelegram.timestamp;
char addedTime[15] = {0};
uint32_t upt = EMS_TxTelegram.timestamp;
snprintf(addedTime,
sizeof(addedTime),
"(%02d:%02d:%02d)",

View File

@@ -89,8 +89,8 @@ typedef struct {
_EMS_SYS_LOGGING emsLogging; // logging
bool emsRefreshed; // fresh data, needs to be pushed out to MQTT
bool emsBusConnected; // is there an active bus
unsigned long emsRxTimestamp; // timestamp of last EMS message received
unsigned long emsPollTimestamp; // timestamp of last EMS poll sent to us
uint32_t emsRxTimestamp; // timestamp of last EMS message received
uint32_t emsPollFrequency; // time between EMS polls
bool emsTxCapable; // able to send via Tx
bool emsTxDisabled; // true to prevent all Tx
uint8_t txRetryCount; // # times the last Tx was re-sent
@@ -109,7 +109,7 @@ typedef struct {
uint8_t comparisonOffset; // offset of where the byte is we want to compare too later
uint8_t comparisonPostRead; // after a successful write call this to read
bool forceRefresh; // should we send to MQTT after a successful Tx?
unsigned long timestamp; // when created
uint32_t timestamp; // when created
uint8_t data[EMS_MAX_TELEGRAM_LENGTH];
} _EMS_TxTelegram;
@@ -120,7 +120,6 @@ typedef struct {
uint8_t length; // length in bytes
} _EMS_RxTelegram;
// default empty Tx
const _EMS_TxTelegram EMS_TX_TELEGRAM_NEW = {
EMS_TX_TELEGRAM_INIT, // action
@@ -297,6 +296,7 @@ bool ems_getEmsRefreshed();
uint8_t ems_getThermostatModel();
void ems_discoverModels();
bool ems_getTxCapable();
uint32_t ems_getPollFrequency();
void ems_scanDevices();
void ems_printAllTypes();

View File

@@ -122,6 +122,7 @@ const _Boiler_Type Boiler_Types[] = {
{EMS_MODEL_UBA, 123, 0x08, "Buderus GB172/Nefit Trendline"},
{EMS_MODEL_UBA, 115, 0x08, "Nefit Topline Compact"},
{EMS_MODEL_UBA, 203, 0x08, "Buderus Logamax U122"},
{EMS_MODEL_UBA, 208, 0x08, "Buderus Logamax plus"},
{EMS_MODEL_UBA, 64, 0x08, "Sieger BK15 Boiler/Nefit Smartline"},
{EMS_MODEL_UBA, 95, 0x08, "Bosch Condens 2500"}

View File

@@ -177,6 +177,7 @@ void ICACHE_FLASH_ATTR emsuart_tx_brk() {
void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) {
for (uint8_t i = 0; i < len; i++) {
USF(EMSUART_UART) = buf[i];
//delayMicroseconds(EMS_TX_BRK_WAIT);
}
emsuart_tx_brk();
}

View File

@@ -22,6 +22,7 @@
#define MQTT_RETAIN false
#define MQTT_KEEPALIVE 120 // 2 minutes
#define MQTT_QOS 1
#define MQTT_MAX_SIZE 700 // max size of a JSON object. See https://arduinojson.org/v6/assistant/
// MQTT for thermostat
#define TOPIC_THERMOSTAT_DATA "thermostat_data" // for sending thermostat values to MQTT

View File

@@ -6,5 +6,5 @@
#pragma once
#define APP_NAME "EMS-ESP"
#define APP_VERSION "1.7.0b1"
#define APP_VERSION "1.6.1b1"
#define APP_HOSTNAME "ems-esp"