Introduction to the Internet of Things

Introduction to the Internet of Things

@ProfGastonPerez
@ProfGastonPerez
1 Follower
1 week ago 49
AI Summary
Bulleted
Text
Key Insights
  • Introduces fundamental concepts of the Internet of Things (IoT) and offers hands-on DIY projects.
  • Covers three main development platforms: Arduino, Raspberry Pi, and BeagleBone Black.
  • Presents projects with step-by-step guidance on building home automation systems, temperature monitoring, and remote video viewing.
  • Explores various technologies, such as web servers, databases (MySQL), programming languages (Python, Java), and protocols (MQTT).
  • Provides practical knowledge for integrating sensors, controlling devices, and enabling machine-to-machine communication in IoT applications.

Introduction to the Internet of Things

@ProfGastonPerez1 week ago

1/582
2/582
Copyright © 2015 by McGraw-Hill Education. All rights reserved. Except as permitted
under the Unit…
3/582
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill
Education and its licensors do no…
4/582
This book is dedicated to my wonderful parents, Harry and Esther Norris,
who provided the love and…
5/582
About the Author
Donald Norris has a degree in electrical engineering and an MBA with a specializa…
6/582
7/582
Contents at a Glance
1 Introduction to the Internet of Things
2 Home Temperature Monitoring Syste…
8/582
9/582
Contents
Acknowledgments
Introduction
1 Introduction to the Internet of Things
Raspberry Pi Pla…
10/582
The Sensor Abstract Class
Child Classes
Real-World Controls
Threads
Java Database Connector
Us…
11/582
Testing the Ethernet Connection
Simplified Garage Door Opener
Actual Garage Door Opener
Modified…
12/582
LCD Operational Test
Message Controller Software
Download and Install the Flask Package
Main App…
13/582
14/582
Acknowledgments
Project books such as this one are never created in a vacuum. They are a product o…
15/582
16/582
Introduction
I suppose the genesis of this book was from long-term interest in connecting computer…
17/582
by the use of a very clever Java library named Pi4J.
Chapter 5 covers three projects involving a w…
18/582
approximately 1 GHz, if desired, but that does increase power consumption and heat
generation. The…
19/582
1
CHAPTER
20/582
Introduction to the Internet of Things
This book offers useful projects that you can build and the…
21/582
Raspberry Pi Platform
The Raspberry Pi has been in existence for almost two years at the time of t…
22/582
FIGURE 1-1 Model B, Raspberry Pi board
A cheaper model, A, is available but it does not have an on…
23/582
digital input and/or output to interface with sensors and actuators. All the different
platforms u…
24/582
FIGURE 1-2 GPIO P1
This multi-pin connector will be the gateway through which the Pi will interfac…
25/582
the functions associated with each of the P1 pins for the Model B, rev 2 Pi.
26/582
27/582
FIGURE 1-3 P1 pin functions
I will not review these pin functions at this time but will discuss th…
28/582
your soldering skills. Just don’t add too much solder to the connector pins as they are
close toge…
29/582
monitor, and mouse to the Pi. You will also need a powered USB hub and either a wireless
Wi-Fi ada…
30/582
FIGURE 1-6 Raspberry Pi standalone workstation block diagram
The Pi has both composite and HDMI vi…
31/582
the HDMI output as that provides a much superior video display as compared to the
analog composite…
32/582
FIGURE 1-8 Plugable powered USB hub
Any USB keyboard and mouse combination will suffice for user i…
33/582
FIGURE 1-10 EDIMAX model EW-7811Un USB Wi-Fi adapter
You should note that it is rated at a maximum…
34/582
FIGURE 1-11 Raspberry Pi headless workstation block diagram
The secret to the simplicity of the he…
35/582
adversely affected. However, don’t be deterred if you purchased a Raspberry Pi starter kit
that ca…
36/582
tool must also be extracted before use.
The freshly formatted and NOOBS-loaded SD card has been de…
37/582
38/582
TABLE 1-3 Initial NOOBS Selection Menu
I strongly recommend you select the first menu item, which …
39/582
FIGURE 1-12 Default username and password screen
You will next see the raspi-config introduction s…
40/582
story, and it will likely remain gone unless you have done the backups as suggested.
Clicking OK o…
41/582
TABLE 1-4 raspi-config Menu and Recommendations
There are also seven Advanced Options menu selecti…
42/582
TABLE 1-5 raspi-config Advanced Options Menu and Recommendations
Click the Finish button after you…
43/582
startx
NOTE I will use the symbol from now on to denote the ENTER key.
The Desktop screen should …
44/582
interface software for it to function with a specific OS.
Clicking the LXDE icon button located at…
45/582
FIGURE 1-14 Win32 Disk Imager program executing
Notice the over 17MB/sec transfer rate shown in th…
46/582
FIGURE 1-15 Raspbian raw image file listing
Shown in the list near the bottom is a file named conf…
47/582
FIGURE 1-16 config.txt file content
You will need to uncomment the following line:
#hdmi_force_ho…
48/582
one, with the addition of expanding the filesystem. The NOOBS installation does it
automatically b…
49/582
3. Enter the username and password to get to the control web page. These are
normally shown in the…
50/582
FIGURE 1-17 Initial PuTTY screen
51/582
Your Pi’s IP address will likely be different than the one I entered into the Host Name
block. Als…
52/582
FIGURE 1-18 Opening Pi login screen over the network
Just enter the default username “pi” and the …
53/582
You will now be able to interact with the Pi in exactly the same way as if you were
sitting in fro…
54/582
55/582
FIGURE 1-20 Opening screen for the TightVNC Viewer
Enter your Pi’s IP address in the Remote Host t…
56/582
57/582
FIGURE 1-21 The Raspberry Pi VNC authentication dialog box
Enter the password you created when you…
58/582
connection.
FIGURE 1-23 Launching a terminal window in the Desktop
It really is very cool technol…
59/582
It is very mature, having been created and updated for almost 18 years as of the time of
this writ…
60/582
servers and downloads and installs the new versions along with any and all
dependent software. An …
61/582
FIGURE 1-24 Screenshot resulting from the ifconfig command
As you can see, the local IP address sh…
62/582
appear in the browser confirming that the Apache web server was working.
FIGURE 1-25 First web pag…
63/582
After you have entered the code, save it by simultaneously pressing the CTRL and O
keys. Simply pr…
64/582
When you visit this web page, you must specifically request it or else the default
index.html file…
65/582
FIGURE 1-27 hello.php test results
The remaining step in creating a complete LAMP project is to in…
66/582
not really occupy a lot of memory, so why not increase your options and overall website
reliabilit…
67/582
This would constitute a sample record that would be part of table structure that, in
part, makes u…
68/582
program doesn’t distinguish between capitalized and lowercase commands but other SQL
programs are …
69/582
FIGURE 1-28 SHOW TABLES command screenshot
This figure shows not only the field names and data typ…
70/582
should be entered in case there is no actual value present in the input record. Usually this
is no…
71/582
FIGURE 1-29 tempData table with three records
But take heart—all the book projects use a program t…
72/582
Be cautious as this is a powerful command that will irretrievably delete all the data
records. The…
73/582
If you wish to remove only certain select records, you can use what is known as a
“where_clause”. …
74/582
FIGURE 1-31 tempData table after the DELETE FROM with a where_clause command
The where_clause is a…
75/582
Up until now, I have been logging into the MySQL as “root” using the following
command:
mysql -u …
76/582
FIGURE 1-32 tester 1 error message
This last error check ends this section and chapter. In the nex…
77/582
IoT. I listed the platforms and software that I use in the book projects to demonstrate how
to bui…
78/582
2
CHAPTER
79/582
Home Temperature Monitoring System
The project in this chapter walks you through the steps in buil…
80/582
81/582
FIGURE 2-1 Temperature monitoring system block diagram
Wires were used in the first system design …
82/582
FIGURE 2-2 Analog Devices model TMP36 temperature sensor
83/582
FIGURE 2-3 Model TMP36 functional block diagram
The TMP36 has only three leads, which are shown in…
84/582
TABLE 2-1 TMP36 Pin Details
The voltage representing the temperature is dependent upon the TMP36 s…
85/582
86/582
FIGURE 2-5 Graph of VOUT voltage versus temperature for a +VS = 3V
The actual temperature measurem…
87/582
accomplishes the analog-to-digital conversion process.
Inner Workings of the Microchip MCP3008 ADC…
88/582
which is the largest number that can be represented with 10 bits. Now each increment
increases the…
89/582
FIGURE 2-8 SPI simplified block diagram
These registers may be hardware or software depending upon…
90/582
will then put the MCP3008 CS pin high, ending the ADC process.
Connecting and Testing the MCP3008 …
91/582
FIGURE 2-9 Digital soldering station
Of course, the station is only as effective as the soldering …
92/582
FIGURE 2-11 Good soldering technique
Another issue regarding a good solder joint is the use of lea…
93/582
shows the test schematic for the Pi Cobbler, MCP3008, and TMP36. I connected the
TMP36 Voutlead to…
94/582
FIGURE 2-13 Physical test setup
On the left side of the breadboard, you can see the TMP36 sensor c…
95/582
code that relies on those circuits. Initially you should check to determine if the native SPI
devi…
96/582
97/582
Run the preceding program by entering the following:
sudo python SingleSensorTest, py
Figure 2-14…
98/582
FIGURE 2-14 Initial test results
I put a comment in the code listing explaining that I needed to a…
99/582
to be underreported by approximately 5°C. I also used a non-contact, precision infrared
temperatur…
100/582
FIGURE 2-16 RJ45 connector attached to a breakout board
Next, take three of the boards and attach …
101/582
side breakout board pins with the sensor’s flat side pointing up, as shown in the figure.
FIGURE 2…
102/582
FIGURE 2-18 RJ45 board with an attached TMP36 sensor
You will now need the interconnecting RJ45 ca…
103/582
the temperature to be measured 2°C less than the real temperature. The drop in voltage is
likely d…
104/582
FIGURE 2-19 TMP36 current boost circuit
Instead of building the boost circuit, I found it simpler …
105/582
However, the current boost circuit is likely essential if you plan on setting up a long cable
run …
106/582
FIGURE 2-21 Physical system arrangement
Multiple Sensor Software
The software controlling the mul…
107/582
program’s flexibility but in the interests of simplicity I don’t believe it is too much of a
compr…
108/582
109/582
110/582
FIGURE 2-22 Sample display from the MultipleSensorTest.py program
I also wanted to point out that …
111/582
become quite large and tedious to enter.
I will now change focus slightly and discuss how to creat…
112/582
database in lieu of combination field lookups.
The channelLocation table’s schema is detailed in T…
113/582
CREATE TABLE channelLocation(tchan NUMERIC NOT NULL, tloc
TEXT,
PRIMARY KEY(tchan));
Note that t…
114/582
An open-source Python package named python-mysqldb contains all the libraries
necessary to establi…
115/582
FIGURE 2-23 mysqlTest program results
Running this program has demonstrated how relatively easy it…
116/582
Inserting Data into a MySQL Database Using a Program
I will demonstrate how to insert data into th…
117/582
118/582
119/582
There is a hidden problem with the preceding program in that it will continue to run
without any p…
120/582
121/582
FIGURE 2-24 Portion of sensorTemp records created by the SensorDatabase program
You can also view …
122/582
FIGURE 2-25 SensorDatabase records displayed by the ViewRecords program
I next modified the ViewRe…
123/582
cur.execute(‘SELECT * FROM sensorTemp WHERE tchan = 0’)
I renamed ViewRecords.py to Chan0ViewRecor…
124/582
FIGURE 2-26 SensorDatabase records displayed by the Chan0ViewRecords program
To view the sensor lo…
125/582
Figure 2-27 shows a portion of the output from the program where the location
description is shown…
126/582
127/582
FIGURE 2-27 SensorDatabase records displayed by the ViewRecords program with the
channelLocation t…
128/582
FIGURE 2-28 SensorDatabase records displayed by the ViewRecords program with the
channelLocation t…
129/582
Database Access Using a Web Browser
This is probably one of the easier portions of the project as …
130/582
To run the script on the Pi, you will need to open a web browser on the Pi. Simply
type in the fol…
131/582
132/582
FIGURE 2-29 Portion of the sensorTemp records displayed on the Pi web browser
You should next try …
133/582
134/582
FIGURE 2-30 Portion of the sensorTemp records displayed on a separate networked
computer
Note tha…
135/582
FIGURE 2-31 ChannelSelector form
Nothing will happen regarding database access until the Submit bu…
136/582
Figure 2-32 shows the browser display after channel 0 was selected via the input
form.
137/582
138/582
FIGURE 2-32 Portion of the channel 0 sensorTemp records displayed on a separate
networked computer…
139/582
Note that there are two underscores before and after the words “name” and “main.”
Flask is set up …
140/582
FIGURE 2-34 Console messages from the Flask web server
Flask also supports templates, which is a h…
141/582
Then change directories by entering cd templates.
Now that you are in the proper place, create the…
142/582
Summary
The chapter began with a discussion of a three-sensor home temperature monitoring
system.…
143/582
3
CHAPTER
144/582
Introduction to Object Orientation Programming
(OOP) with Java
To begin your exploration into obj…
145/582
• Racecar
• Plane
FIGURE 3-2 Unknown object
The answer really lies with your life experience. Mo…
146/582
goals in controlling sensors, it is time to examine some fundamental principles underlying
all obj…
147/582
object instantiation. Abstract classes are useful only when used with the inheritance core
princip…
148/582
FIGURE 3-3 Sensor UML class diagram
149/582
The four child classes, namely Dallas_18B20,SEN_12064, SEN_11084, and DEV_12081,
get their names e…
150/582
An interface is a specialized class that contains only methods but no attributes.
Classes using in…
151/582
152/582
FIGURE 3-4 Eclipse screen for the Hello World program
There are several things to discuss concerni…
153/582
There is a problem inherent in this somewhat naive code, which I will point out later
in the discu…
154/582
The method Dallas_18B20() is known as a constructor and is called any time a new
object is created…
155/582
The test class shown is named TestSensors and is the only class in the package that
contains the m…
156/582
The Console output for this test class is shown in Figure 3-5. It should be easy to see
how messag…
157/582
FIGURE 3-5 Console output for the TestSensors class
The following is an example of sending a messa…
158/582
159/582
FIGURE 3-6 Sensor class diagram with interfaces
Don’t be deterred by the apparent complexity shown…
160/582
There are also two new methods in this class: performCommand() and performData()
will be used in t…
161/582
I have set the interface references commandBehavior and dataBehavior to TempStart and
XferTemp chi…
162/582
following listing. It is associated with the commandBehavior interface, which can readily
be seen …
163/582
The Console output generated by executing the preceding
TestSensorsWithInterfaces program in the E…
164/582
FIGURE 3-7 Console output for the TestSensorsWithInterfaces class
The previous discussion was leng…
165/582
the patterns early on, you will develop good code design practices that will help you in all
your …
166/582
167/582
FIGURE 3-8 Console output for the TestSensorsWithInterfacesDynamic class
Some additional text, “Th…
168/582
actually interfacing with real sensors. In the next chapter, I will be using code that will
direct…
169/582
There is now much greater flexibility using the Runnable interface as the target class
may now ext…
170/582
What follows now are transcribed snippets from the Console displays. I did this to
minimize the nu…
171/582
controls the threads. A thread scheduler within the JVM controls when threads are run and
when the…
172/582
Notice that the JobA thread sleeps for 50 ms and the JobB thread sleeps for 100 ms.
This yields th…
173/582
ms.
Java provides yet another way of controlling thread behavior to some degree: method
synchroni…
174/582
FIGURE 3-9 Terminal window for starting and logging into the MySQL server
I next selected a databa…
175/582
176/582
FIGURE 3-10 Terminal window showing the database procedural steps
Incidentally, you can log off My…
177/582
178/582
Figure 3-11 shows the console output that results from executing the program. Notice
that the reco…
179/582
FIGURE 3-11 Console output that results from executing the program.
180/582
These two declarative statements set up references for Connection and Statement
objects, which are…
181/582
id, tdate, and ttime now hold the current values from the selected record. They have to
be convert…
182/582
This concludes my introduction to a Java database connector, which is all that you
really need bef…
183/582
You are now well prepared to tackle the next chapter’s Java-based project.
184/582
______________
1 Gamma, Helm, Johnson and Vlissides, Design Patterns, Addison-Wesley Pub.,
1995
185/582
4
CHAPTER
186/582
Home Weather Station
This chapter’s project will show you how to build a home weather station that…
187/582
FIGURE 4-1 Raspberry Pi 26 pin GPIO header connector
A GPIO pin is a single-bit digital port, whic…
188/582
an output, depending upon how it has been configured. The voltage levels that can be
applied as an…
189/582
FIGURE 4-2 Ribbon cable attached to the Raspberry Pi’s P1 connector
I have provided Table 4-1 for …
190/582
TABLE 4-1 GPIO Pin Descriptions
Neither the BCM2835 or the RasPi pin labels are used in this chapt…
191/582
192/582
TABLE 4-2 P1 GPIO Connector
Please note the differences between board revisions 1 and 2, shown as …
193/582
194/582
FIGURE 4-3 P1 GPIO pin connector
You should crosscheck your connections with Table 4-2 and Figure …
195/582
196/582
FIGURE 4-4 Additional GPIO pins available for expansion
Table 4-3 describes all these additional p…
197/582
FIGURE 4-5 P5 GPIO pin expansion connector
Figure 4-6 is an excellent reference diagram that was t…
198/582
FIGURE 4-6 P5 connector pins with labels
Interrupts
Java programs created to interface with senso…
199/582
Every GPIO pin can also accommodate an interrupt. An interrupt is an event that stops or
“interrup…
200/582
developer named Robert Savage, who freely made available a fairly complete Java class
library that…
201/582
two new subdirectories (lib and examples) created within it as follows:
/opt/pi4j/lib
/opt/pi4j/e…
202/582
203/582
204/582
The statement
final GpioController gpio = GpioFactory.getInstance();
is an excellent representati…
205/582
working as planned.
The main operating code in this class is a forever loop as shown here:
This a…
206/582
FIGURE 4-8 Blink program test schematic
The schematic shows both the header pin numbers and the wi…
207/582
FIGURE 4-9 Physical setup for the Blink program
208/582
I ran the blink program for a short time and observed that the LEDs did blink as
programmed and th…
209/582
Pi if you have been successful in completing all the previous steps. The following sections
demons…
210/582
TABLE 4-4 I2C Signal Lines
The I2C bandwidth is fairly low, with 400 Kbps maximum and 100 Kbps
no…
211/582
FIGURE 4-12 SEN_11824 connections
212/582
FIGURE 4-13 SEN_11824 with header pins attached
Figure 4-14 is a block diagram showing how the Pi …
213/582
FIGURE 4-14 Weather system block diagram
214/582
215/582
FIGURE 4-15 Physical test system setup
Everything from this point on depends upon the software, wh…
216/582
FIGURE 4-16 Screenshot for the i2cdetect command
It is now time to create a Java program, which wi…
217/582
measurement data. The BMP180 pressure/temperature sensor that is mounted on the
SEN_11824 BoB uses…
218/582
The following is the SEN_11824 class source code. Notice that the constructor has an
integer argum…
219/582
220/582
221/582
222/582
223/582
This class is quite lengthy and I considered separating the calibration portion into a
separate cl…
224/582
The other DataBehavior child class is named XferPres. The XferPres is similar to
the XferTemp clas…
225/582
226/582
227/582
228/582
229/582
230/582
The methods getCal() and read() perform similar functions for the XferPress class
as the identical…
231/582
Figure 4-17 is a screenshot of the TestTemp1 program output after running for
several minutes. And…
232/582
FIGURE 4-17 TestTemp1 program output
Thermostatic Application
In this section, I describe how to …
233/582
monitored by the BMP180 sensor. A GPIO pin will be set high if the measured
temperature is below t…
234/582
235/582
Figure 4-18 shows the screenshot from the PiThermostat program with two set points
separately ente…
236/582
237/582
FIGURE 4-18 PiThermostat program output
I also observed the LED turn on when the set point was set…
238/582
FIGURE 4-19 Browser screenshot for the initial SPInput PHP program
FIGURE 4-20 After clicking the …
239/582
The following is the code for the displaySP.php program, which is executed when the
Submit button …
240/582
241/582
242/582
Figure 4-21 shows the Pi’s screen when the RemotePiThermostat program was run.
Note that the syste…
243/582
FIGURE 4-21 RemotePiThermostat program output display
Database Classes
It is now time to discuss …
244/582
the Java database connector. The obvious first step is to define the MySQL schema or
structure. I …
245/582
I next ran a simple adaptation of the Pi TestTemp1 program, which I named
TestTemp to check if all…
246/582
247/582
FIGURE 4-22 Eclipse TestTemp program output
I next created a client class named FillDB2 that conta…
248/582
Figure 4-23 shows a portion of the sensorMeasurement table contents after the
program had run for …
249/582
250/582
FIGURE 4-23 Portion of the sensorMeasurement table records
At this point, I have demonstrated that…
251/582
252/582
The client class, which is shown next, will instantiate all the required objects, collect
the meas…
253/582
increased during this period.
254/582
255/582
FIGURE 4-24 First 20 and last 20 records from the sensorMeasurement table
Remote Access to the HWS…
256/582
5
CHAPTER
257/582
Webcam and Raspberry Pi Camera Projects
Remotely accessing webcams is a fairly common activity tha…
258/582
FIGURE 5-1 Logitech C920 webcam
This a high-definition camera capable of producing excellent video…
259/582
one of the Pi’s USB ports and then type the following into a command line:
lsusb
Figure 5-2 is a …
260/582
FIGURE 5-2 lsusb output screenshot
Note that I have found this particular webcam to be somewhat se…
261/582
Motion Software Package
I selected an open source software package named Motion to enable remote v…
262/582
Again, be a bit patient as this package is over 20MB in size and has many component
parts.
Motion…
263/582
One nice feature of having the Motion web server running as a daemon is that it is
automatically s…
264/582
FIGURE 5-3 Router Attached Devices list
265/582
The entry RASPBERRYPI has the IP 192.168.1.43 on the wired portion of my home
network. This is all…
266/582
267/582
FIGURE 5-4 Video screen capture from the Pi webcam
This completes the first webcam project, which …
268/582
FIGURE 5-5 Raspberry Pi camera
This camera was specifically designed to operate solely with the Pi…
269/582
connector is for the display serial interface (DSI), which is designed to work with a
display devi…
270/582
I would like to now discuss the Pi camera hardware and its properties before
discussing the camera…
271/582
photograph taken of a Beaglebone Black development board using the preceding
command.
FIGURE 5-7 …
272/582
FIGURE 5-8 Pi Camera stand with a camera holder support
There is also a substantial amount of meta…
273/582
274/582
FIGURE 5-9 Test photograph metadata
The raspistill application has many more options, which I have…
275/582
Start Python and enter the following commands to test the library and see how well it
functions wi…
276/582
FIGURE 5-10 Composite image of six sequential images
You will quickly realize that the 10-second i…
277/582
TABLE 5-3 Pi Camera Properties with Default Values
I recognize that many readers will not know wha…
278/582
regarding the Pi Camera, its properties, operational modes, and a lot more. Best of all, just
abou…
279/582
sudo unzip mjpg-streamer-code-182.zip
5. You now need to compile some of the many downloaded and e…
280/582
281/582
FIGURE 5-11 Initial MJPG-Stream screen capture
The last paragraph in Figure 5-11 states:
“The ima…
282/582
283/582
FIGURE 5-12 Result of clicking on the initial snapshot
So far, so good. What I really wanted was t…
284/582
FIGURE 5-13 One of the continuing streamed pictures from MJPG-Streamer
The streamed pictures may a…
285/582
8. Replace the motion.conf file found in the /etc directory to this one, which you
can download fr…
286/582
FIGURE 5-14 MacBook screen capture of the Safari browser connected with the Motion
web server
Thi…
287/582
program that automatically takes a series of time-lapsed still pictures and stores them on
the SD …
288/582
6
CHAPTER
289/582
Internet-Enabled, Arduino Powered Garage Door
Opener
This chapter’s project will use the classic …
290/582
FIGURE 6-1 Arduino Uno rev 3 board
You can quickly identify rev 3 boards as the reset button was r…
291/582
TABLE 6-1 Arduino Uno Key Specifications
Don’t be concerned if you do not understand some of the s…
292/582
underlying the Arduino boards.
Ethernet Shield Board
Figure 6-2 shows the Ethernet Shield board t…
293/582
FIGURE 6-2 Ethernet Shield board
The word “shield” in the board title simply refers to any one of …
294/582
295/582
FIGURE 6-3 W5100 block diagram
It is important to point out that while the W5100 chip does contain…
296/582
297/582
FIGURE 6-4 Arduino IDE startup screen
The IDE automatically created a default sketch entitled sket…
298/582
299/582
FIGURE 6-5 Blink code
I’m including the following Blink code in order to point out some key progra…
300/582
Compile and upload the changed program by pressing the right-facing arrow and watch
the LED slowly…
301/582
FIGURE 6-6 Ethernet Shield attached to the Uno
Next, connect the Uno’s power and USB cables and al…
302/582
have configured your LAN. In my case, I connected to a 10/100 switch that is on my
development wor…
303/582
selections: Open | Examples | Ethernet menu.
All the current Ethernet library menu selections are …
304/582
FIGURE 6-8 IP address displayed
My network router assigned a 192.18.1.29 IP address to the Uno/Eth…
305/582
come with any sticker showing the actual firmware mac address assigned to the chip. I
think this s…
306/582
Floating input voltage = 5.0 * (300 / 1023) = 1.47V
I soldered a jumper wire between ground and th…
307/582
operating as I expected to see a 0V level when I next opened a browser to the WebServer
page. My e…
308/582
LED’s cathode to ground. Figure 6-12 shows the physical setup. Note that I soldered wires
directly…
309/582
310/582
311/582
312/582
313/582
The code starts with two include statements that refer to all the dependencies
necessary for this …
314/582
FIGURE 6-13 The client after it has connected to the Uno’s web server program
The loop method will…
315/582
system before proceeding with the actual project.
Actual Garage Door Opener
In this section I wil…
316/582
FIGURE 6-14 Garage door opener
I believe this opener is fairly typical of the garage door openers …
317/582
FIGURE 6-15 Garage door opener connection terminals
If you refer to Figure 6-14, you can see these…
318/582
normally open contacts. Figure 6-16 is a schematic for this straightforward control circuit.
Almos…
319/582
easy modification if necessary. Both the breadboard and the Uno board were mounted in a
plastic ca…
320/582
321/582
FIGURE 6-17 Uno and relay switcher mounted in plastic case
I ran both power and an Ethernet cable …
322/582
323/582
324/582
325/582
Figure 6-18 shows the browser connected to the Uno web server for this door opener
program.
326/582
FIGURE 6-18 The browser display for the garage door opener
Selecting the checkbox either opened or…
327/582
not use this garage door software with an open Wi-Fi connection. You might as well hang
your house…
328/582
FIGURE 6-20 Visual Studio 2012 IDE
The second software item is the Arduino IDE, which you have lik…
329/582
Follow the website installation instructions to initially set up the MegunoLink Pro
software. You …
330/582
331/582
FIGURE 6-21 MegunoLink Pro build-tool installation
You will need to enter the directory location f…
332/582
file extension.
3. Select OK.
Figure 6-23 shows the HelloArduino project screen with the source c…
333/582
the F7 function key to do an immediate build. The compiled code that is first created uses
the pro…
334/582
dialog box.
3. Select the solution file (Garage Door Opener.sln).
4. Select OK.
Figure 6-24 show…
335/582
explanation of all these files as that would be well beyond the scope of this chapter and
book. Ho…
336/582
FIGURE 6-25 Include file list
The source code will be displayed in the VS2012 main editor window. …
337/582
338/582
I only changed the constant LOCAL_IP_ADDRESS to match the Uno’s assigned IP
address as I have prev…
339/582
FIGURE 6-26 MegunoLink Pro password configuration
You need first to select the initialize button, …
340/582
Testing the Enhanced Garage Door Opener
The newly programmed Uno with the relay switching circuit …
341/582
FIGURE 6-28 Garage door activation web page
Selecting the Activate Door button either opened or cl…
342/582
FIGURE 6-29 iPad access to garage door opener
This concludes the garage door opener project, which…
343/582
the Uno. Incidentally, no additional parts were required for this demonstration as the
program mak…
344/582
7
CHAPTER
345/582
Arduino Irrigation Control System
This chapter’s project will use the Uno development board with a…
346/582
FIGURE 7-1 Home irrigation block diagram
This system is relatively uncomplicated wherein the contr…
347/582
Figure 7-2 shows the irrigation controller.
FIGURE 7-2 Home irrigation system controller
348/582
In the figure you can also see a wireless rain sensor module located above the
controller, which s…
349/582
350/582
FIGURE 7-3 Arduino development board
I purchased two inexpensive, 4-channel relay-switching module…
351/582
FIGURE 7-5 Arduino-controlled irrigation system block diagram
I need to discuss the new Uno contro…
352/582
The new program uses the same Ethernet connectivity logic that was used in the garage
door opener …
353/582
354/582
355/582
356/582
357/582
358/582
359/582
The logic to find which zone is selected is to match the beginning portion of the
HTTP request str…
360/582
361/582
FIGURE 7-7 Physical installation
The relay modules were connected to the zone water solenoids by s…
362/582
FIGURE 7-8 Zone water solenoid interconnections
CAUTION The wire currently in the existing solenoi…
363/582
FIGURE 7-9 Ribbon cable to relay module connections
The connections made to the 24VAC transformer …
364/582
FIGURE 7-10 24VAC transformer connections
You can even connect two 12VAC bell transformers in seri…
365/582
which is needed to operate the solenoids.
The Uno must also be connected to a 7-12V DC supply alon…
366/582
FIGURE 7-11 Moisture sensing subsystem block diagram
You should immediately notice from the block …
367/582
FIGURE 7-12 XBee Pro transceiver
There are two rows of 10 pins on each side of the module. These p…
368/582
FIGURE 7-13 XBee Arduino Shield
This shield contains all the functionality needed to effectively i…
369/582
you can see in Figure 7-14.
FIGURE 7-14 Close-up of the XBee electronics case
370/582
If you look closely at the figure, you should see the bottom of the antenna wire,
which is located…
371/582
TABLE 7-1 Freescale MC13192 Features and Specifications
The XBee module implements a full network …
372/582
perspective, it means that there must also be a microprocessor present in the electronics
case. Fr…
373/582
FIGURE 7-15 Logical XBee pinout diagram
All the pin and function descriptions are shown in Table 7…
374/582
375/582
TABLE 7-2 XBee Pin Descriptions and Functions
A considerable number of functions are available to …
376/582
377/582
FIGURE 7-16 Moisture sensor
It is a simple design consisting of two, one-foot-long, one-quarter-in…
378/582
FIGURE 7-17 Soil moisture calibration setup
I added water to the pail to change the soil compositi…
379/582
condition and recorded the resistance for each stage. Figure 7-18 is the result of this
calibratio…
380/582
FIGURE 7-18 Soil resistance versus soil condition chart
381/582
I estimated that irrigation should be started once the sensor resistance level is
measured at 40KΩ…
382/582
FIGURE 7-19 Sensor equivalent circuit
It turns out that 1.6 KΩ is the closest standard resistor va…
383/582
FIGURE 7-20 Soil moisture sensor schematic
Note that I included a 12VDC solar panel in the design …
384/582
385/582
FIGURE 7-21 Moisture sensor system
Figure 7-22 shows the interior of the enclosure where you can s…
386/582
FIGURE 7-22 Interior of the moisture system enclosure
NOTE I did not install the system outdoors u…
387/582
test all the outdoor components on a bench top before proceeding to install them
outdoors.
Moistu…
388/582
FIGURE 7-23 XBee jumpers in the USB position
This program reads the ADC value and then selects a n…
389/582
TABLE 7-3 Soil Moisture Zones
I do recognize that these categories may not be very precise, but th…
390/582
391/582
FIGURE 7-24 Transmitter calibration setup
This allowed me to vary the ADC input voltage, simulatin…
392/582
Figure 7-25 is a schematic for this receiver’s calibration test circuit, which must be
used with t…
393/582
rotation. Recheck your receiver wiring if you do not see the LEDs blink on and then off as
the pot…
394/582
395/582
FIGURE 7-27 XBee receiver module connected to Arduino development board
A revised control program …
396/582
397/582
398/582
399/582
400/582
401/582
I next used the calibration circuit to send various simulated soil conditions and
checked the corr…
402/582
FIGURE 7-28 Browser screenshot—Very dry condition
I then increased the voltage to the mid-point an…
403/582
you install it. I did find that my local bird population seemed to like “bombing” the solar
panel,…
404/582
control function via the Web.
The moisture sensor capabilities can also be easily extended to incl…
405/582
406/582
FIGURE 7-31 Mini soil moisture probe
The electronics portion seen on the left-hand side of the fig…
407/582
The chapter ended with some suggested enhancements, including a possible potted
plant monitoring s…
408/582
8
CHAPTER
409/582
Arduino Lighting Controller
This chapter’s project will use the Uno board with an Ethernet Shield …
410/582
411/582
FIGURE 8-1 System block diagram
The controller node is the key system component that supports mult…
412/582
9600 baud rate. The Transparent operational mode allows either XBee S1 or S2
radios to seamlessly …
413/582
ZigBee networks will normally have only one coordinator node and two or more
end nodes. There coul…
414/582
that the XBee jumpers located on the XBee Shield are set in the USB position. I
discussed these ju…
415/582
416/582
FIGURE 8-4 Controller node
However, there is a serious issue that requires a minor modification of…
417/582
must be soldered onto the Ethernet Shield’s ICSP solder points such that the XBee Shield
can be po…
418/582
FIGURE 8-7 Soldered ICSP extension pins
After soldering these pins, you are all set to finish buil…
419/582
FIGURE 8-8 Ethernet Shield board
You probably already noticed that this Ethernet Shield board is d…
420/582
for what appears to be the same board. I don’t think you should pay more than $20USD
for this boar…
421/582
FIGURE 8-9 Controller node case
Its overall dimensions are 125mm × 175mm × 75mm, which is more tha…
422/582
especially for homes with small children present.
I next mounted the controller stack on a piece o…
423/582
424/582
FIGURE 8-10 Controller node mounting arrangement
The Uno board and a small, solderless breadboard …
425/582
Figure 8-12 shows the interior of the controller node with all the components
mounted and wired. T…
426/582
I will defer discussing the program that runs this node until I complete my coverage
of the remain…
427/582
428/582
FIGURE 8-13 Four-channel key fob
The channels are labeled A through D on the fob. The fob RF trans…
429/582
430/582
FIGURE 8-14 RF four-channel latching receiver
The receiver may be purchased from Adafruit Industri…
431/582
I found it very useful to use jumper wires to make all the interconnections between
the breadboard…
432/582
433/582
FIGURE 8-16 Uno XBee receiver node
It is identical to the moisture sensor transmitter node that I …
434/582
FIGURE 8-17 XBee receiver node case
I mounted the XBee receiver node stacks on Lexan sheets just a…
435/582
436/582
FIGURE 8-18 XBee receiver node mounting arrangement
I didn’t add any measurements to this figure a…
437/582
438/582
FIGURE 8-19 XBee receiver node interior
PowerSwitch Tail II
The PowerSwitch Tail II is a power co…
439/582
FIGURE 8-20 PowerSwitch Tail II
It is essentially a power cord that is controlled by a low-level d…
440/582
be directly connected to an Uno’s GPIO pin. The PowerSwitch Tail II, which I will now
refer to as …
441/582
FIGURE 8-22 Uno XBee receiver node to PST2 schematic
Not much is required for the connection other…
442/582
part of the Ethernet Shield. I will discuss this HTML file after I discuss the main program.
443/582
444/582
445/582
446/582
447/582
448/582
I know this is a long code listing, but much of it is involved with LED states and
status, which i…
449/582
leave this bit of code in place as it didn’t slow the program and I have included some
project enh…
450/582
preceding code except that the values used are 3 and 4 instead of 1 and 2. I suggest
identifying t…
451/582
The test sequence, which I have detailed here, is fairly easy to follow:
1. Ensure that all the no…
452/582
Attaching a light intensity sensor to the A2 analog input could also enable a feature
by which a u…
453/582
9
CHAPTER
454/582
BeagleBone Black Message Controller
This chapter’s project will use the BeagleBone Black (BBB), wh…
455/582
FIGURE 9-1 BBB top view
The first board in the series leading up to the BBB was known simply as the
456/582
BeagleBoard. It was a design project that was begun in 2007 by the non-profit
BeagleBoard.org whos…
457/582
at very fast 1 GHz clock speed and have 4GB of onboard flash memory in which the
Linux OS is store…
458/582
FIGURE 9-2 Micro SD memory cardholder
A 4GB, FAT-formatted, micro SD card may be inserted into the…
459/582
possible to overwrite the OS stored in the flash memory with a new or different version if
that is…
460/582
461/582
FIGURE 9-3 Pluggable USB 2.0 7-port hub
I have found that this particular hub model provides suffi…
462/582
FIGURE 9-4 Initial Debian Desktop screen
NOTE You should not have the Run dialog box appear. I jus…
463/582
mini USB connector and then into the laptop. A new disk icon should appear on the
laptop’s Desktop…
464/582
465/582
FIGURE 9-5 BeagleBone 101
You should explore this web page to learn about the BBB and how to progr…
466/582
The prompt shows that you connect as the root user, which means you now have total
control of the …
467/582
FIGURE 9-7 SSH over Ethernet connection
Windows users should use the PuTTY application and enter b…
468/582
two 46-pin sockets aligned at the top and bottom edges. The pins are in groups of two with
pin num…
469/582
470/582
FIGURE 9-8 P8 and P9 pin headers
As you can readily see, a significant number of GPIO pins are ava…
471/582
FIGURE 9-9 TRM P9 header table
I have also used a Python library that preconfigures the GPIO pins …
472/582
I used a generic 16 × 2 LCD display wired to the BBB to show a brief text message
received from a …
473/582
474/582
FIGURE 9-11 LCD to BBB interconnection schematic
The next step is to load some test software once …
475/582
476/582
FIGURE 9-12 Test result
Please recheck your jumper wire interconnections if you do not see the exp…
477/582
FIGURE 9-13 Directory structure
The primary or main application is based upon the Python testLCD.p…
478/582
Much of the code is concerned with interfacing with the HTML code that creates the
web page where …
479/582
The index.html code is dependent on additional code that is contained in the
base.html file. Reade…
480/582
This file is created with the Jinja2 script; it also contains references to JQuery Mobile
librarie…
481/582
FIGURE 9-14 Laptop browser screen
Note that the message that was sent is also shown at the bottom …
482/582
FIGURE 9-15 LCD display for message sent from laptop
You can see clearly that some of the trailing…
483/582
displayed on the second line. Obviously, any characters beyond 32 cannot be displayed
with a 16 × …
484/582
FIGURE 9-16 Android smartphone browser screen
This time I intentionally kept the message very shor…
485/582
The last demonstration involved sending a message from an iPad connected to the
LAN. Figure 9-18 s…
486/582
FIGURE 9-19 LCD display for message sent from an iPad
This last demonstration concludes the BBB me…
487/582
the BBB. I demonstrated a simple Python script to test the BBB to LCD display interface
to show th…
488/582
10
CHAPTER
489/582
BeagleBone Black with Cloud Service
This chapter’s project will demonstrate how to connect a Beagl…
490/582
FIGURE 10-1 TMP36 to BBB connection schematic
Only three connections are required: 5V, output sign…
491/582
encountered when using this project in a typical residence or office environment.
Figure 10-2 show…
492/582
493/582
FIGURE 10-2 Physical system
Nothing else was required from the hardware prospective, so all that’s…
494/582
The program is very simple in that it converts a voltage applied to the P9_40 ADC
input every seco…
495/582
FIGURE 10-3 Test program output
The next step in this project is to connect a cloud service once t…
496/582
Xively is the latest version of a data-based cloud service that began in 2007 as a UK
startup know…
497/582
You are now ready to create the Python program, which will run on the BBB and
send temperature dat…
498/582
If you are the root level, you run the program by entering this:
python xively-temp.py
Non-root u…
499/582
FIGURE 10-4 Terminal console display for the xively-temp.py program
You should now go to the Xivel…
500/582
I used my MacBook Pro browser to go to the Xively website and observe the active
data streaming. F…
501/582
FIGURE 10-6 Temperature vs. time graph
502/582
FIGURE 10-7 Specific data and time values
This data set was taken from a sensor located in my offi…
503/582
There is also an HTTP Request Log window shown on the Workbench just to the
right of the graph win…
504/582
Additional TMP36 Sensors
The TMP36 sensor connection system was designed from the beginning to be …
505/582
506/582
FIGURE 10-9 Expanded TMP36 to BBB connection schematic
I also used a longer cat5 cable to connect …
507/582
508/582
FIGURE 10-10 Expanded physical system
I next created an expanded test program to prove that all th…
509/582
FIGURE 10-11 Expanded test program output
It is time to work on an expanded xively-temp program no…
510/582
I named the expanded xively-temp program ExpandedXively.py; it is essentially the
same as the orig…
511/582
Note that all three Datastream function calls are all contained in the same set of
square brackets…
512/582
FIGURE 10-12 Current values for three channels
You should notice from the Request Log that only on…
513/582
FIGURE 10-13 Outdoor temperature channel graph
Configuring Angstrom to Auto Start the Application
…
514/582
4. Save and exit the nano editor.
5. You use an Angstrom Linux command called systemctl to enable,…
515/582
FIGURE 10-14 xively-logger status
One interesting artifact that I discovered while testing this se…
516/582
FIGURE 10-15 Systemctl status displays immediately after a reboot
Now, the ExpandedXively.py progr…
517/582
located in the same /lib/systemd/system directory as is the xively-logger.service file.
Using the …
518/582
519/582
FIGURE 10-16 BBB and RJ45 connectors mounted on Lexan board
The bottom of the plastic case must ha…
520/582
FIGURE 10-18 Complete assembly
This section wraps up this chapter’s project and it is time to move…
521/582
I reviewed some basic facts about the analog TMP36 temperature sensor, which I
first used in the C…
522/582
11
CHAPTER
523/582
Machine-to-Machine (M2M) Communications
The focus of the chapter, as its name implies, is machine-…
524/582
FIGURE 11-1 Project block diagram
There is a block named MQTT Broker located between the BeagleBon…
525/582
broker on behalf of the publisher. It is obviously the quickest message delivery
method, but it is…
526/582
Initially, I just need to demonstrate the temperature-monitoring program without any
messaging fea…
527/582
FIGURE 11-2 Physical hardware setup
Figure 11-3 shows the terminal display after I entered the fol…
528/582
FIGURE 11-3 Terminal screen showing the tmp36.py program output
sudo python tmp36.py
This figure …
529/582
adding the messaging features into the application. Please follow these steps to load the
Python l…
530/582
incoming messages from the broker.
The following two statements contain references to what are kno…
531/582
FIGURE 11-4 Terminal screen showing the mqttTMP36.py program output
The data in the mqttTMP36.py p…
532/582
The web server located at m2m.eclipse.org is a public sandbox hosted by the Eclipse
Foundation as …
533/582
TABLE 11-2 Public MQTT Brokers
The HTTP bridge is one of the features in the m2m.eclipse.org broke…
534/582
to show you in the next section, that provides an interesting insight into the popularity of
the M…
535/582
FIGURE 11-8 MQTT Dashboard
In the Recently used Topic box, you can see my mv and f topics as well …
536/582
a published topic. The Last Message box on the lower-left side of the figure shows one of
my publi…
537/582
FIGURE 11-9 MQTT Dashboard screen
538/582
I have included this figure to point out the public nature of these MQTT brokers,
which allow your…
539/582
MqttClient.generateClientId());client.connect();
Notice that one of the arguments in the instantia…
540/582
definition named PahoMqttSubscribe.java. You should use the nano editor to enter it or
download it…
541/582
class file.
1. Enter the following while in a Raspberry terminal window:
curl -O https://repo.ecl…
542/582
FIGURE 11-10 Raspberry Pi subscriber client terminal screen
This last step completes the initial M…
543/582
method named messageArrived. The next part of this M2M demonstration project is to
slightly expand…
544/582
545/582
546/582
I have really only added some new functionality to the messageArrived method
where the payload val…
547/582
548/582
FIGURE 11-11 Two-phase thermostat terminal display
This last figure concludes this M2M demonstrati…
549/582
550/582
Index
Please note that index links point to page beginnings from the print edition. Locations
are…
551/582
authentication in VNC, 20–22
auto starting applications, 302–305
B
backups, 11
bandwidth of IC2…
552/582
BBB, 267–269
garage door opener project, 173–176
lighting controller, 247, 250
braces ({}) in Ja…
553/582
Python with, 163–165
remote viewing, 165–169
software, 160–163
camera serial interface (CSI) con…
554/582
Configuration.h file, 199–201
Connection Manager, 195–196
Connection object, 102–103
connections…
555/582
home weather station classes, 142–150
Java connections, 98–104
MySQL installation, 27–28
tempera…
556/582
EDIMAX EW-7811Un adapter, 6–7
Elev-8 quadcopter, 158
.elf file extension, 197
encapsulation in O…
557/582
forName() method, 102
Freescale MC13192, 218–219
FTDI driver utility, 243
full duplex communicat…
558/582
gold plated electrical contact surfaces, 45
GPIO. See general purpose input output (GPIO)
GpioCon…
559/582
home temperature monitoring system, 37
Flask platform, 71–74
MCP3008 connections and testing, 43–…
560/582
OOP, 79–80
threads, 94
initialization code for interrupts, 114
Input Channel Multiplexers, 41
I…
561/582
moisture sensing subsystem, 216–235
operating, 216, 235
program, 209–212
“is a” relationships, 8…
562/582
late binding, 92
LCD display for message controller
operational test, 279–280
setting up, 277–27…
563/582
Logout option, 13
loop() method
garage door opener project, 178–179, 185–187, 191–192
irrigation…
564/582
MJPG Streamer application, 165–169
mkdir command, 47, 73
moisture sensing subsystem
design, 222–…
565/582
multi-drop networks, 122
multiple sensor system
building, 49–53
software, 53–56
MultipleSensorT…
566/582
P
Pachube company, 292–293
Paho project, 309
PahoMqttSubscribe class, 319–323
PahoMqttSubscribe…
567/582
polling, 114–115
polymorphism in OOP, 79
POST method, 69
power and power supplies
BBB, 272
gar…
568/582
python-mysqldb package, 58–60
python-picamera library, 163
Q
Quality of Service (QoS) in MQTT pr…
569/582
receivers in lighting controller, 248–250
reconnecting in MQTT protocol, 311
records in databases…
570/582
S1 firmware, 240–241
S2 firmware, 240–241
safety features for garage door opener, 193
Sample and…
571/582
setDataBehavior() method, 91–92
setDescription() method, 84
setLEDs() method, 259–260
setName() …
572/582
SPData.txt file, 140
SPI (serial peripheral interface) protocol, 39, 42–43
SPInput.php program, 1…
573/582
sudocp command, 170
sudonano command, 156
synchronization methods, 98
system software for lighti…
574/582
remote setting, 138–150
two-phase, 323–325
Thread class, 95
ThreadDemo class, 94–96
threads
Mo…
575/582
Linux software, 23
Upton, Eben, 2
USB tether mode for BBB, 272
USE command, 57
usernames, 10, 1…
576/582
viewing in, 157–158
webLCD.py program, 281–283
WebServer program, 180–182
Wheezy distribution, 2…
577/582
website, 295–297
Xively Developer Workbench, 293
xively-logger.service, 302–303
xively-temp.py p…
578/582
Table of Contents
Title Page
Copyright Page
Dedication
About the Author
Contents at a Glance
…
579/582
Summary
3 Introduction to Object Orientation Programming (OOP) with Java
Java Software Developmen…
580/582
Arduino Uno Software
Testing the Ethernet Connection
Simplified Garage Door Opener
Actual Garage…
581/582
Message Controller Software
Download and Install the Flask Package
Main Application
HTML Code
T…
582/582


  • Previous
  • Next
  • f Fullscreen
  • esc Exit Fullscreen
@ProfGastonPerez

Share

Introduction to the Internet of Things

Embed code

Report Inappropriate Content on Jaunt

Choose the reason you are reporting: Introduction to the Internet of Things as inappropriate to Jaunt's content team.


Swipe LEFT
to view Related

Scroll DOWN
to read doc

We, and our third-party partners, use cookies, pixels, and other technologies (“cookies”) to collect, record, and share information you provide, as well as information about your interactions with, our site for ad targeting, analytics, personalization, and site functionality purposes. By clicking Allow All, you agree to the use of tracking technologies and acknowledge our privacy practices as described in our Privacy Notice.

Cookies to automatically collect, record, and share information about your interactions with our site for analytics purposes.
Cookies used to enable advertising on our site.

Login

OR

Forgot password?

Don't have an account? Sign Up