incremental
diff --git a/static/js/sensorController.js b/static/js/sensorController.js
index f1e0812..67c9d82 100644
--- a/static/js/sensorController.js
+++ b/static/js/sensorController.js
@@ -1,8 +1,41 @@
angular.module('bmcApp').controller('sensorController', [
- '$scope', '$http',
- function($scope, $http) {
- $http.get('/sensortest').then(function(sensor_values) {
- $scope.sensor_values = sensor_values;
- })
+ '$scope', '$http', '$location', 'websocketService',
+ function($scope, $http, $location, websocketService) {
+ $scope.sensor_values = {};
+
+ var host = $location.host();
+ var port = $location.port();
+ var protocol = "ws://";
+ if ($location.protocol() === 'https') {
+ protocol = 'wss://';
+ }
+ websocketService.start(protocol + host + ":" + port + "/sensorws", function (evt) {
+ var obj = JSON.parse(evt.data);
+ $scope.$apply(function () {
+ for (var key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ console.log(key + " -> " + obj[key]);
+ $scope.sensor_values[key] = obj[key];
+ }
+ }
+ });
+ });
+
}
-]);
\ No newline at end of file
+]);
+
+app.factory('websocketService', function () {
+ return {
+ start: function (url, callback) {
+ var websocket = new WebSocket(url);
+ websocket.onopen = function () {
+ };
+ websocket.onclose = function () {
+ };
+ websocket.onmessage = function (evt) {
+ callback(evt);
+ };
+ }
+ }
+ }
+);
\ No newline at end of file