What am I doing with MQTT, Plack and AJAX?

Last weekend at OggCamp11, I decide I’d try to write something to enable a web browser (an HTML5 application perhaps) to interact with an MQTT server just as a typical MQTT client might except over HTTP with an AJAX API.

For the server, I’m writing a Plack::Component. Plack is awesome and allows for a tremendous amount of flexibility at deployment time so it was the obvious choice.

There are lots of options for browser to MQTT bridge communication.

  • Long-poll: the server needs to manage a backlog of messages so that messages are not missed between poll response and next poll being received.

  • multipart/mixed streaming

  • websocket or single request with streaming response perhaps with streaming of the request

The goals are try to keep as many properties of the MQTT protocol when implementing the MQTT-over-HTTP protocol. This unfortunately turns out to be quite tricky as transfering binary over an AJAX interface is not trivial - due to UTF-8 not ASCII encoding assumptions. You can work around this by encoding to UTF-8 on the server so that String.charCodeAt(i) returns the byte values on the client end.

I’ve written something already. However, the API is a long way from where I hope to take it and is really just a toy to help me learn enough JavaScript to make progress to a full client. (And the name is probably a bad idea so it’ll probably change.)