Skip to content

Commit

Permalink
Final Docs for Sensor Management
Browse files Browse the repository at this point in the history
  • Loading branch information
MSiddharthReddy committed Apr 15, 2016
1 parent a2a0b3b commit d643a74
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 34 deletions.
29 changes: 29 additions & 0 deletions change.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
include 'connect.php';



//if ($conn->query($r) === TRUE) {
//echo "New record created successfully";
//} else {
//echo "Error: " . $sql . "<br>" . $conn->er


$id = $_GET['i'];
$hub = $_GET['id'];
$stat=$_GET['stat'];
if($stat=='ON')
$query = "UPDATE sensor_list set status='OFF' WHERE Sensor_id='".$id."' and hub_id = '".$hub."'";
else
$query = "UPDATE sensor_list set status='ON' WHERE Sensor_id='".$id."' and hub_id = '".$hub."'";

echo $query;
if ($conn->query($query) === TRUE) {
echo 'ok';

header("Location: sensor.php?id=".$hub);
}

exit; // finish execution since we only need the "ok" or "err" answers from the server.

?>
2 changes: 1 addition & 1 deletion del.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

$id = $_GET['i'];
$hub = $_GET['id'];
$query = "DELETE FROM sensor_list WHERE Sensor_name='".$id."'";
$query = "DELETE FROM sensor_list WHERE Sensor_id='".$id."'";
echo $query;
if ($conn->query($query) === TRUE) {
echo 'ok';
Expand Down
4 changes: 2 additions & 2 deletions handle.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
$stat = $_GET["status"];
$freq = $_GET["freq"];

$sql = "INSERT INTO sensor_list (Sensor_name, Sensor_id, lon, lat, hub_id,status)
VALUES ('$sensor', '$fromat', '$desc', '$url ', '$hub', '$api')";
$sql = "INSERT INTO sensor_list (Sensor_name, Sensor_id, lon, lat, hub_id,status, type)
VALUES ('$sensor', '$fromat', '$desc', '$url ', '$hub', '$api','$stat')";

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
Expand Down
38 changes: 17 additions & 21 deletions markers.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,11 @@
$(document).ready(function(){
map = new GMaps({
el: '#map',
lat: 37.890998840332,
lng: -122.446998596191,
lat: 36,
lng: -122,
zoom: 4
});
map.addMarker({
lat: 37.890998840332,
lng: -122.446998596191,
title: '',
details: {
database_id: 42,
author: 'HPNeo'
},
click: function(e){
if(console.log)
console.log(e);
alert('You clicked in this marker');
},
mouseover: function(e){
if(console.log)
console.log(e);
}
});

$.ajax({
url: 'un.php', //the script to call to get data
data: "", //you can insert url argumnets here to pass to api.php
Expand All @@ -57,10 +40,23 @@

$.each(data, function(k, v) {
/// do stuff

map.addMarker({
lat: v.lat,
lng: v.lon,
title: v.sensor
title: v.sensor,
se: v.hub,
click: function(e){
if(console.log)
console.log(e);
var newURLString = "sensor.php" +
"?id=" + v.hub;
window.location.href = newURLString;
},
mouseover: function(e){
if(console.log)
console.log(e);
}
});
});

Expand Down
28 changes: 19 additions & 9 deletions sensor.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<thead>
<tr >
<th>Sensor Name</th>
<th>Sensor ID</th>
<th>Sensor Type</th>
<th>Status</th>
<th>Manage</th>
</tr>
Expand All @@ -66,11 +66,12 @@

$a = $conn->query($r);
while( $row = mysqli_fetch_array($a) ){
echo "<tr><td>" . $row['Sensor_name'] . "</td><td>" . $row['Sensor_id'] . "</td><td>" . $row['status'] . "</td>";
$i = $row['Sensor_name']; //$row['index'] the index here is a field name
echo '<td> <a class="btn btn-danger" href="del.php?id='.$id.'&i='.$i.'" ><span class="glyphicon glyphicon-trash">';
echo '</span> Delete </a> &nbsp<button data-toggle="modal" data-target="#myModal2" class="btn btn-info">';
echo '<span class="glyphicon glyphicon-pencil"></span> Edit Status</a>';
echo "<tr><td>" . $row['Sensor_name'] . "</td><td>" . $row['type'] . "</td><td>" . $row['status'] . "</td>";
$i = $row['Sensor_id']; //$row['index'] the index here is a field name
$stat=$row['status'];
echo '<td> <a class="btn btn-danger" href="del.php?id='.$id.'&i='.$i.'"><span class="glyphicon glyphicon-trash">';
echo '</span> Delete </a> &nbsp<a href="change.php?id='.$id.'&i='.$i.'&stat='.$stat.'" class="btn btn-info">';
echo '<span class="glyphicon glyphicon-pencil"></span>Change</a>';
echo '</td>';
echo '</tr>';
}
Expand Down Expand Up @@ -105,9 +106,18 @@
<input type="email" class="form-control" name="format" placeholder="Data Format"><br>
<label for="hub">Select Existing Sensor hub</label>
<input type="email" class="form-control" name="hub" placeholder="Select Existing Sensor hub"><br>


<label for="api">Sensor Type</label>
<select class="form-control" name="status">
<option value="Wind Speed">Wind Speed</option>
<option value="Wind Direction">Wind Direction</option>
<option value="Tidal Speed">Tidal Speed</option>
</select>
<label for="api">Sensor Status</label>
<input type="email" class="form-control" name="api" placeholder="API Token"><br>
<select class="form-control" name="api">
<option value="ON">ON</option>
<option value="OFF">OFF</option>
</select>
<p class="help-block">Please Provide the Correct Information so that We can MAP your Sensor correctly.</p>
<div style="text-align: center;">
<button type="submit" class="btn btn-success">Submit</button>
Expand All @@ -133,7 +143,7 @@
<div class="col-sm-8">
<label for="sensorname">New Status</label>
<input type="email" class="form-control" id="sensorname" placeholder="Sensor Name"><br>
<input id="id" value=''><br>
<!--<input id="id" value=''><br> -->

<div style="text-align: center;">
<button type="submit" class="btn btn-success">Submit</button>
Expand Down
3 changes: 2 additions & 1 deletion un.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
$lat = $row['lat'];
$lon = $row['lon'];
$name = $row['name'];
$id = $row['id'];

$rows[] = array("lat" => $lat, "lon" => $lon, "sensor" => $name );
$rows[] = array("lat" => $lat, "lon" => $lon, "sensor" => $name, "hub" => $id );
# code...
}
header('Content-type:application/json');
Expand Down

0 comments on commit d643a74

Please sign in to comment.