Building Arduino Projects for the Internet of Things

(Steven Felgate) #1
CHAPTER 4 ■ COMPLEX FLOWS: NODE-RED

As you can see, a Node-RED flow is made of nodes. Each node encapsulates a
reusable piece of code that performs a certain task. To create a flow, you simply drag
nodes from palette on the left and drop them on your flow designer. You can find a lot of
nodes pre-built and openly available for use. A flow starts after receiving an input. There
are quite a few standard input sources available, such as HTTP, MQTT, and TCP. A flow
ends with an output task such as a HTTP response, an MQTT publish, a tweet, etc. A flow
is not limited to one input/output node; it can start or end with multiple nodes. Nodes in
between input and output usually transform or manipulate data, for example, converting
an HTTP request into an e-mail body.
You are going to build a simple project in order to get more acquainted with Node-
RED. The idea of this project is to tweet whenever it is sunny outside. Figure  4-2 displays
all the components that will be used to design this system. The first component is an
Arduino device with a light sensor attached to it. The second component is a Node-RED
flow that is started by Arduino. The final component is Twitter, as your Node-RED flow
will tweet a message whenever a certain threshold is crossed.

Figure 4-1. Node-RED development environment

Figure 4-2. Components of the light sensor tweet system

Free download pdf