diff --git a/web/index.html b/web/index.html index 796d7322..1a196215 100755 --- a/web/index.html +++ b/web/index.html @@ -64,6 +64,7 @@ + @@ -83,6 +84,7 @@ Towers Logs Settings + Messaging diff --git a/web/js/main.js b/web/js/main.js index a92eae92..05a576d7 100755 --- a/web/js/main.js +++ b/web/js/main.js @@ -9,6 +9,7 @@ var URL_SATELLITES_GET = "http://" + URL_HOST_BASE + "/getSatellites" var URL_STATUS_WS = "ws://" + URL_HOST_BASE + "/status" var URL_TRAFFIC_WS = "ws://" + URL_HOST_BASE + "/traffic"; var URL_WEATHER_WS = "ws://" + URL_HOST_BASE + "/weather"; +var URL_MESSAGING_WS = "ws://" + URL_HOST_BASE + "/iridium"; var URL_UPDATE_UPLOAD = "http://" + URL_HOST_BASE + "/updateUpload"; var URL_REBOOT = "http://" + URL_HOST_BASE + "/reboot"; var URL_SHUTDOWN = "http://" + URL_HOST_BASE + "/shutdown"; @@ -62,7 +63,14 @@ app.config(function ($stateProvider, $urlRouterProvider) { templateUrl: 'plates/settings.html', controller: 'SettingsCtrl', reloadOnSearch: false + }) + .state('messaging', { + url: '/messaging', + templateUrl: 'plates/messaging.html', + controller: 'MessagingCtrl', + reloadOnSearch: false }); + $urlRouterProvider.otherwise('/'); }); diff --git a/web/plates/js/messaging.js b/web/plates/js/messaging.js new file mode 100644 index 00000000..16563bdd --- /dev/null +++ b/web/plates/js/messaging.js @@ -0,0 +1,72 @@ +angular.module('appControllers').controller('MessagingCtrl', MessagingCtrl); // get the main module contollers set +MessagingCtrl.$inject = ['$rootScope', '$scope', '$state', '$http', '$interval']; // Inject my dependencies + +// create our controller function with all necessary logic +function MessagingCtrl($rootScope, $scope, $state, $http, $interval) { + + $scope.$parent.helppage = 'plates/messaging-help.html'; + $scope.message_list = []; + + function connect($scope) { + if (($scope === undefined) || ($scope === null)) + return; // we are getting called once after clicking away from the status page + + if (($scope.socket === undefined) || ($scope.socket === null)) { + socket = new WebSocket(URL_MESSAGING_WS); + $scope.socket = socket; // store socket in scope for enter/exit usage + } + + $scope.ConnectState = "Disconnected"; + + socket.onopen = function (msg) { + $scope.ConnectState = "Connected"; + }; + + socket.onclose = function (msg) { + $scope.ConnectState = "Disconnected"; + $scope.$apply(); + setTimeout(connect, 1000); + }; + + socket.onerror = function (msg) { + $scope.ConnectState = "Problem"; + $scope.$apply(); + }; + + socket.onmessage = function (msg) { + console.log('Received message update.') + + var message = JSON.parse(msg.data); + + $scope.message_list.unshift(message); + + $scope.$apply(); + + }; + } + + $scope.sendData = function() { + var t = ""; + if ($scope.DataInput !== undefined) + t = $scope.DataInput; + + sendMsg = { + "Command": "send", + "Data": t + }; + j = angular.toJson(sendMsg); + console.log("heyoo" + j + "\n"); + $scope.socket.send(j); + }; + + $state.get('messaging').onExit = function () { + // disconnect from the socket + if (($scope.socket !== undefined) && ($scope.socket !== null)) { + $scope.socket.close(); + $scope.socket = null; + } + }; + + // Messaging controller tasks. + connect($scope); // connect - opens a socket and listens for messages +}; \ No newline at end of file diff --git a/web/plates/messaging-help.html b/web/plates/messaging-help.html new file mode 100644 index 00000000..15c8754f --- /dev/null +++ b/web/plates/messaging-help.html @@ -0,0 +1,10 @@ +
+

The Messaging page provides a method to interface with an Iridium modem to send and receive messages.

+

For each message, the list includes the following details:

+ +
\ No newline at end of file diff --git a/web/plates/messaging.html b/web/plates/messaging.html new file mode 100644 index 00000000..8f630164 --- /dev/null +++ b/web/plates/messaging.html @@ -0,0 +1,59 @@ +
+
+
Send
+
+
+ + +
+ +
+
+
+
+ Messaging + {{ConnectState}} + {{ConnectState}} +
+
+
+ Time + Command + Result + Data +
+ +
+
+ {{message.Time}} + {{message.Command}} + {{message.Result}} + {{message.Data}} +
+
+
+
+ +
+ +
\ No newline at end of file