mirror of
https://github.com/wled/WLED.git
synced 2025-07-19 16:56:35 +00:00
MQTT null termination fix.
Nigtttime detection for PIR fix.
This commit is contained in:
parent
05b86a71fd
commit
2b7f2d4744
@ -108,20 +108,15 @@ private:
|
|||||||
uint8_t hr = hour(localTime);
|
uint8_t hr = hour(localTime);
|
||||||
uint8_t mi = minute(localTime);
|
uint8_t mi = minute(localTime);
|
||||||
|
|
||||||
DEBUG_PRINTF("--Time: %02d:%02d\n", (int)hr, (int)mi);
|
|
||||||
if (sunrise && sunset) {
|
if (sunrise && sunset) {
|
||||||
DEBUG_PRINTLN(F("--Sunrise & sunset detected."));
|
if (hour(sunrise)<hr && hour(sunset)>hr) {
|
||||||
if (hour(sunrise)>hr && hour(sunset)<hr) {
|
|
||||||
isDayTime = true;
|
isDayTime = true;
|
||||||
DEBUG_PRINTLN(F("--It is daytime."));
|
|
||||||
} else {
|
} else {
|
||||||
if (hour(sunrise)==hr && minute(sunrise)<mi) {
|
if (hour(sunrise)==hr && minute(sunrise)<mi) {
|
||||||
isDayTime = true;
|
isDayTime = true;
|
||||||
DEBUG_PRINTLN(F("--It is daytime."));
|
|
||||||
}
|
}
|
||||||
if (hour(sunset)==hr && minute(sunset)>mi) {
|
if (hour(sunset)==hr && minute(sunset)>mi) {
|
||||||
isDayTime = true;
|
isDayTime = true;
|
||||||
DEBUG_PRINTLN(F("--It is daytime."));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,13 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
|||||||
}
|
}
|
||||||
DEBUG_PRINTLN(payload);
|
DEBUG_PRINTLN(payload);
|
||||||
|
|
||||||
|
// payload is not always null terminated
|
||||||
|
char *payload0 = new char[len+1];
|
||||||
|
if (payload0==nullptr) return; // out of memory
|
||||||
|
strncpy(payload0,payload,len);
|
||||||
|
payload0[len] = '\0';
|
||||||
|
DEBUG_PRINTLN(payload0);
|
||||||
|
|
||||||
size_t topicPrefixLen = strlen(mqttDeviceTopic);
|
size_t topicPrefixLen = strlen(mqttDeviceTopic);
|
||||||
if (strncmp(topic, mqttDeviceTopic, topicPrefixLen) == 0) {
|
if (strncmp(topic, mqttDeviceTopic, topicPrefixLen) == 0) {
|
||||||
topic += topicPrefixLen;
|
topic += topicPrefixLen;
|
||||||
@ -73,7 +80,8 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
|||||||
topic += topicPrefixLen;
|
topic += topicPrefixLen;
|
||||||
} else {
|
} else {
|
||||||
// Non-Wled Topic used here. Probably a usermod subscribed to this topic.
|
// Non-Wled Topic used here. Probably a usermod subscribed to this topic.
|
||||||
usermods.onMqttMessage(topic, payload);
|
usermods.onMqttMessage(topic, payload0);
|
||||||
|
delete[] payload0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,25 +89,26 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
|||||||
//Prefix is stripped from the topic at this point
|
//Prefix is stripped from the topic at this point
|
||||||
|
|
||||||
if (strcmp_P(topic, PSTR("/col")) == 0) {
|
if (strcmp_P(topic, PSTR("/col")) == 0) {
|
||||||
colorFromDecOrHexString(col, (char*)payload);
|
colorFromDecOrHexString(col, payload0);
|
||||||
colorUpdated(NOTIFIER_CALL_MODE_DIRECT_CHANGE);
|
colorUpdated(NOTIFIER_CALL_MODE_DIRECT_CHANGE);
|
||||||
} else if (strcmp_P(topic, PSTR("/api")) == 0) {
|
} else if (strcmp_P(topic, PSTR("/api")) == 0) {
|
||||||
if (payload[0] == '{') { //JSON API
|
if (payload0[0] == '{') { //JSON API
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
deserializeJson(doc, payload);
|
deserializeJson(doc, payload0);
|
||||||
deserializeState(doc.as<JsonObject>());
|
deserializeState(doc.as<JsonObject>());
|
||||||
} else { //HTTP API
|
} else { //HTTP API
|
||||||
String apireq = "win&";
|
String apireq = "win&";
|
||||||
apireq += (char*)payload;
|
apireq += payload0;
|
||||||
handleSet(nullptr, apireq);
|
handleSet(nullptr, apireq);
|
||||||
}
|
}
|
||||||
} else if (strlen(topic) != 0) {
|
} else if (strlen(topic) != 0) {
|
||||||
// non standard topic, check with usermods
|
// non standard topic, check with usermods
|
||||||
usermods.onMqttMessage(topic, payload);
|
usermods.onMqttMessage(topic, payload0);
|
||||||
} else {
|
} else {
|
||||||
// topmost topic (just wled/MAC)
|
// topmost topic (just wled/MAC)
|
||||||
parseMQTTBriPayload(payload);
|
parseMQTTBriPayload(payload0);
|
||||||
}
|
}
|
||||||
|
delete[] payload0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// version code in format yymmddb (b = daily build)
|
// version code in format yymmddb (b = daily build)
|
||||||
#define VERSION 2105111
|
#define VERSION 2105112
|
||||||
|
|
||||||
//uncomment this if you have a "my_config.h" file you'd like to use
|
//uncomment this if you have a "my_config.h" file you'd like to use
|
||||||
//#define WLED_USE_MY_CONFIG
|
//#define WLED_USE_MY_CONFIG
|
||||||
|
Loading…
x
Reference in New Issue
Block a user