0

Subscribe to public feed from javascript without exposing AI
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Subscribe to public feed from javascript without exposing AI

by aerialist on Sat Nov 14, 2015 10:51 am

Thank you for creating yet another great service!

Is it possible to subscribe to a public feed from a web browser, javascript mqtt client via web socket, without writing AIO in javascript code?
I'm trying this code but get connection error message.
http://jsfiddle.net/aerialist/3chd6gbk/1/

Is the port number still 1883 when using web socket? Well port 80 didn't work, neither.
https://learn.adafruit.com/adafruit-io/mqtt-api#connection-details

Adafruit.io's dashboard is super. But I still like to build a front end with SVG drawing updated as feed values change.

aerialist
 
Posts: 22
Joined: Fri Jul 20, 2012 10:53 am

Re: Subscribe to public feed from javascript without exposin

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

Here's a demo of publishing and subscribing that will work if you add your own Adafruit IO credentials: https://jsfiddle.net/4wwhu2o6/

It uses MQTT.js: https://github.com/mqttjs/MQTT.js

Let me know if you have any issues.

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

Re: Subscribe to public feed from javascript without exposin

by aerialist on Wed Nov 18, 2015 5:17 am

Thank you very much for the excellent code, uniontownlabs!
I tried it with my credentials and it worked nice. Cool ;-)

Good to know wss://io.adafruit.com:443/mqtt/ is the URL to specify.

I would still like to raise question; could we subscribe to public feed without exposing AIO key in Javascript?

aerialist
 
Posts: 22
Joined: Fri Jul 20, 2012 10:53 am

Please be positive and constructive with your questions and comments.