John C. Shovic

Raspberry Pi IoT Projects

Prototyping Experiments for Makers

John C. Shovic

Liberty Lake, Washington, USA

Any source code or other supplementary materials referenced by the author in this text is available to readers at www.apress.com . For detailed information about how to locate your book’s source code, go to www.apress.com/source-code/ .

ISBN 978-1-4842-1378-0

e-ISBN 978-1-4842-1377-3

DOI 10.1007/978-1-4842-1377-3

Library of Congress Control Number: 2016949468

© John C. Shovic 2016

Raspberry Pi IoT Projects: Prototyping Experiments for Makers

Managing Director: Welmoed Spahr

Lead Editor: Jonathan Gennick

Technical Reviewer: Gheorghe Chesler

Development Editor: James Markham

Editorial Board: Steve Anglin, Pramila Balen, Louise Corrigan, Jonathan Gennick, Robert Hutchinson, Celestin Suresh John, James Markham, Susan McDermott, Matthew Moodie, Gwenan Spearing

Coordinating Editor: Melissa Maldonado

Copy Editor: Karen Jameson

Compositor: SPi Global

Indexer: SPi Global

Artist: SPi Global

For information on translations, please e-mail [email protected] , or visit www.apress.com .

Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales .

This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.

Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.

While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.

Printed on acid-free paper

Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springer.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.

To my best friend Laurie and also to my cat Panther, who is an IOT device by himself.

Introduction

The Internet Of Things (IOT) is a complex concept made up of many computers and many communication paths. Some IOT devices are connected to the Internet and some are not. Some IOT devices form swarms that communicate among themselves. Some are designed for a single purpose, while some are more general purpose computers. This book is designed to show you the IOT from the inside out. By building IOT devices, the reader will understand the basic concepts and will be able to innovate using the basics to create his or her own IOT applications.

These included projects will show the reader how to build their own IOT projects and to expand upon the examples shown. The importance of Computer Security in IOT devices is also discussed and various techniques for keeping the IOT safe from unauthorized users or hackers. The most important takeaway from this book is in building the projects yourself.

Chapters at a Glance

In this book, we built examples of all the major parts of simple and complex IOT devices.

In Chapter 1 , the basic concepts of IOT are explained in basic terms, and you will learn what parts and tools are needed to start prototyping your own IOT devices.

In Chapter 2 , you’ll learn how to sense the environment with electronics and that even the behavior of simple LightSwarm type of devices can be very unpredictable.

Chapter 3 introduces important concepts about how to build real systems that can respond to power issues and programming errors by the use of good system design and watchdogs.

Chapter 4 turns a Raspberry Pi into a battery-powered device that senses iBeacons and controls the lighting in a house while reporting your location to a server.

In Chapter 5 , you’ll do IOT the way the big boys do by connecting up to the IBM BlueMix IOT Server and sending our biometric pulse rates up for storage and display.

In Chapter 6 , we’ll build a small RFID Inventory system and use standard protocols like MQTT to send information to a Raspberry Pi, a complete IOT product.

Chapter 7 shows the dark side of the IOT, Computer Security. The way you protect your IOT device from hackers and network problems is the most difficult part of IOT device and system design.

Are you totally secure? You will never know. Plan for it.

The reference appendix provides resources for further study and suggestions for other projects.

Acknowledgments

The author would like to acknowledge the hard work of the APress editorial team in putting this book together. He would also like to acknowledge the hard work of the Raspberry Pi Foundation and the Arduino group for putting together products and communities that help to make the Internet Of Things more accessible to the general public. Hurray for the democratization of technology!

Contents

  1. Chapter 1:​ Introduction to IOT
    1. Choosing a Raspberry Pi Model
    2. Choosing an IOT Device
    3. Characterizing an IOT Project
    4. Communications
      1. Processor Power
      2. Local Storage
      3. Power Consumption
      4. Functionality
      5. Cost
    5. The Right Tools to Deal with Hardware
    6. Writing Code in Python and the Arduino IDE
    7. In This Book
  2. Chapter 2:​ Sensing Your IOT Environment
    1. IOT Sensor Nets
    2. IOT Characterization​ of This Project
    3. How Does This Device Hook Up to the IOT?​
      1. What Is an ESP8266?​
      2. The LightSwarm Design
    4. Building Your First IOT Swarm
      1. Installing Arduino Support on the PC or Mac
      2. Your First Sketch for the ESP8266
      3. The Hardware
      4. The Software
    5. Self-Organizing Behavior
    6. Monitoring and Debugging the System with the Raspberry Pi (the Smart Guy on the Block)
      1. LightSwarm Logging Software Written in Python
    7. The RasPiConnect Control Panel in Real Time
    8. Results
    9. What Else Can You Do with This Architecture?​
    10. Conclusion
  3. Chapter 3:​ Building a Solar Powered IOT Weather Station
    1. IOT Characterization​ of This Project
    2. How Does This Device Hook Up to the IOT?​
    3. Data Gathering
    4. The Project - IOTWeatherPi
      1. How This All Works
      2. The Subsystems
      3. The I2C Bus
    5. Sizing Your Solar Power System
    6. Power Up and Power Down
      1. The Brownout Problem
      2. Shutting Off the Pi
    7. Starting the Pi
      1. The Issue
      2. Power Your Pi Up and Down with the USB Power Control
      3. The USB Power Controller Board
      4. One More Scenario
    8. What Do You Need to Build This Project?​
    9. Connecting and Testing the Hardware
    10. The Full Wiring List
    11. The Software
      1. Non-Normal Requirements for your Pi
      2. The IOTWeatherPi Python Software
      3. The RasPiConnect Control Panel
      4. Improvements
    12. Tweeting Your Weather Data
      1. Getting Started
      2. Registering a Twitter App
    13. Texting Your Weather Data
    14. Supplying Your Data to the World - CWOP
      1. CWOP
      2. CWOP Software Interface to IOTWeatherPi
      3. CWOP Software
      4. Example CWOP Packet
      5. Results
    15. Conclusion
  4. Chapter 4:​ Changing Your Environment with IOT and iBeacons
    1. The IOTBeaconAir
      1. IOT Characterization​ of This Project
      2. How Does This Device Hook Up to the IOT?​
      3. Hardware List
    2. iBeacons
      1. Bluetooth iBeacon Scanner
      2. Phillips Hue Lighting System
      3. Phillips Hue Hub
    3. BeaconAir Hardware, Software, and Configuration
      1. BeaconAir Hardware Description
      2. BeaconAir Software Description
      3. BeaconAir Configuration File
      4. iBeacon Software
      5. Trilateralizatio​n
      6. The IOTBeaconAir Control Panel
    4. Installing blueZ and phue on the Raspberry Pi
      1. BlueZ
      2. phue
    5. RasPiConnectServ​er Startup
      1. Startup Procedure
      2. Making IOTBeaconAir Start on Bootup
      3. How It Works in Practice
    6. Things to Do
    7. The Classic Distributed System Problems
    8. Conclusion
  5. Chapter 5:​ Connecting an IOT Device to a Cloud Server - IOTPulse
    1. IOT Characterization​ of This Project
    2. The Internet Of Things on the Global Network
      1. Cloud Computing
      2. Application Builders
      3. Display and Report Generation
      4. The IBM Bluemix Internet Of Things Solution
    3. The IOTPulse Design
      1. Building the IOTPulse
      2. 3D Printing Files for the IOT Case
      3. Software Needed
      4. The IOTPulse Code
      5. Reviewing the Arduino IDE Serial Monitor Results
    4. Joining IBM Bluemix and the IoT Foundation
      1. Sending your Data to Bluemix
      2. Displaying Real-Time Data on the IBM Bluemix IOT Platform
    5. Advanced Topics
      1. Historical Data
      2. Node-RED Applications
      3. Watson Applications
    6. Conclusion
  6. Chapter 6:​ Using IOT for RFID and MQTT and the Raspberry Pi
    1. IOT Characterization​ of This Project
    2. What Is RFID Technology?​
    3. What Is MQTT?​
    4. Hardware Used for IOTRFID
    5. Building an MQTT Server on a Raspberry Pi
    6. The Software on the Raspberry Pi
      1. Installing the MQTT “Mosquitto”
      2. Configuring and Starting the Mosquitto Server
      3. Starting the Mosquitto Server
      4. Testing the Mosquitto Server
    7. Building the IOTRFID
      1. The Parts Needed
      2. Installing Arduino Support on the PC or Mac
      3. The Hardware
      4. What Is This Sensor We Are Using?​
      5. 3D Printed Case
      6. The Full Wiring List
    8. The Software for the IOTRFID Project
      1. The Libraries
      2. The Main Software
      3. Testing the IOTRFID System
      4. Setting Up the Mosquitto Debug Window
      5. Set Up a Subscriber on the Raspberry Pi
      6. Testing the Entire IOTRFID System
    9. What to Do with the RFID Data on the Server
    10. Conclusion
  7. Chapter 7:​ Computer Security and the IOT
    1. IOT:​ Top Five Things to Know About IOT Computer Security
      1. Number 1:​ This is important .​ You can prove your application is insecure , but you can’t prove your application is secure .​
      2. Number 2:​ Security through Obscurity Is Not Security
      3. Number 3:​ Always Connected?​ Always Vulnerable
      4. Number 4:​ Focus On What Is Important to Be Secure in your IOT Application
      5. Number 5:​ Computer Security Rests on Three Main Aspects:​ Confidentiality, Integrity, and Availability
    2. What Are the Dangers?​
    3. Assigning Value to Information
    4. Building The Three Basic Security Components for IOT Computers
      1. Confidentiality - Cryptography
      2. Integrity - Authentication
      3. Availability - Handling DOS /​ Loss of Server /​ Watchdogs
    5. Key Management
    6. Update Management
    7. Conclusion
  8. Appendix: Suggestions for Further Work
  9. Parting Words
  10. Index

About the Author and About the Technical Reviewer

About the Author

A367492_1_En_BookFrontmatter_Figb_HTML.jpg

John C. Shovic is currently Chief Technical Officer of SwitchDoc Labs, a company specializing in technical products for the Maker Movement and the IOT; and InstiComm, a company specializing in mobile medical software solutions for health practitioners. He was also Chief Technology Strategist at Stratus Global Partners with a focus on supplying expertise in computer security regulatory and technical areas to health care providers. He has worked in the industry for over thirty years and has founded seven companies: Advanced Hardware Architectures, TriGeo Network Security, Blue Water Technologies, MiloCreek, InstiComm, SwitchDoc Labs, and bankCDA. As a founding member of the bankCDA board of directors, he currently serves as the chairman of the technology committee. He has also served as a Professor of Computer Science at Eastern Washington University, Washington State University, and the University of Idaho. Dr. Shovic has given over eighty invited talks and has published over seventy papers on a variety of topics on Arduinos/Raspberry Pi’s, HIPAA, GLB, computer security, computer forensics, and embedded systems.

About the Technical Reviewer

Gheorghe Chesler is a Senior Software Engineer with expertise in Quality Assurance, System Automation, Performance Engineering, and e-Publishing. He works at ServiceNow as a Senior Performance Engineer, and is a principal technical consultant for Plural Publishing, a medical-field publishing company. His preferred programming language is Perl (so much so that he identifies with the Perl mascot, hence the camel picture), but also worked on many Java and Objective-C projects.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.27.91