Commits

Cmed Technology committed e2d8eae

wip

  • Participants
  • Parent commits 398f494

Comments (0)

Files changed (2)

 def provision():
     # sudo('apt-get update')
     # sudo('apt-get upgrade')
-    # sudo('apt-get install python-serial')
+    sudo('apt-get install python-serial')
+    sudo('chmod a+rw /dev/ttyAMA0')
     put('inittab', '/etc/', use_sudo=True)
     put('cmdline.txt', '/boot/', use_sudo=True)
     reboot()
 import serial
-
+import time
 
 s = serial.Serial('/dev/ttyAMA0', 9600, parity='N', stopbits=1)
 
+N = 30
 
-for i in range(10):
-    print s.read()
+
+def read(s):
+    s.flushInput()
+    data = [int(x.strip()) for x in s.read(N).split('R')[1:-1] if x.strip()]
+    return sorted(data)[len(data)/2]
+
+
+while True:
+    time.sleep(1)
+    print read(s)