Skip to Content
Practical Internet of Things with JavaScript
book

Practical Internet of Things with JavaScript

by Arvind Ravulavaru
December 2017
Intermediate to advanced
296 pages
5h 56m
English
Packt Publishing
Content preview from Practical Internet of Things with JavaScript

MQTT client

Finally, we are going to look at the MQTT client integration with our api-engine. If we open api-engine/server/mqtt/index.js, we should see the default setup of the MQTTS client.

We are using the following configuration to connect to the Mosca broker over MQTTS:

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});

And we are subscribing to two events: one when the connection is established and the other when we receive a message. On the connect event, we subscribe to a topic named greet and we are publishing a simple message ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Test-Driving JavaScript Applications

Test-Driving JavaScript Applications

Venkat Subramaniam
Web Caching and Replication

Web Caching and Replication

Michael Rabinovich, Oliver Spatscheck

Publisher Resources

ISBN: 9781788292948Supplemental Content