-
Notifications
You must be signed in to change notification settings - Fork 3
/
listen.py
59 lines (48 loc) · 1.29 KB
/
listen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
#Original Code Martin Bateman 2013
#Modified by Simon Walters
#GPLv2 applies
#V0.1 2Aug13
import sys
from socket import *
from subprocess import Popen, call
import shlex
import os
import sys
def getserial():
# Extract serial from cpuinfo file
cpuserial = "0000000000000000"
try:
f = open('/proc/cpuinfo','r')
for line in f:
if line[0:6]=='Serial':
cpuserial = line[10:26]
f.close()
except:
cpuserial = "ERROR000000000"
return cpuserial
myserial = getserial()
print myserial
print myserial[-4:]
s = socket(AF_INET, SOCK_DGRAM)
s.bind(('', 50000))
s.settimeout(300)
while 1:
try:
#print "try reading socket"
data, wherefrom = s.recvfrom(1500, 0) # get the data from the socket
except (KeyboardInterrupt, SystemExit):
#print "reraise error"
raise
except timeout:
print "No data received: socket timeout"
#print sys.exc_info()[0]
break
# except:
# print "Unknown error occured with receiving data"
# continue
print (data + " " + repr(wherefrom[0]))
# if (data.find("Start SID" + myserial[-4:]) != -1):
# call(['sudo', 'python', '/home/pi/simplesi_scratch_handler/scratch_gpio_handler2.py', str(repr(wherefrom[0]))])
# break
sys.exit()