Commit 88363bce authored by schneefux's avatar schneefux

first commit

parents
#!/usr/bin/python
import time
import Adafruit_DHT
while True:
sensor = Adafruit_DHT.DHT22
pin = 4
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
data = [str(int(round(time.time() * 1000))), str(humidity), str(temperature)]
with open('/var/www/data.csv', 'a') as f:
f.write(','.join(data) + '\r\n')
This source diff could not be displayed because it is too large. You can view the blob instead.
<html>
<head>
<meta charset="utf-8">
<title>Feel</title>
</head>
<body>
<script src="jquery.js"></script>
<script src="highcharts.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<p>Anzahl Messungen: <span id="messungen" /></p>
<p>Zeige die letzten <input type="number" id="maxMessungen" min="100" max="100000" value="1000" /> Messungen</p>
<script type="text/javascript">
var chart;
function updateData () {
$.ajax({
url: "data.csv",
cache: false
}).done(function (content) {
updateChart(content);
});
}
function updateChart (data) {
var datarows = data.split("\n");
var temperaturen = [], feuchtigkeiten = [];
$('#messungen').text(datarows.length);
var firstNeeded = datarows.length - $('#maxMessungen').val();
if (firstNeeded > 0) {
datarows.splice(0, firstNeeded);
}
$.each(datarows, function (lineNumber, datarow) {
var data = datarow.split(",");
var date = parseInt(data[0]);
feuchtigkeiten.push([date, parseFloat(data[1])]);
temperaturen.push([date, parseFloat(data[2])]);
});
chart.series[0].setData(feuchtigkeiten, true);
chart.series[1].setData(temperaturen, true);
}
updateData();
setInterval(updateData, 5000);
Highcharts.setOptions({
global: {
useUTC: false
}
});
chart = new Highcharts.Chart({
credits: {
enabled: false
},
chart: {
type: 'spline',
animation: Highcharts.svg, // IE support
renderTo: 'container'
},
title: {
text: 'Feel'
},
subtitle: {
text: 'Temperatur und Luftfeuchtigkeit im Wohnzimmer'
},
plotOptions: {
spline: {
marker: {
enabled: true
}
}
},
xAxis: {
type: 'datetime',
title: {
text: 'Uhrzeit'
}
},
yAxis: [{
title: {
text: 'Prozent'
},
/*min: 30,
max: 50*/
},
{
title: {
text: 'Grad Celsius'
},
opposite: true,
/*min: 15,
max: 25*/
}],
series: [{
yAxis: 0,
name: 'Feuchtigkeit',
data: []
}, {
yAxis: 1,
name: 'Temperatur',
data: []
}]
});
</script>
</body>
</html>
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment