Skip to content

Commit

Permalink
Add victron serial to mqtt topics
Browse files Browse the repository at this point in the history
  • Loading branch information
helgeerbe committed Feb 7, 2023
1 parent 37d3bb0 commit 82ecf6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/MqttHandlVedirectHass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ void MqttHandleVedirectHassClass::publishConfig()
if (!MqttSettings.getConnected()) {
return;
}
if (VeDirect.veMap.find("SER") == VeDirect.veMap.end()) {
// ensure data is revieved from victron
if (VeDirect.veMap.find("SER") == VeDirect.veMap.end()) {
return;
}

Expand Down
13 changes: 11 additions & 2 deletions src/MqttHandleVedirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ void MqttHandleVedirectClass::loop()

if (!MqttSettings.getConnected() || !config.Vedirect_Enabled) {
return;
}
}

String serial;
auto pos = VeDirect.veMap.find("SER");
if (pos == VeDirect.veMap.end()) {
return;
}
else {
serial = pos->second;
}

if (millis() - _lastPublish > (config.Mqtt_PublishInterval * 1000)) {
String key;
Expand All @@ -44,7 +53,7 @@ void MqttHandleVedirectClass::loop()

// publish only changed key, values pairs
if (!config.Vedirect_UpdatesOnly || (bChanged && config.Vedirect_UpdatesOnly)) {
topic = "victron/";
topic = "victron/" + serial + "/";
topic.concat(key);
MqttSettings.publish(topic.c_str(), value.c_str());
}
Expand Down

0 comments on commit 82ecf6c

Please sign in to comment.