Add victron serial to mqtt topics
This commit is contained in:
parent
37d3bb0eb0
commit
82ecf6cd6d
@ -46,6 +46,7 @@ void MqttHandleVedirectHassClass::publishConfig()
|
|||||||
if (!MqttSettings.getConnected()) {
|
if (!MqttSettings.getConnected()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// ensure data is revieved from victron
|
||||||
if (VeDirect.veMap.find("SER") == VeDirect.veMap.end()) {
|
if (VeDirect.veMap.find("SER") == VeDirect.veMap.end()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,15 @@ void MqttHandleVedirectClass::loop()
|
|||||||
return;
|
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)) {
|
if (millis() - _lastPublish > (config.Mqtt_PublishInterval * 1000)) {
|
||||||
String key;
|
String key;
|
||||||
String value;
|
String value;
|
||||||
@ -44,7 +53,7 @@ void MqttHandleVedirectClass::loop()
|
|||||||
|
|
||||||
// publish only changed key, values pairs
|
// publish only changed key, values pairs
|
||||||
if (!config.Vedirect_UpdatesOnly || (bChanged && config.Vedirect_UpdatesOnly)) {
|
if (!config.Vedirect_UpdatesOnly || (bChanged && config.Vedirect_UpdatesOnly)) {
|
||||||
topic = "victron/";
|
topic = "victron/" + serial + "/";
|
||||||
topic.concat(key);
|
topic.concat(key);
|
||||||
MqttSettings.publish(topic.c_str(), value.c_str());
|
MqttSettings.publish(topic.c_str(), value.c_str());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user