Last active
December 20, 2015 18:08
-
-
Save izumogeiger/6173265 to your computer and use it in GitHub Desktop.
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
# 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