diff --git a/controller/api/sensor.go b/controller/api/sensor.go index dea5a90..cd987f8 100644 --- a/controller/api/sensor.go +++ b/controller/api/sensor.go @@ -40,9 +40,6 @@ func HandleSensorRequest(w http.ResponseWriter, r *http.Request, ps httprouter.P message = "Data inserted into database" } - //send response back - fmt.Fprint(w, "{ message : \""+message+"\"}") - //compare current readings with dialy_sensor readings //update daily_sensor readings if out of bounds //********************************************************************************** @@ -98,6 +95,9 @@ func HandleSensorRequest(w http.ResponseWriter, r *http.Request, ps httprouter.P } else { message = "Incorrect api key" } + + //send response back + fmt.Fprint(w, "{ message : \""+message+"\"}") } func HandleAllSensors(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { diff --git a/public/js/app.js b/public/js/app.js index c4010b1..0cf088f 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -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; -}); + $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 app.controller('PostController', function($scope, $route, $routeParams) { diff --git a/public/view/sensors.html b/public/view/sensors.html index 1191de4..9822165 100644 --- a/public/view/sensors.html +++ b/public/view/sensors.html @@ -4,18 +4,19 @@
Note: 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.