Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
1.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed May 11, 2019
2 parents 4e1b0a2 + 2548e87 commit 9fc7a9d
Show file tree
Hide file tree
Showing 27 changed files with 2,251 additions and 1,571 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Language: Cpp
BasedOnStyle: LLVM
UseTab: Never
IndentWidth: 4
ColumnLimit: 140
ColumnLimit: 160
TabWidth: 4
#BreakBeforeBraces: Custom
BraceWrapping:
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
platformio.ini
lib/readme.txt
.travis.yml
stackdmp.txt
*.jar
;stackdmp.txt
;*.jar
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.7.0] 2019-05-11

### Added

- EMS+ core support (thanks too @gl3nni3 for doing the first research)
- MQTT 'restart' topic to reboot ESP (thanks @balk77)
- Support for multiple thermostat heating circuits like the HC1/HC2 on a RC35, also via MQTT (thanks @lobocobra)
- `boiler flowtemp` command to set the flow temperature [(issue 59)](https://github.com/proddy/EMS-ESP/issues/59)
- added a test harness to try out response to various telegrams (test command)
- `tx_delay` setting for circuits where we needed to slow down Tx transmission
- new boiler: Nefit proline hrc 24 cw4 thermostat and Nefit Enviline heatpump
- new boiler: Buderus Logamax plus
- new thermostat: Buderus RC300 and RC310 thermostats, read-only [(issue 37)](https://github.com/proddy/EMS-ESP/issues/37)
- new thermostat: Junkers FR10, read-only [(issue 98)](https://github.com/proddy/EMS-ESP/issues/98)
- new devices: Buderus Web Gateway KM200, Buderus Solar Module SM100

### Changed

- `types` renamed to `devices` to also show all detected devices
- renamed `silent_mode` to `listen_mode`
- increased Tx queue to 100

## [1.6.0] 2019-03-24

### Added
Expand Down
678 changes: 0 additions & 678 deletions LICENSE

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions doc/Domoticz/readme.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
to install the plugin:
- copy the directory 'nefit' to the domoticz/plugins directory
- make sure that 'Accept new Hardware Devices' is enabeled in settings/sysem
- create new hardware with type 'Nefit EMS-ESP with Proddy firmware'
- set MQTT server and port
The plugin crrently creates 3 devices:
- a room temperature meter
- a system pressure meter
to install the plugin:
- copy the directory 'nefit' to the domoticz/plugins directory
- make sure that 'Accept new Hardware Devices' is enabeled in settings/sysem
- create new hardware with type 'Nefit EMS-ESP with Proddy firmware'
- set MQTT server and port

The plugin crrently creates 3 devices:
- a room temperature meter
- a system pressure meter
- a thermostat setpoint control
12 changes: 9 additions & 3 deletions doc/home_assistant/climate.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
- platform: mqtt
name: Thermostat
modes:
- low
- manual
- auto
- "auto"
- "manual"
- "off"

mode_state_topic: "home/ems-esp/thermostat_data"
current_temperature_topic: "home/ems-esp/thermostat_data"
Expand All @@ -20,6 +20,9 @@

- platform: mqtt
name: boiler
modes:
- "on"
- "off"
min_temp: 40
max_temp: 60
temp_step: 1
Expand All @@ -28,3 +31,6 @@
temperature_command_topic: "home/ems-esp/boiler_cmd_wwtemp"
current_temperature_template: "{{ value_json.wWCurTmp }}"
temperature_state_template: "{{ value_json.wWSelTemp }}"
mode_state_template: "{{ value_json.wWActivated }}"
mode_state_topic: "home/ems-esp/boiler_data"
mode_command_topic: "home/ems-esp/wwactivated"
119 changes: 91 additions & 28 deletions lib/myESP/MyESP.cpp → lib/MyESP/MyESP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ void MyESP::_wifiCallback(justwifi_messages_t code, char * parameter) {
// finally if we don't want Serial anymore, turn it off
if (!_use_serial) {
myDebug_P(PSTR("Disabling serial port"));
Serial.flush();
Serial.end();
SerialAndTelnet.setSerial(NULL);
} else {
myDebug_P(PSTR("Using serial port output"));
Expand Down Expand Up @@ -231,6 +229,22 @@ void MyESP::_mqttOnMessage(char * topic, char * payload, size_t len) {
topic = topic_magnitude + 1;
}

// check for standard messages
// Restart the device
if (strcmp(topic, MQTT_TOPIC_RESTART) == 0) {
myDebug_P(PSTR("[MQTT] Received restart command"), message);
myESP.resetESP();
return;
}

// handle response from a start message
// for example with HA it sends the system time from the server
if (strcmp(topic, MQTT_TOPIC_START) == 0) {
myDebug_P(PSTR("[MQTT] Received boottime: %s"), message);
myESP.setBoottime(message);
return;
}

// Send message event to custom service
(_mqtt_callback)(MQTT_MESSAGE_EVENT, topic, message);
}
Expand Down Expand Up @@ -269,6 +283,13 @@ void MyESP::_mqttOnConnect() {
// say we're alive to the Last Will topic
mqttClient.publish(_mqttTopic(_mqtt_will_topic), 1, true, _mqtt_will_online_payload);

// subscribe to general subs
mqttSubscribe(MQTT_TOPIC_RESTART);

// subscribe to a start message and send the first publish
myESP.mqttSubscribe(MQTT_TOPIC_START);
myESP.mqttPublish(MQTT_TOPIC_START, MQTT_TOPIC_START_PAYLOAD);

// call custom function to handle mqtt receives
(_mqtt_callback)(MQTT_CONNECT_EVENT, NULL, NULL);
}
Expand Down Expand Up @@ -308,10 +329,9 @@ void MyESP::_mqtt_setup() {

//mqttClient.onPublish([this](uint16_t packetId) { myDebug_P(PSTR("[MQTT] Publish ACK for PID %d"), packetId); });

mqttClient.onMessage(
[this](char * topic, char * payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
_mqttOnMessage(topic, payload, len);
});
mqttClient.onMessage([this](char * topic, char * payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
_mqttOnMessage(topic, payload, len);
});
}

// WiFI setup
Expand Down Expand Up @@ -428,8 +448,23 @@ void MyESP::setTelnet(command_t * cmds, uint8_t count, telnetcommand_callback_f
void MyESP::_telnetConnected() {
myDebug_P(PSTR("[TELNET] Telnet connection established"));
_consoleShowHelp(); // Show the initial message

// show crash dump if just restarted after a fatal crash
#ifdef CRASH
uint32_t crash_time;
EEPROMr.get(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_CRASH_TIME, crash_time);
if ((crash_time != 0) && (crash_time != 0xFFFFFFFF)) {
crashDump();
// clear crash data
crash_time = 0xFFFFFFFF;
EEPROMr.put(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_CRASH_TIME, crash_time);
EEPROMr.commit();
}
#endif

// call callback
if (_telnet_callback) {
(_telnet_callback)(TELNET_EVENT_CONNECT); // call callback
(_telnet_callback)(TELNET_EVENT_CONNECT);
}
}

Expand Down Expand Up @@ -467,7 +502,7 @@ void MyESP::_consoleShowHelp() {

myDebug_P(PSTR("*"));
myDebug_P(PSTR("* Commands:"));
myDebug_P(PSTR("* ?=help, CTRL-D=quit telnet"));
myDebug_P(PSTR("* ?=help, CTRL-D/quit=exit telnet session"));
myDebug_P(PSTR("* set, system, reboot"));
#ifdef CRASH
myDebug_P(PSTR("* crash <dump | clear | test [n]>"));
Expand Down Expand Up @@ -679,10 +714,26 @@ bool MyESP::_changeSetting(uint8_t wc, const char * setting, const char * value)
return ok;
}

// force the serial on/off
void MyESP::setUseSerial(bool toggle) {
//(void)fs_saveConfig(); // save the setting for next reboot

if (toggle) {
SerialAndTelnet.setSerial(&Serial);
_use_serial = true;
} else {
SerialAndTelnet.setSerial(NULL);
_use_serial = false;
}
}

void MyESP::_telnetCommand(char * commandLine) {
char * str = commandLine;
bool state = false;

if (strlen(commandLine) == 0)
return;

// count the number of arguments
unsigned wc = 0;
while (*str) {
Expand Down Expand Up @@ -732,6 +783,14 @@ void MyESP::_telnetCommand(char * commandLine) {
return;
}

// show system stats
if ((strcmp(ptrToCommandName, "quit") == 0) && (wc == 1)) {
myDebug_P(PSTR("[TELNET] exiting telnet session"));
SerialAndTelnet.disconnectClient();
return;
}


// crash command
#ifdef CRASH
if ((strcmp(ptrToCommandName, "crash") == 0) && (wc >= 2)) {
Expand Down Expand Up @@ -820,12 +879,16 @@ void MyESP::showSystemStats() {
if (_boottime != NULL) {
myDebug_P(PSTR(" [APP] Boot time: %s"), _boottime);
}

// uptime
uint32_t t = _getUptime(); // seconds
uint32_t h = (uint32_t)t / (uint32_t)3600L;
uint32_t rem = (uint32_t)t % (uint32_t)3600L;
uint32_t m = rem / 60;
uint32_t s = rem % 60;
myDebug_P(PSTR(" [APP] Uptime: %d seconds (%02d:%02d:%02d)"), t, h, m, s);
uint32_t d = t / 86400L;
uint32_t h = (t / 3600L) % 60;
uint32_t rem = t % 3600L;
uint8_t m = rem / 60;
uint8_t s = rem % 60;
myDebug_P(PSTR(" [APP] Uptime: %d days, %d hours, %d minutes, %d seconds"), d, h, m, s);

myDebug_P(PSTR(" [APP] System Load: %d%%"), getSystemLoadAverage());

if (isAPmode()) {
Expand Down Expand Up @@ -873,8 +936,7 @@ void MyESP::showSystemStats() {
myDebug_P(PSTR(" [FLASH] Flash chip ID: 0x%06X"), ESP.getFlashChipId());
#endif
myDebug_P(PSTR(" [FLASH] Flash speed: %u Hz"), ESP.getFlashChipSpeed());
myDebug_P(PSTR(" [FLASH] Flash mode: %s"),
mode == FM_QIO ? "QIO" : mode == FM_QOUT ? "QOUT" : mode == FM_DIO ? "DIO" : mode == FM_DOUT ? "DOUT" : "UNKNOWN");
myDebug_P(PSTR(" [FLASH] Flash mode: %s"), mode == FM_QIO ? "QIO" : mode == FM_QOUT ? "QOUT" : mode == FM_DIO ? "DIO" : mode == FM_DOUT ? "DOUT" : "UNKNOWN");
#if defined(ESP8266)
myDebug_P(PSTR(" [FLASH] Flash size (CHIP): %d"), ESP.getFlashChipRealSize());
#endif
Expand All @@ -884,9 +946,6 @@ void MyESP::showSystemStats() {
myDebug_P(PSTR(" [MEM] Max OTA size: %d"), (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000);
myDebug_P(PSTR(" [MEM] OTA Reserved: %d"), 4 * SPI_FLASH_SEC_SIZE);
myDebug_P(PSTR(" [MEM] Free Heap: %d"), ESP.getFreeHeap());
#if defined(ESP8266)
myDebug_P(PSTR(" [MEM] Stack: %d"), ESP.getFreeContStack());
#endif
myDebug_P(PSTR(""));
}

Expand All @@ -899,12 +958,16 @@ void MyESP::_telnetHandle() {
while (SerialAndTelnet.available()) {
char c = SerialAndTelnet.read();

if (c == 0)
return;

SerialAndTelnet.serialPrint(c); // echo to Serial (if connected)

switch (c) {
case '\r': // likely have full command in buffer now, commands are terminated by CR and/or LF
case '\n':
_command[charsRead] = '\0'; // null terminate our command char array

if (charsRead > 0) {
charsRead = 0; // is static, so have to reset
_suspendOutput = false;
Expand Down Expand Up @@ -948,7 +1011,7 @@ void MyESP::_telnetHandle() {
}
}

// ensure we have a connection to MQTT broker
// make sure we have a connection to MQTT broker
void MyESP::_mqttConnect() {
if (!_mqtt_host)
return; // MQTT not enabled
Expand Down Expand Up @@ -1155,7 +1218,7 @@ bool MyESP::_fs_loadConfig() {
// Deserialize the JSON document
DeserializationError error = deserializeJson(doc, configFile);
if (error) {
Serial.println(F("[FS] Failed to read file"));
myDebug_P(PSTR("[FS] Failed to read config file. Error %s"), error.c_str());
return false;
}

Expand Down Expand Up @@ -1360,15 +1423,15 @@ extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack

void MyESP::crashTest(uint8_t t) {
if (t == 1) {
myDebug("[CRASH] Attempting to divide by zero ...");
myDebug_P(PSTR("[CRASH] Attempting to divide by zero ..."));
int result, zero;
zero = 0;
result = 1 / zero;
myDebug("Result = %d", result);
myDebug_P(PSTR("Result = %d"), result);
}

if (t == 2) {
myDebug("[CRASH] Attempting to read through a pointer to no object ...");
myDebug_P(PSTR("[CRASH] Attempting to read through a pointer to no object ..."));
int * nullPointer;
nullPointer = NULL;
// null pointer dereference - read
Expand All @@ -1377,7 +1440,7 @@ void MyESP::crashTest(uint8_t t) {
}

if (t == 3) {
Serial.printf("[CRASH] Crashing with hardware WDT (%ld ms) ...\n", millis());
myDebug_P(PSTR("[CRASH] Crashing with hardware WDT (%ld ms) ...\n"), millis());
ESP.wdtDisable();
while (true) {
// stay in an infinite loop doing nothing
Expand All @@ -1390,7 +1453,7 @@ void MyESP::crashTest(uint8_t t) {
}

if (t == 4) {
Serial.printf("[CRASH] Crashing with software WDT (%ld ms) ...\n", millis());
myDebug_P(PSTR("[CRASH] Crashing with software WDT (%ld ms) ...\n"), millis());
while (true) {
// stay in an infinite loop doing nothing
// this way other process can not be executed
Expand Down Expand Up @@ -1444,7 +1507,7 @@ void MyESP::crashDump() {

uint32_t stack_trace;

myDebug(">>>stack>>>");
myDebug_P(PSTR(">>>stack>>>"));

for (int16_t i = 0; i < stack_len; i += 0x10) {
SerialAndTelnet.printf("%08x: ", stack_start + i);
Expand All @@ -1455,7 +1518,7 @@ void MyESP::crashDump() {
}
SerialAndTelnet.println();
}
myDebug("<<<stack<<<");
myDebug_P(PSTR("<<<stack<<<"));
}
#else
void MyESP::crashTest(uint8_t t) {
Expand All @@ -1478,7 +1541,7 @@ void MyESP::begin(const char * app_hostname, const char * app_name, const char *
_eeprom_setup(); // set up eeprom for storing crash data
_fs_setup(); // SPIFFS setup, do this first to get values
_wifi_setup(); // WIFI setup
_ota_setup();
_ota_setup(); // init OTA
}

/*
Expand Down
Loading

0 comments on commit 9fc7a9d

Please sign in to comment.