1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-11 18:32:50 +00:00

adding api functionality to sensor information page

This commit is contained in:
2016-05-18 04:03:42 -05:00
parent b6d5854250
commit b3da7be0b8
3 changed files with 95 additions and 20 deletions

View File

@@ -40,9 +40,6 @@ func HandleSensorRequest(w http.ResponseWriter, r *http.Request, ps httprouter.P
message = "Data inserted into database" message = "Data inserted into database"
} }
//send response back
fmt.Fprint(w, "{ message : \""+message+"\"}")
//compare current readings with dialy_sensor readings //compare current readings with dialy_sensor readings
//update daily_sensor readings if out of bounds //update daily_sensor readings if out of bounds
//********************************************************************************** //**********************************************************************************
@@ -98,6 +95,9 @@ func HandleSensorRequest(w http.ResponseWriter, r *http.Request, ps httprouter.P
} else { } else {
message = "Incorrect api key" message = "Incorrect api key"
} }
//send response back
fmt.Fprint(w, "{ message : \""+message+"\"}")
} }
func HandleAllSensors(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { func HandleAllSensors(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

View File

@@ -68,19 +68,93 @@ app.controller('IndexController', function($scope, $http) {
}); });
app.controller('SensorInfoController', function($scope, $route, $routeParams) { app.controller('SensorsController', function($scope, $http) {
$http({
method: 'GET',
url: '/api/allsensors'
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
$scope.information = response.data;
for (i in $scope.information) {
var date = new Date($scope.information[i].updated);
var options = { month: 'numeric', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true };
$scope.information[i].date = date.toLocaleString('en-US', options);
if ((Date.now() - date) < 120000) {
$scope.information[i].status = "Connected";
$scope.information[i].css = "colorGreen";
} else {
$scope.information[i].status = "Disconnected";
$scope.information[i].css = "colorRed";
}
}
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
});
app.controller('SensorInfoController', function($scope, $http, $routeParams) {
$scope.location = $routeParams.location; $scope.location = $routeParams.location;
}); $http({
method: 'GET',
url: '/api/sensor/' + $scope.location
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
app.controller('SensorsController', function($scope) { $scope.information = response.data;
$scope.message = 'This is Show orders screen'; var list = [];
for (i in $scope.information) {
var exists = false,
index = 0;
for (j in list) {
if ($scope.information[i].year == list[j].year) {
exists = true;
index = j;
break;
}
}
if (exists == true) {
if (list[index].months.indexOf($scope.information[i].month) < 0) {
list[index].months.push($scope.information[i].month);
}
} else {
//console.log("pusing" + $scope.information[i].year);
list.push({ year: $scope.information[i].year, months: [$scope.information[i].month] });
}
}
console.log(JSON.stringify(list));
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
}); });
//handle each post page after individual posts are selected //handle each post page after individual posts are selected
app.controller('PostController', function($scope, $route, $routeParams) { app.controller('PostController', function($scope, $route, $routeParams) {

View File

@@ -4,18 +4,19 @@
<p><span class="colorRed">Note:</span> I am using a DHT11 analog sensor for both temperature and humidity readings. I am also using a DS18B20 digital sensor, which only takes temperature readings. The digital sensor seems to get more accurate readings. Some of the data may be inconsistent as this is an experimental process. <p><span class="colorRed">Note:</span> I am using a DHT11 analog sensor for both temperature and humidity readings. I am also using a DS18B20 digital sensor, which only takes temperature readings. The digital sensor seems to get more accurate readings. Some of the data may be inconsistent as this is an experimental process.
</p> </p>
<hr> <hr>
<div class="col-lg-4"> <div ng-repeat="sensorInfo in information">
<h3>Sensor Title</h3> <div class="col-lg-4">
<h4>Temperature: °F </h4> <h3>{{sensorInfo.location}}</h3>
<h4>Humidity: </h4> <h4>Temperature: {{sensorInfo.temperature}}°F </h4>
<span>Updated:</span> <span>Updated: {{sensorInfo.date}}</span>
<br> <br>
<span class="colorGreen">Connected</span> <span class="{{sensorInfo.css}}">{{sensorInfo.status}}</span>
<br> <br>
<br> <br>
<a href="/sensors/location"> <a href="/sensors/{{sensorInfo.location}}">
<button class="btn btn-default">View Graph</button> <button class="btn btn-default">View Graph</button>
</a> </a>
</div>
</div> </div>
</div> </div>
<br> <br>