diff --git a/interface/.env.development b/interface/.env.development index 2e6df040d..30b432990 100644 --- a/interface/.env.development +++ b/interface/.env.development @@ -1,10 +1,6 @@ # Change the IP address to that of your ESP device to enable local development of the UI. -# Remember to also enable CORS in platformio.ini before uploading the code to the device. +# Remember to also enable CORS in platformio.ini before uploading the code to the device +# with -DENABLE_CORS -# ESP32 dev REACT_APP_HTTP_ROOT=http://10.10.10.101 REACT_APP_WEB_SOCKET_ROOT=ws://10.10.10.101 - -# ESP8266 dev -#REACT_APP_HTTP_ROOT=http://10.10.10.140 -#REACT_APP_WEB_SOCKET_ROOT=ws://10.10.10.140 diff --git a/interface/src/security/SecuritySettingsForm.tsx b/interface/src/security/SecuritySettingsForm.tsx index 41d5bbaa8..2c9d12779 100644 --- a/interface/src/security/SecuritySettingsForm.tsx +++ b/interface/src/security/SecuritySettingsForm.tsx @@ -35,7 +35,7 @@ class SecuritySettingsForm extends React.Component { /> - The Super User password is used to sign authentication tokens and also the Console's `su` password. If you modify this all users will be signed out. + The Super User password is used to sign authentication tokens and is also the Console's `su` password. If you modify this all users will be signed out. diff --git a/src/command.cpp b/src/command.cpp index cbb42ee64..704e51995 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -26,16 +26,8 @@ uuid::log::Logger Command::logger_{F_(command), uuid::log::Facility::DAEMON}; std::vector Command::cmdfunctions_; -/* -static emsesp::array cmdfunctions_(90, 255, 16); // reserve space for 90 commands - -emsesp::array * Command::commands() { - return &cmdfunctions_; -} -*/ - // calls a command -// id may be used to represent a heating circuit for example +// id may be used to represent a heating circuit for example, it's optional // returns false if error or not found bool Command::call(const uint8_t device_type, const char * cmd, const char * value, const int8_t id) { auto cf = find_command(device_type, cmd); @@ -99,14 +91,6 @@ void Command::add(const uint8_t device_type, const __FlashStringHelper * cmd, cm return; } - /* - CmdFunction cf; - cf.cmd_ = cmd; - cf.device_type_ = device_type; - cf.cmdfunction_json_ = nullptr; // empty - cf.cmdfunction_ = cb; - cmdfunctions_.push(cf); - */ cmdfunctions_.emplace_back(device_type, cmd, cb, nullptr); // see if we need to subscribe @@ -122,15 +106,6 @@ void Command::add_with_json(const uint8_t device_type, const __FlashStringHelper return; } - /* - CmdFunction cf; - cf.cmd_ = cmd; - cf.device_type_ = device_type; - cf.cmdfunction_json_ = cb; - cf.cmdfunction_ = nullptr; // empty - cmdfunctions_.push(cf); - */ - cmdfunctions_.emplace_back(device_type, cmd, nullptr, cb); // add command } diff --git a/src/command.h b/src/command.h index af82d0700..6207cdd35 100644 --- a/src/command.h +++ b/src/command.h @@ -26,8 +26,6 @@ #include #include -// #include "containers.h" - #include "console.h" #include @@ -59,10 +57,8 @@ class Command { return cmdfunctions_; } - // static emsesp::array * commands(); - static bool call(const uint8_t device_type, const char * cmd, const char * value, const int8_t id, JsonObject & json); - static bool call(const uint8_t device_type, const char * cmd, const char * value, const int8_t id); + static bool call(const uint8_t device_type, const char * cmd, const char * value, const int8_t id = 0); static void add(const uint8_t device_type, const __FlashStringHelper * cmd, cmdfunction_p cb); static void add_with_json(const uint8_t device_type, const __FlashStringHelper * cmd, cmdfunction_json_p cb); static void show_all(uuid::console::Shell & shell); diff --git a/src/devices/boiler.cpp b/src/devices/boiler.cpp index 16adcfac3..d3cc75136 100644 --- a/src/devices/boiler.cpp +++ b/src/devices/boiler.cpp @@ -227,8 +227,7 @@ bool Boiler::publish_ha_config() { char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; snprintf_P(topic, sizeof(topic), PSTR("homeassistant/sensor/%s/boiler/config"), Mqtt::base().c_str()); - Mqtt::publish_ha(topic, - doc.as()); // publish the config payload with retain flag + Mqtt::publish_ha(topic, doc.as()); // publish the config payload with retain flag return true; } diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index a6860d5fd..0ea2609da 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -448,9 +448,9 @@ bool Thermostat::thermostat_ha_cmd(const char * message, uint8_t hc_num) { return false; } - // check for mode first + // check for mode first, which is a string if (!set_mode(message, hc_num)) { - // handle as a numerical temperature value + // otherwise handle as a numerical temperature value and set the setpoint temp float f = strtof((char *)message, 0); set_temperature(f, HeatingCircuit::Mode::AUTO, hc_num); } diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index f7f31495f..10629f487 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -124,7 +124,7 @@ std::string EMSdevice::brand_to_string() const { return std::string{}; } -// returns the name of the MQTT topic to use for a specific device +// returns the name of the MQTT topic to use for a specific device, without the base std::string EMSdevice::device_type_2_device_name(const uint8_t device_type) { switch (device_type) { case DeviceType::SYSTEM: @@ -308,6 +308,7 @@ bool EMSdevice::get_toggle_fetch(uint16_t telegram_id) { } // list device values, only for EMSESP_DEBUG mode +#if defined(EMSESP_DEBUG) void EMSdevice::show_device_values_debug(uuid::console::Shell & shell) { size_t total_s = 0; uint8_t count = 0; @@ -324,7 +325,7 @@ void EMSdevice::show_device_values_debug(uuid::console::Shell & shell) { shell.printfln("Total size of %d elements: %d", count, total_s); shell.println(); } - +#endif // list all the telegram type IDs for this device void EMSdevice::show_telegram_handlers(uuid::console::Shell & shell) { diff --git a/src/emsesp.cpp b/src/emsesp.cpp index fbaae3074..c573447cc 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -824,7 +824,7 @@ void EMSESP::show_devices(uuid::console::Shell & shell) { #if defined(EMSESP_DEBUG) emsdevice->show_mqtt_handlers(shell); shell.println(); - emsdevice->show_device_values_debug(shell); + // emsdevice->show_device_values_debug(shell); #endif shell.println(); diff --git a/src/telegram.cpp b/src/telegram.cpp index 3cd18262a..87608e05d 100644 --- a/src/telegram.cpp +++ b/src/telegram.cpp @@ -22,19 +22,15 @@ namespace emsesp { // CRC lookup table with poly 12 for faster checking -const uint8_t ems_crc_table[] = {0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E, 0x20, 0x22, 0x24,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2, 0xF4, 0xF6, 0xF8, 0xFA, 0xFC, 0xFE, 0x19, 0x1B, 0x1D, 0x1F, 0x11, 0x13, 0x15, 0x17, 0x09, 0x0B, 0x0D, 0x0F, 0x01, 0x03, 0x05, 0x07, 0x39, + 0x3B, 0x3D, 0x3F, 0x31, 0x33, 0x35, 0x37, 0x29, 0x2B, 0x2D, 0x2F, 0x21, 0x23, 0x25, 0x27, 0x59, 0x5B, 0x5D, 0x5F, 0x51, 0x53, 0x55, 0x57, 0x49, 0x4B, 0x4D, 0x4F, 0x41, 0x43, + 0x45, 0x47, 0x79, 0x7B, 0x7D, 0x7F, 0x71, 0x73, 0x75, 0x77, 0x69, 0x6B, 0x6D, 0x6F, 0x61, 0x63, 0x65, 0x67, 0x99, 0x9B, 0x9D, 0x9F, 0x91, 0x93, 0x95, 0x97, 0x89, 0x8B, 0x8D, + 0x8F, 0x81, 0x83, 0x85, 0x87, 0xB9, 0xBB, 0xBD, 0xBF, 0xB1, 0xB3, 0xB5, 0xB7, 0xA9, 0xAB, 0xAD, 0xAF, 0xA1, 0xA3, 0xA5, 0xA7, 0xD9, 0xDB, 0xDD, 0xDF, 0xD1, 0xD3, 0xD5, 0xD7, + 0xC9, 0xCB, 0xCD, 0xCF, 0xC1, 0xC3, 0xC5, 0xC7, 0xF9, 0xFB, 0xFD, 0xFF, 0xF1, 0xF3, 0xF5, 0xF7, 0xE9, 0xEB, 0xED, 0xEF, 0xE1, 0xE3, 0xE5, 0xE7}; uint32_t EMSbus::last_bus_activity_ = 0; // timestamp of last time a valid Rx came in bool EMSbus::bus_connected_ = false; // start assuming the bus hasn't been connected @@ -59,13 +55,7 @@ uint8_t EMSbus::calculate_crc(const uint8_t * data, const uint8_t length) { // creates a telegram object // stores header in separate member objects and the rest in the message_data block -Telegram::Telegram(const uint8_t operation, - const uint8_t src, - const uint8_t dest, - const uint16_t type_id, - const uint8_t offset, - const uint8_t * data, - const uint8_t message_length) +Telegram::Telegram(const uint8_t operation, const uint8_t src, const uint8_t dest, const uint16_t type_id, const uint8_t offset, const uint8_t * data, const uint8_t message_length) : operation(operation) , src(src) , dest(dest) @@ -202,8 +192,7 @@ void RxService::add(uint8_t * data, uint8_t length) { // if we're watching and "raw" print out actual telegram as bytes to the console if (EMSESP::watch() == EMSESP::Watch::WATCH_RAW) { uint16_t trace_watch_id = EMSESP::watch_id(); - if ((trace_watch_id == WATCH_ID_NONE) || (type_id == trace_watch_id) - || ((trace_watch_id < 0x80) && ((src == trace_watch_id) || (dest == trace_watch_id)))) { + if ((trace_watch_id == WATCH_ID_NONE) || (type_id == trace_watch_id) || ((trace_watch_id < 0x80) && ((src == trace_watch_id) || (dest == trace_watch_id)))) { LOG_NOTICE(F("Rx: %s"), Helpers::data_to_hex(data, length).c_str()); } else if (EMSESP::trace_raw()) { LOG_TRACE(F("Rx: %s"), Helpers::data_to_hex(data, length).c_str()); @@ -234,13 +223,6 @@ void RxService::add(uint8_t * data, uint8_t length) { } rx_telegrams_.emplace_back(rx_telegram_id_++, std::move(telegram)); // add to queue - - /* - QueuedRxTelegram qrxt; - qrxt.telegram_ = std::make_shared(operation, src, dest, type_id, offset, message_data, message_length); - qrxt.id_ = rx_telegram_id_++; - rx_telegrams_.push(qrxt); - */ } // start and initialize Tx @@ -285,15 +267,11 @@ void TxService::send() { } delayed_send_ = 0; - // auto telegram = tx_telegrams_.pop(); // get the Telegram, also removes from queue - // if we're in read-only mode (tx_mode 0) forget the Tx call if (tx_mode() != 0) { - // send_telegram(telegram); send_telegram(tx_telegrams_.front()); } - // auto telegram = tx_telegrams_.pop(); tx_telegrams_.pop_front(); // remove the telegram from the queue } @@ -371,10 +349,7 @@ void TxService::send_telegram(const QueuedTxTelegram & tx_telegram) { length++; // add one since we want to now include the CRC - LOG_DEBUG(F("Sending %s Tx [#%d], telegram: %s"), - (telegram->operation == Telegram::Operation::TX_WRITE) ? F("write") : F("read"), - tx_telegram.id_, - Helpers::data_to_hex(telegram_raw, length).c_str()); + LOG_DEBUG(F("Sending %s Tx [#%d], telegram: %s"), (telegram->operation == Telegram::Operation::TX_WRITE) ? F("write") : F("read"), tx_telegram.id_, Helpers::data_to_hex(telegram_raw, length).c_str()); set_post_send_query(tx_telegram.validateid_); // send the telegram to the UART Tx @@ -414,14 +389,7 @@ void TxService::send_telegram(const uint8_t * data, const uint8_t length) { } */ -void TxService::add(const uint8_t operation, - const uint8_t dest, - const uint16_t type_id, - const uint8_t offset, - uint8_t * message_data, - const uint8_t message_length, - const uint16_t validateid, - const bool front) { +void TxService::add(const uint8_t operation, const uint8_t dest, const uint16_t type_id, const uint8_t offset, uint8_t * message_data, const uint8_t message_length, const uint16_t validateid, const bool front) { auto telegram = std::make_shared(operation, ems_bus_id(), dest, type_id, offset, message_data, message_length); #ifdef EMSESP_DEBUG @@ -490,7 +458,7 @@ void TxService::add(uint8_t operation, const uint8_t * data, const uint8_t lengt if (dest & 0x80) { operation = Telegram::Operation::TX_READ; } else { - operation = Telegram::Operation::TX_WRITE; + operation = Telegram::Operation::TX_WRITE; validate_id = type_id; } EMSESP::set_read_id(type_id); @@ -507,13 +475,6 @@ void TxService::add(uint8_t operation, const uint8_t * data, const uint8_t lengt LOG_DEBUG(F("[DEBUG] New Tx [#%d] telegram, length %d"), tx_telegram_id_, message_length); #endif - /* - QueuedTxTelegram qtxt; - qtxt.id_ = tx_telegram_id_++; - qtxt.retry_ = false; - qtxt.telegram_ = std::make_shared(operation, ems_bus_id(), dest, type_id, offset, message_data, message_length); - */ - if (front) { // tx_telegrams_.push_front(qtxt); // add to front of queue tx_telegrams_.emplace_front(tx_telegram_id_++, std::move(telegram), false, validate_id); // add to front of queue @@ -580,9 +541,7 @@ void TxService::retry_tx(const uint8_t operation, const uint8_t * data, const ui reset_retry_count(); // give up increment_telegram_fail_count(); // another Tx fail - LOG_ERROR(F("Last Tx %s operation failed after %d retries. Ignoring request."), - (operation == Telegram::Operation::TX_WRITE) ? F("Write") : F("Read"), - MAXIMUM_TX_RETRIES); + LOG_ERROR(F("Last Tx %s operation failed after %d retries. Ignoring request."), (operation == Telegram::Operation::TX_WRITE) ? F("Write") : F("Read"), MAXIMUM_TX_RETRIES); return; } @@ -600,14 +559,6 @@ void TxService::retry_tx(const uint8_t operation, const uint8_t * data, const ui } tx_telegrams_.emplace_front(tx_telegram_id_++, std::move(telegram_last_), true, get_post_send_query()); - - /* - QueuedTxTelegram qtxt; - qtxt.id_ = tx_telegram_id_++; - qtxt.retry_ = true; // this time it is a retry - qtxt.telegram_ = telegram_last_; - tx_telegrams_.push_front(qtxt); // add to front of queue - */ } uint16_t TxService::read_next_tx() { @@ -635,7 +586,7 @@ uint16_t TxService::post_send_query() { uint8_t dest = (this->telegram_last_->dest & 0x7F); // when set a value with large offset before and validate on same type, we have to add offset 0, 26, 52, ... uint8_t offset = (this->telegram_last_->type_id == post_typeid) ? ((this->telegram_last_->offset / 26) * 26) : 0; - uint8_t message_data[1] = {EMS_MAX_TELEGRAM_LENGTH}; // request all data, 32 bytes + uint8_t message_data[1] = {EMS_MAX_TELEGRAM_LENGTH}; // request all data, 32 bytes this->add(Telegram::Operation::TX_READ, dest, post_typeid, offset, message_data, 1, 0, true); // add to top/front of queue // read_request(telegram_last_post_send_query_, dest, 0); // no offset LOG_DEBUG(F("Sending post validate read, type ID 0x%02X to dest 0x%02X"), post_typeid, dest); diff --git a/src/telegram.h b/src/telegram.h index 2761f73f7..80032e0d0 100644 --- a/src/telegram.h +++ b/src/telegram.h @@ -31,7 +31,6 @@ #include -// #include "containers.h" #include "helpers.h" #define MAX_RX_TELEGRAMS 10 // size of Rx queue @@ -239,17 +238,6 @@ class RxService : public EMSbus { return rx_telegrams_; } - /* - struct QueuedRxTelegram { - uint16_t id_; - std::shared_ptr telegram_; - }; - - const emsesp::queue queue() const { - return rx_telegrams_; - } - */ - private: static constexpr uint8_t EMS_BUS_QUALITY_RX_THRESHOLD = 5; // % threshold before reporting quality issues @@ -258,7 +246,6 @@ class RxService : public EMSbus { uint32_t telegram_error_count_ = 0; // # Rx CRC errors std::shared_ptr rx_telegram; // the incoming Rx telegram std::deque rx_telegrams_; // the Rx Queue - // emsesp::queue rx_telegrams_ = emsesp::queue(MAX_RX_TELEGRAMS); // the Rx Queue }; class TxService : public EMSbus { @@ -271,7 +258,7 @@ class TxService : public EMSbus { void start(); void send(); - void add(const uint8_t operation, const uint8_t dest, const uint16_t type_id, const uint8_t offset, uint8_t * message_data, const uint8_t message_length, const uint16_t validateid, const bool front = false); + void add(const uint8_t operation, const uint8_t dest, const uint16_t type_id, const uint8_t offset, uint8_t * message_data, const uint8_t message_length, const uint16_t validateid, const bool front = false); void add(const uint8_t operation, const uint8_t * data, const uint8_t length, const uint16_t validateid, const bool front = false); void read_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset = 0); void send_raw(const char * telegram_data); @@ -359,18 +346,6 @@ class TxService : public EMSbus { return tx_telegrams_; } - /* - struct QueuedTxTelegram { - uint16_t id_; - std::shared_ptr telegram_; - bool retry_; // true if its a retry - }; - - const emsesp::queue queue() const { - return tx_telegrams_; - } - */ - #if defined(EMSESP_DEBUG) static constexpr uint8_t MAXIMUM_TX_RETRIES = 0; // when compiled with EMSESP_DEBUG don't retry #else @@ -380,7 +355,6 @@ class TxService : public EMSbus { private: std::deque tx_telegrams_; // the Tx queue - // emsesp::queue tx_telegrams_ = emsesp::queue(MAX_TX_TELEGRAMS); // the Tx Queue uint32_t telegram_read_count_ = 0; // # Tx successful reads uint32_t telegram_write_count_ = 0; // # Tx successful writes