Book Image

BeagleBone Home Automation Blueprints

By : Rodolfo Giometti
Book Image

BeagleBone Home Automation Blueprints

By: Rodolfo Giometti

Overview of this book

BeagleBone is a microboard PC that runs Linux. It can connect to the Internet and can run OSes such as Android and Ubuntu. BeagleBone is used for a variety of different purposes and projects, from simple projects such as building a thermostat to more advanced ones such as home security systems. Packed with real-world examples, this book will provide you with examples of how to connect several sensors and an actuator to the BeagleBone Black. You’ll learn how to give access to them, in order to realize simple-to-complex monitoring and controlling systems that will help you take control of the house. You will also find software examples of implementing web interfaces using the classical PHP/HTML pair with JavaScript, using complex APIs to interact with a Google Docs account, WhatsApp, or Facebook. This guide is an invaluable tutorial if you are planning to use a BeagleBone Black in a home automation project.
Table of Contents (18 chapters)
BeagleBone Home Automation Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Final test


Once everything has been connected and the software is ready, it's time to do a little test of our new system. The demonstration can be done by using a lighter. In fact, our system is really sensitive to the gas inside the lighter!

First of all, we have to check the system configuration:

root@beaglebone:~# ./my_dump.sh config
n   v
mq2_gain   0.125
mq2_off   0
mq2_th_ppm   150
mq4_gain   0.125
mq4_off   0
mq4_th_ppm   150
mq5_gain   0.125
mq5_off   0
mq5_th_ppm   150
mq7_gain   0.125
mq7_off   0
mq7_th_ppm   150
sms_delay_s   300

Tip

Note that I used a very weak calibration setting; however, these are okay for a demo.

Then, we can take a look at the system's current status:

root@beaglebone:~# ./my_dump.sh status
n   v
mq2   73.5
mq4   121.75
mq5   53
mq7   80.5
alarm   0

Then, we can do all hardware settings at once by using the chapter_01/SYSINIT.sh script in the book's example code repository as follows:

root@beaglebone:~# ./SYSINIT.sh
done!

Okay, now let's start all the required process daemons:

root@beaglebone:~# ./read_sensors.php -d -T 2
root@beaglebone:~# ./write_actuators.php -d -T 2
root@beaglebone:~# ./monitor.php -d -T 2

Tip

Note that all the daemons are running in background in this way; however, the debugging messages are enabled and they can be viewed into the system log with the following command:

# tail -f /var/log/syslog

Now, we have to approach the lighter to the sensors and press the button on the lighter in order to allow the sensor to detect the gas. After a while, the alarms should be turned on, and looking at the system status, we should get the following:

root@beaglebone:~# ./my_dump.sh status
n   v
mq2   203.875
mq4   166.5
mq5   52.5
mq7   122.625
alarm   1

Also, if we have set up a phone number, we should receive an SMS on the phone!

As last step, let's display the data logged by plotting them. We can use the following command to extract the data from the database:

root@beaglebone:~# ./my_dump.sh mq2_log | awk '{ print $2 " " $3 }' > mq2.log

In the mq2.log file, we should find something like the following:

root@beaglebone:~# cat mq2.log
15:02:07 75.25
15:02:10 74.25
15:02:12 74.25
15:02:14 74.375
15:02:16 74.25
...

Now, using the next command, we're going to create a PNG image holding a plot of our data:

$ gnuplot mq2.plot

Tip

Note that in order to execute this command, you need the gnuplot command, which can be installed by using the following command:

# aptitude install gnuplot

Also, both the mq2.log and mq2.plot files are need. The former is created by the preceding command line, while the latter can be found in the chapter_01/mq2.plot file in the book's example code repository. It holds the gnuplot instructions to effectively draw the plot.

The plot of the MQ-2 data of my test is shown in the following screenshot:

As you can see, the sensors are very sensitive to the gas; as soon as I opened my lighter and the gas reached them, the ppm concentration went to high values very quickly.

To stop the test, we can use the following commands:

root@beaglebone:~# killall read_sensors.php
root@beaglebone:~# killall write_actuators.php
root@beaglebone:~# killall monitor.php