Skip to content

Instantly share code, notes, and snippets.

@izumogeiger
Last active December 20, 2015 18:08
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 izumogeiger/6173265 to your computer and use it in GitHub Desktop.
Save izumogeiger/6173265 to your computer and use it in GitHub Desktop.
# coding:utf-8
require "pp"
require "net/https"
def xively(temp)
uri = URI.parse('https://api.xively.com/v2/feeds/xxxxxxxxxx.xml')
https = Net::HTTP.new(uri.host,uri.port)
https.use_ssl = true
headers = {
'X-ApiKey' => 'xxxxxxxxxxxxx',
'Content-Type' => 'application/xml'
}
data =<<-EOS
<?xml version="1.0" encoding="UTF-8"?>
<eeml>
<environment>
<data id="raspberrypi_temp">
<current_value>#{temp}</current_value>
</data>
</environment>
</eeml>
EOS
res = https.send_request('PUT',uri.request_uri,data,headers)
end
%r|temp=(\d+\.\d+)| =~ `vcgencmd measure_temp`
temp = $1
begin
xively(temp)
rescue Exception => ex
puts ex
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment