Reader small image

You're reading from  BeagleBone Home Automation Blueprints

Product typeBook
Published inFeb 2016
Publisher
ISBN-139781783986026
Edition1st Edition
Right arrow
Author (1)
Rodolfo Giometti
Rodolfo Giometti
author image
Rodolfo Giometti

Rodolfo Giometti is an engineer, IT specialist, GNU/Linux expert and software libre evangelist. He is the author of the books BeagleBone Essentials, BeagleBone Home Automation Blueprints and GNU/Linux Rapid Embedded Programming by Packt Publishing and maintainer of the LinuxPPS projects. He still actively contributes to the Linux source code with several patches and new device drivers for industrial applications devices. During his 20+ years of experience, he has worked on the x86, ARM, MIPS, and PowerPC-based platforms. Now, he is the co-chief at HCE Engineering S.r.l., where he designs new hardware and software systems for the quick prototyping in industry environment, control automation, and remote monitoring.
Read more about Rodolfo Giometti

Right arrow

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
Previous PageNext Page
You have been reading a chapter from
BeagleBone Home Automation Blueprints
Published in: Feb 2016Publisher: ISBN-13: 9781783986026
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Rodolfo Giometti

Rodolfo Giometti is an engineer, IT specialist, GNU/Linux expert and software libre evangelist. He is the author of the books BeagleBone Essentials, BeagleBone Home Automation Blueprints and GNU/Linux Rapid Embedded Programming by Packt Publishing and maintainer of the LinuxPPS projects. He still actively contributes to the Linux source code with several patches and new device drivers for industrial applications devices. During his 20+ years of experience, he has worked on the x86, ARM, MIPS, and PowerPC-based platforms. Now, he is the co-chief at HCE Engineering S.r.l., where he designs new hardware and software systems for the quick prototyping in industry environment, control automation, and remote monitoring.
Read more about Rodolfo Giometti