Building Arduino Projects for the Internet of Things

(Steven Felgate) #1

CHAPTER 4 ■ COMPLEX FLOWS: NODE-RED


Listing 4-2. Code for Creating the Tweet


msg.payload = "Sunny Outside! " + msg.payload.requestVar + " #IoT";
return msg;


Connect the Set Tweet Message node to the first path of the Check Threshold switch
node. This connection will make sure that whenever a light sensor value crosses the
threshold of 750, the flow follows path 1 that tweets.
Next, drag and drop a Tweet node on to the flow diagram after the Set Tweet Message
node, as shown in Figure  4-19.


Figure 4-19. T w e e t n o d e


For Node-RED to be able to tweet, you need to configure your Twitter credentials.
Double-click the twitter out node to open the properties dialog box shown in Figure  4-20.
If you already have your Twitter credentials configured in Node-RED, select them from
the Twitter dropdown. Otherwise, select the Add New Twitter- Credentials option from
the dropdown and click on the Edit/Pencil icon to start the configuration steps.


Figure 4-20. Add new Twitter credentials


Figure  4-21 shows the next dialog box that appears. Click on the Click Here to
Authenticate with Twitter button.

Free download pdf