feat: mark Modbus connection loss in InfluxDB
SolarEdge firmware is known to silently drop the Modbus TCP listener (port refuses connections while still shown as enabled). Write a connection_state=1 point on first failed poll and 0 on recovery so the outage is visible in Grafana instead of just a data gap. ConnectionException is re-raised from read() - it is fatal for the whole cycle, not a flaky single block. Marker points carry no tags (registers unreadable during outage), so the tile query skips the serial filter. Also includes threshold tweaks on the power stat tiles.
This commit is contained in:
3 files changed
+128
-2
No files matched your search
@@ -81,15 +81,24 @@ if __name__ == '__main__':
|
||||
unit=config['modbus']['unit']
|
||||
)
|
||||
|
||||
modbus_ok = True
|
||||
measurement = config['influx'].get('measurement', 'solaredge')
|
||||
|
||||
while True:
|
||||
try:
|
||||
raw = inverter.read()
|
||||
if not modbus_ok:
|
||||
publish(to_line_protocol({'connection_state': 0}, measurement), config['influx'])
|
||||
modbus_ok = True
|
||||
solar_data = SolarData(raw)
|
||||
line = to_line_protocol(solar_data.data, config['influx'].get('measurement', 'solaredge'))
|
||||
line = to_line_protocol(solar_data.data, measurement)
|
||||
if line:
|
||||
publish(line, config['influx'])
|
||||
except ConnectionException as err:
|
||||
print('Cannot connect to SolarEdge Modbus server on {0}:{1}, error: {2}'.format(
|
||||
config['modbus']['host'], config['modbus']['port'], err))
|
||||
if modbus_ok:
|
||||
publish(to_line_protocol({'connection_state': 1}, measurement), config['influx'])
|
||||
modbus_ok = False
|
||||
|
||||
time.sleep(config['poll_interval'])
|
||||
Reference in new issue
Block a user