mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
1.5.3
This commit is contained in:
14
CHANGELOG.md
14
CHANGELOG.md
@@ -5,6 +5,20 @@ 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.5.3] 2019-02-22
|
||||
|
||||
### Changed
|
||||
|
||||
- Support for latest esp8266 arduino core version [2.5.0](https://github.com/esp8266/Arduino/releases/tag/2.5.0) and platform espressif8266 version 2.0.0
|
||||
- Added board type to the info screen
|
||||
|
||||
### Added
|
||||
|
||||
- Improved MQTT LWT (Last Will Testament). Uses payload called 'online' and 'offline'. See https://github.com/proddy/EMS-ESP/issues/57
|
||||
- Added ESP32 support to MyESP library
|
||||
- Added Bosch Easy thermostat, Buderus Logamax U122
|
||||
- Support for changing boiler wwtemp via MQTT (merge #58 from egrekov). thanks!
|
||||
|
||||
## [1.5.2] 2019-02-04
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -5,7 +5,7 @@ EMS-ESP is a project to build an electronic controller circuit using an Espressi
|
||||
There are 3 parts to this project, first the design of the circuit, secondly the code for the ESP8266 microcontroller firmware with telnet and MQTT support, and lastly an example configuration for Home Assistant to monitor the data and issue direct commands via a MQTT broker.
|
||||
|
||||
[](https://app.codacy.com/app/proddy/EMS-ESP?utm_source=github.com&utm_medium=referral&utm_content=proddy/EMS-ESP&utm_campaign=Badge_Grade_Settings)
|
||||
[](CHANGELOG.md)
|
||||
[](CHANGELOG.md)
|
||||
|
||||
- [EMS-ESP](#ems-esp)
|
||||
- [Introduction](#introduction)
|
||||
@@ -61,7 +61,7 @@ The code and circuit has been tested with a few ESP8266 development boards such
|
||||
## Getting Started
|
||||
|
||||
1. Either build the circuit described below or purchase a ready built board
|
||||
2. Get an ESP8266 dev board and connect the 2 EMS output lines from the boiler to the circuit and the Rx and Tx out to ESP pins D7 and D8 respectively. To prevent interference with the serial ports and debug messages we use pins RX1 and TX1 (GPIO13/D7 and GPIO15/D8 respectively). The EMS connection can either be the 12-15V AC direct from the thermostat bus line or from the 3.5" Service Jack at the front of the boiler.
|
||||
2. Get an ESP8266 dev board and connect the 2 EMS output lines from the boiler to the circuit and the Rx and Tx out to ESP pins D7 and D8 respectively. To prevent interference with the serial ports and debug messages we use these pins RX1 and TX1. The EMS connection can either be the 12-15V AC direct from the thermostat bus line or from the 3.5" Service Jack at the front of the boiler.
|
||||
3. Optionally connect an external LED or decide to use the onboard ESP8266 LED. This will flash when there is an error on the EMS bus line or stay solid when it's connected to the EMS bus.
|
||||
4. Modify `my_custom.h` if needed
|
||||
5. Build and upload the firmware to the ESP8266 device. I used PlatformIO with Visual Studio Code but using Atom or a command-line is just as easy if you don't plan to make many code changes.
|
||||
@@ -313,7 +313,7 @@ pre-baked firmwares for some ESP8266 devices are available in the directory `/fi
|
||||
3. Connect the ESP via USB, figure out the COM port
|
||||
4. run `esptool.py -p <com> write_flash 0x00000 <firmware>` where firmware is the `.bin` file and \<com\> is the COM port, e.g. `COM3`
|
||||
|
||||
The ESP8266 will start in Access Point (AP) mode. Connect via WiFi to the SSID **EMS-ESP** and telnet to **192.168.4.1**. Then use the `set wifi` command to configure your own network settings like `set wifi your_ssid your_password`. Alternatively connect the ESP8266 to your PC and open a Serial monitor to configure the settings. Make sure you disable Serial support before connecting the EMS lines using `set serial off`.
|
||||
The ESP8266 will start in Access Point (AP) mode. Connect via WiFi to the SSID **EMS-ESP** and telnet to **192.168.4.1**. Then use the `set wifi` command to configure your own network settings like `set wifi your_ssid your_password`. Alternatively connect the ESP8266 to your PC and open a Serial monitor (with baud 115200) to configure the settings. Make sure you disable Serial support before connecting the EMS lines using `set serial off`.
|
||||
|
||||
`set erase` will clear all settings.
|
||||
|
||||
@@ -321,7 +321,7 @@ The ESP8266 will start in Access Point (AP) mode. Connect via WiFi to the SSID *
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
When flashing for the first time the Serial port is enabled by default. You can then use a PC with USB to the ESP8266 to set the settings like wifi, mqtt etc and also monitor the boot up procedure. Remember to disable the serial (`set serial off`) when connecting to the EMS lines.
|
||||
When flashing for the first time the Serial port is enabled by default with baud 115200. You can then use a PC with USB to the ESP8266 to set the settings like wifi, mqtt etc and also monitor the boot up procedure. Remember to disable the serial (`set serial off`) when connecting to the EMS lines.
|
||||
|
||||
The onboard LED will flash if there is no connection with the EMS bus. You can disable LED support by the 'set led' command from the telnet client
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* MyESP - my ESP helper class to handle Wifi, MDNS, MQTT and Telnet
|
||||
*
|
||||
* Paul Derbyshire - December 2018
|
||||
* Version 1.1 - Feb 22 2019. Added support for ESP32
|
||||
*
|
||||
* Ideas borrowed from Espurna https://github.com/xoseperez/espurna
|
||||
*/
|
||||
@@ -34,7 +35,8 @@ MyESP::MyESP() {
|
||||
_mqtt_retain = false;
|
||||
_mqtt_keepalive = 300;
|
||||
_mqtt_will_topic = NULL;
|
||||
_mqtt_will_payload = NULL;
|
||||
_mqtt_will_online_payload = NULL;
|
||||
_mqtt_will_offline_payload = NULL;
|
||||
_mqtt_base = NULL;
|
||||
_mqtt_topic = NULL;
|
||||
_mqtt_qos = 0;
|
||||
@@ -43,6 +45,7 @@ MyESP::MyESP() {
|
||||
_wifi_password = NULL;
|
||||
_wifi_ssid = NULL;
|
||||
_wifi_callback = NULL;
|
||||
_wifi_connected = false;
|
||||
|
||||
_suspendOutput = false;
|
||||
}
|
||||
@@ -66,7 +69,9 @@ void MyESP::myDebug(const char * format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
char test[1];
|
||||
|
||||
int len = ets_vsnprintf(test, 1, format, args) + 1;
|
||||
|
||||
char * buffer = new char[len];
|
||||
ets_vsnprintf(buffer, len, format, args);
|
||||
va_end(args);
|
||||
@@ -76,6 +81,7 @@ void MyESP::myDebug(const char * format, ...) {
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
|
||||
// for flashmemory. Must use PSTR()
|
||||
void MyESP::myDebug_P(PGM_P format_P, ...) {
|
||||
if (_suspendOutput)
|
||||
@@ -88,8 +94,10 @@ void MyESP::myDebug_P(PGM_P format_P, ...) {
|
||||
va_start(args, format_P);
|
||||
char test[1];
|
||||
int len = ets_vsnprintf(test, 1, format, args) + 1;
|
||||
|
||||
char * buffer = new char[len];
|
||||
ets_vsnprintf(buffer, len, format, args);
|
||||
|
||||
va_end(args);
|
||||
|
||||
// capture & print timestamp
|
||||
@@ -107,7 +115,7 @@ bool MyESP::getUseSerial() {
|
||||
return (_use_serial);
|
||||
}
|
||||
|
||||
// called when WiFi is connected, and used to start MDNS
|
||||
// called when WiFi is connected, and used to start MDNS, OTA, MATT
|
||||
void MyESP::_wifiCallback(justwifi_messages_t code, char * parameter) {
|
||||
if ((code == MESSAGE_CONNECTED)) {
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
@@ -128,15 +136,35 @@ void MyESP::_wifiCallback(justwifi_messages_t code, char * parameter) {
|
||||
|
||||
// start MDNS
|
||||
if (MDNS.begin((char *)hostname.c_str())) {
|
||||
_mdns_setup(); // MDNS setup
|
||||
myDebug_P(PSTR("[MDNS] OK"));
|
||||
} else {
|
||||
myDebug_P(PSTR("[MDNS] FAIL"));
|
||||
}
|
||||
|
||||
// start OTA
|
||||
ArduinoOTA.begin(); // moved to support esp32
|
||||
myDebug_P(PSTR("[OTA] listening to %s.local:%u"), ArduinoOTA.getHostname().c_str(), OTA_PORT);
|
||||
|
||||
// MQTT Setup
|
||||
_mqtt_setup();
|
||||
|
||||
_wifi_connected = true;
|
||||
|
||||
// call any final custom settings
|
||||
if (_wifi_callback) {
|
||||
_wifi_callback();
|
||||
}
|
||||
|
||||
// finally if we don't want Serial anymore, turn it off
|
||||
if (!_use_serial) {
|
||||
Serial.println("Disabling serial port");
|
||||
Serial.flush();
|
||||
Serial.end();
|
||||
SerialAndTelnet.setSerial(NULL);
|
||||
} else {
|
||||
Serial.println("Using serial port output");
|
||||
}
|
||||
}
|
||||
|
||||
if (code == MESSAGE_ACCESSPOINT_CREATED) {
|
||||
@@ -153,14 +181,17 @@ void MyESP::_wifiCallback(justwifi_messages_t code, char * parameter) {
|
||||
|
||||
if (code == MESSAGE_CONNECTING) {
|
||||
myDebug_P(PSTR("[WIFI] Connecting to %s"), parameter);
|
||||
_wifi_connected = false;
|
||||
}
|
||||
|
||||
if (code == MESSAGE_CONNECT_FAILED) {
|
||||
myDebug_P(PSTR("[WIFI] Could not connect to %s"), parameter);
|
||||
_wifi_connected = false;
|
||||
}
|
||||
|
||||
if (code == MESSAGE_DISCONNECTED) {
|
||||
myDebug_P(PSTR("[WIFI] Disconnected"));
|
||||
_wifi_connected = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,6 +245,9 @@ void MyESP::_mqttOnConnect() {
|
||||
myDebug_P(PSTR("[MQTT] Connected"));
|
||||
_mqtt_reconnect_delay = MQTT_RECONNECT_DELAY_MIN;
|
||||
|
||||
// say we're alive to the Last Will topic
|
||||
mqttClient.publish(_mqttTopic(_mqtt_will_topic), 1, true, _mqtt_will_online_payload);
|
||||
|
||||
// call custom function to handle mqtt receives
|
||||
(_mqtt_callback)(MQTT_CONNECT_EVENT, NULL, NULL);
|
||||
}
|
||||
@@ -276,24 +310,15 @@ void MyESP::_mdns_setup() {
|
||||
MDNS.addService("telnet", "tcp", TELNETSPY_PORT);
|
||||
|
||||
// for OTA discovery
|
||||
#if defined(ARDUINO_ARCH_ESP32) // TODO: doesn't work for esp32
|
||||
//MDNS.addServiceTxt("_arduino", "_tcp", "app_name", (const char *)_app_name);
|
||||
//MDNS.addServiceTxt("_arduino", "_tcp", "app_version", (const char *)_app_version);
|
||||
//MDNS.addServiceTxt("_arduino", "_tcp", "mac", WiFi.macAddress());
|
||||
#else
|
||||
MDNS.addServiceTxt("arduino", "tcp", "app_name", (const char *)_app_name);
|
||||
MDNS.addServiceTxt("arduino", "tcp", "app_version", (const char *)_app_version);
|
||||
MDNS.addServiceTxt("arduino", "tcp", "mac", WiFi.macAddress());
|
||||
{
|
||||
char buffer[6] = {0};
|
||||
itoa(ESP.getFlashChipRealSize() / 1024, buffer, 10);
|
||||
MDNS.addServiceTxt("arduino", "tcp", "mem_size", (const char *)buffer);
|
||||
}
|
||||
{
|
||||
char buffer[6] = {0};
|
||||
itoa(ESP.getFlashChipSize() / 1024, buffer, 10);
|
||||
MDNS.addServiceTxt("arduino", "tcp", "sdk_size", (const char *)buffer);
|
||||
}
|
||||
{
|
||||
char buffer[6] = {0};
|
||||
itoa(ESP.getFreeSketchSpace(), buffer, 10);
|
||||
MDNS.addServiceTxt("arduino", "tcp", "free_space", (const char *)buffer);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// OTA Setup
|
||||
@@ -304,6 +329,8 @@ void MyESP::_ota_setup() {
|
||||
|
||||
ArduinoOTA.setPort(OTA_PORT);
|
||||
ArduinoOTA.setHostname(_app_hostname);
|
||||
//ArduinoOTA.setMdnsEnabled(true); // because we're using our own MDNS
|
||||
|
||||
ArduinoOTA.onStart([this]() { myDebug_P(PSTR("[OTA] Start")); });
|
||||
ArduinoOTA.onEnd([this]() { myDebug_P(PSTR("[OTA] Done, restarting...")); });
|
||||
ArduinoOTA.onProgress([this](unsigned int progress, unsigned int total) {
|
||||
@@ -327,8 +354,6 @@ void MyESP::_ota_setup() {
|
||||
else if (error == OTA_END_ERROR)
|
||||
myDebug_P(PSTR("End Failed"));
|
||||
});
|
||||
|
||||
ArduinoOTA.begin();
|
||||
}
|
||||
|
||||
// sets boottime
|
||||
@@ -364,16 +389,11 @@ void MyESP::_telnetDisconnected() {
|
||||
|
||||
// Initialize the telnet server
|
||||
void MyESP::_telnet_setup() {
|
||||
SerialAndTelnet.setWelcomeMsg("");
|
||||
SerialAndTelnet.setWelcomeMsg((char *)"");
|
||||
SerialAndTelnet.setCallbackOnConnect([this]() { _telnetConnected(); });
|
||||
SerialAndTelnet.setCallbackOnDisconnect([this]() { _telnetDisconnected(); });
|
||||
|
||||
if (!_use_serial) {
|
||||
SerialAndTelnet.setSerial(NULL);
|
||||
}
|
||||
|
||||
SerialAndTelnet.begin(115200); // baud is 115200
|
||||
SerialAndTelnet.setDebugOutput(false);
|
||||
SerialAndTelnet.begin(TELNET_SERIAL_BAUD); // default baud is 115200
|
||||
|
||||
// init command buffer for console commands
|
||||
memset(_command, 0, TELNET_MAX_COMMAND_LENGTH);
|
||||
@@ -398,6 +418,9 @@ void MyESP::_consoleShowHelp() {
|
||||
hostname.c_str(),
|
||||
WiFi.localIP().toString().c_str(),
|
||||
WiFi.macAddress().c_str());
|
||||
#ifdef ARDUINO_BOARD
|
||||
SerialAndTelnet.printf(" Board: %s", ARDUINO_BOARD);
|
||||
#endif
|
||||
SerialAndTelnet.println();
|
||||
SerialAndTelnet.printf("* Connected to WiFi SSID: %s", WiFi.SSID().c_str());
|
||||
SerialAndTelnet.println();
|
||||
@@ -418,7 +441,6 @@ void MyESP::_consoleShowHelp() {
|
||||
SerialAndTelnet.println(FPSTR("* set erase"));
|
||||
SerialAndTelnet.println(FPSTR("* set serial"));
|
||||
|
||||
|
||||
// print custom commands if available. Taken from progmem
|
||||
if (_telnetcommand_callback) {
|
||||
// find the longest key length so we can right align it
|
||||
@@ -446,7 +468,7 @@ void MyESP::resetESP() {
|
||||
myDebug_P(PSTR("* Reboot ESP..."));
|
||||
end();
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
ESP.reset(); // for ESP8266 only
|
||||
ESP.restart();
|
||||
#else
|
||||
ESP.restart();
|
||||
#endif
|
||||
@@ -718,7 +740,7 @@ void MyESP::_mqttConnect() {
|
||||
// last will
|
||||
if (_mqtt_will_topic) {
|
||||
myDebug_P(PSTR("[MQTT] Setting last will topic %s"), _mqttTopic(_mqtt_will_topic));
|
||||
mqttClient.setWill(_mqttTopic(_mqtt_will_topic), _mqtt_qos, _mqtt_retain, _mqtt_will_payload);
|
||||
mqttClient.setWill(_mqttTopic(_mqtt_will_topic), 1, true, _mqtt_will_offline_payload); // retain always true
|
||||
}
|
||||
|
||||
if (_mqtt_username && _mqtt_password) {
|
||||
@@ -733,7 +755,7 @@ void MyESP::_mqttConnect() {
|
||||
}
|
||||
|
||||
// Setup everything we need
|
||||
void MyESP::setWIFI(char * wifi_ssid, char * wifi_password, wifi_callback_f callback) {
|
||||
void MyESP::setWIFI(const char * wifi_ssid, const char * wifi_password, wifi_callback_f callback) {
|
||||
// Check SSID too long or missing
|
||||
if (!wifi_ssid || *wifi_ssid == 0x00 || strlen(wifi_ssid) > 31) {
|
||||
_wifi_ssid = NULL;
|
||||
@@ -753,15 +775,16 @@ void MyESP::setWIFI(char * wifi_ssid, char * wifi_password, wifi_callback_f call
|
||||
}
|
||||
|
||||
// init MQTT settings
|
||||
void MyESP::setMQTT(char * mqtt_host,
|
||||
char * mqtt_username,
|
||||
char * mqtt_password,
|
||||
char * mqtt_base,
|
||||
void MyESP::setMQTT(const char * mqtt_host,
|
||||
const char * mqtt_username,
|
||||
const char * mqtt_password,
|
||||
const char * mqtt_base,
|
||||
unsigned long mqtt_keepalive,
|
||||
unsigned char mqtt_qos,
|
||||
bool mqtt_retain,
|
||||
char * mqtt_will_topic,
|
||||
char * mqtt_will_payload,
|
||||
const char * mqtt_will_topic,
|
||||
const char * mqtt_will_online_payload,
|
||||
const char * mqtt_will_offline_payload,
|
||||
mqtt_callback_f callback) {
|
||||
// can be empty
|
||||
if (!mqtt_host || *mqtt_host == 0x00) {
|
||||
@@ -804,10 +827,17 @@ void MyESP::setMQTT(char * mqtt_host,
|
||||
} else {
|
||||
_mqtt_will_topic = strdup(mqtt_will_topic);
|
||||
}
|
||||
if (!mqtt_will_payload || *mqtt_will_payload == 0x00) {
|
||||
_mqtt_will_payload = NULL;
|
||||
|
||||
if (!mqtt_will_online_payload || *mqtt_will_online_payload == 0x00) {
|
||||
_mqtt_will_online_payload = NULL;
|
||||
} else {
|
||||
_mqtt_will_payload = strdup(mqtt_will_payload);
|
||||
_mqtt_will_online_payload = strdup(mqtt_will_online_payload);
|
||||
}
|
||||
|
||||
if (!mqtt_will_offline_payload || *mqtt_will_offline_payload == 0x00) {
|
||||
_mqtt_will_offline_payload = NULL;
|
||||
} else {
|
||||
_mqtt_will_offline_payload = strdup(mqtt_will_offline_payload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -821,8 +851,6 @@ char * MyESP::_mqttTopic(const char * topic) {
|
||||
strlcat(buffer, "/", sizeof(buffer));
|
||||
strlcat(buffer, topic, sizeof(buffer));
|
||||
|
||||
//snprintf(buffer, sizeof(buffer), "%s/%s/%s", _mqtt_base, _app_hostname, topic);
|
||||
|
||||
if (_mqtt_topic) {
|
||||
free(_mqtt_topic);
|
||||
}
|
||||
@@ -833,15 +861,15 @@ char * MyESP::_mqttTopic(const char * topic) {
|
||||
|
||||
|
||||
// print contents of file
|
||||
// assume Serial is open
|
||||
void MyESP::_fs_printConfig() {
|
||||
File configFile = SPIFFS.open("/config.json", "r");
|
||||
|
||||
myDebug_P(PSTR("[FS] Contents...."));
|
||||
myDebug_P(PSTR("[FS] Contents:"));
|
||||
|
||||
File configFile = SPIFFS.open(MYEMS_CONFIG_FILE, "r");
|
||||
while (configFile.available()) {
|
||||
SerialAndTelnet.print((char)configFile.read());
|
||||
}
|
||||
SerialAndTelnet.println();
|
||||
myDebug_P(PSTR(""));
|
||||
configFile.close();
|
||||
}
|
||||
|
||||
@@ -862,18 +890,17 @@ void MyESP::setSettings(fs_callback_f callback_fs, fs_settings_callback_f callba
|
||||
|
||||
// load from spiffs
|
||||
bool MyESP::_fs_loadConfig() {
|
||||
File configFile = SPIFFS.open("/config.json", "r");
|
||||
if (!configFile) {
|
||||
myDebug_P(PSTR("[FS] Failed to open config file"));
|
||||
// file does not exist, so assume its the first install. Set serial to on
|
||||
_use_serial = true;
|
||||
return false; // this will trigger a new file being created
|
||||
}
|
||||
File configFile = SPIFFS.open(MYEMS_CONFIG_FILE, "r");
|
||||
|
||||
size_t size = configFile.size();
|
||||
if (size > 1024) {
|
||||
myDebug_P(PSTR("[FS] Config file size is too large"));
|
||||
return false;
|
||||
} else if (size == 0) {
|
||||
myDebug_P(PSTR("[FS] Failed to open config file"));
|
||||
// file does not exist, so assume its the first install. Set serial to on
|
||||
_use_serial = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// assign buffer
|
||||
@@ -934,35 +961,38 @@ bool MyESP::fs_saveConfig() {
|
||||
// callback for saving custom settings
|
||||
(void)(_fs_callback)(MYESP_FSACTION_SAVE, json);
|
||||
|
||||
File configFile = SPIFFS.open("/config.json", "w");
|
||||
File configFile = SPIFFS.open(MYEMS_CONFIG_FILE, "w");
|
||||
if (!configFile) {
|
||||
myDebug_P(PSTR("[FS] Failed to open config file for writing"));
|
||||
Serial.println("[FS] Failed to open config file for writing");
|
||||
return false;
|
||||
}
|
||||
|
||||
json.printTo(configFile);
|
||||
|
||||
configFile.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// init the SPIFF file system and load the config
|
||||
// if it doesn't exist try and create it
|
||||
// force Serial for debugging, and turn it off afterwards
|
||||
void MyESP::_fs_setup() {
|
||||
if (!SPIFFS.begin()) {
|
||||
myDebug_P(PSTR("[FS] Failed to mount the file system"));
|
||||
Serial.println("[FS] Failed to mount the file system");
|
||||
return;
|
||||
}
|
||||
|
||||
// _fs_printConfig(); // for debugging
|
||||
|
||||
// load the config file. if it doesn't exist create it
|
||||
if (!_fs_loadConfig()) {
|
||||
myDebug_P(PSTR("[FS] Re-creating config file"));
|
||||
Serial.println("[FS] Re-creating config file");
|
||||
fs_saveConfig();
|
||||
}
|
||||
|
||||
// _fs_printConfig(); // for debugging
|
||||
}
|
||||
|
||||
unsigned long MyESP::getSystemLoadAverage() {
|
||||
uint16_t MyESP::getSystemLoadAverage() {
|
||||
return _load_average;
|
||||
}
|
||||
|
||||
@@ -986,19 +1016,32 @@ void MyESP::_calculateLoad() {
|
||||
}
|
||||
}
|
||||
|
||||
// return true if wifi is connected
|
||||
// WL_NO_SHIELD = 255, // for compatibility with WiFi Shield library
|
||||
// WL_IDLE_STATUS = 0,
|
||||
// WL_NO_SSID_AVAIL = 1,
|
||||
// WL_SCAN_COMPLETED = 2,
|
||||
// WL_CONNECTED = 3,
|
||||
// WL_CONNECT_FAILED = 4,
|
||||
// WL_CONNECTION_LOST = 5,
|
||||
// WL_DISCONNECTED = 6
|
||||
bool MyESP::isWifiConnected() {
|
||||
return (_wifi_connected);
|
||||
}
|
||||
|
||||
// register new instance
|
||||
void MyESP::begin(char * app_hostname, char * app_name, char * app_version) {
|
||||
void MyESP::begin(const char * app_hostname, const char * app_name, const char * app_version) {
|
||||
_app_hostname = strdup(app_hostname);
|
||||
_app_name = strdup(app_name);
|
||||
_app_version = strdup(app_version);
|
||||
|
||||
// call setup of the services...
|
||||
_fs_setup(); // SPIFFS setup, do this first to get values
|
||||
_telnet_setup(); // Telnet setup
|
||||
_fs_setup(); // SPIFFS setup, do this first to get values
|
||||
_wifi_setup(); // WIFI setup
|
||||
_mqtt_setup(); // MQTT Setup
|
||||
_mdns_setup(); // MDNS setup
|
||||
_ota_setup(); // OTA setup
|
||||
_ota_setup();
|
||||
|
||||
// the other setups will be done after the wifi has connected
|
||||
// _mqtt_setup() _mdns_setup()
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1006,11 +1049,10 @@ void MyESP::begin(char * app_hostname, char * app_name, char * app_version) {
|
||||
*/
|
||||
void MyESP::loop() {
|
||||
_calculateLoad();
|
||||
_telnetHandle(); // Telnet/Debugger
|
||||
|
||||
jw.loop(); // WiFi
|
||||
|
||||
_telnetHandle(); // Telnet/Debugger
|
||||
|
||||
// do nothing else until we've got a wifi connection
|
||||
if (WiFi.getMode() & WIFI_AP) {
|
||||
return;
|
||||
|
||||
@@ -11,20 +11,23 @@
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <AsyncMqttClient.h> // https://github.com/marvinroger/async-mqtt-client
|
||||
#include <AsyncMqttClient.h> // https://github.com/marvinroger/async-mqtt-client and for ESP32 see https://github.com/marvinroger/async-mqtt-client/issues/127
|
||||
#include <DNSServer.h>
|
||||
#include <ESPAsyncTCP.h> // https://github.com/me-no-dev/ESPAsyncTCP
|
||||
#include <FS.h>
|
||||
#include <JustWifi.h> // https://github.com/xoseperez/justwifi
|
||||
#include <TelnetSpy.h> // modified from https://github.com/yasheena/telnetspy
|
||||
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include <ESPmDNS.h>
|
||||
#include <SPIFFS.h> // added for ESP32
|
||||
#define ets_vsnprintf vsnprintf // added for ESP32
|
||||
#else
|
||||
#include <ESP8266mDNS.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
#endif
|
||||
|
||||
#define MYEMS_CONFIG_FILE "/config.json"
|
||||
|
||||
#define LOADAVG_INTERVAL 30000 // Interval between calculating load average (in ms)
|
||||
|
||||
// WIFI
|
||||
@@ -32,7 +35,7 @@
|
||||
#define WIFI_RECONNECT_INTERVAL 60000 // If could not connect to WIFI, retry after this time in ms
|
||||
|
||||
// OTA
|
||||
#define OTA_PORT 8266 // OTA port
|
||||
#define OTA_PORT 3232 // OTA port. Was 8266
|
||||
|
||||
// MQTT
|
||||
#define MQTT_PORT 1883 // MQTT port
|
||||
@@ -48,9 +51,12 @@
|
||||
#define MQTT_MESSAGE_EVENT 2
|
||||
|
||||
// Telnet
|
||||
#define TELNET_SERIAL_BAUD 115200
|
||||
#define TELNET_MAX_COMMAND_LENGTH 80 // length of a command
|
||||
#define TELNET_EVENT_CONNECT 1
|
||||
#define TELNET_EVENT_DISCONNECT 0
|
||||
|
||||
// ANSI Colors
|
||||
#define COLOR_RESET "\x1B[0m"
|
||||
#define COLOR_BLACK "\x1B[0;30m"
|
||||
#define COLOR_RED "\x1B[0;31m"
|
||||
@@ -60,6 +66,9 @@
|
||||
#define COLOR_MAGENTA "\x1B[0;35m"
|
||||
#define COLOR_CYAN "\x1B[0;36m"
|
||||
#define COLOR_WHITE "\x1B[0;37m"
|
||||
#define COLOR_BOLD_ON "\x1B[1m"
|
||||
#define COLOR_BOLD_OFF "\x1B[21m"
|
||||
|
||||
|
||||
// SPIFFS
|
||||
#define SPIFFS_MAXSIZE 500 // https://arduinojson.org/v5/assistant/
|
||||
@@ -92,21 +101,23 @@ class MyESP {
|
||||
|
||||
// wifi
|
||||
void setWIFICallback(void (*callback)());
|
||||
void setWIFI(char * wifi_ssid, char * wifi_password, wifi_callback_f callback);
|
||||
void setWIFI(const char * wifi_ssid, const char * wifi_password, wifi_callback_f callback);
|
||||
bool isWifiConnected();
|
||||
|
||||
// mqtt
|
||||
void mqttSubscribe(const char * topic);
|
||||
void mqttUnsubscribe(const char * topic);
|
||||
void mqttPublish(const char * topic, const char * payload);
|
||||
void setMQTT(char * mqtt_host,
|
||||
char * mqtt_username,
|
||||
char * mqtt_password,
|
||||
char * mqtt_base,
|
||||
void setMQTT(const char * mqtt_host,
|
||||
const char * mqtt_username,
|
||||
const char * mqtt_password,
|
||||
const char * mqtt_base,
|
||||
unsigned long mqtt_keepalive,
|
||||
unsigned char mqtt_qos,
|
||||
bool mqtt_retain,
|
||||
char * mqtt_will_topic,
|
||||
char * mqtt_will_payload,
|
||||
const char * mqtt_will_topic,
|
||||
const char * mqtt_will_online_payload,
|
||||
const char * mqtt_will_offline_payload,
|
||||
mqtt_callback_f callback);
|
||||
|
||||
// debug & telnet
|
||||
@@ -122,10 +133,10 @@ class MyESP {
|
||||
// general
|
||||
void end();
|
||||
void loop();
|
||||
void begin(char * app_hostname, char * app_name, char * app_version);
|
||||
void begin(const char * app_hostname, const char * app_name, const char * app_version);
|
||||
void setBoottime(const char * boottime);
|
||||
void resetESP();
|
||||
unsigned long getSystemLoadAverage();
|
||||
uint16_t getSystemLoadAverage();
|
||||
|
||||
private:
|
||||
// mqtt
|
||||
@@ -146,7 +157,8 @@ class MyESP {
|
||||
unsigned char _mqtt_qos;
|
||||
bool _mqtt_retain;
|
||||
char * _mqtt_will_topic;
|
||||
char * _mqtt_will_payload;
|
||||
char * _mqtt_will_online_payload;
|
||||
char * _mqtt_will_offline_payload;
|
||||
char * _mqtt_topic;
|
||||
|
||||
// wifi
|
||||
@@ -156,6 +168,7 @@ class MyESP {
|
||||
wifi_callback_f _wifi_callback;
|
||||
char * _wifi_ssid;
|
||||
char * _wifi_password;
|
||||
bool _wifi_connected;
|
||||
|
||||
// mdns
|
||||
void _mdns_setup();
|
||||
@@ -185,6 +198,7 @@ class MyESP {
|
||||
bool _fs_loadConfig();
|
||||
void _fs_printConfig();
|
||||
void _fs_eraseConfig();
|
||||
|
||||
fs_callback_f _fs_callback;
|
||||
fs_settings_callback_f _fs_settings_callback;
|
||||
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
env_default = d1_mini
|
||||
|
||||
[common]
|
||||
; platform = espressif8266
|
||||
platform = espressif8266@1.8.0
|
||||
platform = espressif8266
|
||||
flash_mode = dout
|
||||
build_flags = -g -w
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ typedef struct {
|
||||
command_t PROGMEM project_cmds[] = {
|
||||
|
||||
{"set led <on | off>", "toggle status LED on/off"},
|
||||
{"set led_gpio <pin>", "set the LED pin. Default is the onboard LED."},
|
||||
{"set led_gpio <pin>", "set the LED pin. Default is the onboard LED (D1=5)"},
|
||||
{"set dallas_gpio <pin>", "set the pin for the external Dallas temperature sensor (D5=14)"},
|
||||
{"set thermostat_type <hex type ID>", "set the thermostat type id (e.g. 10 for 0x10)"},
|
||||
{"set boiler_type <hex type ID>", "set the boiler type id (e.g. 8 for 0x08)"},
|
||||
@@ -364,7 +364,7 @@ void showInfo() {
|
||||
myDebug(" Thermostat type: %s", ems_getThermostatDescription(buffer_type));
|
||||
_renderFloatValue("Setpoint room temperature", "C", EMS_Thermostat.setpoint_roomTemp);
|
||||
_renderFloatValue("Current room temperature", "C", EMS_Thermostat.curr_roomTemp);
|
||||
if (ems_getThermostatModel() != EMS_MODEL_EASY) {
|
||||
if ((ems_getThermostatModel() != EMS_MODEL_EASY) && (ems_getThermostatModel() != EMS_MODEL_BOSCHEASY)) {
|
||||
myDebug(" Thermostat time is %02d:%02d:%02d %d/%d/%d",
|
||||
EMS_Thermostat.hour,
|
||||
EMS_Thermostat.minute,
|
||||
@@ -657,6 +657,9 @@ bool SettingsCallback(MYESP_FSACTION action, uint8_t wc, const char * setting, c
|
||||
// led_gpio
|
||||
if ((strcmp(setting, "led_gpio") == 0) && (wc == 2)) {
|
||||
EMSESP_Status.led_gpio = atoi(value);
|
||||
// reset pin
|
||||
pinMode(EMSESP_Status.led_gpio, OUTPUT);
|
||||
digitalWrite(EMSESP_Status.led_gpio, (EMSESP_Status.led_gpio == LED_BUILTIN) ? HIGH : LOW); // light off. For onboard high=off
|
||||
ok = true;
|
||||
}
|
||||
|
||||
@@ -1115,7 +1118,8 @@ void setup() {
|
||||
#endif
|
||||
|
||||
// MQTT host, username and password taken from the SPIFFS settings
|
||||
myESP.setMQTT(NULL, NULL, NULL, MQTT_BASE, MQTT_KEEPALIVE, MQTT_QOS, MQTT_RETAIN, MQTT_WILL_TOPIC, MQTT_WILL_PAYLOAD, MQTTCallback);
|
||||
myESP.setMQTT(NULL, NULL, NULL, MQTT_BASE, MQTT_KEEPALIVE, MQTT_QOS, MQTT_RETAIN, MQTT_WILL_TOPIC,
|
||||
MQTT_WILL_ONLINE_PAYLOAD, MQTT_WILL_OFFLINE_PAYLOAD, MQTTCallback);
|
||||
|
||||
// custom settings in SPIFFS
|
||||
myESP.setSettings(FSCallback, SettingsCallback);
|
||||
|
||||
@@ -113,6 +113,8 @@ const _EMS_Type EMS_Types[] = {
|
||||
|
||||
// Easy
|
||||
{EMS_MODEL_EASY, EMS_TYPE_EasyStatusMessage, "EasyStatusMessage", _process_EasyStatusMessage},
|
||||
{EMS_MODEL_BOSCHEASY, EMS_TYPE_EasyStatusMessage, "EasyStatusMessage", _process_EasyStatusMessage},
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -1257,7 +1259,7 @@ void _process_SetPoints(uint8_t type, uint8_t * data, uint8_t length) {
|
||||
* common for all thermostats
|
||||
*/
|
||||
void _process_RCTime(uint8_t type, uint8_t * data, uint8_t length) {
|
||||
if (EMS_Thermostat.model_id == EMS_MODEL_EASY) {
|
||||
if ((EMS_Thermostat.model_id == EMS_MODEL_EASY) || (EMS_Thermostat.model_id == EMS_MODEL_BOSCHEASY)) {
|
||||
return; // not supported
|
||||
}
|
||||
|
||||
@@ -1347,7 +1349,7 @@ void ems_getThermostatValues() {
|
||||
} else if ((model_id == EMS_MODEL_RC35) || (model_id == EMS_MODEL_ES73)) {
|
||||
ems_doReadCommand(EMS_TYPE_RC35StatusMessage, type); // to get the setpoint temp
|
||||
ems_doReadCommand(EMS_TYPE_RC35Set, type); // to get the mode
|
||||
} else if (model_id == EMS_MODEL_EASY) {
|
||||
} else if ((model_id == EMS_MODEL_EASY) || (model_id == EMS_MODEL_BOSCHEASY)) {
|
||||
ems_doReadCommand(EMS_TYPE_EasyStatusMessage, type);
|
||||
}
|
||||
|
||||
@@ -1723,7 +1725,7 @@ void ems_setWarmWaterTemp(uint8_t temperature) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the warm water mode to comfort ot Eco
|
||||
* Set the warm water mode to comfort to Eco/Comfort
|
||||
*/
|
||||
void ems_setWarmWaterModeComfort(bool comfort) {
|
||||
myDebug("Setting boiler warm water to comfort mode %s\n", comfort ? "Comfort" : "Eco");
|
||||
|
||||
13
src/ems.h
13
src/ems.h
@@ -34,19 +34,6 @@
|
||||
#define EMS_THERMOSTAT_WRITE_YES true
|
||||
#define EMS_THERMOSTAT_WRITE_NO false
|
||||
|
||||
// ANSI Colors
|
||||
#define COLOR_RESET "\x1B[0m"
|
||||
#define COLOR_BLACK "\x1B[0;30m"
|
||||
#define COLOR_RED "\x1B[0;31m"
|
||||
#define COLOR_GREEN "\x1B[0;32m"
|
||||
#define COLOR_YELLOW "\x1B[0;33m"
|
||||
#define COLOR_BLUE "\x1B[0;34m"
|
||||
#define COLOR_MAGENTA "\x1B[0;35m"
|
||||
#define COLOR_CYAN "\x1B[0;36m"
|
||||
#define COLOR_WHITE "\x1B[0;37m"
|
||||
#define COLOR_BOLD_ON "\x1B[1m"
|
||||
#define COLOR_BOLD_OFF "\x1B[21m"
|
||||
|
||||
// trigger settings to determine if hot tap water or the heating is active
|
||||
#define EMS_BOILER_BURNPOWER_TAPWATER 100
|
||||
#define EMS_BOILER_SELFLOWTEMP_HEATING 70
|
||||
|
||||
@@ -100,6 +100,7 @@ typedef enum {
|
||||
EMS_MODEL_RC30,
|
||||
EMS_MODEL_RC35,
|
||||
EMS_MODEL_EASY,
|
||||
EMS_MODEL_BOSCHEASY,
|
||||
EMS_MODEL_RC310,
|
||||
EMS_MODEL_CW100
|
||||
|
||||
@@ -112,6 +113,7 @@ const _Boiler_Type Boiler_Types[] = {
|
||||
{EMS_MODEL_UBA, 72, 0x08, "MC10"},
|
||||
{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, 64, 0x08, "Sieger BK15 Boiler/Nefit Smartline"},
|
||||
{EMS_MODEL_UBA, 190, 0x09, "BC10 Base Controller"},
|
||||
{EMS_MODEL_UBA, 114, 0x09, "BC10 Base Controller"},
|
||||
@@ -135,6 +137,7 @@ const _Thermostat_Type Thermostat_Types[] = {
|
||||
{EMS_MODEL_RC30, 78, 0x10, "RC30/Nefit Moduline 400)", EMS_THERMOSTAT_READ_YES, EMS_THERMOSTAT_WRITE_YES},
|
||||
{EMS_MODEL_RC35, 86, 0x10, "RC35", EMS_THERMOSTAT_READ_YES, EMS_THERMOSTAT_WRITE_YES},
|
||||
{EMS_MODEL_EASY, 202, 0x18, "TC100/Nefit Easy", EMS_THERMOSTAT_READ_YES, EMS_THERMOSTAT_WRITE_NO},
|
||||
{EMS_MODEL_BOSCHEASY, 206, 0x02, "Bosch Easy", EMS_THERMOSTAT_READ_YES, EMS_THERMOSTAT_WRITE_NO},
|
||||
{EMS_MODEL_RC310, 158, 0x10, "RC310", EMS_THERMOSTAT_READ_NO, EMS_THERMOSTAT_WRITE_NO},
|
||||
{EMS_MODEL_CW100, 255, 0x18, "Bosch CW100", EMS_THERMOSTAT_READ_NO, EMS_THERMOSTAT_WRITE_NO}
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
#define MQTT_TOPIC_START "start"
|
||||
#define MQTT_TOPIC_START_PAYLOAD "start"
|
||||
#define MQTT_WILL_TOPIC "status" // for last will & testament topic name
|
||||
#define MQTT_WILL_PAYLOAD "0" // for last will & testament payload
|
||||
#define MQTT_WILL_ONLINE_PAYLOAD "online" // for last will & testament payload
|
||||
#define MQTT_WILL_OFFLINE_PAYLOAD "offline" // for last will & testament payload
|
||||
#define MQTT_RETAIN false
|
||||
#define MQTT_KEEPALIVE 300
|
||||
#define MQTT_QOS 1
|
||||
@@ -53,8 +54,9 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Set LED pin used for showing ems bus connection status. Solid is connected, Flashing is error
|
||||
// can be either the onboard LED on the ESP8266 (LED_BULLETIN) or external via an external pull-up LED (e.g. D1 on bbqkees' board)
|
||||
// can be enabled and disabled via the 'set led' command
|
||||
// can be either the onboard LED on the ESP8266 (LED_BULLETIN) or external via an external pull-up LED
|
||||
// (e.g. D1/5 on a bbqkees' board
|
||||
// can be enabled and disabled via the 'set led'
|
||||
// pin can be set by 'set led_gpio'
|
||||
#define EMSESP_LED_GPIO LED_BUILTIN
|
||||
|
||||
|
||||
@@ -6,5 +6,5 @@
|
||||
#pragma once
|
||||
|
||||
#define APP_NAME "EMS-ESP"
|
||||
#define APP_VERSION "1.5.2"
|
||||
#define APP_VERSION "1.5.3"
|
||||
#define APP_HOSTNAME "ems-esp"
|
||||
|
||||
Reference in New Issue
Block a user