Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: add dtu serial to mqtt status topics #304

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/MQTT_Topics.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ The base topic, as configured in the web GUI is prepended to all follwing topics

## General topics

serial will be replaced with the serial number of the OpenDTU device.

| Topic | R / W | Description | Value / Unit |
| --------------------------------------- | ----- | ---------------------------------------------------- | -------------------------- |
| dtu/ip | R | IP address of OpenDTU | IP address |
| dtu/hostname | R | Current hostname of the dtu (as set in web GUI) | |
| dtu/rssi | R | WiFi network quality | db value |
| dtu/[serial]/ip | R | IP address of OpenDTU | IP address |
| dtu/[serial]/hostname | R | Current hostname of the dtu (as set in web GUI) | |
| dtu/[serial]/rssi | R | WiFi network quality | db value |
| dtu/status | R | Indicates whether OpenDTU network is reachable | online / offline |
| dtu/uptime | R | Time in seconds since startup | seconds |
| dtu/[serial]/uptime | R | Time in seconds since startup | seconds |

## Inverter specific topics

Expand Down
15 changes: 11 additions & 4 deletions src/MqttPublishing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ void MqttPublishingClass::loop()
const CONFIG_T& config = Configuration.get();

if (millis() - _lastPublish > (config.Mqtt_PublishInterval * 1000)) {
MqttSettings.publish("dtu/uptime", String(millis() / 1000));
MqttSettings.publish("dtu/ip", NetworkSettings.localIP().toString());
MqttSettings.publish("dtu/hostname", NetworkSettings.getHostname());

// compose subtopic "dtu/<serialnumber>" with config.DtuSerial as hex
char dtu_subtopic[sizeof(uint64_t) * 8 + 5];
snprintf(dtu_subtopic, sizeof(dtu_subtopic), "dtu/%0x%08x",
((uint32_t)((config.Dtu_Serial >> 32) & 0xFFFFFFFF)),
((uint32_t)(config.Dtu_Serial & 0xFFFFFFFF)));

MqttSettings.publish(String(dtu_subtopic) + "/uptime", String(millis() / 1000));
MqttSettings.publish(String(dtu_subtopic) + "/ip", NetworkSettings.localIP().toString());
MqttSettings.publish(String(dtu_subtopic) + "/hostname", NetworkSettings.getHostname());
if (NetworkSettings.NetworkMode() == network_mode::WiFi) {
MqttSettings.publish("dtu/rssi", String(WiFi.RSSI()));
MqttSettings.publish(String(dtu_subtopic) + "/rssi", String(WiFi.RSSI()));
}

// Loop all inverters
Expand Down