Fix MQTT Null publish

This commit is contained in:
Gregory Schmidt 2021-10-10 17:05:55 -08:00
parent 0327f9428e
commit 445b6ee13f

View File

@ -60,7 +60,6 @@ private:
static const char _str_subFormat[];
static const char _str_topicFormat[];
unsigned long _overlaySevenSegmentProcess()
{
//Do time for now.
@ -270,19 +269,23 @@ private:
void _publishMQTTint_P(const char *subTopic, int value)
{
if(mqtt == NULL) return;
char buffer[64];
char valBuffer[12];
sprintf_P(buffer, PSTR("%s/sevenSeg/%S"), mqttDeviceTopic, subTopic);
Serial.println(buffer);
sprintf_P(valBuffer, PSTR("%d"), value);
mqtt->publish(buffer, 2, true, valBuffer);
}
void _publishMQTTstr_P(const char *subTopic, String Value)
{
if(mqtt == NULL) return;
char buffer[64];
sprintf_P(buffer, PSTR("%s/sevenSeg/%S"), mqttDeviceTopic, subTopic);
mqtt->publish(buffer, 2, true, Value.c_str(), Value.length());
}
void _updateMQTT()
{
_publishMQTTint_P(_str_perSegment, ssLEDPerSegment);
@ -295,7 +298,9 @@ private:
_publishMQTTstr_P(_str_displayMask, ssDisplayMask);
_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)
{
*((int *)value) = strtol(payload, NULL, 10);
@ -304,6 +309,7 @@ private:
}
return false;
}
bool _handleSetting(char *topic, char *payload)
{
if (_cmpIntSetting_P(topic, payload, _str_perSegment, &ssLEDPerSegment))
@ -424,7 +430,6 @@ public:
//Trim /set and handle it
topic[topicLen - 4] = '\0';
_handleSetting(topic, payload);
}
return true;
}
@ -432,7 +437,8 @@ public:
void addToConfig(JsonObject &root)
{
JsonObject top = root[FPSTR(_str_sevenSeg)];
if (top.isNull()) {
if (top.isNull())
{
top = root.createNestedObject(FPSTR(_str_sevenSeg));
}
top[FPSTR(_str_perSegment)] = ssLEDPerSegment;
@ -452,7 +458,8 @@ public:
bool configComplete = !top.isNull();
//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_perPeriod)], ssLEDPerPeriod);
@ -466,7 +473,6 @@ public:
configComplete &= getJsonValue(top[FPSTR(_str_timeEnabled)], ssTimeEnabled);
configComplete &= getJsonValue(top[FPSTR(_str_scrollSpd)], ssScrollSpeed);
return configComplete;
}