Created
July 9, 2012 02:07
-
-
Save skierkowski/3073834 to your computer and use it in GitHub Desktop.
Arduino data collector and pusher
This file contains 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
require 'net/telnet' | |
require 'json' | |
require 'cosm-rb' | |
key = "xxx" | |
hostname = '192.168.2.4' | |
port = 4000 | |
localhost = Net::Telnet::new("Host" => hostname, "Port" => port, "Timeout" => 10) | |
while | |
localhost.cmd("a") { |c| | |
data = JSON.parse(c.split("\n").last) | |
puts data | |
data.each do |tag,val| | |
datapoint = Cosm::Datapoint.new(:at => Time.now, :value => val.to_f.round(2)) | |
response = Cosm::Client.post("/v2/feeds/63163/datastreams/#{tag}/datapoints", :headers => {"X-ApiKey" => key}, :body => {:datapoints => [datapoint]}.to_json) | |
end | |
sleep 60*5 | |
} | |
end | |
localhost.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment