Skip to content

Commit

Permalink
Fix exception if no MQTT data
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Mar 3, 2018
1 parent a16e231 commit 15886c1
Show file tree
Hide file tree
Showing 24 changed files with 11 additions and 8 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@ bool TasmotaMqtt::Connected()

void TasmotaMqtt::_onMqttDataCb(const char* topic, uint32_t topic_len, const char* data, uint32_t data_len)
{
char topic_copy[topic_len];
char topic_copy[topic_len +1];

memcpy(topic_copy, topic, topic_len);
topic_copy[topic_len] = 0;
memcpy(topic_copy, topic, topic_len);
topic_copy[topic_len] = 0;
if (0 == data_len) data = (const char*)&topic_copy + topic_len;
onMqttDataCb((char*)topic_copy, (byte*)data, data_len);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 7 additions & 5 deletions sonoff/xdrv_00_mqtt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,14 @@ void MqttDisconnectedCb()
MqttDisconnected(MqttClient->getState()); // status codes are documented in file mqtt.h as tConnState
}

void MqttMyDataCb(const char* topic, uint32_t topic_len, const char *data, uint32_t data_len)
void MqttMyDataCb(const char* topic, uint32_t topic_len, const char* data, uint32_t data_len)
{
char topicCpy[topic_len];
memcpy(topicCpy, topic, topic_len);
topicCpy[topic_len] = 0;
MqttDataHandler((char*)topicCpy, (byte*)data, data_len);
char topic_copy[topic_len +1];

memcpy(topic_copy, topic, topic_len);
topic_copy[topic_len] = 0;
if (0 == data_len) data = (const char*)&topic_copy + topic_len;
MqttDataHandler((char*)topic_copy, (byte*)data, data_len);
}

void MqttSubscribeLib(char *topic)
Expand Down

0 comments on commit 15886c1

Please sign in to comment.