Free ebooks ==> www.Ebook777.com www.Ebook777.com Free ebooks ==> www.Ebook777.com BeagleBone Home Automation Blueprints Automate and control your home using the power of the BeagleBone Black with practical home automation projects Rodolfo Giometti BIRMINGHAM - MUMBAI www.Ebook777.com 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 Project Coordinator Judie Jose Proofreader Safis Editing Elango Palanisamy Michele Scafoglieri Commissioning Editor Akram Hussain Indexer Tejal Daruwale Soni Production Coordinator Aparna Bhagat Acquisition Editor Vivek Anantharaman Cover Work Aparna Bhagat Content Development Editor Rashmi Suvarna Technical Editor Anushree Arun Tendulkar Copy Editor Vatsal Surti Free ebooks ==> www.Ebook777.com 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 what I today www.Ebook777.com 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 service@packtpub.com for more details 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 TM 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 entirely free books Simply use your login credentials for immediate access Free ebooks ==> www.Ebook777.com Table of Contents Preface vii Chapter 1: Dangerous Gas Sensors The basics of functioning Setting up the hardware Connecting the gas sensors Connecting the alarm actuators 2 LED and buzzer GSM module The final picture 11 Setting up the software 12 Managing the ADCs 15 Managing the actuators 18 Controlling the environment 22 Final test 24 Summary 27 Chapter 2: Ultrasonic Parking Assistant The basics 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 [i] www.Ebook777.com 29 29 29 30 30 34 35 35 38 39 40 40 Chapter 11 dbg("detecting the switch node ") for node in network.nodes: for val in network.nodes[node].get_switches(): data = network.nodes[node].values[val].data values["switch"] = "on" if data else "off" sw_node = node sw_val = val dbg(" - device %s(%s) is %s" % \ (network.nodes[node].values[val].label, node, values["switch"])) # We can manage just one switch! break info("Press CTRL+C to stop") The get_switches() method is used to get all the nodes that can act as a switch, so we use it to detect our wall plug and then to store its information into the sw_node and sw_val variables in order to be used later in the do_POST() method to turn on/off the switch based on the user request Here, it is really clear that the code is written for only one wall plug at a time in the network! Now, we only have to define the web server to finish the job, and we can it with the following code: # Create a web server and define the handler to manage the incoming requests try: server = HTTPServer(('', port), myHandler) info("Started HTTP server on port %d" % port) # Wait forever for incoming HTTP requests server.serve_forever() except KeyboardInterrupt: info("CTRL+C received, shutting down ") server.socket.close() network.stop() info("Done.") [ 337 ] A Wireless Home Controller with Z-Wave The main function is the HTTPServer() function that starts the internal web server listening at the 8080 port Now, to complete the software presentation, I need to show how the house.html file works This is the file that is served by the web server each time a new client gets connected to it Again, as before, I'm going to show the relevant parts only, but you can get the complete code in the chapter_11/house.html file in the book's example code repository In the head part, I define the CSS file name and the JavaScript code to use: var polldata = function() { $.getJSON('/get', function(data) { $.each(data, function(key, val) { var e = document.getElementById(key); if (e != null) { if (e.type == "text") e.value = val; else e.textContent = val; } }); }); }; setInterval(polldata, 1000); $(function() { $('button[class="do-button"]').click(function() { var id = $(this).attr("id"); $.ajax({ url: "/set", [ 338 ] Chapter 11 type: "POST", data: "do=" + id, success: function() { console.log('do POST success'); }, error: function() { console.log('do POST error'); } }); }); }); In this code, we used the same technique used in Chapter 7, Facebook Plant Monitor, where I installed a polling function that executes several GET requests on the server, one per second, to update the displayed data returned in the JSON format Also, each time a button is pressed, we a POST request to the server, passing the button ID to it to manage In the body part of the house.html file, we define the table to show our data in a nice manner: Home monitor status Internal variables Switch off switch www.Ebook777.com Using Yocto Project with BeagleBone Black ISBN: 978-1-78528-973-6 Paperback: 144 pages Unleash the power of the BeagleBone Black embedded platform with Yocto Project Build real world embedded system projects using the impressive combination of Yocto Project and Beaglebone Black Learn how to effectively add multimedia to your board and save time by exploiting layers from the existing ones A step-by-step, comprehensive guide for embedded system development with hands-on examples Mastering BeagleBone Robotics ISBN: 978-1-78398-890-7 Paperback: 234 pages Master the power of the BeagleBone Black to maximize your robot-building skills and create awesome projects Create complex robots to explore land, sea, and the skies Control your robots through a wireless interface, or make them autonomous and self-directed This is a step-by-step guide to advancing your robotics skills through the power of the BeagleBone Please check www.PacktPub.com for information on our titles www.Ebook777.com ... ebooks ==> www.Ebook777.com BeagleBone Home Automation Blueprints Automate and control your home using the power of the BeagleBone Black with practical home automation projects Rodolfo Giometti... https://github.com/giometti/beaglebone _home_ automation_ blueprints Just use the following command to get it at once: $ git clone https://github.com/giometti/beaglebone _home_ automation_ blueprints The examples... 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