-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinternetControl.php
68 lines (62 loc) · 3.47 KB
/
internetControl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
$jsonLocation = 'dimmerInstruction.json'; // the name and the path of the json file that will be created
// the above path need to be associated with link defined in the python program (web_serial.py)
if (isset($_POST['modeSelector'])) { //check if form was submitted
$modeSelector = $_POST['modeSelector'];// get the selected mode
$signalStrength = $_POST['signalStrength']; // get the signal strength
$response = array(); // assigning the array
$response["My_home"] = array("Mode" => $modeSelector, "Times" => $signalStrength); // filling the array with data
$fp = fopen($jsonLocation, 'w');// open the json file and overwrite it or create new if it doesn't exist,
fwrite($fp, json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); // writing our new created array in the json location
fclose($fp); // close the json file
echo '<script type="text/javascript">alert("Successful");</script>'; // Alert success
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Internet Control</title>
</head>
<body>
<div class="content-wrapper">
<section class="content">
<div class="row">
<div class="col-md-6">
<!-- general form elements -->
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title"></h3>
</div>
<div class="box-body">
Select signal strength
<form name='f' method='POST' action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<div class='form-group'>
<label>
Signal strength
</label>
<input type="range" class='form-control' name="signalStrength" min="1" max="7">
<div class='form-group'><select name='modeSelector' class='form-control' onchange="this.form.submit()">
<option disabled selected>click to chose</option>
<option value="a">Slow dimming</option>
<option value="0">No light</option>
<option value="1">Low level 1</option>
<option value="2">Low level 2</option>
<option value="3">Low level 3</option>
<option value="4">Mid level 1</option>
<option value="5">Mid level 2</option>
<option value="6">Mid level 3</option>
<option value="7">High level 1</option>
<option value="8">High level 2</option>
<option value="9">Open full light</option>
</select>
</div>
<input type='submit' value='submit' name='B1' class="btn btn-info pull-right">
</div>
</form>
</div>
</div>
</div>
</div>
</section>
</div>
</body>