Last active
August 29, 2015 14:23
-
-
Save ps-jay/b1f87615a2096f6fdef2 to your computer and use it in GitHub Desktop.
Temperature to dashing.io
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
| /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