Write data to socket for EmonHub
This commit is contained in:
@@ -1,7 +1,17 @@
|
||||
require "socket"
|
||||
|
||||
class InSyncState < StatePattern::State
|
||||
|
||||
END_OF_FRAME = "!\n"
|
||||
|
||||
# def initialize(stateful, previous_state)
|
||||
# # open socket to EmonHub
|
||||
# @hub = TCPSocket.new 'raspberrypi.lan', 5050
|
||||
# @hub.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
|
||||
# super(stateful, previous_state)
|
||||
# end
|
||||
|
||||
|
||||
def handle_byte_stream(bytes)
|
||||
idx = 0
|
||||
#sync_pattern_length = Synchronizer::SYNC_PATTERN.length
|
||||
@@ -84,7 +94,17 @@ class InSyncState < StatePattern::State
|
||||
else
|
||||
reading.save
|
||||
end
|
||||
|
||||
# Write to EmonHub
|
||||
begin
|
||||
TCPSocket.open("raspberrypi.lan",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
|
||||
return reading
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user