0

Adafruit IO / WebSockets Friendly?
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Adafruit IO / WebSockets Friendly?

by callen5914 on Wed Nov 11, 2015 10:54 pm

Greetings,

So I am in the middle of building an AngularJS App and wondered how when I push the button (followed the tutorial) I can get that to update with refreshing the browser. I have been looking around but can't seem to tell how this is accomplished. Is this MQTT Sockets friendly?

Cheers,

Clayton Allen

callen5914
 
Posts: 37
Joined: Mon Jun 22, 2015 9:36 pm

Re: Adafruit IO / WebSockets Friendly?

by callen5914 on Thu Nov 12, 2015 9:44 pm

BUMPING

callen5914
 
Posts: 37
Joined: Mon Jun 22, 2015 9:36 pm

Re: Adafruit IO / WebSockets Friendly?

by jwcooper on Fri Nov 13, 2015 12:22 pm

I'm not entirely sure what your project requirements are, but you can connect to IO through MQTT. Can you give some more details on what you're attempting?

Our dashboard is indeed using mqtt over websockets, which allows the data to sync up without refreshing the page.

jwcooper
 
Posts: 670
Joined: Tue May 01, 2012 9:08 pm

Re: Adafruit IO / WebSockets Friendly?

by callen5914 on Fri Nov 13, 2015 6:10 pm

Okay, thanks for the response.

So here is what I wanted to do. I wanted to build a web based UI using AngularJS that is hosted on my own server. In this UI I wanted to receive live data from my sensors connected to the Adafruit IO. So for example when I push the button it will not only show up on the IO but my UI as well without a page refresh. I did successfully bring in the JSON data to a development server on localhost. But in order to update the push button value on my UI I have to refresh the page. I was wondering what is the correct way to hook into that perhaps with Socket.IO to emit changes so to speak.

Code: Select all | TOGGLE FULL SIZE
angular.module('mqttDemo',[])
.controller('mqttStatus', ['$scope', '$http', function($scope, $http){

   $http({
        method: 'GET',
        url: 'https://io.adafruit.com/api/feeds/button',
        headers: {
           'X-AIO-Key': '04d4ad825a1db960fa8af7c0b985ef28760be169',
           'Accept-Language': 'en-us'
        }
   }).then(function successCallback(response) {
       
       $scope.status = response.data['last_value'];
     }, function errorCallback(response) {
       //
     });
   
}]);

callen5914
 
Posts: 37
Joined: Mon Jun 22, 2015 9:36 pm

Re: Adafruit IO / WebSockets Friendly?

by callen5914 on Sun Nov 15, 2015 1:28 am

Bumping

callen5914
 
Posts: 37
Joined: Mon Jun 22, 2015 9:36 pm

Re: Adafruit IO / WebSockets Friendly?

by jwcooper on Mon Nov 16, 2015 1:29 pm

I think your best bet is going to be to subscribe to your feeds over MQTT from your server, and when you receive data, push that from your server to your front-end over socket.io. I just don't think it's going to be easy (or possible?) to directly subscribe to IO from your front-end over websockets and mqtt.

jwcooper
 
Posts: 670
Joined: Tue May 01, 2012 9:08 pm

Re: Adafruit IO / WebSockets Friendly?

by uniontownlabs on Mon Nov 16, 2015 3:08 pm

More info about Websocket support can be found here:
https://github.com/adafruit/io-issues/issues/74

uniontownlabs
 
Posts: 112
Joined: Wed Dec 17, 2014 10:56 pm

Please be positive and constructive with your questions and comments.