【问题标题】:Raspberry pi and Pusher树莓派和 Pusher
【发布时间】:2014-12-09 11:38:22
【问题描述】:

我目前有一个 DS18B20 温度传感器连接到我的树莓派,我可以使用这段代码读取这些数据:

import time

def main():
    while True:
        tfile = open("/sys/bus/w1/devices/28-0000051e739/w1_slave")
        text = tfile.read()
        tfile.close()
        secondline = text.split("\n")[1]
        temperaturedata = secondline.split(" ")[9]
        temperature = float(temperaturedata[2:])
        temperature = temperature / 1000
        print "Temperature: ", temperature, "C"
        time.sleep(0.5)
main()

这在终端中运行良好。 我还安装了 apache2 并在我的树莓派上工作。 现在我正在尝试将我从温度传感器获得的数据实时显示到我的网页上。我遵循了一些关于让 python 脚本在 html(http://raspberrywebserver.com/cgiscripting/writing-cgi-scripts-in-python.html) 中工作的教程,但它不是实时的。因此,我搜索并找到了 Pusher。谷歌搜索一个小时后,我找不到与我的项目相似的任何东西。

谁能帮帮我?

(对于任何英语错误,我很抱歉,英语不是我的母语)

【问题讨论】:

    标签: python html linux raspberry-pi pusher


    【解决方案1】:

    为什么不直接删除循环并从 Apache 运行 CGI?每次有人加载页面时,它都会显示当前温度。你可以有一个小助手脚本来执行sudo yourcode.py,然后将yourcode.py 添加到/etc/sudoers 文件中。

    【讨论】:

    • 因为我不想每次想读新书都刷新网页。
    猜你喜欢
    • 2013-11-05
    • 2015-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-14
    • 2014-09-20
    • 2018-02-07
    相关资源
    最近更新 更多