August 2018
Beginner to intermediate
214 pages
6h 39m
English
If you are using two Pis, carry out this entire section on the broker Pi. If you are using one Pi, do all of this on your one Pi.
We're going to use the Mosca library to set up an MQTT broker on our Pi. The mosca npm library makes it really easy to set up and start an MQTT broker. All we need is a running mongoDB instance (which we took care of in the last step, Setting up light sensor).
In the broker folder (either on your original or broker Pi), in the index.js file, we're going to set up mosca:
const mosca = require('mosca')const mqttBroker = new mosca.Server({ port: 1883, backend: { type: 'mongo', url: 'mongodb://localhost:27017/mqtt', pubsubCollection: 'MQTT-broker-NodeBots', mongo: {} }})server.on('ready', ...Read now
Unlock full access