O'Reilly logo

Practical Internet of Things with JavaScript by Arvind Ravulavaru

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Updating the API engine

Now that we are done with the Raspberry Pi setup, we will update the API engine to accept the incoming data.

The first thing we are going to do is update api-engine/server/mqtt/index.js as follows:

var Data = require('../api/data/data.model'); var mqtt = require('mqtt'); var config = require('../config/environment'); var fs = require('fs'); var client = mqtt.connect({ port: config.mqtt.port, protocol: 'mqtts', host: config.mqtt.host, clientId: config.mqtt.clientId, reconnectPeriod: 1000, username: config.mqtt.clientId, password: config.mqtt.clientId, keepalive: 300, rejectUnauthorized: false }); client.on('connect', function() { console.log('Connected to Mosca at ' + config.mqtt.host + ' on port ' + config.mqtt.port); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required