Skip to content

Commit c1f345e

Browse files
committed
added webcam + private mods
1 parent 88196ea commit c1f345e

File tree

8 files changed

+146
-10
lines changed

8 files changed

+146
-10
lines changed

black.png

106 Bytes
Loading

camera.html

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
<body>
3+
<video src="rtsp://admin:[email protected]/onvif1">
4+
Your browser does not support the VIDEO tag and/or RTP streams.
5+
</video>
6+
</body>
7+
</html>

db.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
-->
1010
<?php
1111
$servername = "localhost";
12-
$username = "USERNAME";
13-
$password = "PASSWORD";
12+
$username = "martin";
13+
$password = "TSA20tmo01";
1414
$dbname = "beer";
1515

1616
// Create connection

index.php

+103-7
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ function SG($plato)
2020
if($show != '')
2121
{
2222
$id = intval($show);
23+
$sh = "&show=$id";
2324
$sql = "SELECT pk_id, name, timestamp, plato FROM batch WHERE pk_id = '$id'"; // selected
2425
}
2526
else
2627
{
28+
$sh = "";
2729
$sql = "SELECT pk_id, name, timestamp, plato FROM batch ORDER BY timestamp DESC"; // last
2830
}
2931

@@ -37,6 +39,17 @@ function SG($plato)
3739
$show = $row['pk_id'];
3840
}
3941

42+
// webcam - jpg
43+
$webcam = '';
44+
$webdir = date('YmdHis', strtotime($time_start));
45+
$files = array_diff(scandir("/var/www/html/webcam/$webdir", SCANDIR_SORT_DESCENDING), array('..', '.'));
46+
$numFiles = count($files);
47+
for ($i = 0; $i < $numFiles; $i++)
48+
{
49+
$file = $files[$i];
50+
$webcam .= "<img class=\"mySlides\" src=\"black.png\" data-src=\"webcam/$webdir/$file\" title=\"$file\" width=\"640\" height=\"480\" />";
51+
}
52+
4053
// find time_end if exists
4154
$sql = "SELECT timestamp FROM batch WHERE timestamp > '$time_start' ORDER BY timestamp ASC";
4255
$result = $conn->query($sql);
@@ -51,9 +64,9 @@ function SG($plato)
5164
while($row = $result->fetch_assoc())
5265
{
5366
$timestamp = $row["timestamp"];
67+
$temp = $row["temperature"];
5468
$plato = $row["gravity"];
5569
if($plato > $plato_max) $plato_max = $plato;
56-
$temp = $row["temperature"];
5770
$battery = $row["battery"];
5871
$angle = $row["angle"];
5972
$line_chart .= "[new Date('$timestamp'), $plato, $temp],";
@@ -74,6 +87,8 @@ function SG($plato)
7487

7588
<html>
7689
<head>
90+
<title>Pivo - kvašení</title>
91+
<meta name="robots" content="noindex">
7792
<style>
7893
table.data {
7994
border-collapse: collapse;
@@ -95,6 +110,19 @@ function SG($plato)
95110
table.data th.r {
96111
background: #B6D7A8;
97112
}
113+
.w3-display-left{position:absolute;top:50%;left:0%;transform:translate(0%,-50%);-ms-transform:translate(-0%,-50%)}
114+
.w3-display-right{position:absolute;top:50%;right:0%;transform:translate(0%,-50%);-ms-transform:translate(0%,-50%)}
115+
.w3-button{border:none;display:inline-block;padding:8px 8px;vertical-align:middle;overflow:hidden;text-decoration:none;color:inherit;background-color:inherit;text-align:center;cursor:pointer;white-space:nowrap;margin-bottom: 15px;margin-top:15px;width:60px;font-weight:bold}
116+
.w3-button:hover{color:#000!important;background-color:#B6D7A8!important}
117+
.w3-button:disabled{cursor:not-allowed;opacity:0.3}
118+
.w3-black,.w3-hover-black:hover{color:#000!important;background-color:#A4C2F4!important}
119+
body, p, table {
120+
font: 10pt Verdana, Arial, sans-serif;
121+
}
122+
h1 {
123+
font-size: 16pt;
124+
font-weight: bold;
125+
}
98126
</style>
99127
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
100128
<script type="text/javascript">
@@ -120,8 +148,11 @@ function drawChart()
120148
format: '#.##'
121149
},
122150
colors: ['red', 'blue'],
123-
width: 1400,
124-
height: 520
151+
width: 1250,
152+
height: 520,
153+
legend: {
154+
position: 'none'
155+
}
125156
};
126157
var chart = new google.charts.Line(document.getElementById('plato_temp_chart_div'));
127158
chart.draw(data, google.charts.Line.convertOptions(options));
@@ -147,28 +178,92 @@ function drawChart()
147178
</head>
148179
<body>
149180
<h1><?php echo $beer_name; ?></h1>
181+
182+
<div style="float: right; position:relative; margin-left: 20px; margin-bottom: 20px; width: 640px; height: 480px;">
183+
<?php echo $webcam; ?>
184+
<div class="w3-display-left">
185+
<button id="minus15" class="w3-button w3-black" onclick="plusDivs(1)">-15 min</button><br />
186+
<button id="minus60" class="w3-button w3-black" onclick="plusDivs(4)">-1 hod</button><br />
187+
<button id="start" class="w3-button w3-black" onclick="showDiv(<?php echo $numFiles - 1; ?>)">Start</button><br />
188+
</div>
189+
<div class="w3-display-right">
190+
<button id="plus15" class="w3-button w3-black" onclick="plusDivs(-1)">+15 min</button><br />
191+
<button id="plus60" class="w3-button w3-black" onclick="plusDivs(-4)">+1 hod</button><br />
192+
<button id="end" class="w3-button w3-black" onclick="showDiv(0)">Konec</button>
193+
</div>
194+
</div>
195+
<script type="text/javascript">
196+
var slideIndex = 0;
197+
showDivs(slideIndex);
198+
199+
function plusDivs(n)
200+
{
201+
showDivs(slideIndex += n);
202+
}
203+
function showDiv(n)
204+
{
205+
showDivs(slideIndex = n);
206+
}
207+
208+
function showDivs(n)
209+
{
210+
var i;
211+
var x = document.getElementsByClassName("mySlides");
212+
var maxIndex = x.length - 1;
213+
if (n >= maxIndex) slideIndex = maxIndex;
214+
if (n < 0) slideIndex = 0;
215+
216+
document.getElementById("minus15").disabled = slideIndex == maxIndex;
217+
document.getElementById("minus60").disabled = slideIndex > maxIndex - 4;
218+
document.getElementById("start").disabled = slideIndex == maxIndex;
219+
220+
document.getElementById("plus15").disabled = slideIndex == 0;
221+
document.getElementById("plus60").disabled = slideIndex < 4;
222+
document.getElementById("end").disabled = slideIndex == 0;
223+
224+
for (i = 0; i < x.length; i++)
225+
{
226+
x[i].style.display = "none";
227+
}
228+
// preload images
229+
for(i = slideIndex - 4; i <= slideIndex + 4; i++)
230+
{
231+
if(i >= 0 && i <= maxIndex)
232+
{
233+
if(x[i].getAttribute("data-src"))
234+
{
235+
x[i].src = x[i].getAttribute("data-src");
236+
x[i].removeAttribute("data-src");
237+
}
238+
}
239+
}
240+
241+
x[slideIndex].style.display = "block";
242+
}
243+
</script>
244+
150245
<table class="data">
151246
<tr>
152247
<th width="170">Čas posledního bodu</th>
153248
<td width="170"><?php echo $timestamp; ?></td>
154-
<td width="50" class="noborder"></td>
249+
<td width="30" class="noborder"></td>
155250
<th width="170" class="r">Počáteční síla</th>
156251
<td width="170"><?php echo(sprintf('%.2f', $plato_start)); ?> °P (<?php echo(sprintf('%.3f', $SG_start)); ?>)</td>
157-
<td width="50" class="noborder"></td>
252+
<td width="30" class="noborder"></td>
158253
<td class="noborder"><a href="settings.php"><strong>Nastavení</strong></a></td>
159254
</tr>
160255
<tr>
161256
<th>Plato</th>
162257
<td><?php echo(sprintf('%.2f', $plato)); ?> °P (<?php echo(sprintf('%.3f', $SG)); ?>)</td>
163258
<td class="noborder"></td>
164-
<th class="r">Zdálivé prokvašení</th>
259+
<th class="r">Zdánlivé prokvašení</th>
165260
<td><?php echo(sprintf('%.1f', 100 * $Az)); ?> %</td>
166261
</tr>
167262
<tr>
168263
<th>Teplota</th>
169264
<td><?php echo(sprintf('%.2f', $temp)); ?> °C</td>
170265
<td class="noborder"></td>
171-
<th class="r">ABV</th>
266+
<th class="r">Alkohol</th>
172267
<td><?php echo(sprintf('%.1f', $ABV)); ?> %</td>
173268
<td class="noborder"></td>
174269
<td class="noborder"><a href="values.php?show=<?php echo $show; ?>"><strong>Hodnoty</strong></a></td>
@@ -193,6 +288,7 @@ function drawChart()
193288
<td><div id="plato_chart_div"></div></td>
194289
<td><div id="temp_chart_div"></div></td>
195290
<td><div id="battery_chart_div"></div></td>
291+
<td style="vertical-align: bottom; text-align: right" width="100%"><img src="legend.png" width="124" height="77" /></td>
196292
</tr>
197293
</table>
198294
<div id="plato_temp_chart_div"></div>

legend.png

2.92 KB
Loading

settings.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,21 @@
3333
else
3434
{
3535
$sql = "INSERT INTO batch (name, plato) VALUES('$form_name', '$form_plato')";
36-
if($conn->query($sql) == TRUE) $form_name = $form_plato = '';
36+
if($conn->query($sql) == TRUE)
37+
{
38+
$form_name = $form_plato = '';
39+
// create webdir
40+
$sql = "SELECT timestamp FROM batch ORDER BY timestamp DESC";
41+
$result = $conn->query($sql);
42+
if($row = $result->fetch_assoc())
43+
{
44+
$timestamp = $row["timestamp"];
45+
$webdir = date('YmdHis', strtotime($timestamp));
46+
$old_umask = umask(0);
47+
mkdir("/var/www/html/webcam/$webdir", 0777);
48+
umask($old_umask);
49+
}
50+
}
3751
}
3852
}
3953
$action = 'Nové';
@@ -60,6 +74,7 @@
6074

6175
<html>
6276
<head>
77+
<title>Pivo - nastavení</title>
6378
<style>
6479
table.list {
6580
border-collapse: collapse;
@@ -78,6 +93,13 @@
7893
table.list td.l {
7994
text-align: left;
8095
}
96+
body, p, table {
97+
font: 10pt Verdana, Arial, sans-serif;
98+
}
99+
h1 {
100+
font-size: 16pt;
101+
font-weight: bold;
102+
}
81103
</style>
82104
</head>
83105
<body>

values.php

+7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@
7272
border: 1px solid black;
7373
text-align: center;
7474
}
75+
body, p, table {
76+
font: 10pt Verdana, Arial, sans-serif;
77+
}
78+
h1 {
79+
font-size: 16pt;
80+
font-weight: bold;
81+
}
7582
</style>
7683
</head>
7784
<body>

webcam.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
export WEBCAM_FILENAME=`ls -r -d /var/www/html/webcam/* | head -1`"/"`date +%Y%m%d%H%M%S`".jpg"
3+
ffmpeg -loglevel error -err_detect aggressive -fflags discardcorrupt -noaccurate_seek -discard nokey -rtsp_transport -udp_multicast -i rtsp://admin:[email protected]/onvif1 -ss 10 -frames 1 -pix_fmt gray -vf format=gray,scale=640:480 -qscale:v 3 $WEBCAM_FILENAME
4+
chmod 0666 $WEBCAM_FILENAME

0 commit comments

Comments
 (0)