I'm trying to start playing with node and mqtt and I found this really nice library for the MQTT protocol that integrates it to node.js. The library is simply called mqttjs: https://npmjs.org/package/mqttjs
I've walked through setting up node js according to this simple guide: http://shapeshed.com/setting-up-nodejs-and-npm-on-mac-osx/ and the server created and launched in that example works fine.
I installed the mqttjs library according to the instructions on the node website (npm install mqttjs).
In the docs for the mqttjs library they say there is a server example in "examples/broadcast.js". It seems this has been moved to "examples/server/broadcast.js". I'm having some issues running this example though, the server never starts and in the end throws an error. Here is the output from my terminal:
daniel$ pwd
/Users/daniel/test/node_modules/mqttjs/examples/server
daniel$ node broadcast.js
/Users/daniel/test/node_modules/mqttjs/lib/parse.js:113
packet.topic = topic_and_len[0];
^
TypeError: Cannot read property '0' of null
at Object.module.exports.publish (/Users/daniel/test/node_modules/mqttjs/lib/parse.js:113:31)
at Connection.parse (/Users/daniel/test/node_modules/mqttjs/lib/connection.js:81:26)
at Socket.EventEmitter.emit (events.js:88:17)
at TCP.onread (net.js:397:14)
I've tried reading the docs but they do not seem to be updated and I can find no reference on how to run the examples given with the library. If anyone has any experience in this, I'd be very greatful. Thanks.
It seems that you are trying to access the server through a web-interface. I have had this probem before :)
Run this command:
node orig.js
Then in another terminal window, run this command from the client folder:
node client_test.js
It should start pinging the server