Skip to content

Instantly share code, notes, and snippets.

@adrianpike
Created May 12, 2020 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianpike/e1ba2f65de3af7bc1be5c8b1b31eb4fb to your computer and use it in GitHub Desktop.
Save adrianpike/e1ba2f65de3af7bc1be5c8b1b31eb4fb to your computer and use it in GitHub Desktop.
Ardexa Sunny Boy to Graphite
#!/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