我目前有一个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)中工作的教程,但它不是实时的。所以我在google上找到了Pusher。一个小时后,我找不到任何与我的项目类似的东西。在
有人能帮我吗?在
(很抱歉我犯了英语错误,英语不是我的母语)
为什么不直接删除循环并从Apache运行CGI呢?每次有人加载页面时,它都会显示当前温度。您可以有一个小的助手脚本来完成
sudo yourcode.py
,然后将yourcode.py
添加到/etc/sudoers
文件中。在相关问题 更多 >
编程相关推荐