Last active
December 19, 2015 18:38
-
-
Save sekjal/5999917 to your computer and use it in GitHub Desktop.
Code for posting temperatures to Thingspeak (http://thingspeak.com/channels/6392). Basis for expandable module package?
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
import sys, getopt | |
import requests | |
# set to 1 to print temps to STDOUT instead of posting | |
debug = sys.argv[0] | |
thingspeak_api_key = '04SOECFW1HNRWSUI' | |
openweathermapcityid= '4951357' | |
values = { 'key' : thingspeak_api_key } | |
# get temp from Filtrete 3m-50 | |
r1 = requests.get('http://192.168.1.102/tstat') | |
j1 = r1.json | |
temp1 = j1['temp'] | |
if debug: | |
print temp1 | |
if (temp1 != -1): | |
values['field1'] = temp1 | |
# get temp from OpenWeatherMap | |
r2 = requests.get('http://api.openweathermap.org/data/2.1/weather/city/' + openweathermapcityid + '?units=imperial') | |
j2 = r2.json | |
temp2 = j2['main']['temp'] | |
if debug: | |
print temp2 | |
values['field2'] = temp2 | |
# post temps to Thingspeak | |
if debug: | |
print values | |
else: | |
tspost = requests.post('http://api.thingspeak.com/update', params=values) | |
print tspost.status_code | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment