Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
704 views

Contents - Programming With Node-RED

This document provides an overview and summary of chapters in a book about programming Internet of Things (IoT) projects using Node-RED on a Raspberry Pi. The chapters cover setting up a Raspberry Pi, installing the operating system and Node-RED software, using the command line, and creating various Node-RED projects involving inputs, functions, outputs and GPIO controls. The document describes projects for displaying text, time, weather data, sensor readings and controlling LEDs to demonstrate Node-RED's capabilities.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
704 views

Contents - Programming With Node-RED

This document provides an overview and summary of chapters in a book about programming Internet of Things (IoT) projects using Node-RED on a Raspberry Pi. The chapters cover setting up a Raspberry Pi, installing the operating system and Node-RED software, using the command line, and creating various Node-RED projects involving inputs, functions, outputs and GPIO controls. The document describes projects for displaying text, time, weather data, sensor readings and controlling LEDs to demonstrate Node-RED's capabilities.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Programming with Node-RED

Design IoT Projects with Raspberry Pi,


Arduino and ESP32

Dogan Ibrahim

LEARN DESIGN SHARE


Contents

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

Chapter 1 • Raspberry Pi 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

1.2 Parts of the Raspberry Pi 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

1.3.1 Setup option 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

1.3.2 Setup option 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Chapter 2 • Installing the Raspberry Pi operating system . . . . . . . . . . . . . . . . . . . 20

2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

2.2 Raspbian Buster installation steps on Raspberry Pi 4 . . . . . . . . . . . . . . . . . . . . . . 20

2.3 Remote access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

2.4 Using Putty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

2.4.1 Configuring Putty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

2.5 Remote access of the desktop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

2.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

Chapter 3 • Using the command line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

3.2 The Raspberry Pi directory structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

3.3 File permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

3.4 Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

3.5 Date, time, and calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

3.6 File operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

3.7 System and user information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

3.8 Resource monitoring on Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

3.9 Shutting down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

3.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

Chapter 4 • Installing Node-RED software on Raspberry Pi . . . . . . . . . . . . . . . . . . 41

4.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

4.2 Raspberry Pi Node-RED installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

4.3 Node-RED interface to external world . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

4.4 Node-RED screen layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

4.5 Project 1 – Hello World! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

●5
Programming with Node-RED

4.6 Project 2 – Date and time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

4.7 Project 3 – Temperature conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

4.8 Importing and exporting flow programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

4.8.1 Exporting flows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

4.8.2 Importing aflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

4.9 Copying nodes in the same workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

4.10 Core nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

4.10.1 Input nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

4.10.2 Output nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

4.10.3 Function nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

4.10.4 Social nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

4.10.5 Storage nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

4.10.6 Analysis nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

4.10.7 Advanced nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

4.10.8 Raspberry Pi nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

4.11 Project 4 – Dice number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

4.12 Project 5 – Double dice numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

4.13 Project 6 – Unit conversions - Multiple inputs to a function . . . . . . . . . . . . . . . . 62

4.14 Multiple inputs and multiple outputs from a function . . . . . . . . . . . . . . . . . . . . . 65

4.15 Project 7 – Mean of numbers - Using the smooth node . . . . . . . . . . . . . . . . . . . 67

4.16 Project 8 – Squares of numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

4.17 Project 9 – Getting the weather reports – Display the local weather report . . . . . 70

4.18 Project 10 – Display the current temperature . . . . . . . . . . . . . . . . . . . . . . . . . . 73

4.19 Project 11 – Sending the current temperature to an email . . . . . . . . . . . . . . . . . 74

4.20 Project 12 – Sending the current temperature and atmospheric


pressure to your twitter account . . . . . . . . . . . . . . . . . . . . . . . . . . 76

4.21 Node-RED configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

4.22 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

Chapter 5 • Node-RED based Raspberry Pi projects using GPIO . . . . . . . . . . . . . . 80

5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

5.2 GPIO – Parallel interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

5.3 Project 13 – LED control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

5.4 Project 14 – Flashing LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

●6


5.4.1 Using a context variable to flash the LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

5.5 Project 15 – Alternately flashing LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

5.5.1 Using context variables to flash the LEDs alternately . . . . . . . . . . . . . . . . . . . . 89

5.6 Project 16 – Temperature alarm with buzzer . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

5.7 Project 17 – Controlling a GPIO port remotely using email . . . . . . . . . . . . . . . . . . 93

5.8 Project 18 – Confirmation of the buzzer state . . . . . . . . . . . . . . . . . . . . . . . . . . 95

5.9 Project 19 – Controlling multiple GPIO ports remotely using email . . . . . . . . . . . . 98

5.10 Project 20 – Traffic lights simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

5.11 Project 21 – Push-Button switch input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

5.12 Project 22 – Changing LED brightness – The PWM output . . . . . . . . . . . . . . . . 110

5.13 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

6.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

6.2 Raspberry Pi I2C ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

6.3 I2C LCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115

6.4 Installing the I2C LCD software on Node-RED . . . . . . . . . . . . . . . . . . . . . . . . . . 115

6.5 Project 23 – Displaying current time on the LCD . . . . . . . . . . . . . . . . . . . . . . . . 118

6.6 Project 24 – Displaying local temperature and humidity on the LCD . . . . . . . . . . 120

6.7 Project 25 – Displaying dice numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

6.8 Project 26 – Event counter with LCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

6.9 Project 27 – DHT11 temperature and humidity sensor with LCD Display . . . . . . . 124

6.10 Project 28 – Ultrasonic distance sensor with LCD display . . . . . . . . . . . . . . . . . 129

6.11 Project 29 – Ultrasonic distance alarm with buzzer . . . . . . . . . . . . . . . . . . . . . 134

6.12 Project 30 – Ultrasonic car parking system with buzzer . . . . . . . . . . . . . . . . . . 135

6.13 Using a parallel LCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137

6.14 Project 31 – Displaying message on a parallel LCD . . . . . . . . . . . . . . . . . . . . . 139

6.15 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141

Chapter 7 • Using ADC in Raspberry Pi Node-RED projects . . . . . . . . . . . . . . . . . 142

7.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142

7.2 The MCP3002 ADC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142

7.3 Project 32 – Voltmeter with LCD output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

7.4 Project 33 – Temperature measurement using analog sensor . . . . . . . . . . . . . . . 146

7.5 Project 34 – ON/OFF temperature control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148

●7
Programming with Node-RED

7.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

Chapter 8 • The dashboard palette . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153

8.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153

8.2 Installing the dashboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153

8.3 Project 35 – Using a gauge to display the temperature . . . . . . . . . . . . . . . . . . . 154

8.4 Using a Line Chart to display the temperature . . . . . . . . . . . . . . . . . . . . . . . . . 156

8.5 Using a Bar Chart to display the temperature . . . . . . . . . . . . . . . . . . . . . . . . . . 157

8.6 Project 36 – Using gauges to display the temperature and humidity . . . . . . . . . . 158

8.7 Project 37 – Using multiple gauges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160

8.8 Project 38 – Using a slider to change LED brightness . . . . . . . . . . . . . . . . . . . . 161

8.9 Project 39 – Using button nodes to control an LED . . . . . . . . . . . . . . . . . . . . . . 163

8.10 Project 40 – Using switch and text nodes to control an LED . . . . . . . . . . . . . . . 165

8.11 Project 41 – Talking weather forecast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166

8.12 Configuring the dashboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

8.13 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

Chapter 9 • Wi-Fi UDP/TCP Network-Based projects . . . . . . . . . . . . . . . . . . . . . . 170

9.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170

9.2 Project 42 – Controlling an LED from a mobile phone –


UDP based communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170

9.3 Project 43 – Controlling multiple LEDs from a mobile phone – UDP based
communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173

9.5 Project 45 – Controlling an LED from a mobile phone –


TCP based communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178

9.6 Project 46 – Controlling Multiple LEDs From a Mobile Phone –


TCP Based Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181

9.7 Project 47 – Sending the temperature and humidity to the mobile phone –
TCP based communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

9.8 Project 48 – Chat program – Mobile phone to Raspberry Pi chat . . . . . . . . . . . . . 184

9.9 Project 49 – Using the ping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

9.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189

Chapter 10 • Storage Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190

10.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190

10.2 Project 50 – S
 toring timestamped temperature and
humidity data in a file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190

●8


10.3 Project 51 – Reading contents of a file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192

10.4 Project 52 – Reading a file line by line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195

10.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197

Chapter 11 • Serial communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198

11.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198

11.2 Project 53 – Communicating with Arduino over serial line . . . . . . . . . . . . . . . . 199

11.3 Project 54 – Receiving serial data – Receiving GPS data . . . . . . . . . . . . . . . . . 204

11.4 Project 55 – Receiving GPS data – Extracting the latitude and longitude . . . . . . 208

11.5 Project 56 – Displaying our location on a map . . . . . . . . . . . . . . . . . . . . . . . . 212

11.6 Project 57 – Sending out serial data to arduino . . . . . . . . . . . . . . . . . . . . . . . 216

11.7 Project 58 – Connecting Raspberry Pi and Arduino Uno using USB ports . . . . . . 220

11.8 Project 59 – Sending serial data from Raspberry Pi to Arduino over RF Radio . . . 222

11.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224

Chapter 12 • Using Sense HAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225

12.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225

12.2 The Sense HAT board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225

12.3 Node-RED Sense HAT nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226

12.4 Project 60 - D
 isplaying the temperature, humidity,
and pressure (environmental events) . . . . . . . . . . . . . . . . . . . . . . 227

12.5 Project 61 - Displaying the compass heading (motion events) . . . . . . . . . . . . . 229

12.6 Project 62 - Displaying the acceleration (motion events) . . . . . . . . . . . . . . . . . 230

12.7 Project 63 - Displaying the orientation (motion events) . . . . . . . . . . . . . . . . . . 231

12.8 Using the joystick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233

12.9 Using the LED matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234

12.10 Project 64 – Random flashing LED lights having random colours . . . . . . . . . . . 238

12.11 Project 65 – Display of temperature by LED count . . . . . . . . . . . . . . . . . . . . . 239

12.12 Displaying and scrolling data on LED Matrix . . . . . . . . . . . . . . . . . . . . . . . . . 242

12.13 Project 66 – Scrolling the pressure readings on the LED matrix . . . . . . . . . . . 242

12.14 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244

Chapter 13 • Node-RED with Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245

13.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245

13.2 Installing Node-RED For Arduino Uno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245

●9
Programming with Node-RED

13.3 Project 67 – Flashing LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247

13.4 Project 68 – Displaying the ambient temperature in the debug window . . . . . . . 248

13.5 Project 69 – Displaying the ambient temperature in the dashboard . . . . . . . . . . 250

13.6 Project 70 – Displaying the ambient temperature as gauge and chart . . . . . . . . 251

13.7 Using the Arduino Uno serial port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253

13.7.1 Project 71 – Using the DHT11 with the Arduino . . . . . . . . . . . . . . . . . . . . . . 253

13.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256

Chapter 14 • Using the ESP32 DevkitC with Node-RED . . . . . . . . . . . . . . . . . . . . 257

14.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257

14.2 ESP32 DevKitC and Node-RED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259

14.3 Project 72 – Controlling an LED connected to ESP32 DevKitC . . . . . . . . . . . . . . 259

14.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262

Chapter 15 • Using Amazon Alexa in Node-RED projects . . . . . . . . . . . . . . . . . . . 263

15.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263

15.2 Project 73 – Controlling an LED using Alexa . . . . . . . . . . . . . . . . . . . . . . . . . . 263

15.3 Project 74 – Controlling an LED and a buzzer using Alexa . . . . . . . . . . . . . . . . 265

15.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268

Chapter 16 • Accessing Raspberry Pi Node-RED from anywhere . . . . . . . . . . . . . 269

16.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269

16.2 The ngrok . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269

16.3 Starting Node-RED automatically at reboot time . . . . . . . . . . . . . . . . . . . . . . . 271

16.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271

Chapter 17 • Using Bluetooth with Node-RED . . . . . . . . . . . . . . . . . . . . . . . . . . . 272

17.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272

17.2 Project 75 – Controlling an LED and a buzzer using Bluetooth . . . . . . . . . . . . . 272

17.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276

Chapter 18 • Node-RED and MQTT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278

18.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278

18.2 How MQTT works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278

18.3 The Mosquitto broker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280

18.4 Using MQTT in home automation and in IoT projects . . . . . . . . . . . . . . . . . . . . 281

18.5 Project 76 – Controlling an LED using MQTT . . . . . . . . . . . . . . . . . . . . . . . . . . 282

● 10


18.6 The ESP8266 processor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283

18.7 Project 77 – Flashing an LED using ESP8266 NodeMCU . . . . . . . . . . . . . . . . . . 285

18.8 Using the ESP8266 NodeMCU with MQTT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287

18.9 Project 78 – Controlling an LED using ESP8266 NodeMCU with MQTT –


LED connected to Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . 288

18.10 Project 79 – Controlling an LED using ESP8266 NodeMCU with MQTT – LED
connected to ESP8266 NodeMCU . . . . . . . . . . . . . . . . . . . . . . . 293

18.11 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299

Chapter 19 • Using HTTP in Node-RED projects . . . . . . . . . . . . . . . . . . . . . . . . . . 300

19.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300

19.2 Using HTTP GET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300

19.3 Web server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301

19.4 Project 80 – Controlling 4 Relays using web server . . . . . . . . . . . . . . . . . . . . . 302

19.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308

Appendix A • The function node . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309

A.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309

A.2 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309

A.3 Multiple outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310

A.4 String manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310

A.5 Mathematical functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313

A.6 Number conversions and checking numbers . . . . . . . . . . . . . . . . . . . . . . . . . . 314

A.7 Date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315

A.8 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315

A.9 Conditional statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316

A.10 Repetition (loops) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317

A.12 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319

Appendix B • Flow programs used in the book . . . . . . . . . . . . . . . . . . . . . . . . . . . 321

A.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321

A.2 Using the flow programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321

Appendix C • Components used in the book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323

● 11

You might also like