【发布时间】:2021-06-07 23:03:30
【问题描述】:
我有一个我喜欢监控的后院锦鲤/金鱼池。我有一个树莓派进行监控并发送到我的网站。我正在尝试将 csv 数据加载到我的 index.html 文件中。我不需要保留数据。我有索引 3 创建了解析数据并放入表中。我很难理解如何将变量添加到 csv 字段并将该变量放入 html 文件中。
<!DOCTYPE html>
<body bgcolor="000000">
<center>
<p style="color:White; font-size:50px; font-family:Couier;">Pond Temperature & Camera<br></p>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
/* Create three equal columns that floats next to each other */
.column {
float: left;
width: 30%;
padding: 1px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
</style>
<div class="row">
<div class="column" style="background-color:#000000; color:white;">
<h2>Bio Falls Temperature</h2>
<p> ° F</p>
</div>
<div class="column" style="background-color:#000000; color:white;">
<h2>Stream Temperature</h2>
<p> ° F</p>
</div>
<div class="column" style="background-color:#000000; color:white;">
<h2>Waterfall Temperature</h2>
<p> ° F</p>
</div>
<div class="column" style="background-color:#000000; color:white;">
<h2>Deep End Temperature</h2>
<p> ° F</p>
</div>
<div class="column" style="background-color:#000000; color:white;">
<h2>Skimmer Temperature</h2>
<p> ° F</p>
</div>
<div class="column" style="background-color:#000000; color:white;">
<h2>Outside Air Temperature</h2>
<p> ° F</p>
</div>
</div>
<img id="jpeg_0" width="800" height="600">
<script type="text/javascript">
var camera_0 = {
addEvent: function(elem, event, func ){
if (typeof (window.event) != 'undefined')
{elem.attachEvent('on' + event, func);}
else
{elem.addEventListener(event, func, false);}
},
initCamera: function(jpeg, serverUrl, token, id, interval){
this.addEvent(jpeg, 'load', function(){setTimeout(function() {camera_0.showJpegFrame(jpeg, serverUrl, token, id);}, interval);});
this.showJpegFrame(jpeg, serverUrl, token, id);
},
showJpegFrame: function(jpeg, serverUrl, token, id){
jpeg.src = serverUrl+"/Jpeg/"+id+"?authToken="+token+"&"+new Date().getTime();
}
}
camera_0.initCamera(jpeg_0, "http://100.6.115.166:8100", "4fbbf273-1691-428d-bd09-6b625aeafe0f", 0, 40);
</script>
</center>
```
```
<!DOCTYPE html>
<html>
<head>
<title>Pond Temperature & Camera</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="table-responsive">
<META HTTP-EQUIV="refresh" CONTENT="15">
<h1 align="center">Pond Temperature & Camera</h1>
<br />
<br />
<div id="pond_table">
</div>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function(){
$.ajax({
url:"pond_temp.csv",
dataType:"text",
success:function(data)
{
var pond_data = data.split(/\r?\n|\r/);
var table_data = '<table class="table table-bordered table-striped">';
for(var count = 0; count<pond_data.length; count++)
{
var cell_data = pond_data[count].split(",");
table_data += '<tr>';
for(var cell_count=0; cell_count<cell_data.length; cell_count++)
{
if(count === 0)
{
table_data += '<th>'+cell_data[cell_count]+'</th>';
}
else
{
table_data += '<td>'+cell_data[cell_count]+'</td>';
}
}
table_data += '</tr>';
}
table_data += '</table>';
$('#pond_table').html(table_data);
}
});
});
</script>
```
First probe temp is 66.4
Second probe temp is 66.2
Third probe temp is 65.4
Fourth probe temp is 66.5
Fifth probe temp is 65.5
```
【问题讨论】:
-
请在您的大代码转储中找出我们应该在哪里寻找问题。很有可能,我们不需要看到任何 CSS 声明。请减少您的问题,使其仅包含相关的代码部分。请参阅minimal reproducible example。这是一个python问题吗?一个php问题?一个javascript问题? 需要更多关注问题?
-
您好,maserowik,您在上面的问题帖子中是否有一些示例数据可以从您的 CSV 中显示?另外,是否可以在您的问题中说明您要添加的变量是什么? :)
-
从底部的 CSV 文件中,我希望将这些值自动添加到 www/n3bsq.com/pond。我已经创建了索引和表,只是试图让临时进入该位置。
-
您好,maserowik,您可以提供 CSV 数据文件中的示例行吗?从您上面的帖子信息中,我目前似乎看不到您的数据文件格式的示例。
-
68.9 68.8 68.9 69.3 70.1