From 83c90dec0843cd65faf0f66f28f54732a701aed3 Mon Sep 17 00:00:00 2001 From: proddy Date: Wed, 3 Jun 2020 17:25:20 +0200 Subject: [PATCH 01/12] start console before network, added delay to help telnet performance --- src/emsesp.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/emsesp.cpp b/src/emsesp.cpp index ce89b6c45..93548aa7b 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -247,7 +247,6 @@ std::string EMSESP::pretty_telegram(std::shared_ptr telegram) { // get the type name, any match will do if (type_name.empty()) { type_name = emsdevice->telegram_type_name(telegram); - } } } @@ -364,11 +363,7 @@ void EMSESP::process_version(std::shared_ptr telegram) { // get version as XX.XX std::string version(5, '\0'); - snprintf_P(&version[0], - version.capacity() + 1, - PSTR("%02d.%02d"), - telegram->message_data[offset + 1], - telegram->message_data[offset + 2]); + snprintf_P(&version[0], version.capacity() + 1, PSTR("%02d.%02d"), telegram->message_data[offset + 1], telegram->message_data[offset + 2]); // some devices store the protocol type (HT3, Buderus) in the last byte uint8_t brand; @@ -569,7 +564,7 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) { uint8_t first_value = data[0]; if (((first_value & 0x7F) == txservice_.ems_bus_id()) && (length > 1)) { rxservice_.add(data, length); // just for logging - return; // it's an echo + return; // it's an echo } // are we waiting for a response from a recent Tx Read or Write? @@ -786,7 +781,7 @@ void EMSESP::console_commands(Shell & shell, unsigned int context) { Settings settings; shell.printfln(F_(tx_mode_fmt), settings.ems_tx_mode()); shell.printfln(F_(bus_id_fmt), settings.ems_bus_id()); - shell.printfln(F_(read_only_fmt), settings.ems_read_only() ? F_(enabled) : F_(disabled)); + shell.printfln(F_(read_only_fmt), settings.ems_read_only() ? F_(on) : F_(off)); }); // enter the context @@ -801,8 +796,8 @@ void EMSESP::start() { }; system_.start(); - network_.start(); console_.start(); + network_.start(); sensors_.start(); rxservice_.start(); txservice_.start(); @@ -817,20 +812,23 @@ void EMSESP::loop() { // network returns false if an OTA is being carried out // so we disable all services when an OTA is happening if (network_.loop()) { - console_.loop(); // telnet/serial console system_.loop(); // does LED and checks system health, and syslog service mqtt_.loop(); // starts mqtt, and sends out anything in the queue rxservice_.loop(); // process what ever is in the rx queue txservice_.loop(); // check that the Tx is all ok shower_.loop(); // check for shower on/off sensors_.loop(); // this will also send out via MQTT + console_.loop(); // telnet/serial console // force a query on the EMS devices to fetch latest data at a set interval (1 min) if ((uuid::get_uptime() - last_fetch_ > EMS_FETCH_FREQUENCY)) { last_fetch_ = uuid::get_uptime(); fetch_device_values(); } + + // helps ease wifi outages + // https://github.com/esp8266/Arduino/blob/e721089e601985e633641ab7323f81a84ea0cd1b/cores/esp8266/core_esp8266_wiring.cpp#L41-L57 + delay(1); } -} } // namespace emsesp From 2cc10016235e9b173bcd36dcabdd800f77590d2f Mon Sep 17 00:00:00 2001 From: proddy Date: Wed, 3 Jun 2020 17:25:33 +0200 Subject: [PATCH 02/12] update things todo --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index a484eaa51..46c58ad59 100644 --- a/README.md +++ b/README.md @@ -125,8 +125,6 @@ thermostat ``` TODO ESP32 - when saving SPIFFS the UART stop and restart() functions need to flush queue to avoid miss fires -TODO network issues with ESP8266 - can take a while to get an IP address. DNS issue? -TODO figure out why sometimes telnet on ESP32 (and sometimes ESP8266) has slow response times. After a manual reset it seems to fix itself. Perhaps the telnet service needs to start after the wifi is up & running. TODO sometimes with tx_mode 0 there are a few CRC errors due to collision when waiting for a BRK signal. TODO console auto-complete with 'set' command in the system context is not showing all commands, only the hostname. ``` From 456fdcb895f1066223033a747c3295078500d68f Mon Sep 17 00:00:00 2001 From: proddy Date: Wed, 3 Jun 2020 17:25:55 +0200 Subject: [PATCH 03/12] revert to original. use pio_local for local settings --- .gitignore | 3 --- platformio.ini | 20 +++++--------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 887d4c52b..9f5029d80 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,4 @@ scripts/stackdmp.txt firmware *.bin emsesp -doc/github.txt -doc/test_data.txt -/src/uart/uart_proddy.txt diff --git a/platformio.ini b/platformio.ini index f94869833..918b8b425 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,10 +1,8 @@ -; PlatformIO Project Configuration File -; For EMS-ESP +; PlatformIO Project Configuration File for EMS-ESP [platformio] default_envs = esp8266 ; default_envs = esp32 -; default_envs = esp32_d1 # override any settings with your own local ones in pio_local.ini extra_configs = pio_local.ini @@ -22,7 +20,7 @@ extra_configs = pio_local.ini ;debug_flags = -DDEBUG_ESP_PORT=Serial -DDEBUG_ESP_CORE -DDEBUG_ESP_SSL -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_TLS_MEM debug_flags = - ; -D EMSESP_DEBUG + -D EMSESP_DEBUG ; -D EMSESP_SAFE_MODE ; -D ENABLE_CORS -D CORS_ORIGIN=\"http://localhost:3000\" @@ -63,7 +61,7 @@ check_flags = clangtidy: --checks=-*,clang-analyzer-*,performance-* ; USB upload - ;upload_protocol = esptool +; upload_protocol = esptool ; example ports for OSX ;upload_port = /dev/cu.wchusbserial14403 ;upload_port = /dev/cu.usbserial-1440 @@ -74,20 +72,20 @@ upload_protocol = espota upload_flags = --port=8266 --auth=neo -;upload_port = 192.168.0.20 +upload_port = ems-esp.local [env:esp8266] build_type = release platform = espressif8266 ; https://github.com/platformio/platform-espressif8266/releases ;platform = espressif8266@2.4.0 ; Arduino core 2.6.3 board = esp12e +board_build.flash_mode = dout ; board = d1_mini ; https://github.com/platformio/platform-espressif8266/blob/master/boards/d1_mini.json lib_deps = ${common.libs_core} ${common.libs_esp8266} board_build.f_cpu = 160000000L ; 160MHz board_build.ldscript = eagle.flash.4m1m.ld ; 1019 KB sketch, 1000 KB SPIFFS. 4KB EEPROM, 4KB RFCAL, 12KB WIFI stack, 2052 KB OTA & buffer ; board_build.ldscript = eagle.flash.4m2m.ld ; 1019 KB sketch, 2024 KB SPIFFS. 4KB EEPROM, 4KB RFCAL, 12KB WIFI stack, 1028 KB OTA & buffer build_flags = ${common.build_flags} ${common.debug_flags} -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY -upload_port = 192.168.0.20 [env:esp32] build_type = release @@ -95,11 +93,3 @@ platform = espressif32 board = esp32dev lib_deps = ${common.libs_core} ${common.libs_esp32} build_flags = ${common.build_flags} ${common.debug_flags} -D PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH - -[env:esp32_d1] -build_type = release -platform = espressif32 -board = wemos_d1_mini32 -lib_deps = ${common.libs_core} ${common.libs_esp32} -build_flags = ${common.build_flags} ${common.debug_flags} -D PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH -D WEMOS_D1_32 -upload_port = 192.168.0.23 From caba2a9df09bac8321d30887564b8c3e6591cf46 Mon Sep 17 00:00:00 2001 From: proddy Date: Wed, 3 Jun 2020 17:26:13 +0200 Subject: [PATCH 04/12] added telnet write timeout --- src/console.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/console.cpp b/src/console.cpp index c0c61053f..df5b9b270 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -438,7 +438,7 @@ void Console::start() { // note, this must be started after the network/wifi for ESP32 otherwise it'll crash #ifndef EMSESP_STANDALONE telnet_.start(); - // telnet_.default_write_timeout(1000); // in ms, socket timeout 1 second + telnet_.default_write_timeout(1000); // in ms, socket timeout 1 second #endif } From 1562c98c3afcbf2f8a4095806a3db94899083d89 Mon Sep 17 00:00:00 2001 From: proddy Date: Wed, 3 Jun 2020 17:27:37 +0200 Subject: [PATCH 05/12] clang formatting --- src/device_library.h | 10 ++++------ src/helpers.cpp | 2 +- src/mixing.h | 1 - src/thermostat.cpp | 15 +++++++-------- src/thermostat.h | 32 ++++++++++++++++---------------- src/uart/emsuart_esp32.cpp | 16 ++++++++-------- src/uart/emsuart_esp32.h | 2 +- src/uart/emsuart_esp8266.cpp | 8 ++++---- src/uart/emsuart_esp8266.h | 2 +- 9 files changed, 42 insertions(+), 46 deletions(-) diff --git a/src/device_library.h b/src/device_library.h index 2f1e9a492..7f40fdae5 100644 --- a/src/device_library.h +++ b/src/device_library.h @@ -39,7 +39,6 @@ {208, DeviceType::BOILER, F("Logamax plus/GB192/Condens GC9000"), DeviceFlags::EMS_DEVICE_FLAG_NONE}, {234, DeviceType::BOILER, F("Logamax Plus GB122"), DeviceFlags::EMS_DEVICE_FLAG_NONE}, - // Solar Modules - 0x30 { 73, DeviceType::SOLAR, F("SM10"), DeviceFlags::EMS_DEVICE_FLAG_SM10}, {101, DeviceType::SOLAR, F("ISM1"), DeviceFlags::EMS_DEVICE_FLAG_SM100}, @@ -58,7 +57,7 @@ {252, DeviceType::HEATPUMP, F("HP Module"), DeviceFlags::EMS_DEVICE_FLAG_NONE}, // Switches - 0x11 -{ 71, DeviceType::SWITCH, F("WM10"), DeviceFlags::EMS_DEVICE_FLAG_NONE}, // 0x11 +{ 71, DeviceType::SWITCH, F("WM10"), DeviceFlags::EMS_DEVICE_FLAG_NONE}, // Controllers - 0x09 / 0x10 / 0x50 { 68, DeviceType::CONTROLLER, F("BC10/RFM20"), DeviceFlags::EMS_DEVICE_FLAG_NONE}, // 0x09 @@ -75,11 +74,10 @@ {230, DeviceType::CONTROLLER, F("BC Base"), DeviceFlags::EMS_DEVICE_FLAG_NONE}, // 0x09 {241, DeviceType::CONTROLLER, F("Condens 5000i"), DeviceFlags::EMS_DEVICE_FLAG_NONE}, // 0x09 - // Connect devices - 0x02 -{171, DeviceType::CONNECT, F("OpenTherm Converter"), DeviceFlags::EMS_DEVICE_FLAG_NONE}, // 0x02 -{205, DeviceType::CONNECT, F("Moduline Easy Connect"), DeviceFlags::EMS_DEVICE_FLAG_NONE}, // 0x02 -{206, DeviceType::CONNECT, F("Easy Connect"), DeviceFlags::EMS_DEVICE_FLAG_NONE}, // 0x02 +{171, DeviceType::CONNECT, F("OpenTherm Converter"), DeviceFlags::EMS_DEVICE_FLAG_NONE}, +{205, DeviceType::CONNECT, F("Moduline Easy Connect"), DeviceFlags::EMS_DEVICE_FLAG_NONE}, +{206, DeviceType::CONNECT, F("Easy Connect"), DeviceFlags::EMS_DEVICE_FLAG_NONE}, // Gateways - 0x48 / 0x18 { 94, DeviceType::GATEWAY, F("RFM20 Remote Base for RC20RF"), DeviceFlags::EMS_DEVICE_FLAG_NONE}, // 0x18 diff --git a/src/helpers.cpp b/src/helpers.cpp index 2350f53e1..c0c176559 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -279,7 +279,7 @@ uint32_t Helpers::hextoint(const char * hex) { byte = byte - 'a' + 10; else if (byte >= 'A' && byte <= 'F') byte = byte - 'A' + 10; - else + else return 0; // error // shift 4 to make space for new digit, and add the 4 bits of the new digit val = (val << 4) | (byte & 0xF); diff --git a/src/mixing.h b/src/mixing.h index 6b430f62e..d81443b7f 100644 --- a/src/mixing.h +++ b/src/mixing.h @@ -63,7 +63,6 @@ class Mixing : public EMSdevice { uint8_t status_ = EMS_VALUE_UINT_NOTSET; uint8_t flowSetTemp_ = EMS_VALUE_UINT_NOTSET; Type type_ = Type::NONE; - }; } // namespace emsesp diff --git a/src/thermostat.cpp b/src/thermostat.cpp index faa76608c..ceb892731 100644 --- a/src/thermostat.cpp +++ b/src/thermostat.cpp @@ -400,7 +400,7 @@ bool Thermostat::updated_values() { static uint16_t current_value_ = 0; for (const auto & hc : heating_circuits_) { // don't publish if we haven't yet received some data -// if ((hc->setpoint_roomTemp == EMS_VALUE_SHORT_NOTSET) || (hc->curr_roomTemp == EMS_VALUE_SHORT_NOTSET)) { + // if ((hc->setpoint_roomTemp == EMS_VALUE_SHORT_NOTSET) || (hc->curr_roomTemp == EMS_VALUE_SHORT_NOTSET)) { if (hc->setpoint_roomTemp == EMS_VALUE_SHORT_NOTSET) { return false; } @@ -469,7 +469,7 @@ void Thermostat::publish_values() { // go through all the heating circuits for (const auto & hc : heating_circuits_) { -// if ((hc->setpoint_roomTemp == EMS_VALUE_SHORT_NOTSET) || (hc->curr_roomTemp == EMS_VALUE_SHORT_NOTSET)) { + // if ((hc->setpoint_roomTemp == EMS_VALUE_SHORT_NOTSET) || (hc->curr_roomTemp == EMS_VALUE_SHORT_NOTSET)) { if (hc->setpoint_roomTemp == EMS_VALUE_SHORT_NOTSET) { break; // skip this HC } @@ -776,7 +776,7 @@ std::string Thermostat::mode_tostring(uint8_t mode) const { void Thermostat::show_values(uuid::console::Shell & shell) { EMSdevice::show_values(shell); // always call this to show header - char buffer[10]; // for formatting only + char buffer[10]; // for formatting only uint8_t flags = (this->flags() & 0x0F); // specific thermostat characteristics, strip the option bits if (datetime_.size()) { @@ -828,7 +828,6 @@ void Thermostat::show_values(uuid::console::Shell & shell) { } } if (flags == EMS_DEVICE_FLAG_RC35 || flags == EMS_DEVICE_FLAG_RC30_1) { - if (ibaCalIntTemperature != EMS_VALUE_INT_NOTSET) { print_value(shell, 2, F("Offset int. temperature"), F_(degrees), Helpers::render_value(buffer, ibaCalIntTemperature, 2)); } @@ -1053,7 +1052,7 @@ void Thermostat::process_RC35Monitor(std::shared_ptr telegram) { std::shared_ptr hc = heating_circuit(telegram); telegram->read_value8(hc->setpoint_roomTemp, 2); // is * 2, force to single byte, is 0 in summermode - telegram->read_value(hc->curr_roomTemp, 3); // is * 10 - or 0x7D00 if thermostat is mounted on boiler + telegram->read_value(hc->curr_roomTemp, 3); // is * 10 - or 0x7D00 if thermostat is mounted on boiler telegram->read_value(hc->mode_type, 1, 1); telegram->read_value(hc->summer_mode, 1, 0); telegram->read_value(hc->holiday_mode, 0, 5); @@ -1309,13 +1308,13 @@ void Thermostat::set_temperature(const float temperature, const uint8_t mode, co case HeatingCircuit::Mode::OFFSET: // change the offset temp offset = EMS_OFFSET_RC35Set_temp_offset; break; - case HeatingCircuit::Mode::DESIGN: + case HeatingCircuit::Mode::DESIGN: offset = EMS_OFFSET_RC35Set_temp_design; break; - case HeatingCircuit::Mode::SUMMER: + case HeatingCircuit::Mode::SUMMER: offset = EMS_OFFSET_RC35Set_temp_summer; break; - case HeatingCircuit::Mode::NOFROST: + case HeatingCircuit::Mode::NOFROST: offset = EMS_OFFSET_RC35Set_temp_nofrost; break; default: diff --git a/src/thermostat.h b/src/thermostat.h index e38c2a835..508b731fd 100644 --- a/src/thermostat.h +++ b/src/thermostat.h @@ -46,22 +46,22 @@ class Thermostat : public EMSdevice { } ~HeatingCircuit() = default; - int16_t setpoint_roomTemp = EMS_VALUE_SHORT_NOTSET; - int16_t curr_roomTemp = EMS_VALUE_SHORT_NOTSET; - uint8_t mode = EMS_VALUE_UINT_NOTSET; - uint8_t mode_type = EMS_VALUE_UINT_NOTSET; - uint8_t summer_mode = EMS_VALUE_UINT_NOTSET; - uint8_t holiday_mode = EMS_VALUE_UINT_NOTSET; - uint8_t daytemp = EMS_VALUE_UINT_NOTSET; - uint8_t nighttemp = EMS_VALUE_UINT_NOTSET; - uint8_t holidaytemp = EMS_VALUE_UINT_NOTSET; - uint8_t heatingtype = EMS_VALUE_UINT_NOTSET; // type of heating: 1 radiator, 2 convectors, 3 floors, 4 room supply - uint8_t circuitcalctemp = EMS_VALUE_UINT_NOTSET; - uint8_t summertemp = EMS_VALUE_UINT_NOTSET; - uint8_t nofrosttemp = EMS_VALUE_UINT_NOTSET; - uint8_t designtemp = EMS_VALUE_UINT_NOTSET; // heatingcurve design temp at MinExtTemp - uint8_t offsettemp = 100; // heatingcurve offest temp at roomtemp signed! - uint16_t remotetemp = EMS_VALUE_SHORT_NOTSET; // for simulating a RC20 remote + int16_t setpoint_roomTemp = EMS_VALUE_SHORT_NOTSET; + int16_t curr_roomTemp = EMS_VALUE_SHORT_NOTSET; + uint8_t mode = EMS_VALUE_UINT_NOTSET; + uint8_t mode_type = EMS_VALUE_UINT_NOTSET; + uint8_t summer_mode = EMS_VALUE_UINT_NOTSET; + uint8_t holiday_mode = EMS_VALUE_UINT_NOTSET; + uint8_t daytemp = EMS_VALUE_UINT_NOTSET; + uint8_t nighttemp = EMS_VALUE_UINT_NOTSET; + uint8_t holidaytemp = EMS_VALUE_UINT_NOTSET; + uint8_t heatingtype = EMS_VALUE_UINT_NOTSET; // type of heating: 1 radiator, 2 convectors, 3 floors, 4 room supply + uint8_t circuitcalctemp = EMS_VALUE_UINT_NOTSET; + uint8_t summertemp = EMS_VALUE_UINT_NOTSET; + uint8_t nofrosttemp = EMS_VALUE_UINT_NOTSET; + uint8_t designtemp = EMS_VALUE_UINT_NOTSET; // heatingcurve design temp at MinExtTemp + uint8_t offsettemp = 100; // heatingcurve offest temp at roomtemp signed! + uint16_t remotetemp = EMS_VALUE_SHORT_NOTSET; // for simulating a RC20 remote uint8_t hc_num() const { diff --git a/src/uart/emsuart_esp32.cpp b/src/uart/emsuart_esp32.cpp index b56b97e30..11ac5dc05 100644 --- a/src/uart/emsuart_esp32.cpp +++ b/src/uart/emsuart_esp32.cpp @@ -49,7 +49,7 @@ void EMSuart::emsuart_recvTask(void * para) { EMSESP::incoming_telegram(telegram, telegramSize); vRingbufferReturnItem(buf_handle, (void *)telegram); } - } + } } /* * UART interrupt, on break read the fifo and put the whole telegram to ringbuffer @@ -60,7 +60,7 @@ void IRAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) { if (EMS_UART.int_st.brk_det) { EMS_UART.int_clr.brk_det = 1; // clear flag - length = 0; + length = 0; while (EMS_UART.status.rxfifo_cnt) { uint8_t rx = EMS_UART.fifo.rw_byte; // read all bytes from fifo if (length < EMS_MAXBUFFERSIZE) { @@ -85,7 +85,7 @@ void EMSuart::start(uint8_t tx_mode) { restart(); return; } - tx_mode_ = tx_mode; + tx_mode_ = tx_mode; uart_config_t uart_config = { .baud_rate = EMSUART_BAUD, .data_bits = UART_DATA_8_BITS, @@ -96,9 +96,9 @@ void EMSuart::start(uint8_t tx_mode) { ESP_ERROR_CHECK(uart_param_config(EMSUART_UART, &uart_config)); ESP_ERROR_CHECK(uart_set_pin(EMSUART_UART, EMSUART_TXPIN, EMSUART_RXPIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); - EMS_UART.int_ena.val = 0; // disable all intr. + EMS_UART.int_ena.val = 0; // disable all intr. EMS_UART.int_clr.val = 0xFFFFFFFF; // clear all intr. flags - EMS_UART.idle_conf.tx_brk_num = 11; // breaklength 11 bit + EMS_UART.idle_conf.tx_brk_num = 11; // breaklength 11 bit EMS_UART.idle_conf.rx_idle_thrhd = 256; drop_next_rx = true; buf_handle = xRingbufferCreate(128, RINGBUF_TYPE_NOSPLIT); @@ -119,8 +119,8 @@ void EMSuart::stop() { */ void EMSuart::restart() { if (EMS_UART.int_raw.brk_det) { - EMS_UART.int_clr.brk_det = 1; // clear flag - drop_next_rx = true; // and drop first frame + EMS_UART.int_clr.brk_det = 1; // clear flag + drop_next_rx = true; // and drop first frame } EMS_UART.int_ena.brk_det = 1; // activate only break }; @@ -139,7 +139,7 @@ void EMSuart::send_poll(uint8_t data) { * returns code, 1=success */ EMSUART_STATUS EMSuart::transmit(uint8_t * buf, uint8_t len) { - if (millis() -emsRxTime > EMS_RX_TO_TX_TIMEOUT) { + if (millis() - emsRxTime > EMS_RX_TO_TX_TIMEOUT) { return EMS_TX_WTD_TIMEOUT; } if (len > 0) { diff --git a/src/uart/emsuart_esp32.h b/src/uart/emsuart_esp32.h index 5a3a18189..4a2a9e289 100644 --- a/src/uart/emsuart_esp32.h +++ b/src/uart/emsuart_esp32.h @@ -41,7 +41,7 @@ // customize the GPIO pins for RX and TX here #ifdef WEMOS_D1_32 #define EMSUART_RXPIN 23 // 17 is UART2 RX. Use 23 for D7 on a Wemos D1-32 mini for backwards compatabilty -#define EMSUART_TXPIN 5 // 16 is UART2 TX. Use 5 for D8 on a Wemos D1-32 mini for backwards compatabilty +#define EMSUART_TXPIN 5 // 16 is UART2 TX. Use 5 for D8 on a Wemos D1-32 mini for backwards compatabilty #else #define EMSUART_RXPIN 17 // 17 is UART2 RX. Use 23 for D7 on a Wemos D1-32 mini for backwards compatabilty #define EMSUART_TXPIN 16 // 16 is UART2 TX. Use 5 for D8 on a Wemos D1-32 mini for backwards compatabilty diff --git a/src/uart/emsuart_esp8266.cpp b/src/uart/emsuart_esp8266.cpp index eb27cef33..86b5d9aee 100644 --- a/src/uart/emsuart_esp8266.cpp +++ b/src/uart/emsuart_esp8266.cpp @@ -54,7 +54,7 @@ void ICACHE_RAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) { drop_next_rx = true; } } - USIC(EMSUART_UART) = (1 << UIBD); // INT clear the BREAK detect interrupt + USIC(EMSUART_UART) = (1 << UIBD); // INT clear the BREAK detect interrupt USC0(EMSUART_UART) &= ~(1 << UCBRK); // reset tx-brk if (!drop_next_rx) { pEMSRxBuf->length = length; @@ -91,7 +91,7 @@ void ICACHE_FLASH_ATTR EMSuart::emsuart_recvTask(os_event_t * events) { // ignore double BRK at the end, possibly from the Tx loopback // also telegrams with no data value // then transmit EMS buffer, excluding the BRK - if (length > 4) { + if (length > 4) { EMSESP::incoming_telegram((uint8_t *)pCurrent->buffer, length - 1); } } @@ -188,7 +188,7 @@ void ICACHE_FLASH_ATTR EMSuart::stop() { void ICACHE_FLASH_ATTR EMSuart::restart() { if (USIR(EMSUART_UART) & ((1 << UIBD))) { USIC(EMSUART_UART) = (1 << UIBD); // INT clear the BREAK detect interrupt - drop_next_rx = true; + drop_next_rx = true; } ETS_UART_INTR_ENABLE(); } @@ -249,7 +249,7 @@ EMSUART_STATUS ICACHE_FLASH_ATTR EMSuart::transmit(uint8_t * buf, uint8_t len) { if (len == 0) { return EMS_TX_STATUS_OK; // nothing to send } - if(millis() > (emsRxTime + EMS_RX_TO_TX_TIMEOUT)) { // send allowed within 20 ms + if (millis() > (emsRxTime + EMS_RX_TO_TX_TIMEOUT)) { // send allowed within 20 ms return EMS_TX_WTD_TIMEOUT; } diff --git a/src/uart/emsuart_esp8266.h b/src/uart/emsuart_esp8266.h index ecf1c3574..c92ea6fd5 100644 --- a/src/uart/emsuart_esp8266.h +++ b/src/uart/emsuart_esp8266.h @@ -47,7 +47,7 @@ #define EMSUART_TX_LAG 8 #define EMSUART_BUSY_WAIT (EMSUART_BIT_TIME / 8) #define EMS_TX_TO_CHARS (2 + 20) -#define EMS_TX_TO_COUNT ((EMS_TX_TO_CHARS) * 8) +#define EMS_TX_TO_COUNT ((EMS_TX_TO_CHARS)*8) namespace emsesp { From 848689c100e277217ae9c23bf7e31a68f7bcacd4 Mon Sep 17 00:00:00 2001 From: proddy Date: Wed, 3 Jun 2020 17:27:51 +0200 Subject: [PATCH 06/12] version bump to a12 --- src/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h b/src/version.h index 4c1414bcc..efc44d9a0 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define EMSESP_APP_VERSION "2.0.0a11" +#define EMSESP_APP_VERSION "2.0.0a12" From 85fb40d310f46da0ff5b9fb864618f158b9db428 Mon Sep 17 00:00:00 2001 From: proddy Date: Wed, 3 Jun 2020 17:28:07 +0200 Subject: [PATCH 07/12] added no sleep mode to wifi --- src/network.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/network.cpp b/src/network.cpp index 39394d473..036070384 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -44,6 +44,12 @@ void Network::start() { sta_mode_disconnected_ = WiFi.onStationModeDisconnected(std::bind(&Network::sta_mode_disconnected, this, _1)); sta_mode_got_ip_ = WiFi.onStationModeGotIP(std::bind(&Network::sta_mode_got_ip, this, _1)); + WiFi.setSleepMode(WIFI_NONE_SLEEP); // added to possibly fix wifi dropouts in arduino core 2.5.0 + // ref: https://github.com/esp8266/Arduino/issues/6471 + // ref: https://github.com/esp8266/Arduino/issues/6366 + // high tx power causing weird behavior, slightly lowering from 20.5 to 20.0 may help stability + // WiFi.setOutputPower(20.0); // in DBM + connect(); // connect to WiFi ota_setup(); // initialize OTA @@ -164,9 +170,8 @@ void Network::connect() { #endif } - if (!settings.wifi_ssid().empty()) { - WiFi.begin(settings.wifi_ssid().c_str(), settings.wifi_password().c_str()); - } + LOG_INFO(F("Connecting to wifi ssid %s..."), settings.wifi_ssid().c_str()); + WiFi.begin(settings.wifi_ssid().c_str(), settings.wifi_password().c_str()); #endif } From 2d1627be3cb1bc650ca96de8f85cf393fbef5d4e Mon Sep 17 00:00:00 2001 From: proddy Date: Wed, 3 Jun 2020 17:28:21 +0200 Subject: [PATCH 08/12] remove interval. using mark instead --- src/system.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/system.cpp b/src/system.cpp index eacf4075b..d9dc6e478 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -20,7 +20,6 @@ #include "emsesp.h" // for send_raw_telegram() command MAKE_PSTR_WORD(syslog) -MAKE_PSTR_WORD(interval) MAKE_PSTR_WORD(mark) MAKE_PSTR_WORD(level) MAKE_PSTR_WORD(host) @@ -85,7 +84,6 @@ void System::mqtt_commands(const char * message) { // restart EMS-ESP // mode = safe mode. true to enable on next boot void System::restart(bool mode) { - // check for safe mode if (mode) { LOG_NOTICE("Restarting system in safe mode..."); From 13aae48bffb42ca8a4d4698aea67951f65e027f3 Mon Sep 17 00:00:00 2001 From: proddy Date: Wed, 3 Jun 2020 17:28:32 +0200 Subject: [PATCH 09/12] added test for unknown devices --- src/test/test_data.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/test_data.h b/src/test/test_data.h index de01ba0ea..ea8d96f91 100644 --- a/src/test/test_data.h +++ b/src/test/test_data.h @@ -35,6 +35,15 @@ void EMSESP::run_test(uuid::console::Shell & shell, const std::string & command) return; } + if (command == "unknown2") { + // simulate getting version information back from an unknown device + uint8_t t[] = {0x09, 0x0B, 0x02, 0x00, 0x5A, 0x01, 0x02, 0x5A}; // product id is 90 + rxservice_.add(t, sizeof(t)); + rxservice_.loop(); + + return; + } + if (command == "thermostats") { shell.printfln(F("Testing adding devices on the EMS bus...")); From 9d1f6b94797a83c8fcb9fd70a27af50e7ee30100 Mon Sep 17 00:00:00 2001 From: proddy Date: Wed, 3 Jun 2020 17:31:27 +0200 Subject: [PATCH 10/12] fix typo --- src/emsesp.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 93548aa7b..1a081d49c 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -830,5 +830,6 @@ void EMSESP::loop() { // https://github.com/esp8266/Arduino/blob/e721089e601985e633641ab7323f81a84ea0cd1b/cores/esp8266/core_esp8266_wiring.cpp#L41-L57 delay(1); } +} } // namespace emsesp From fa2e7f127b5f049958d435ec2ed133d25f579b8a Mon Sep 17 00:00:00 2001 From: proddy Date: Wed, 3 Jun 2020 17:31:37 +0200 Subject: [PATCH 11/12] updated readme text --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 46c58ad59..79ac9a0cc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # EMS-ESP version 2.0 (alpha) -*Warning: this is a snapshot from my EMS-ESP2 development repo and still in early stages of it's development. Not all features have been fully tested. Use at your own risk!* +*Warning: this is still in early stages of it's development. Not all features have been fully tested. Use at your own risk!* Note: Version 2.0 is not backward compatible with v1.0. The File system structure is different. When coming from version 1.9.x its best if you first erase the flash on the ESP and upload using USB. `esptool.py erase_flash` will clean the flash and `esptool.py -p COM6 -b 921600 write_flash 0x00000 firmware.bin` is an example of how to upload the firmware over USB. @@ -41,7 +41,7 @@ Note: Version 2.0 is not backward compatible with v1.0. The File system structur common commands available in all contexts: exit help - log [level] [raw] [trace ID] + log [level] [full|raw] [trace ID] su (top level) From c43b915a86cf5cb3cc9e9e09e24d5985923e2917 Mon Sep 17 00:00:00 2001 From: proddy Date: Wed, 3 Jun 2020 17:37:05 +0200 Subject: [PATCH 12/12] default boot in non-debug mode --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 918b8b425..d786a40d2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,7 +20,7 @@ extra_configs = pio_local.ini ;debug_flags = -DDEBUG_ESP_PORT=Serial -DDEBUG_ESP_CORE -DDEBUG_ESP_SSL -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_TLS_MEM debug_flags = - -D EMSESP_DEBUG + ; -D EMSESP_DEBUG ; -D EMSESP_SAFE_MODE ; -D ENABLE_CORS -D CORS_ORIGIN=\"http://localhost:3000\"