Windows 10 for the Internet of Things — Charles Bell Windows 10 for the Internet of Things Charles Bell Windows 10 for the Internet of Things Charles Bell Warsaw, Virginia, USA ISBN-13 (pbk): 978-1-4842-2107-5 ISBN-13 (electronic): 978-1-4842-2108-2 DOI 10.1007/978-1-4842-2108-2 Library of Congress Control Number: 2016956879 Copyright © 2016 by Charles Bell 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. The MIT License (MIT) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Managing Director: Welmoed Spahr Lead Editor: Jonathan Gennick Technical Reviewer: Reggie Burnett Editorial Board: Steve Anglin, Pramila Balan, Laura Berendson, Aaron Black, Louise Corrigan, Jonathan Gennick, Todd Green, Robert Hutchinson, Celestin Suresh John, Nikhil Karkal, James Markham, Susan McDermott, Matthew Moodie, Natalie Pao, Gwenan Spearing Coordinating Editor: Jill Balzano Copy Editor: Kim Burton-Weisman Compositor: SPi Global Indexer: SPi Global Artist: SPi Global 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 o [email protected] , or visit w ww.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. For information on translations, please e-mail [email protected] , or visit w ww.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 w ww.apress.com/bulk-sales . Any source code or other supplementary materials referenced by the author in this text are 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/ . Readers can also access source code at SpringerLink in the Supplementary Material section for each chapter. Printed on acid-free paper —I dedicate this book to my good friend Russ, who thought I had given up on Windows. Clearly, I haven’t. Contents at a Glance About the Author ....................................................................................................xix About the Technical Reviewer ................................................................................xxi Acknowledgments ................................................................................................xxiii Introduction ...........................................................................................................xxv ■ Chapter 1: What Is the Internet of Things? ............................................................1 ■ Chapter 2: Introducing the Windows 10 IoT Core ................................................21 ■ Chapter 3: Introducing the Raspberry Pi .............................................................71 ■ Chapter 4: Developing IoT Solutions with Windows 10 .......................................97 ■ Chapter 5: Windows 10 IoT Development with C++ ..........................................125 ■ Chapter 6: Windows 10 IoT Development with C# .............................................155 ■ Chapter 7: Windows 10 IoT Development with Python ......................................183 ■ Chapter 8: Electronics for Beginners .................................................................203 ■ Chapter 9: The Adafruit Microsoft IoT Pack for Raspberry Pi............................233 ■ Chapter 10: Project 1: Building an LED Power Meter ........................................255 ■ Chapter 11: Project 2: Measuring Light .............................................................271 ■ Chapter 12: Project 3: Using Weather Sensors ..................................................291 ■ Chapter 13: Project 4: Using MySQL to Store Data ............................................307 ■ Chapter 14: Project 5: Using a Web Server to Control Hardware ......................331 ■ Chapter 15: Project 6: Windows IoT and Arduino ..............................................361 v ■ CONTENTS AT A GLANCE ■ Chapter 16: Azure IoT Solutions: Cloud Services ..............................................397 ■ Chapter 17: Where to Go from Here? .................................................................435 ■ Appendix ............................................................................................................447 Index .....................................................................................................................457 vi Contents About the Author ....................................................................................................xix About the Technical Reviewer ................................................................................xxi Acknowledgments ................................................................................................xxiii Introduction ...........................................................................................................xxv ■ Chapter 1: What Is the Internet of Things? ............................................................1 The Internet of Things and You .........................................................................................2 IoT Is More Than Just Connected to the Internet ....................................................................................2 IoT Services ............................................................................................................................................3 A Brief Look at IoT Solutions ............................................................................................4 Sensor Networks ....................................................................................................................................4 Medical Applications...............................................................................................................................5 Automotive IoT Solutions ........................................................................................................................7 Fleet Management ................................................................................................................................10 IoT and Security .............................................................................................................11 Security Begins at Home ......................................................................................................................11 Secure Your Devices .............................................................................................................................12 Use Encryption ......................................................................................................................................12 Security Doesn’t End at the Cloud ........................................................................................................13 Introducing Windows 10 .................................................................................................13 Overview of Windows 10 Features .......................................................................................................14 Windows 10 and the IoT .......................................................................................................................18 Summary ........................................................................................................................18 vii ■ CONTENTS ■ Chapter 2: Introducing the Windows 10 IoT Core ................................................21 Windows 10 IoT Core Features .......................................................................................21 Interacting with Hardware ....................................................................................................................22 Video Support .......................................................................................................................................22 One Platform, Many Devices .................................................................................................................22 Supported Hardware .............................................................................................................................23 So Which One Should I Choose? ...........................................................................................................29 Things You’ll Need ..........................................................................................................30 Additional Hardware .............................................................................................................................30 Software Development Tools ................................................................................................................33 Getting Started with Windows 10 IoT Core .....................................................................34 Setting up Your Computer .....................................................................................................................34 Getting Started with Your Board ...........................................................................................................45 Raspberry Pi Confi guration ...................................................................................................................46 MinnowBoard Max Turbot Confi guration ..............................................................................................51 DragonBoard 410c Confi guration .........................................................................................................58 Connecting to Your Board .....................................................................................................................63 Summary ........................................................................................................................70 ■ Chapter 3: Introducing the Raspberry Pi .............................................................71 Getting Started with the Raspberry Pi ............................................................................71 Raspberry Pi Origins .............................................................................................................................72 Versions that Work with Windows 10 IoT Core .....................................................................................73 A Tour of the Board ...............................................................................................................................75 Required Accessories ...........................................................................................................................76 Recommended Accessories .................................................................................................................77 Where to Buy ........................................................................................................................................77 Setting up the Raspberry Pi ...........................................................................................77 Choosing a Boot Image (Operating System) .........................................................................................78 Creating the Boot Image .......................................................................................................................79 Booting the Board .................................................................................................................................80 Setting up Wi-Fi on the Raspberry Pi 3 .................................................................................................82 viii ■ CONTENTS A Brief Linux Primer .......................................................................................................82 Getting Help ..........................................................................................................................................83 File and Directory Commands ..............................................................................................................84 System Commands ...............................................................................................................................86 Administrative Commands....................................................................................................................87 Useful Utilities .......................................................................................................................................90 Working with Python: Blink an LED ................................................................................90 Hardware Connections .........................................................................................................................92 Writing the Code ...................................................................................................................................93 Running the Script ................................................................................................................................94 Summary ........................................................................................................................96 ■ Chapter 4: Developing IoT Solutions with Windows 10 .......................................97 Working with GPIO Headers ...........................................................................................97 Raspberry Pi .........................................................................................................................................98 MinnowBoard Turbot .............................................................................................................................99 DragonBoard 410C..............................................................................................................................100 Visual Studio 2015 Primer ............................................................................................101 Major Features ...................................................................................................................................102 The Interface ......................................................................................................................................103 Windows 10 IoT Core Project Templates.............................................................................................107 Example Project: Hello, World .......................................................................................111 Create the Project ...............................................................................................................................112 Write the Code ....................................................................................................................................113 Build and Test Your Code ....................................................................................................................115 Set up your Windows 10 IoT Device ...................................................................................................116 Deploy and Test to your Windows 10 IoT Device ................................................................................117 Summary ......................................................................................................................124 ix ■ CONTENTS ■ Chapter 5: Windows 10 IoT Development with C++ ..........................................125 Getting Started .............................................................................................................125 C++ Crash Course ........................................................................................................127 The Basics ..........................................................................................................................................127 Variables and Types ............................................................................................................................131 Arithmetic ...........................................................................................................................................133 Flow Control Statements ....................................................................................................................134 Basic Data Structures .........................................................................................................................136 Pointers ..............................................................................................................................................138 Blink an LED, C++ Style ...............................................................................................141 Required Components ........................................................................................................................142 Set up the Hardware ...........................................................................................................................142 Write the Code: User Interface ............................................................................................................143 Test and Execute: User Interface Only ................................................................................................147 Add the GPIO Code ..............................................................................................................................148 Deploy and Execute: Completed Application ......................................................................................152 Summary ......................................................................................................................154 ■ Chapter 6: Windows 10 IoT Development with C# .............................................155 Getting Started .............................................................................................................156 C# Crash Course ...........................................................................................................158 C# Fundamentals ................................................................................................................................158 How C# Programs Are Structured .......................................................................................................162 Variables and Types ............................................................................................................................164 Arithmetic ...........................................................................................................................................165 Flow Control Statements ....................................................................................................................166 Basic Data Structures .........................................................................................................................168 Blink an LED, C# Style ..................................................................................................169 Required Components ........................................................................................................................170 Set up the Hardware ...........................................................................................................................170 Write the Code: User Interface ............................................................................................................171 Test and Execute: User Interface Only ................................................................................................174 x