Post to MQTT

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
=
2026-04-26 13:04:29 +02:00
parent d5a4a8c791
commit a5aa6de67b
6 changed files with 119 additions and 52 deletions

View File

@@ -94,15 +94,11 @@ class InSyncState < StatePattern::State
reading.save
end
# Write to EmonHub
begin
TCPSocket.open("printserver",5050){|s|
s.write(sprintf("8 %d %d\r\n", reading.current_kw_consumed*1000, reading.current_kw_produced*1000))
}
rescue
p "Socket problem."
end
# Result
# Post current_kw_consumed and current_kw_produced to MQTT
MqttClient.publish("home/energy/current_kw_consumed", reading.current_kw_consumed.to_s)
MqttClient.publish("home/energy/current_kw_produced", reading.current_kw_produced.to_s)
# Result
return reading
end