我是 web 开发的新手和新手,我对多种语言感到不知所措。我对发生的事情有了基本的了解,但我仍然不知道我在哪里卡住了。
我有一个连接到我的 Raspberry Pi 的 DS18B20,我能够获取终端中的温度。我也成功运行了 WebIOPi,并且能够在设备下的默认网页中看到温度。因此,我希望创建自己的网页,以便将来使用其他选项做同样的事情。我有一些关于 WebIOPi 的教程,我有 4 个文件。HTML 文件、JavaScript 文件、CSS 文件和 Python 文件。据我了解,HTML 文件包含逻辑和指向其他内容的链接,例如可点击按钮和背景等。CSS 文件包含背景,可能还有文本,JavaScript 文件包含动画和按钮?在这里我感到困惑。最后但并非最不重要的一点是,Python 文件运行包含传感器模型和库的代码。http://webiopi.trouch.com/OneWireTemp.html。我正在松散地尝试遵循本教程,其中我获得了大部分代码:http ://webiopi.trouch.com/Tutorial_Devices.html 。
现在,当我从浏览器登录网页时,背景显示正确,但没有其他内容。没有显示温度的框或按钮。附上图片。我希望有一个像图片中所附的按钮。
任何指导或帮助将不胜感激!
索引.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>WebIOPi | UNB Temperature</title>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">
<script type="text/javascript" src="/scripts/bacon.js"></script>
<link rel="stylesheet" type="text/css" href="/styles/bacon.css">
<script type="text/javascript">
// declare few global variables
var tmp;
webiopi().ready(init);
// defines function passed to webiopi().ready()
function init() {
// setup helpers to remotely control devices
tmp = new Temperature("tmp");
// automatically refresh UI each seconds
setInterval(updateUI, 1000);
}
// function called through setInterval
function updateUI() {
// call Temperature.getCelsius REST API
// result is asynchronously displayed using the callback
tmp.getCelsius(temperatureCallback);
}
// callback function used to display the temperature
function temperatureCallback(sensorName, data) {
// jQuery functions
$("#bt_heater").text(data + "°C");
}
培根.js
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<div align="center">
<button id="bt_mode" onclick="toggleMode()"/><br>
<button id="bt_heater" onclick="toggleHeater()"/>
</div>
</body>
</html>
培根.css
body {
background-color:#000000;
background-image:url('/img/wall.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
background-size: cover;
}
脚本.py
import webiopi
GPIO = webiopi.GPIO
AUTO = True
def loop():
if (AUTO):
tmpwebiopi.deviceInstance("tmp")
celsius = tmp.getCelsius()
print ("Temperature: %f" % celsius)
webiopi.sleep(1)