Sha256: f1d3f9b948d93b7c6b403a171184377f7be845b7119514a5ab07a7bbc20ce0f9
Contents?: true
Size: 1.24 KB
Versions: 1
Compression:
Stored size: 1.24 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('/etc/saj_collector/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"' 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 * 100).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.3.0 | exe/saj_output_collector |