Losant MQTT Javascript Client


I am developing an interface between a Raspberry Pi 3B and Losant and it appears that the Losant MQTT Javascript client is the way to go.

At this point all I am trying to accomplish is to get the basic.js example running on the RPI. I copied basic.js to example.js and added my device id, key, and secret.

I am running v7.9.0 of Node.js and have the environment variable NODE_PATH set to /usr/lib/nodejs:/home/pmmi/node_modules/losant-mqtt/lib

When executing example.js via Node.js, I get the following error.

this.mqtt.on(‘message’, this.handleMessage.bind(this));

TypeError: Cannot read property ‘bind’ of undefined
at Device (/home/pmmi/node_modules/losant-mqtt/lib/device.js:57:45)
at Object. (/home/pmmi/node_modules/losant-mqtt/examples/example.js:11:14)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:423:7)
at startup (bootstrap_node.js:147:9)

Has anyone had the same problem? Any help would be very much appreciated!


Oh great catch! It looks like we didn’t update the example/basic.js file when we released v2 of losant-mqtt. Instead of what is currently in there:

var device = Device({ .... });

you need to do create a new device instance using “new”:

var device = new Device({ .... });

We will be updating the examples in the repository shortly. Thanks for pointing it out!