Last active
March 27, 2016 22:37
-
-
Save adamrunner/05fd4af5da7728b9dfd7 to your computer and use it in GitHub Desktop.
A very simple data polling ruby script. It's intended to be ran on a Cron schedule where it will then poll the data from my ESP8266, and also the Forecast.IO API. It will then upload the data to data.sparkfun.com and also my very own ElasticSearch cluster.
This file contains hidden or 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 'time' | |
require 'forecast_io' | |
require 'curb' | |
phant_public_key = '---' | |
phant_private_key = '---' | |
location = ['45.2912', '-122.4037'] | |
#NOTE: This script is intended to be ran on a Cron schedule. | |
ForecastIO.configure do |configuration| | |
configuration.api_key = '---' | |
end | |
outside_temp = ForecastIO.forecast(*location)["currently"]["temperature"] | |
temperature_client = Curl::Easy.http_get('http://192.168.1.110/temp') | |
indoor_temp = temperature_client.body | |
payload = {outside_temp: outside_temp, indoor_temp: indoor_temp}.to_json | |
c = Curl::Easy.http_post("http://data.sparkfun.com/input/#{phant_public_key}", payload) do |curl| | |
curl.headers['Accept'] = 'application/json' | |
curl.headers['Content-Type'] = 'application/json' | |
curl.headers['Phant-Private-Key'] = phant_private_key | |
end | |
#NOTE: if using ElasticSearch, uncomment this. | |
# elastic_payload = {outside_temp: outside_temp, indoor_temp: indoor_temp, timestamp: DateTime.now.iso8601}.to_json | |
# elastic = Curl::Easy.http_post("http://es.adamrunner.com:9200/temperature/data", elastic_payload) do |curl| | |
# curl.headers['Accept'] = 'application/json' | |
# curl.headers['Content-Type'] = 'application/json' | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment