Skip to content

Instantly share code, notes, and snippets.

@aleksmk
Created May 3, 2012 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aleksmk/2586220 to your computer and use it in GitHub Desktop.
Save aleksmk/2586220 to your computer and use it in GitHub Desktop.
import serial
import sys
import urllib2
import json
S = serial.Serial("/dev/ttyUSB0")
lst = []
S.flushInput()
T = S.readline()
while True:
T = float(S.readline())
lst.append(T)
# print float(T)
if len(lst) >= 20 :
avg = sum(lst) / len(lst)
lst = []
# print 'a'
try:
urllib2.urlopen(urllib2.Request("http://prisutni.spodeli.org/push/update",
json.dumps({'type':'temperature', 'values': {'s1':avg}}),
{'content-type': 'application/json'}))
except:
print "Could not connect to server"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment