kopia lustrzana https://github.com/Aircoookie/WLED
Fix MQTT Null publish
rodzic
0327f9428e
commit
445b6ee13f
|
@ -60,7 +60,6 @@ private:
|
||||||
static const char _str_subFormat[];
|
static const char _str_subFormat[];
|
||||||
static const char _str_topicFormat[];
|
static const char _str_topicFormat[];
|
||||||
|
|
||||||
|
|
||||||
unsigned long _overlaySevenSegmentProcess()
|
unsigned long _overlaySevenSegmentProcess()
|
||||||
{
|
{
|
||||||
//Do time for now.
|
//Do time for now.
|
||||||
|
@ -270,19 +269,23 @@ private:
|
||||||
|
|
||||||
void _publishMQTTint_P(const char *subTopic, int value)
|
void _publishMQTTint_P(const char *subTopic, int value)
|
||||||
{
|
{
|
||||||
|
if(mqtt == NULL) return;
|
||||||
|
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
char valBuffer[12];
|
char valBuffer[12];
|
||||||
sprintf_P(buffer, PSTR("%s/sevenSeg/%S"), mqttDeviceTopic, subTopic);
|
sprintf_P(buffer, PSTR("%s/sevenSeg/%S"), mqttDeviceTopic, subTopic);
|
||||||
Serial.println(buffer);
|
|
||||||
sprintf_P(valBuffer, PSTR("%d"), value);
|
sprintf_P(valBuffer, PSTR("%d"), value);
|
||||||
mqtt->publish(buffer, 2, true, valBuffer);
|
mqtt->publish(buffer, 2, true, valBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _publishMQTTstr_P(const char *subTopic, String Value)
|
void _publishMQTTstr_P(const char *subTopic, String Value)
|
||||||
{
|
{
|
||||||
|
if(mqtt == NULL) return;
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
sprintf_P(buffer, PSTR("%s/sevenSeg/%S"), mqttDeviceTopic, subTopic);
|
sprintf_P(buffer, PSTR("%s/sevenSeg/%S"), mqttDeviceTopic, subTopic);
|
||||||
mqtt->publish(buffer, 2, true, Value.c_str(), Value.length());
|
mqtt->publish(buffer, 2, true, Value.c_str(), Value.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
void _updateMQTT()
|
void _updateMQTT()
|
||||||
{
|
{
|
||||||
_publishMQTTint_P(_str_perSegment, ssLEDPerSegment);
|
_publishMQTTint_P(_str_perSegment, ssLEDPerSegment);
|
||||||
|
@ -295,7 +298,9 @@ private:
|
||||||
_publishMQTTstr_P(_str_displayMask, ssDisplayMask);
|
_publishMQTTstr_P(_str_displayMask, ssDisplayMask);
|
||||||
_publishMQTTstr_P(_str_displayMsg, ssDisplayMessage);
|
_publishMQTTstr_P(_str_displayMsg, ssDisplayMessage);
|
||||||
}
|
}
|
||||||
bool _cmpIntSetting_P(char* topic, char* payload, const char* setting, void* value){
|
|
||||||
|
bool _cmpIntSetting_P(char *topic, char *payload, const char *setting, void *value)
|
||||||
|
{
|
||||||
if (strcmp_P(topic, setting) == 0)
|
if (strcmp_P(topic, setting) == 0)
|
||||||
{
|
{
|
||||||
*((int *)value) = strtol(payload, NULL, 10);
|
*((int *)value) = strtol(payload, NULL, 10);
|
||||||
|
@ -304,6 +309,7 @@ private:
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _handleSetting(char *topic, char *payload)
|
bool _handleSetting(char *topic, char *payload)
|
||||||
{
|
{
|
||||||
if (_cmpIntSetting_P(topic, payload, _str_perSegment, &ssLEDPerSegment))
|
if (_cmpIntSetting_P(topic, payload, _str_perSegment, &ssLEDPerSegment))
|
||||||
|
@ -424,7 +430,6 @@ public:
|
||||||
//Trim /set and handle it
|
//Trim /set and handle it
|
||||||
topic[topicLen - 4] = '\0';
|
topic[topicLen - 4] = '\0';
|
||||||
_handleSetting(topic, payload);
|
_handleSetting(topic, payload);
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -432,7 +437,8 @@ public:
|
||||||
void addToConfig(JsonObject &root)
|
void addToConfig(JsonObject &root)
|
||||||
{
|
{
|
||||||
JsonObject top = root[FPSTR(_str_sevenSeg)];
|
JsonObject top = root[FPSTR(_str_sevenSeg)];
|
||||||
if (top.isNull()) {
|
if (top.isNull())
|
||||||
|
{
|
||||||
top = root.createNestedObject(FPSTR(_str_sevenSeg));
|
top = root.createNestedObject(FPSTR(_str_sevenSeg));
|
||||||
}
|
}
|
||||||
top[FPSTR(_str_perSegment)] = ssLEDPerSegment;
|
top[FPSTR(_str_perSegment)] = ssLEDPerSegment;
|
||||||
|
@ -452,7 +458,8 @@ public:
|
||||||
bool configComplete = !top.isNull();
|
bool configComplete = !top.isNull();
|
||||||
|
|
||||||
//if sevenseg section doesn't exist return
|
//if sevenseg section doesn't exist return
|
||||||
if(!configComplete) return configComplete;
|
if (!configComplete)
|
||||||
|
return configComplete;
|
||||||
|
|
||||||
configComplete &= getJsonValue(top[FPSTR(_str_perSegment)], ssLEDPerSegment);
|
configComplete &= getJsonValue(top[FPSTR(_str_perSegment)], ssLEDPerSegment);
|
||||||
configComplete &= getJsonValue(top[FPSTR(_str_perPeriod)], ssLEDPerPeriod);
|
configComplete &= getJsonValue(top[FPSTR(_str_perPeriod)], ssLEDPerPeriod);
|
||||||
|
@ -466,7 +473,6 @@ public:
|
||||||
|
|
||||||
configComplete &= getJsonValue(top[FPSTR(_str_timeEnabled)], ssTimeEnabled);
|
configComplete &= getJsonValue(top[FPSTR(_str_timeEnabled)], ssTimeEnabled);
|
||||||
configComplete &= getJsonValue(top[FPSTR(_str_scrollSpd)], ssScrollSpeed);
|
configComplete &= getJsonValue(top[FPSTR(_str_scrollSpd)], ssScrollSpeed);
|
||||||
|
|
||||||
return configComplete;
|
return configComplete;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue