Created
January 22, 2015 14:14
-
-
Save luismbo/1ef3bae121cf35a04f37 to your computer and use it in GitHub Desktop.
hygrophobia.py
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
#!/usr/bin/env python | |
API_KEY='XXX' | |
API_URL='https://api.xively.com/v2/feeds/XXX' | |
SERIAL_PORT='/dev/tty.usbserial-A9005aBb' | |
import serial | |
import json | |
import requests | |
s = serial.Serial(SERIAL_PORT, 9600) | |
s.readline() | |
while True: | |
values = s.readline().strip().split(':') | |
o = { 'version': '1.0.0', | |
'datastreams': [ { 'id': 'Humidity', | |
'current_value': values[0] }, | |
{ 'id': 'Temperature', | |
'current_value': values[1] } ] } | |
print o | |
r = requests.put(API_URL, | |
data = json.dumps(o), | |
headers = { 'X-ApiKey': API_KEY }) | |
print r.text | |
print r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment