From 962131592f1dc7779313241d64fb0730d84ec78e Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Sun, 23 Jul 2023 13:51:40 +0200 Subject: [PATCH] fix mqtt on_message --- interface/package.json | 2 +- interface/yarn.lock | 10 +++++----- src/mqtt.cpp | 13 +++++-------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/interface/package.json b/interface/package.json index 931471f7e..64a6a026e 100644 --- a/interface/package.json +++ b/interface/package.json @@ -27,7 +27,7 @@ "@preact/compat": "^17.1.2", "@table-library/react-table-library": "4.1.4", "@types/lodash-es": "^4.17.8", - "@types/node": "^20.4.2", + "@types/node": "^20.4.4", "@types/react": "^18.2.15", "@types/react-dom": "^18.2.7", "@types/react-router-dom": "^5.3.3", diff --git a/interface/yarn.lock b/interface/yarn.lock index cb640505a..baa56f00e 100644 --- a/interface/yarn.lock +++ b/interface/yarn.lock @@ -1730,10 +1730,10 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:^20.4.2": - version: 20.4.2 - resolution: "@types/node@npm:20.4.2" - checksum: ca506e089737d54effabda5d6534fdf9fdbe22adbcc4864a170feea390389f38cbae6abcf89c2b1ce5c3e4ffc450b35341509a7619f850babf43106009f01b2d +"@types/node@npm:^20.4.4": + version: 20.4.4 + resolution: "@types/node@npm:20.4.4" + checksum: 93748f53c7f34acde229436717408a0b8f88540647a4bacb863ee46a1545d53a056fa9b486721067b5a7bf0d5123fb1c13519e977b34aef1ddef9857a1c1e5fc languageName: node linkType: hard @@ -1971,7 +1971,7 @@ __metadata: "@preact/preset-vite": ^2.5.0 "@table-library/react-table-library": 4.1.4 "@types/lodash-es": ^4.17.8 - "@types/node": ^20.4.2 + "@types/node": ^20.4.4 "@types/react": ^18.2.15 "@types/react-dom": ^18.2.7 "@types/react-router-dom": ^5.3.3 diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 98d1b4dc5..fd52b7626 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -211,18 +211,15 @@ void Mqtt::incoming(const char * topic, const char * payload) { // received an MQTT message that we subscribed too // topic is the full path // payload is json or a single string and converted to a json with key 'value' -void Mqtt::on_message(const char * topic, const char * message, size_t len) const { - // This causes a compile error "error: variable-sized object may not be initialized" - // so commenting out and assuming with the new mqtt lib it's always null terminated - - /* - // sometimes the payload is not terminated correctly, so make a copy +void Mqtt::on_message(const char * topic, const char * payload, size_t len) const { + // the payload is not terminated correctly, so make a copy // convert payload to a null-terminated char string - char message[len + 2] = {'\0'}; + char message[len + 1]; if (payload != nullptr) { strlcpy(message, payload, len + 1); + } else { + message[0] = '\0'; } - */ #if defined(EMSESP_DEBUG) if (len) {