Skip to content

Instantly share code, notes, and snippets.

@luismbo
Created January 22, 2015 14:14
Show Gist options
  • Save luismbo/1ef3bae121cf35a04f37 to your computer and use it in GitHub Desktop.
Save luismbo/1ef3bae121cf35a04f37 to your computer and use it in GitHub Desktop.
hygrophobia.py
#!/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