socket_listen.py
Listens for XBee packets containing the dryer status and updates a corresponding webpage. -
Anonymous, 04/30/2012 11:52 am
Download (1.2 kB)
1
2
3
4
5 import socket
6 import re
7
8 xbeeip = '192.168.1.3'
9
10
11 HOST = socket.gethostbyname(socket.gethostname())
12
13
14 s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
15 s.bind((HOST, 9750))
16
17
18
19
20 s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
21
22
23 s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
24
25
26 check = True
27 while(check):
28 data = s.recvfrom(65565)
29
30 datas = data[0].encode("hex")
31 if (len(datas) > 80):
32 status = datas[80:].decode("hex")
33 status_match = re.match(r"^Dryer",status)
34 if (status_match):
35 if (status[-1]=='\x00'):
36 status = status[0:-1]
37 fileout = open('C:/inetpub/wwwroot/dryer1.txt','w')
38 print status
39 fileout.write(status)
40 fileout.close()
41
42
43
44 s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)