Losant JavaScript MQTT Client in the Browser?


Can I use losant-mqtt,js in my browser? Can I import it as use it as part of the JavaScript on a webpage?


I haven’t confirmed it myself, but losant-mqtt is a wrapper around MQTT.js, which is supported in the browser: https://github.com/mqttjs/MQTT.js#browser

So with something like Webpack or Browserify, you should be able to use losant-mqtt in the browser. Give it a try and let us know!



Thanks! will do. If I can get it to work,



Worst-case scenario, our underlying mqtt protocol is pretty straightforward, so you could use MQTT.js directly in the browser.


Greg, I just confirmed that it works.

Check out this gist: https://gist.github.com/anaptfox/708cd010a53d19b7b7dc029a235ca092

The key is to set the transport to web sockets. I did that here:

Just add transport: 'ws' to the Device options.


You can also test things out pretty quickly with: RequireBin.com



Thanks! I had some thoughts along the same line, just not sure how to use the Losant without the wrapper. A bit new to this IoT and MQTT game. Amazingly I had the weather station example up connected to a slack channel AND my edison sending data to Losant in a matter of a couple of hours. Losant is pretty amazing.




Thanks! Will try as soon as I can!



No Problem! Please reach out if you have more questions.