Chapter 11. Entering the Cloud
Now that we’ve examined some examples that worked on a local network, it is time to see how to connect devices across networks. Instead of sending messages between devices, a place in the network will act as a message broker. With a message broker, location of devices is just another abstraction.
The use case of message brokers is usually this: imagine a number of sensors in different houses or different cities. If these sensors used the same physical network, it would be difficult to collect data (this becomes less of a problem with new kinds of LoRaWAN networks). Instead, you need messages to travel via gateways or “message brokers” that are accessible from different locations.
To enable messaging across networks, a popular technology is the Message Queue Telemetry Transport (MQTT) protocol. With MQTT, you can apply the publish–subscribe pattern to multiple devices and locations. There are different ways to use MQTT. You can either set up an MQTT server, or you can rent services for message transmission.
The publish–subscribe software pattern provides the foundations for MQTT. It is not too difficult to implement publish–subscribe patterns with JavaScript yourself. With this, you’ll see some more options to distribute state over a network, or to subscribe to updates from devices.
Publish–Subscribe Pattern
The publish–subscribe pattern is an important software design pattern for distributed systems. In a nutshell, it works similarly to a newspaper ...
Get Node.js for Embedded Systems now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.