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.
Locked
User avatar
callen5914
 
Posts: 37
Joined: Mon Jun 22, 2015 9:36 pm

Adafruit IO / WebSockets Friendly?

Post by callen5914 »

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

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

Re: Adafruit IO / WebSockets Friendly?

Post by callen5914 »

BUMPING

User avatar
jwcooper
 
Posts: 1004
Joined: Tue May 01, 2012 9:08 pm

Re: Adafruit IO / WebSockets Friendly?

Post by jwcooper »

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.

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

Re: Adafruit IO / WebSockets Friendly?

Post by callen5914 »

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

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) {
    	//
  	});
	
}]);

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

Re: Adafruit IO / WebSockets Friendly?

Post by callen5914 »

Bumping

User avatar
jwcooper
 
Posts: 1004
Joined: Tue May 01, 2012 9:08 pm

Re: Adafruit IO / WebSockets Friendly?

Post by jwcooper »

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.

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

Re: Adafruit IO / WebSockets Friendly?

Post by uniontownlabs »

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

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”