Sha256: 7f0bdf8c15cc3261c1b982b924ab3344d4e71b7c8e8cc71e968691752c5138f4
Contents?: true
Size: 1.52 KB
Versions: 1
Compression:
Stored size: 1.52 KB
Contents
#!/usr/bin/env ruby require 'rexml/document' require 'net/http' require 'pvoutput/client' require 'yaml' # Load the configuration from the yaml file sajcollector_config = YAML::load_file('saj_collector.yaml') # Create a pvoutput with the configured system_id and api_key which both # can be obtained from the pvoutput website pvoutput = PVOutput::Client.new(sajcollector_config[:system_id], sajcollector_config[:api_key]) # Get the current day trend data from the SAJ device c = Net::HTTP.get(sajcollector_config[:saj], '/day_trend.xml') # Let REXML parse the XML file doc = REXML::Document.new c # Get the current day number, we can't post data for future dates time = Time.now days = time.day m = time.strftime('%Y%m') puts "Number of days until now for this month #{days}" options = { } counter = 0 current_day = '00' day_trend_multiplication = 100 # Some SAJ Inverters provide they energy_generated in granularity of 0.1kWh and # others in 0.01kWh. unless sajcollector_config[:day_trend_multiplication_factor].nil? day_trend_multiplication = sajcollector_config[:day_trend_multiplication_factor].to_i end while counter < days value = { :energy_generated => 0 } # Get the power output of the day, doc.elements.each("day_trend/d#{counter}") { |e| value[:energy_generated] = (e.text.to_i * day_trend_multiplication).to_s } options[:"#{m}#{current_day.next!}"] = value counter += 1 end options.each do |date, values| puts "Energy generated #{date}: #{values[:energy_generated]} Wh" end pvoutput.add_batch_output(options)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
saj_collector-0.5.1 | exe/saj_output_collector |