更新网页上Web服务器程序的实时输出

Update live output from a Web server program on a web page

本文关键字:程序 实时输出 服务器 Web 网页 更新      更新时间:2024-02-21

更具体地说,我想从我的网络服务器(Linux/Rastberry Pi)上运行的GPSd进程中获得当前/最新的输出,并显示实时纬度/经度、速度和路线。

我试着编写一个可以调用的CGI脚本(jquery),它跟踪gpspipe的输出并获取最新数据,但速度有点慢——每次调用最多5秒。

类似于调用一个每隔几秒钟运行一次"top-b-n 1"的CGI脚本,并为您要查找的数据解析输出。

我以为有人会有更有效的方法。

取决于GPS单位转换值所需的时间(通常约为一秒)你可以做一个小程序,连续读取GPS,将值存储在共享内存或文件中,并在调用Rasp时获取这些值。所以你会得到[Time+Geolocation],它可能会根据你的应用程序有所帮助。

如果你想要更灵敏的东西,你可以在GPS转换后使用长轮询。通过这种方式,您可以注册多个客户端或服务来收听GPS转换web服务。

有一个适合您的Python 2.7-3.5 gpsd客户端。它有一个线程适配器,你可以用它来获取你想要的数据

from agps3threaded import AGPS3mechanism

然后啮合线程三元病毒,

agps_thread = AGPS3mechanism()  # This instantiate the mechanism, as I believe it's called.
agps_thread.stream_data()    #  Stream the data from host, port, devicepath.
agps_thread.run_thread()  #  Iterate stream as a thread with throttle control for empty look ups.

四行代码可以让你连接、通信和控制你期望gpsd做的大部分事情。

while True:  # All data is available via instantiated thread data_stream attributes. Confur
             # lines #140-ff of the client /usr/local/lib/python3.5/dist-packages/gps3/agps.py
      print('----------------')
      print(                   agps_thread.data_stream.time)
      print('Lat:{}   '.format(agps_thread.data_stream.lat))
      print('Lon:{}   '.format(agps_thread.data_stream.lon))
      print('Speed:{} '.format(agps_thread.data_stream.speed))
      print('Course:{}'.format(agps_thread.data_stream.track))
      print('----------------')
      sleep(60)  # Sleep, or do other things for as long as you like.

在括号之间没有自变量的情况下,线程客户端默认为host='127.0.01'port=2947gpsd_protocol='json'usnap=0.2,在每次空套接字查找后,默认值为十分之二秒的微快照。项目的其余部分位于DESCRIPTION.rst中,或记录在文件本身中。

如果您正在寻找一个到gpsd共享内存段的Python接口,那么

也是可用的