Skip to content

Instantly share code, notes, and snippets.

@ps-jay
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save ps-jay/b1f87615a2096f6fdef2 to your computer and use it in GitHub Desktop.

Select an option

Save ps-jay/b1f87615a2096f6fdef2 to your computer and use it in GitHub Desktop.
Temperature to dashing.io
/usr/bin/vim temp2dash
import json
import requests
import sys
from temperusb import TemperHandler
URL="http://localhost:3030/widgets/inside"
SCALE=1.0
OFFSET=-1.0
th = TemperHandler()
devs = th.get_devices()
if len(devs) != 1:
print "Expected exactly one TEMPer device, found %d" % len(devs)
sys.exit(1)
dev = devs[0]
dev.set_calibration_data(scale=SCALE, offset=OFFSET)
temperature = dev.get_temperature(sensor=1)
payload = {
'auth_token': 'abcdefghijklmnopqrstuvwxyz',
'temperature': '%0.0f%s' % (
temperature,
u'\N{DEGREE SIGN}',
),
}
post = requests.post(URL, data=json.dumps(payload))
# Debug output - not compatible with cron thanks to unicode
#print "POST Status: %s; Temperature: %s (rounded from %s)" % (
# post.status_code,
# payload['temperature'],
# temperature,
#)
if post.status_code != 204:
sys.exit(255)
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment