Skip to content

Commit 91302bb

Browse files
committed
Initial commit
0 parents  commit 91302bb

14 files changed

Lines changed: 1309 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/* Device definitions
3+
*
4+
* JSON object structure of each device is used for GET data for setting new values
5+
* For example:
6+
* JSON status of device: {"servo_attached":1,"door_angle":130}
7+
*
8+
* Setting servo_attached to 0 can be done by sending the GET command to the device status address
9+
* with JSON data {"servo_attached":0}.
10+
*
11+
*/
12+
13+
14+
// EXAMPLE CONFIG FOR TWO NODES:
15+
$id=0;
16+
$device_name[$id]="Tuinhuis";
17+
$device_address[$id]="http://192.168.1.35";
18+
$device_sensors[$id]=array(
19+
// supported types: boolean, integer, float, string
20+
// supported operators: w (writeable), c (writeable config). r (read-only)
21+
// "ip" => array("IP adres", "string", "r"),
22+
// "ssid" => array("WIFI SSID", "string", "r"),
23+
"rssi" => array("WIFI RSSI (dB)", "integer", "r"),
24+
"relay_state" => array("Lamp tuinhuis", "boolean", "w"),
25+
"servo_attached" => array("Servo actief","boolean", "w"),
26+
"servo_ref_angle" => array("Deur ingestelde hoek (graden)", "integer", "w"),
27+
"servo_angle" => array("Deur hoek (graden)", "integer", "r"),
28+
"loadcell_value_b" => array("Zitstok gewicht (L)", "float", "r"),
29+
"loadcell_value_a" => array("Zitstok gewicht (R)", "float", "r"),
30+
"loadcell_tare_b" => array("Zitstok tare (L)", "float", "c"),
31+
"loadcell_tare_a" => array("Zitstok tare (R)", "float", "c"),
32+
"loadcell_scale_b" => array("Zitstok schaling (L)", "float", "c"),
33+
"loadcell_scale_a" => array("Zitstok schaling (R)", "float", "c")
34+
);
35+
36+
37+
38+
$id=1;
39+
$device_name[$id]="Voordeur";
40+
$device_address[$id]="http://192.168.1.31/";
41+
$device_sensors[$id]=array(
42+
// "ip" => array("IP adres", "string", "r"),
43+
// "ssid" => array("WIFI SSID", "string", "r"),
44+
"rssi" => array("WIFI RSSI (dB)", "integer", "r"),
45+
"deurbel_status" => array("Deurbel ingedrukt","boolean", "r"),
46+
"lamp_status" => array("Lamp voordeur", "boolean", "w")
47+
);
48+
?>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
</body>
2+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
$ch = curl_init();
3+
4+
foreach($device_name as $index=>$name){
5+
curl_setopt($ch, CURLOPT_URL, $device_address[$index]);
6+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
7+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
8+
$output = curl_exec($ch);
9+
10+
$device_status[$index]=json_decode($output,TRUE);
11+
}
12+
13+
curl_close($ch);
14+
?>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title><?php echo $PAGE_TITLE; ?></title>
6+
7+
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
8+
<script
9+
src="https://code.jquery.com/jquery-3.4.1.min.js"
10+
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
11+
crossorigin="anonymous"></script>
12+
13+
<!-- Include plugins -->
14+
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js" type="text/javascript"></script>
15+
16+
<!-- Include stylesheet -->
17+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootswatch/4.4.1/sandstone/bootstrap.css" media="screen">
18+
19+
<!-- Required meta tags -->
20+
<meta charset="utf-8">
21+
<meta name="viewport" content="width=device-width, initial-scale=1">
22+
23+
</head>
24+
25+
<body>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<nav class="navbar navbar-expand navbar-dark bg-primary">
2+
<div class="container">
3+
<a class="navbar-brand" href="index.php"><?php echo $PAGE_TITLE; ?></a>
4+
<ul class="navbar-nav mr-auto">
5+
<li class="nav-item <?php if($page==="sensors"){echo "active";} ?>">
6+
<a class="nav-link" href="?page=sensors">Sensors</a>
7+
</li>
8+
<li class="nav-item <?php if($page==="config"){echo "active";} ?>">
9+
<a class="nav-link" href="?page=config">Config</a>
10+
</li>
11+
<li class="nav-item <?php if($page==="timers"){echo "active";} ?>">
12+
<a class="nav-link" href="?page=timers">Timers</a>
13+
</li>
14+
</ul>
15+
</div>
16+
</nav>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
include "../config/devices.php";
3+
$device_index=$_POST["device_index"];
4+
$status_index=$_POST["status_index"];
5+
$status_value=$_POST["status_value"];
6+
7+
header('Location: ../index.php');
8+
9+
// rewrite value if neccessary
10+
if($device_sensors[$device_index][$status_index][1]=="boolean"){
11+
if($status_value=="true"){
12+
$status_value=1;
13+
}else{
14+
$status_value=0;
15+
}
16+
}
17+
18+
if($device_sensors[$device_index][$status_index][1]=="integer"){
19+
$status_value=(int)$status_value;
20+
}
21+
22+
if($device_sensors[$device_index][$status_index][1]=="float"){
23+
$status_value=(float)$status_value;
24+
}
25+
26+
// Setup request to send json via POST
27+
$payload = json_encode(array($status_index => $status_value));
28+
29+
// Create a new cURL resource
30+
$url = $device_address[$device_index];
31+
$ch = curl_init($url);
32+
33+
// Attach encoded JSON string to the POST fields
34+
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
35+
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
36+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
37+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
38+
$result = curl_exec($ch);
39+
curl_close($ch);
40+
?>

ESPNodes_frontend/index.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
$PAGE_TITLE="ESPNodes frontend";
3+
4+
if(isset($_GET['page'])){
5+
$page=preg_replace('/[^A-Za-z0-9-_\/]/', '', $_GET['page']);
6+
}else{
7+
$page='sensors';
8+
}
9+
$filename="pages/". $page .".php";
10+
11+
12+
include "config/devices.php";
13+
14+
include "include/header.php";
15+
include "include/navbar.php";
16+
?>
17+
18+
19+
<div class="container">
20+
<div class="jumbotron">
21+
22+
<?php
23+
if(file_exists($filename)){
24+
include $filename;
25+
}else{
26+
echo "Error 404: page not found.";
27+
}
28+
?>
29+
30+
</div></div>
31+
<?php
32+
include "include/footer.php";
33+
?>

ESPNodes_frontend/pages/config.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php include "include/get_device_status.php"; ?>
2+
3+
<p><i>Warning: you are changing the configuration of your sensors.</i></p>
4+
<div style="width: 100%; max-width: 700px;">
5+
<?php
6+
foreach($device_name as $device_index=>$name){
7+
echo "<h2>".$name."</h2>";
8+
?>
9+
<table class="table">
10+
<?php
11+
$n_items=0;
12+
foreach($device_sensors[$device_index] as $status_index=>$status_key){
13+
if($status_key[2]=="c"){
14+
$n_items++;
15+
?>
16+
<tr>
17+
<td><?php echo $status_key[0]; ?></td>
18+
<td width="250px">
19+
<?php
20+
echo '<form action="include/set_device_status.php" method="POST">';
21+
echo '<input type="hidden" name="device_index" value="'.$device_index.'">';
22+
echo '<input type="hidden" name="status_index" value="'.$status_index.'">';
23+
$disabled="";
24+
25+
26+
switch($status_key[1]) {
27+
case "integer":
28+
echo '<input type="text" name="status_value" style="width:150px;" value="'.$device_status[$device_index][$status_index].'" '. $disabled .'>';
29+
break;
30+
31+
case "float":
32+
echo '<input type="text" name="status_value" style="width:150px;" value="'.$device_status[$device_index][$status_index].'" '. $disabled .'>';
33+
break;
34+
35+
case "boolean":
36+
if($device_status[$device_index][$status_index]==1){
37+
$checked="checked";
38+
}else{
39+
$checked="";
40+
}
41+
echo '<div class="custom-control custom-switch">
42+
<input type="checkbox" class="custom-control-input" id="toggle-'.$device_index.'-'.$status_index.'" '. $checked .' name="status_value" value="true" onClick="this.form.submit();"'. $disabled .'>
43+
<label class="custom-control-label" for="toggle-'.$device_index.'-'.$status_index.'"></label>
44+
</div>';
45+
46+
// echo '<input type="checkbox" '. $checked .' name="status_value" value="true" onClick="this.form.submit();"'. $disabled .'>';
47+
break;
48+
49+
case "string":
50+
echo '<input type="text" name="status_value" style="width:150px;" value="'.$device_status[$device_index][$status_index].'" '. $disabled .'>';
51+
break;
52+
}
53+
54+
if($status_key[1]!="boolean") echo '<button type="submit" class="btn btn-primary">Set</button>';
55+
echo '</form>';
56+
?>
57+
</td>
58+
</tr>
59+
<?php
60+
}
61+
}
62+
if($n_items==0){
63+
echo "<tr><td>No configurable sensors available for this node.</td></tr>";
64+
}
65+
?>
66+
</table>
67+
<?php
68+
}
69+
?>
70+
</div>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php include "include/get_device_status.php"; ?>
2+
3+
<div style="width: 100%; max-width: 700px;">
4+
<?php
5+
foreach($device_name as $device_index=>$name){
6+
echo "<h2>".$name."</h2>";
7+
?>
8+
<table class="table">
9+
<?php
10+
$n_items=0;
11+
foreach($device_sensors[$device_index] as $status_index=>$status_key){
12+
13+
$n_items++;
14+
15+
if($status_key[2]!="c"){
16+
?>
17+
<tr>
18+
<td><?php echo $status_key[0]; ?></td>
19+
<td width="250px">
20+
<?php
21+
22+
if($status_key[2]=="w"){
23+
echo '<form action="include/set_device_status.php" method="POST">';
24+
echo '<input type="hidden" name="device_index" value="'.$device_index.'">';
25+
echo '<input type="hidden" name="status_index" value="'.$status_index.'">';
26+
$disabled="";
27+
}else{
28+
$disabled="disabled";
29+
}
30+
31+
32+
switch($status_key[1]) {
33+
case "integer":
34+
echo '<input type="text" name="status_value" style="width:150px;" value="'.$device_status[$device_index][$status_index].'" '. $disabled .'>';
35+
break;
36+
37+
case "float":
38+
echo '<input type="text" name="status_value" style="width:150px;" value="'.$device_status[$device_index][$status_index].'" '. $disabled .'>';
39+
break;
40+
41+
case "boolean":
42+
if($device_status[$device_index][$status_index]==1){
43+
$checked="checked";
44+
}else{
45+
$checked="";
46+
}
47+
echo '<div class="custom-control custom-switch">
48+
<input type="checkbox" class="custom-control-input" id="toggle-'.$device_index.'-'.$status_index.'" '. $checked .' name="status_value" value="true" onClick="this.form.submit();" '. $disabled .'>
49+
<label class="custom-control-label" for="toggle-'.$device_index.'-'.$status_index.'"></label>
50+
</div>';
51+
52+
// echo '<input type="checkbox" '. $checked .' name="status_value" value="true" onClick="this.form.submit();"'. $disabled .'>';
53+
break;
54+
55+
case "string":
56+
echo '<input type="text" name="status_value" style="width:150px;" value="'.$device_status[$device_index][$status_index].'" '. $disabled .'>';
57+
break;
58+
}
59+
60+
if($status_key[2]=="w"){
61+
if($status_key[1]!="boolean") echo '<button type="submit" class="btn btn-primary">Set</button>';
62+
echo '</form>';
63+
}
64+
?>
65+
</td>
66+
</tr>
67+
<?php
68+
}
69+
}
70+
if($n_items==0){
71+
echo "<tr><td>No sensors available for this node.</td></tr>";
72+
}
73+
?>
74+
</table>
75+
<?php
76+
}
77+
?>
78+
</div>

ESPNodes_frontend/pages/timers.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Not implemented yet.

0 commit comments

Comments
 (0)