diff --git a/mock-api/server.js b/mock-api/server.js index 215d50f08..5ade146ce 100644 --- a/mock-api/server.js +++ b/mock-api/server.js @@ -899,17 +899,17 @@ app.get(EMSESP_STATUS_ENDPOINT, (req, res) => { }) app.post(EMSESP_DEVICEDATA_ENDPOINT, (req, res) => { const id = req.body.id - if (id == 1) { + if (id === 1) { const encoded = msgpack.encode(emsesp_devicedata_1) res.write(encoded, 'binary') res.end(null, 'binary') } - if (id == 2) { + if (id === 2) { const encoded = msgpack.encode(emsesp_devicedata_2) res.write(encoded, 'binary') res.end(null, 'binary') } - if (id == 3) { + if (id === 3) { const encoded = msgpack.encode(emsesp_devicedata_3) res.write(encoded, 'binary') res.end(null, 'binary') diff --git a/src/helpers.cpp b/src/helpers.cpp index 6504f04df..949326686 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -36,14 +36,14 @@ char * Helpers::hextoa(char * result, const uint8_t value) { #ifdef EMSESP_STANDALONE // special function to work outside of ESP's libraries char * Helpers::ultostr(char * ptr, uint32_t value, const uint8_t base) { - unsigned long t = 0, res = 0; - unsigned long tmp = value; - int count = 0; - if (NULL == ptr) { return NULL; } + unsigned long t = 0; + unsigned long tmp = value; + int count = 0; + if (tmp == 0) { count++; } @@ -57,6 +57,8 @@ char * Helpers::ultostr(char * ptr, uint32_t value, const uint8_t base) { *ptr = '\0'; + unsigned long res = 0; + do { res = value - base * (t = value / base); if (res < 10) { diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 0d1ce33ac..0e3476a79 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -107,8 +107,8 @@ void Mqtt::register_command(const uint8_t device_type, const __FlashStringHelper // register the individual commands too (e.g. ems-esp/boiler/wwonetime) // https://github.com/emsesp/EMS-ESP32/issues/31 - std::string topic(MQTT_TOPIC_MAX_SIZE, '\0'); if (subscribe_format_ == Subscribe_Format::INDIVIDUAL_ALL_HC && ((flags & CommandFlag::MQTT_SUB_FLAG_HC) == CommandFlag::MQTT_SUB_FLAG_HC)) { + std::string topic(MQTT_TOPIC_MAX_SIZE, '\0'); topic = cmd_topic + "/hc1/" + uuid::read_flash_string(cmd); queue_subscribe_message(topic); topic = cmd_topic + "/hc2/" + uuid::read_flash_string(cmd); @@ -118,6 +118,7 @@ void Mqtt::register_command(const uint8_t device_type, const __FlashStringHelper topic = cmd_topic + "/hc4/" + uuid::read_flash_string(cmd); queue_subscribe_message(topic); } else if (subscribe_format_ != Subscribe_Format::GENERAL && ((flags & CommandFlag::MQTT_SUB_FLAG_NOSUB) == CommandFlag::MQTT_SUB_FLAG_NOSUB)) { + std::string topic(MQTT_TOPIC_MAX_SIZE, '\0'); topic = cmd_topic + "/" + uuid::read_flash_string(cmd); queue_subscribe_message(topic); }