fix mqtt on_message

This commit is contained in:
MichaelDvP
2023-07-23 13:51:40 +02:00
parent 168a31d331
commit 962131592f
3 changed files with 11 additions and 14 deletions

View File

@@ -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) {