BeagleBone Home Automation Blueprints
()
About this ebook
About This Book
- Build, set up, and develop your circuits via step-by-step tutorial of practical examples, from initial board setup to device driver management
- Get access to several kinds of computer peripherals to monitor and control your domestic environment using this guide
- This book is spread across 10 chapters all focused on one practical home automation project
Who This Book Is For
This book is for developers who know how to use BeagleBone and are just above the “beginner” level. If you want to learn to use embedded machine learning capabilities, you should have some experience of creating simple home automation projects.
What You Will Learn
- Build a CO (and other gas) sensor with a buzzer/LED alarm to signal high concentrations
- Log environment data and plot it in a fancy manner
- Develop a simple web interface with a LAMP platform
- Prepare complex web interfaces in JavaScript and get to know how to stream video data from a webcam
- Use APIs to get access to a Google Docs account or a WhatsApp/Facebook account to manage a home automation system
- Add custom device drivers to manage an LED with different blinking frequencies
- Discover how to work with electronic components to build small circuits
- Use an NFS, temperature sensor, relays, and other peripherals to monitor and control your surroundings
In Detail
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.
Style and approach
This step-by-step guide contains several home automation examples that can be used as base projects for tons of other home automation and control systems. Through clear, concise examples based on real-life situations, you will quickly get to grips with the core concepts needed to develop home automation applications with the BeagleBone Black using both the C language and high-level scripting languages such as PHP, Python, and JavaScript.
Read more from Giometti Rodolfo
GNU/Linux Rapid Embedded Programming Rating: 0 out of 5 stars0 ratingsBeagleBone Essentials Rating: 0 out of 5 stars0 ratings
Related to BeagleBone Home Automation Blueprints
Related ebooks
Programming the BeagleBone Rating: 0 out of 5 stars0 ratingsCommercial and Industrial Internet of Things Applications with the Raspberry Pi: Prototyping IoT Solutions Rating: 0 out of 5 stars0 ratingsIntel Galileo Essentials Rating: 0 out of 5 stars0 ratingsIntel Galileo Blueprints Rating: 0 out of 5 stars0 ratingsRaspberry Pi Home Automation with Arduino - Second Edition Rating: 0 out of 5 stars0 ratingsHome Automation with Intel Galileo Rating: 2 out of 5 stars2/5Raspberry Pi By Example Rating: 0 out of 5 stars0 ratingsBuilding Wireless Sensor Networks Using Arduino Rating: 4 out of 5 stars4/5Raspberry Pi Blueprints Rating: 0 out of 5 stars0 ratingsBuilding a Home Security System with Raspberry Pi Rating: 0 out of 5 stars0 ratingsRaspberry Pi Server Essentials Rating: 0 out of 5 stars0 ratingsBeagleBone By Example Rating: 0 out of 5 stars0 ratingsLearning Raspbian Rating: 5 out of 5 stars5/5Building Smart Homes with Raspberry Pi Zero Rating: 0 out of 5 stars0 ratingsArduino Home Automation Projects Rating: 3 out of 5 stars3/5Raspberry Pi Android Projects Rating: 0 out of 5 stars0 ratingsArduino Electronics Blueprints Rating: 4 out of 5 stars4/5Programming the BeagleBone Black: Getting Started with JavaScript and BoneScript Rating: 0 out of 5 stars0 ratingsInternet of Things with Arduino Blueprints Rating: 0 out of 5 stars0 ratingsRaspberry Pi Robotic Projects - Third Edition Rating: 0 out of 5 stars0 ratingsSmart Internet of Things Projects Rating: 4 out of 5 stars4/5Mastering BeagleBone Robotics Rating: 5 out of 5 stars5/5Learning BeagleBone Python Programming Rating: 0 out of 5 stars0 ratingsLearning Raspberry Pi Rating: 0 out of 5 stars0 ratingsLearn Arduino Prototyping in 10 days Rating: 0 out of 5 stars0 ratingsArduino Networking Rating: 4 out of 5 stars4/5Internet of Things with ESP8266 Rating: 5 out of 5 stars5/5Raspberry Pi LED Blueprints Rating: 0 out of 5 stars0 ratingsComputer Vision with Maker Tech: Detecting People With a Raspberry Pi, a Thermal Camera, and Machine Learning Rating: 0 out of 5 stars0 ratingsArduino for Secret Agents Rating: 4 out of 5 stars4/5
Hardware For You
Dancing with Qubits: How quantum computing works and how it can change the world Rating: 5 out of 5 stars5/5iPhone Photography: A Ridiculously Simple Guide To Taking Photos With Your iPhone Rating: 0 out of 5 stars0 ratingsChip War: The Fight for the World's Most Critical Technology Rating: 4 out of 5 stars4/5CompTIA A+ Complete Review Guide: Exam Core 1 220-1001 and Exam Core 2 220-1002 Rating: 5 out of 5 stars5/5Apple Watch Series 4: Your Ultimate Guide to Using the Apple Watch Like A Pro Rating: 5 out of 5 stars5/5Essential iPad iOS 12 Edition: The Illustrated Guide to Using your iPad Rating: 5 out of 5 stars5/5CompTIA A+ Complete Review Guide: Core 1 Exam 220-1101 and Core 2 Exam 220-1102 Rating: 5 out of 5 stars5/5Creative Selection: Inside Apple's Design Process During the Golden Age of Steve Jobs Rating: 5 out of 5 stars5/5Computer Science: A Concise Introduction Rating: 4 out of 5 stars4/5Amazon Web Services (AWS) Interview Questions and Answers Rating: 5 out of 5 stars5/5Raspberry Pi Cookbook for Python Programmers Rating: 0 out of 5 stars0 ratingsProgramming Arduino: Getting Started with Sketches Rating: 4 out of 5 stars4/5Mastering ChatGPT Rating: 0 out of 5 stars0 ratingsiPhone For Seniors For Dummies: Updated for iPhone 12 models and iOS 14 Rating: 4 out of 5 stars4/5Build Your Own PC Do-It-Yourself For Dummies Rating: 4 out of 5 stars4/53D Printing For Dummies Rating: 4 out of 5 stars4/5Computer Organization and Design: The Hardware / Software Interface Rating: 4 out of 5 stars4/5iPhone X Hacks, Tips and Tricks: Discover 101 Awesome Tips and Tricks for iPhone XS, XS Max and iPhone X Rating: 3 out of 5 stars3/5Evernote Essentials Guide (Boxed Set): Evernote Guide For Beginners for Organizing Your Life Rating: 3 out of 5 stars3/5CompTIA A+ Complete Review Guide: Exams 220-901 and 220-902 Rating: 5 out of 5 stars5/5Debugging: The 9 Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems Rating: 4 out of 5 stars4/5iPhone 14 Pro Max User Guide for Beginners and Seniors Rating: 0 out of 5 stars0 ratingsFitbit For Dummies Rating: 0 out of 5 stars0 ratingsMacs All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsThe Ridiculously Simple Guide To iPad Air (2020 Model): Getting the Most Out of the Latest Generation of iPad Air Rating: 0 out of 5 stars0 ratingsMacs For Dummies Rating: 5 out of 5 stars5/5Essential iPhone iOS 12 Edition: The Illustrated Guide to Using iPhone Rating: 0 out of 5 stars0 ratings
Reviews for BeagleBone Home Automation Blueprints
0 ratings0 reviews
Book preview
BeagleBone Home Automation Blueprints - Giometti Rodolfo
Table of Contents
BeagleBone Home Automation Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Software prerequisites
Hardware prerequisites
Who this book is for
Conventions
Codes and command lines
Kernel and logging messages
File modifications
Serial and network connections
Other conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Dangerous Gas Sensors
The basic of functioning
Setting up the hardware
Connecting the gas sensors
Connecting the alarm actuators
LED and buzzer
GSM module
The final picture
Setting up the software
Managing the ADCs
Managing the actuators
Controlling the environment
Final test
Summary
2. Ultrasonic Parking Assistant
The basic of functioning
Setting up the hardware
First setup – all devices near the BeagleBone Black
Using the analog output of the distance sensor
Connecting the LEDs in the first setup
Second setup – the distance sensor is remotized
Using the serial output of the distance sensor
Connecting the LEDs in the second setup
The final picture
Setting up the software
Managing the LEDs
The distance monitor
Final test
Summary
3. Aquarium Monitor
The basics of functioning
Setting up the hardware
Setting up the 12V devices
Setting up the webcam
Connecting the temperature sensor
Connecting the feeder
The water sensor
The final picture
Setting up the software
Managing the system status and configuration
Building up the web control panel
Handling the control panel
Knowing the internal state-machine
Final test
Summary
4. Google Docs Weather Station
The basics of functioning
Setting up the hardware
Setting up the temperature/humidity sensor
Setting up the barometric sensor
The final picture
Setting up the software
Installing a new kernel
Running the weather station software
Adding the Google Docs API
Final test
Summary
5. WhatsApp Laundry Room Monitor
The basics of functioning
Setting up the hardware
Setting up the sound detector
Setting up the light sensor
Connecting the LEDs
The final picture
Setting up the software
The sound detector manager
The light sensor manager
Controlling the LEDs
Setting up the WhatsApp API
The state-machine
Final test
Summary
6. Baby Room Sentinel
The basics of functioning
Setting up the hardware
Setting up the contactless temperature sensor
Setting up the pressure sensor
Setting up the sound detector
Connecting the tiny LCD
The final picture
Setting up the software
The ADC manager
The LCD manager
Final test
Summary
7. Facebook Plant Monitor
The basics of functioning
Setting up the hardware
Connecting the moisture sensor
Connecting the light sensor
Setting up the contactless temperature sensor
Setting up the waterproof temperature sensor
Setting up the webcam
Adding a water pump
The final picture
Setting up the software
The Facebook API
Downloading the code
Creating a new Facebook app
Getting access to the Facebook account
The monitoring loop
The web interface
Final test
Summary
8. Intrusion Detection System
The basics of functioning
Setting up the hardware
Setting up the webcams
The final picture
Setting up the software
Setting up the mailer
Using motion
Downloading the code
Configuring the daemon
The web interface
Managing events
Final test
Summary
9. Twitter Access Control System with Smart Card and RFID
The basics of functioning
Setting up the hardware
Setting up the smart card reader
Setting up the RFID LF reader
Setting up the RFID UHF reader
The final picture
Setting up the software
Setting up the Twitter utility
The smart card implementation
The RFID LF implementation
The RFID UHF implementation
Final test
Summary
10. A Lights Manager with a TV Remote Controller
The basics of functioning
Setting up the hardware
Setting up the infrared detector
Setting up the relays array
The final picture
Setting up the software
Setting up the kernel driver
The LIRC tools
The input events manager
The final test
Summary
11. A Wireless Home Controller with Z-Wave
The basics of functioning
Setting up the hardware
Setting up the Z-Wave controller
Setting up the Z-Wave wall plug
Setting up the Z-Wave multisensor
The final picture
Setting up the software
Setting up the Python bindings
The Z-Wave manager
The final test
Summary
Index
BeagleBone Home Automation Blueprints
BeagleBone Home Automation Blueprints
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: January 2016
Production reference: 1280116
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78398-602-6
www.packtpub.com
Credits
Author
Rodolfo Giometti
Reviewers
Armando Genovese
Elango Palanisamy
Michele Scafoglieri
Commissioning Editor
Akram Hussain
Acquisition Editor
Vivek Anantharaman
Content Development Editor
Rashmi Suvarna
Technical Editor
Anushree Arun Tendulkar
Copy Editor
Vatsal Surti
Project Coordinator
Judie Jose
Proofreader
Safis Editing
Indexer
Tejal Daruwale Soni
Production Coordinator
Aparna Bhagat
Cover Work
Aparna Bhagat
About the Author
Rodolfo Giometti is an engineer, IT specialist, and GNU/Linux expert. He has over 15 years of experience working with platforms based on x86 (PC), ARM, MIPS, and PowerPC. He is the first author and a maintainer of the LinuxPPS project (Linux's pulse per second subsystem.) He actively contributes to the Linux source code with several patches and new device drivers for several devices. His areas of core expertise are in writing device drivers for new peripherals, realizing special Linux ports for several custom embedded boards, and developing control automation and remote monitoring systems. He is the cofounder of the Cosino Project, where he develops software for industry control automation systems. He is also the co-CEO at HCE Engineering S.r.l., a leading industrial embedded systems-based company.
I would like to thank my wife Valentina and my children Romina and Raffaele for their patience during the writing of this book. I also give deep thanks and gratitude to the guys at Packt: Vivek Anantharaman, who gave to me the opportunity to write this book, and Rashmi Suvarna, who supported me in finishing this book.
Many thanks to Armando Genovese for his help in designing the circuitries, to Michele Scafoglieri and Elango Palanisamy for their support and effort in reviewing this book so carefully and to Vatsal Surti for his help in fixing up my English.
In the end, I cannot forget to thank my parents who, by giving me my first computer when I was a child, allowed me to do what I do today.
About the Reviewers
Armando Genovese is an electronics engineer with over 25 years of experience in analog and digital design, management, and marketing. Specializing in embedded circuits and systems, he has carried out projects for various industrial, medical, and consumer applications. Genovese is the founder of HCE Engineering S.r.l., which specializes in the creation of embedded systems, and is one of the founders of the Cosino Project. Genovese received a master's degree in electronics from Università degli Studi di Pisa.
Elango Palanisamy has a bachelor's degree in electronics and communication engineering from Anna University, Chennai. He is currently pursuing a master's in embedded system technologies at the same university. He has experience in firmware, board bring-ups, power management in consumer electronic devices, Linux driver development, and optimizations for thermal printers and car multimedia-related sensors. He also has experience of using build tools such as Yocto Project and Buildroot for Ti, Freescale, and Atmel boards. He currently works for HCL technologies, Chennai.
I would like to thank my parents and friends for their help and support throughout my career.
Michele Scafoglieri is an electronic engineer who designs software systems. In recent years, he has worked as a project manager for a software house and as a control engineer for manufacturing and logistics companies. Michele has over 20 years of experience in project management, software development, and embedded systems. He handled numerous projects ranging from small embedded devices to automated warehouses. Nowadays, as an independent consultant, he likes to speak at seminars, write articles, and use his skills to help others build useful systems for healthcare, logistics, and many other fields.
He can be reached at http://www.studiosigma.pro.
www.PacktPub.com
Support files, eBooks, discount offers, and more
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Free access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
Preface
The BeagleBone Black is an embedded system that is able to run an embedded GNU/Linux distribution as well as normal (and powerful) distributions like Debian or Ubuntu, and to which the user can connect several external peripherals via two dedicated expansion connectors.
Because it has powerful distribution capabilities with an easily expandable embedded board, the BeagleBone Black system is a state-of-the-art device that allows the user to build powerful and versatile monitoring and controlling applications.
This book presents several home automation prototypes in both hardware and software in order to explain to you how we can use the BeagleBone Black board connected with several devices to control your home.
Each prototype is discussed in its respective chapter in both hardware and software, explaining all the connections and the software packages necessary to manage several peripherals. Then, the code to glue all of it together is explained in detail till the final test of each project.
The hardware devices used in this book have been chosen in order to cover all the possible connection types we can encounter while working with a BeagleBone Black board, so you will find I2C, SPI, USB, 1-Wire, serial, and digital and analog devices.
The programming languages used in this book have been chosen according to the rule to find the quickest and easiest solution to solve the current problem; in particular, you can find example code in Bash, C, PHP, Python, HTML, and even JavaScript.
Note
Warning! All the projects in this book are prototypes and cannot be used as final applications.
Neither the author of this book nor Packt Publishing recommend or endorse these products to be used alone or as a component in any application without the necessary modifications to turn these prototypes into final products.
Neither the author of this book nor Packt Publishing will be held liable for unauthorized use of these prototypes. The user can use both the hardware and software of these devices at their own risk!
In the chapters where we will need to use a daemon or a kernel module, or where we will need to recompile the whole kernel, I've added a short description about what the reader should do and where they can get more information regarding the tools used; however, some basic skills in managing a GNU/Linux system, the kernel's modules, or the kernel itself are required (the reader can take a look at the book BeagleBone Essentials, Packt Publishing, written by the author of this book, in order to have more information about these topics).
What this book covers
Chapter 1, Dangerous Gas Sensors, will show how to use the BeagleBone Black to monitor some dangerous gases such as CO, Methane, LPG, and so on in a room and how to enable an acoustic and visive alarm in case of danger. Also, by using a GSM module, the user will be able to send an SMS message to a predefined phone number to alert, for instance, a relative.
Chapter 2, Ultrasonic Parking Assistant, will show how to use the BeagleBone Black to implement a park assistant. We will use an ultrasonic sensor to detect the distance between our car and the garage wall, and some LEDs to give feedback to the driver about the car's position in order to avoid collisions.
Chapter 3, Aquarium Monitor, will show how to make an aquarium monitor through which we'll be able to record all the environment data as well as control the life of our beloved fish from a web panel on our PC, smartphone, or tablet.
Chapter 4, Google Docs Weather Station, will take a look at a simple weather station that can also be used as an Internet-of-Things device. This time, our BeagleBone Black will collect environment data and will send them to a remote database (a Google Docs spreadsheet) in order to be reworked and presented into a shared environment.
Chapter 5, WhatsApp Laundry Room Monitor, will present an implementation of a laundry monitor room with several sensors capable of alerting the user directly on their WhatsApp account when a specific event occurs.
Chapter 6, Baby Room Sentinel, will present a possible implementation of a baby room sentinel capable of monitoring the room by detecting if the baby is crying or if the baby is actually breathing during sleep. Also, as a special feature, the system will be able to measure the baby's temperature with a contactless temperature sensor.
Chapter 7, Facebook Plant Monitor, will show how to implement a plant monitor capable of measuring light, soil moisture, and soil temperature (in the soil and outside it), and how to take some pictures, at specific intervals, via a webcam, and then publishing them on a Facebook timeline.
Chapter 8, Intrusion Detection System, will show how we can implement a low cost intrusion detection system with a reasonable quality level by using our BeagleBone Black and two (or more) webcams. The system will be able to alert the user by sending an e-mail message with a photo of the intruder.
Chapter 9, Twitter Access Control System with Smart Card and RFID, will show how to use a smart card reader as well as two kinds of RFID reader (LF and UHF) in order to show different ways to implement a minimal identification system for access control that can send an alert message to a Twitter account.
Chapter 10, A Lights Manager with a TV Remote Controller, will show how to manage a simple on/off device connected to our BeagleBone Black by using a TV remote controller or any infraredcapable device.
Chapter 11, A Wireless Home Controller with Z-Wave, will present how to implement a little wireless home controller by using a Z-Wave controller connected to our BeagleBone Black and two Z-Wave devices: a wall plug and a multisensor device.
What you need for this book
You need the following prerequisites to get the most from this book.
Software prerequisites
Regarding the software, the reader should have a little knowledge of a non-graphical text editor such as vi, emacs, or nano. Even if the reader can connect an LCD display, a keyboard, and a mouse directly to the BeagleBone Black and can use the graphical interface, we assume in this book that the reader is able to do little modifications to text files by using a text-only editor.
The host computer, that is, the computer the reader will use to cross-compile the code and/or manage the BeagleBone Black, is assumed to be running a GNU/Linux-based distribution. My host PC is running an Ubuntu 14.04 LTS, but the reader can also use a Debian-based system with a little modification, or they may use another GNU/Linux distribution, but with a little effort mainly for the installation of the cross-compiling tool. Systems such as Windows, Mac OS, or similar are not covered in this book due to the fact that we should not use low technology systems to develop code for a high technology system!
Knowing how a C compiler works and how to manage a Makefile could help, but don't worry, all examples start from the very beginning so that even a non-skilled developer should be able to do the job.
This book will present some kernel programming techniques, but it must not be taken as a kernel programming course. You need a proper book for such a topic! However, each example is well documented, and the reader will find several suggested resources.
Regarding the kernel, I'd like to state that by default I used the onboard kernel, that is, version 3.8.13. However, in some chapters, I used a self-compiled kernel, version 3.13.11; in that case, I gave a little tutorial about how to do the job.
If you're using a newer kernel release you may get minor issues, but you should be able to port whatever I did without problems. In the case that you are using a very recent kernel, please consider that the cape manager file /sys/devices/bone_capemgr.9/slots has been relocated to /sys/devices/platform/bone_capemgr/slots, so you have to change all related commands accordingly.
As a final note, I assume that the reader knows how to connect a BeagleBone Black board to the Internet in order to download a package or a generic file.
Hardware prerequisites
In this book, all code is developed for the BeagleBone Black board revision C, but the reader can use an older revision without any issues; in fact, the code is portable and it should work on other systems too!
Regarding the computer peripherals used in this book, I reported in each chapter where I got the hardware and where the reader can buy it, but, of course, they can decide to surf the Internet in order to find a better and cheaper offer. A note on where to find the datasheet is also present.
The reader should not have any difficulty in connecting the hardware presented in this book with the BeagleBone Black since the connections are very few and well documented. Readers don't require any particular hardware skills (apart from knowing how to use a soldering iron); however, a small amount of knowledge of electronics may help.
During the reading, I'm going to refer to BeagleBone Black's pins, especially the ones on the expansion connectors. All the pins used are explained, but, if needed, you can find a complete description of BeagleBone Black's connectors at http://elinux.org/Beagleboard:Cape_Expansion_Headers.
Who this book is for
If you are a developer who wants to learn how to use embedded machine learning capabilities and get access to a GNU/Linux device driver to collect data from a peripheral or to control a device, this is the book for you.
If you wish to manage your home by implementing different kinds of home automation devices that can interact with a smartphone, tablet, or PC, or if you are just working standalone, have some hardware or electrical engineering experience then this book is for you. Knowing the basics of C, Bash, Python, PHP, and JavaScript programming in a UNIX environment is also required.
Conventions
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Codes and command lines
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: To get the preceding kernel messages, we can use both the dmesg and tail -f /var/log/kern.log commands.
A block of code is set as follows:
CREATE TABLE status (
n VARCHAR(64) NOT NULL,
v VARCHAR(64) NOT NULL,
PRIMARY KEY (n)
) ENGINE=MEMORY;
Any command line input or output given on the BeagleBone Black is written as follows:
root@beaglebone:~# make CFLAGS=-Wall -O2
helloworldcc -Wall -O2 helloworld.c -o helloworld
Any command line input or output given on my host computer as a non-privileged user is written as follows:
$ tail -f /var/log/kern.log
When I need to give a command as a privileged user (root) on my host computer the command line input or output is then written as follows:
# /etc/init.d/apache2 restart
The reader should notice that all the privileged commands can also be executed by a normal user by using the sudo command with the form:
$ sudo
So, the preceding command can be executed by a normal user as:
$ sudo /etc/init.d/apache2 restart
Kernel and logging messages
On several GNU/Linux distributions, a kernel message has the following form:
Oct 27 10:41:56 hulk kernel: [46692.664196] usb 2-1.1: new high-speed USB device number 12 using ehci-pci
This is a quite long line for this book, which is why the characters from the beginning of the line until the point where the real information begins are dropped. So, in the preceding example, the line's output will be reported as follows:
usb 2-1.1: new high-speed USB device number 12 using ehci-pci
Long outputs and repeated or less important lines in a terminal are dropped by replacing them with three dots (...), as follows:
output begin output line 1 output line 2 ... output line 10 output end
File modifications
When the reader should modify a text file, I'm going to use the unified context diff format, since this is a very efficient and compact way to represent a text modification. This format can be obtained by using the diff command with the -u option argument.
As a simple example, let's consider the following text in file1.old:
This is first line
This is the second line
This is the third line
...
...
This is the last line
Suppose we have to modify the third line, as highlighted in the following snippet:
This is first line
This is the second line
This is the new third line modified by me
...
...
This is the last line
The reader can easily understand that reporting the whole file each time for a simple modification is quite obscure and space consuming; however, by using the unified context diff format, the preceding modification can be written as follows:
$ diff -u file1.old file1.new
--- file1.old 2015-03-23 14:49:04.354377460 +0100
+++ file1.new 2015-03-23 14:51:57.450373836 +0100
@@ -1,6 +1,6 @@
This is first line
This is the second line
-This is the third line
+This is the new third line modified by me
...
...
This is the last line
Now, the modification is very clear and is written in a compact form! It starts with a two-line header where the original file is preceded by --- and the new file is preceded by +++, then there are one or more changed hunks that contain the line