PubNub Time Series AI w/ Falkonry UI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.5.0.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script> | |
<script src="https://cdn.pubnub.com/sdk/pubnub-angular/pubnub-angular-4.0.2.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script> | |
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" /> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" /> | |
</head> | |
<body> | |
<div class="container" ng-app="PubNubAngularApp" ng-controller="MyAICtrl"> | |
<pre> | |
NOTE: make sure to update the PubNub keys below with your keys, | |
and ensure that the AI BLOCK is configured properly! | |
</pre> | |
<h3>MyApp IoT Data Feed</h3> | |
<p>Device ID: <input ng-model="deviceid" /></p> | |
<p>Device Temp: <input ng-model="devicetemp" /></p> | |
<p>Device Speed: <input ng-model="devicespeed" /></p> | |
<p><input type="button" ng-click="publish()" value="Send!" /></p> | |
<br /><br /> | |
<ul> | |
<li ng-repeat="message in messages track by $index"> | |
Device: {{message.id}} | |
<br /> | |
Temp: {{message.temp}} | |
<br /> | |
Speed: {{message.speed}} | |
<br /> | |
</li> | |
</ul> | |
</div> | |
<script> | |
angular.module('PubNubAngularApp', ["pubnub.angular.service"]) | |
.controller('MyAICtrl', function($rootScope, $scope, Pubnub) { | |
$scope.deviceid = parseInt(Math.random() * 10000); | |
$scope.devicetemp = 20; | |
$scope.devicespeed = 100; | |
$scope.messages = []; | |
$scope.channel = 'falkonry-input'; | |
if (!$rootScope.initialized) { | |
Pubnub.init({ | |
publishKey: 'YOUR_PUB_KEY', | |
subscribeKey: 'YOUR_SUB_KEY', | |
ssl:true | |
}); | |
$rootScope.initialized = true; | |
} | |
var msgCallback = function(payload) { | |
$scope.$apply(function() { | |
$scope.messages.unshift(payload); | |
}); | |
}; | |
$scope.publish = function() { | |
Pubnub.publish({ | |
channel: $scope.channel, | |
message: {id:$scope.deviceid, temp:$scope.devicetemp, speed:$scope.devicespeed} | |
}); | |
}; | |
Pubnub.subscribe({ channels: [$scope.channel] }); | |
Pubnub.addListener({ message: msgCallback }); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment