Created
May 12, 2020 02:07
-
-
Save adrianpike/e1ba2f65de3af7bc1be5c8b1b31eb4fb to your computer and use it in GitHub Desktop.
Ardexa Sunny Boy to Graphite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'socket' | |
require 'time' | |
$file = ARGV[0] || "opt/ardexa/sma/logs/{}/latest.csv" | |
puts "Streaming readings from #{$file}..." | |
sock = TCPSocket.new 'localhost', 2003 | |
File.open($file).each_line do |line| | |
next if line[0] == '#' | |
l = line.split(',') | |
ts = Time.parse(l[0]).to_i | |
power = l[1] | |
energy = l[2] | |
mode = l[-2] | |
status = l[-1].strip | |
sock.write("solar.power #{power} #{ts}\n") | |
sock.write("solar.energy #{energy} #{ts}\n") | |
sock.write("solar.mode #{mode} #{ts}\n") | |
sock.write("solar.status #{status} #{ts}\n") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment