Skip to content
This repository was archived by the owner on Feb 11, 2020. It is now read-only.

MQTT over Websockets

SudoPlz edited this page May 4, 2014 · 7 revisions

Since v0.13.0 Mosca support MQTT over Websocket through the mows package.

It is very easy to use, just prepare an index.html file:

<html>
  <head>
    <script src="/mqtt.js"></script>
  </head>
  <body>
    <script>
      var client = mqtt.createClient();

      client.subscribe("mqtt/demo");

      client.on("message", function(topic, payload) {
        alert([topic, payload].join(": "));
        client.end();
      });

      client.publish("mqtt/demo", "hello world!");
    </script>
  </body>
</html>

Then serve it with Mosca:

$ mosca --http-port 3000 --http-static . --http-bundle \
        --very-verbose | bunyan

And point your browser to http://localhost:3000.

Clone this wiki locally