I have a very simple Python script which I use to poll a serial device (an Xbee module). It's essentially just an endless while loop. Each iteration through this loop I want a web page to update. I've seen a lot of samples showing UI interaction where the user clicks buttons to send an ajax post to the server and back, but I want the python back end loop to do the updating to the client without user interaction. I've looked at web.py and ajax and it seems to be the way to go, I just can't seem to get it going and would love some help. Here's the gist of my python script:
ser = serial.Serial('COM3', baudrate=9600)
while 1:
data = ser.readline()
if len(data) == 14:
num = struct.unpack('BBBBBBBBBBBBBB', data)[9]
if num == 1:
// update the web client with 1
elif num == 2:
// update the web client with 2
else:
// update the web client with 0
app.processEvents()
The setup is running on ubuntu 12.04 with apache2 and python 2.7.