Skip to content

Commit

Permalink
Fix: Do not publish leading blanks in MQTT payload
Browse files Browse the repository at this point in the history
Fixes #1011
  • Loading branch information
tbnobody committed Jun 7, 2023
1 parent 82b0272 commit 3b6c529
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/MqttHandleInverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ void MqttHandleInverterClass::publishField(std::shared_ptr<InverterAbstract> inv
String value = String(
inv->Statistics()->getChannelFieldValue(type, channel, fieldId),
static_cast<unsigned int>(inv->Statistics()->getChannelFieldDigits(type, channel, fieldId)));
value.trim();

MqttSettings.publish(topic, value);
}
Expand Down
6 changes: 5 additions & 1 deletion src/MqttSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ void MqttSettingsClass::publish(const String& subtopic, const String& payload)
{
String topic = getPrefix();
topic += subtopic;
mqttClient->publish(topic.c_str(), 0, Configuration.get().Mqtt_Retain, payload.c_str());

String value = payload;
value.trim();

mqttClient->publish(topic.c_str(), 0, Configuration.get().Mqtt_Retain, value.c_str());
}

void MqttSettingsClass::publishGeneric(const String& topic, const String& payload, bool retain, uint8_t qos)
Expand Down

0 comments on commit 3b6c529

Please sign in to comment.