Skip to content

Instantly share code, notes, and snippets.

@skierkowski
Created July 9, 2012 02:07
Show Gist options
  • Save skierkowski/3073834 to your computer and use it in GitHub Desktop.
Save skierkowski/3073834 to your computer and use it in GitHub Desktop.
Arduino data collector and pusher
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