gpt4 book ai didi

python - 自动更新 python 脚本的 Web 前端

转载 作者:太空宇宙 更新时间:2023-11-04 06:33:23 25 4
gpt4 key购买 nike

<分区>

我有一个非常简单的 Python 脚本,用于轮询串行设备(Xbee 模块)。它本质上只是一个无休止的 while 循环。通过此循环的每次迭代我都希望更新网页。我见过很多显示 UI 交互的示例,其中用户单击按钮将 ajax post 发送到服务器并返回,但我希望 python 后端循环在没有用户交互的情况下对客户端进行更新。我看过 web.py 和 ajax,这似乎是要走的路,但我似乎无法让它继续下去,希望得到一些帮助。这是我的 python 脚本的要点:

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()

安装程序在 ubuntu 12.04 上运行,带有 apache2 和 python 2.7。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com