Charles Bell

Windows 10 for the Internet of Things

Charles Bell

Warsaw, Virginia, USA

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.

ISBN 978-1-4842-2107-5

e-ISBN 978-1-4842-2108-2

DOI 10.1007/978-1-4842-2108-2

Library of Congress Control Number: 2016956879

© Charles Bell 2016

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.

—I dedicate this book to my good friend Russ, who thought I had given up on Windows. Clearly, I haven’t.

Introduction

Internet of Things (IoT) solutions are not nearly as complicated as the name may seem to indicate. Indeed, the IoT is largely another name for what we have already been doing. You may have heard of connected devices or Internet-ready or even cloud-enabled. All of these refer to the same thing—be it a single device such as a toaster or a plant monitor or a complex, multidevice product like home automation solutions. They all share one thing in common: they can be accessed via the Internet to either display data or interact with the devices directly. The trick is applying knowledge of technologies to leverage them to the best advantages for your IoT solution. Until the release of Windows 10 IoT Core, those who use Windows wanting to experiment with IoT solutions and in particular hardware like the Raspberry Pi had to learn a new operating system in order to get started. That is no longer true! In this book, we explore how to leverage Windows 10 in your IoT solutions.

Intended Audience

I wrote this book to share my passion for IoT solutions and Windows 10. I especially wanted to show how anyone could use Windows 10 along with a low-cost computing board to create cool IoT projects—all without having to learn a new operating system!

The intended audience therefore includes anyone interested in learning how to use Windows 10 for IoT projects, such as hobbyists and enthusiasts, and even designers and engineers building commercial Windows 10-based IoT solutions.

How This Book Is Structured

The book was written to guide the reader from a general knowledge of IoT to expertise in developing Windows 10 solutions for the IoT. The first several chapters cover general topics, which includes a short introduction to the Internet of Things, the Windows 10 IoT Core technologies, and some of the available hardware for IoT. Additional chapters are primers on how to write IoT solutions in a variety of programming languages. Rather than focusing on a single language, which often forces readers unfamiliar with the language to learn new skills just to read the book, I’ve included tutorials in a number of languages to make the book usable by more readers. Throughout the book are examples of how to implement IoT solutions in the various languages. As you will see, some languages are better suited for certain projects. The book contains six detailed and increasingly complex projects for you to explore and enjoy as you develop IoT solutions with Windows 10. There is even a chapter that shows you how to work with Arduino-compatibe microcontroller boards. The book concludes with a look at how to grow beyond the material presented. An appendix listing the hardware components for each chapter is included for your convenience. The following is a brief overview of each chapter in this book.

  • Chapter 1 : What Is the Internet of Things? This chapter answers general questions about the IoT and how IoT solutions are constructed. You are introduced to some terminology describing the architecture of IoT solutions and you are provided examples of well-known IoT solutions. The chapter concludes with a brief introduction to Windows 10.

  • Chapter 2 : Introducing the Windows 10 IoT Core . This chapter presents a version of Windows 10 called the Windows 10 IoT Core that runs on low-cost computers, such as the Raspberry Pi. You discover the basic features of Windows 10, including how to prepare your PC and get started with Windows 10 on your device. You will also see how to boot up the Raspberry Pi with Windows 10!

  • Chapter 3 : Introducing the Raspberry Pi . This chapter explores the Raspberry Pi and how to set up and configure it using the Linux operating system in order to understand the platform and supporting technologies. You’ll also discover a few key concepts of how to work with Linux and get a brief look at writing Python scripts, which are used to write Windows 10 IoT applications in later chapters.

  • Chapter 4 : Developing IoT Solutions with Windows 10 . This chapter presents a demonstration on how to get started using Visual Studio 2015. The chapter introduces several Windows 10 IoT Core–compatible hardware boards, including the layout of the GPIO headers. The chapter demonstrates how to build, deploy, and test your first Windows 10 IoT Core application.

  • Chapter 5 : Windows 10 IoT Development with C++ . This chapter provides a crash course on the basics of C++ programming in Visual Studio, including an explanation of some of the most commonly used language features. As such, this chapter provides you with the skills that you need to understand the growing number of IoT project examples available on the Internet. The chapter concludes by walking through a C++ example project that shows you how to interact with hardware.

  • Chapter 6 : Windows 10 IoT Development with C# . This chapter offers a crash course on the basics of C# programming in Visual Studio, including an explanation of some of the most commonly used language features. As such, this chapter provides you with the skills that you need to understand the growing number of IoT project examples available on the Internet. The chapter concludes by walking through a C# example project that shows you how to interact with hardware.

  • Chapter 7 : Windows 10 IoT Development with Python . This chapter is a crash course on the basics of Python programming in Visual Studio, including an explanation of some of the most commonly used language features. As such, this chapter provides you with the skills that you need to understand the growing number of IoT project examples available on the Internet. The chapter concludes by walking through a Python example project that shows you how to interact with hardware.

  • Chapter 8 : Electronics for Beginners . This chapter presents an overview of electronics for those who want to work with the types of electronic components commonly found in IoT projects. The chapter includes an overview of some of the basics, descriptions of common components, and a look at sensors. If you are new to electronics, this chapter gives you the extra boost that you need to understand the components used in the projects in this book.

  • Chapter 9 : The Adafruit Microsoft IoT Pack for Raspberry Pi . This chapter explores the Adafruit Microsoft IoT Pack for Raspberry Pi 3 and demonstrates a small project that uses the components in the kit (well, mostly) to read data from a simple sensor.

  • Chapter 10 : Project 1: Building an LED Power Meter . This chapter walks through a project using LEDs to display power (volts). You see how to use a potentiometer as a variable input device, read from an analog to digital converter (ADC), learn how to set up and use a serial peripheral interface (SPI), discover a powerful debugging technique, and learn how to create a class to encapsulate functionality.

  • Chapter 11 : Project 2: Measuring Light . This chapter explores a solution that demonstrates how to measure light using a sensor. The project measures the ambient light in the room and then calculates how much power to send to the LED using a technique called pulse-width modulation (PWM).

  • Chapter 12 : Project 3: Using Weather Sensors . This chapter demonstrates a very common type of IoT solution—a weather station. In this case, the project uses sensors from the Adafruit kit and implements the code by mixing C# and C++ in the same solution, reusing existing code, and combining it with new code in another language.

  • Chapter 13 : Project 4: Using MySQL to Store Data . This chapter revisits the project from Chapter 12 and modifies it to store the IoT data collected in a MySQL database. Thus, you see an example of how to complete the data storage element of your IoT solutions.

  • Chapter 14 : Project 5: Using a Web Server to Control Hardware . This chapter presents one method for building IoT solutions that control hardware remotely using a web page.

  • Chapter 15 : Project 6: Windows IoT and Arduino . In this chapter, you explore the Arduino platform along with the three Arduino technologies from Microsoft. You begin with a short tutorial on the Arduino and an in-depth look at using the Arduino Wiring libraries. This project combines many of the techniques and components from the previous chapters.

  • Chapter 16 : Azure IoT Solutions: Cloud Services . This chapter presents a few of the newer concepts and features of Microsoft Azure at a high level and in context of a sample project. You can therefore consider this chapter a bonus project chapter.

  • Chapter 17 : Where to Go from Here? This chapter explores what you can do to continue your craft of building IoT solutions. Most people want to simply continue to develop projects for themselves, either for fun or to solve problems around the home or office. However, some want to take their skills to the next level. This chapter shows you how to do just that.

  • Appendix . Contains a list of the required hardware components for each chapter.

How to Use This Book

This book is designed to guide you through learning more about what the Internet of Things is, discovering the power of Windows 10 IoT Core, and seeing how to build your IoT solutions using the best language suited for the task.

If you are familiar with some of the topics early in the book, I recommend you skim them so that you are familiar with the context presented so that the later chapters—especially the examples—are easy to understand and implement on your own. You may also want to read some of the chapters out of order so that you can get your project moving, but I recommend going back to the chapters you skip to ensure that you get all of the data presented.

If you are just getting started with Windows 10 or are not well versed in using Visual Studio, I recommend reading Chapters 19 in their entirety before developing your own IoT solution or jumping to the example projects. That said, many of the examples permit you to build small examples that you can use to help learn the concepts.

Downloading the Code

The code for the examples shown in this book is available on the Apress web site, www.apress.com . You can find a link on the book’s information page on the Source Code/Downloads tab. This tab is located in the Related Titles section of the page.

Contacting the Author

Should you have any questions or comments—or even spot a mistake you think I should know about—you can contact me, the author, at [email protected] .

Acknowledgments

I would like to thank all of the many talented and energetic professionals at Apress. I appreciate the understanding and patience of my editor, Jonathan Gennick, and managing editor, Jill Balzano. They were instrumental in the success of this project. I would also like to thank the army of publishing professionals at Apress for making me look so good in print. Thank you all very much!

I’d like to especially thank the technical reviewer, Reggie Burnett, for his often-profound insights, constructive criticism, and encouragement. I’d also like to thank my friends for their encouragement and suggestions for things to include in the book.

Most importantly, I want to thank my wife, Annette, for her unending patience and understanding while I spent so much time with my laptop.

Contents

  1. Chapter 1:​ What Is the Internet of Things?​
    1. The Internet of Things and You
      1. IoT Is More Than Just Connected to the Internet
      2. IoT Services
    2. A Brief Look at IoT Solutions
      1. Sensor Networks
      2. Medical Applications
      3. Automotive IoT Solutions
      4. Fleet Management
    3. IoT and Security
      1. Security Begins at Home
      2. Secure Your Devices
      3. Use Encryption
      4. Security Doesn’t End at the Cloud
    4. Introducing Windows 10
      1. Overview of Windows 10 Features
      2. Windows 10 and the IoT
    5. Summary
  2. Chapter 2:​ Introducing the Windows 10 IoT Core
    1. Windows 10 IoT Core Features
      1. Interacting with Hardware
      2. Video Support
      3. One Platform, Many Devices
      4. Supported Hardware
      5. So Which One Should I Choose?​
    2. Things You’ll Need
      1. Additional Hardware
      2. Software Development Tools
    3. Getting Started with Windows 10 IoT Core
      1. Setting up Your Computer
      2. Getting Started with Your Board
      3. Raspberry Pi Configuration
      4. MinnowBoard Max Turbot Configuration
      5. DragonBoard 410c Configuration
      6. Connecting to Your Board
    4. Summary
  3. Chapter 3:​ Introducing the Raspberry Pi
    1. Getting Started with the Raspberry Pi
      1. Raspberry Pi Origins
      2. Versions that Work with Windows 10 IoT Core
      3. A Tour of the Board
      4. Required Accessories
      5. Recommended Accessories
      6. Where to Buy
    2. Setting up the Raspberry Pi
      1. Choosing a Boot Image (Operating System)
      2. Creating the Boot Image
      3. Booting the Board
      4. Setting up Wi-Fi on the Raspberry Pi 3
    3. A Brief Linux Primer
      1. Getting Help
      2. File and Directory Commands
      3. System Commands
      4. Administrative Commands
      5. Useful Utilities
    4. Working with Python:​ Blink an LED
      1. Hardware Connections
      2. Writing the Code
      3. Running the Script
    5. Summary
  4. Chapter 4:​ Developing IoT Solutions with Windows 10
    1. Working with GPIO Headers
      1. Raspberry Pi
      2. MinnowBoard Turbot
      3. DragonBoard 410C
    2. Visual Studio 2015 Primer
      1. Major Features
      2. The Interface
      3. Windows 10 IoT Core Project Templates
    3. Example Project:​ Hello, World
      1. Create the Project
      2. Write the Code
      3. Build and Test Your Code
      4. Set up your Windows 10 IoT Device
      5. Deploy and Test to your Windows 10 IoT Device
    4. Summary
  5. Chapter 5:​ Windows 10 IoT Development with C++
    1. Getting Started
    2. C++ Crash Course
      1. The Basics
      2. Variables and Types
      3. Arithmetic
      4. Flow Control Statements
      5. Basic Data Structures
      6. Pointers
    3. Blink an LED, C++ Style
      1. Required Components
      2. Set up the Hardware
      3. Write the Code:​ User Interface
      4. Test and Execute:​ User Interface Only
      5. Add the GPIO Code
      6. Deploy and Execute:​ Completed Application
    4. Summary
  6. Chapter 6:​ Windows 10 IoT Development with C#
    1. Getting Started
    2. C# Crash Course
      1. C# Fundamentals
      2. How C# Programs Are Structured
      3. Variables and Types
      4. Arithmetic
      5. Flow Control Statements
      6. Basic Data Structures
    3. Blink an LED, C# Style
      1. Required Components
      2. Set up the Hardware
      3. Write the Code:​ User Interface
      4. Test and Execute:​ User Interface Only
      5. Add the GPIO Code
      6. Deploy and Execute:​ Completed Application
    4. Summary
  7. Chapter 7:​ Windows 10 IoT Development with Python
    1. Getting Started
      1. Why Do I Need to Learn Python?​
      2. Installing Python on Windows 10
    2. Python Crash Course
      1. The Basics
      2. Arithmetic
      3. Flow Control Statements
      4. Functions
      5. Basic Data Structures
    3. Blink an LED, Python Style
      1. Required Components
      2. Set up the Hardware
      3. Write the Code
      4. Deploy and Set as Startup
    4. Summary
  8. Chapter 8:​ Electronics for Beginners
    1. The Basics
      1. Powering Your Electronics
      2. Tools
      3. Soldering Iron
      4. Using a Multimeter
    2. Electronic Components
      1. Button
      2. Capacitor
      3. Diode
      4. Fuse
      5. Light Emitting Diode (LED)
      6. Relay
      7. Resistor
      8. Switch
      9. Transistor
      10. Voltage Regulator
      11. Breakout Boards and Circuits
    3. Using a Breadboard to Build Circuits
    4. What Are Sensors?​
      1. How Sensors Measure
      2. Examples of Sensors
    5. Summary
  9. Chapter 9:​ The Adafruit Microsoft IoT Pack for Raspberry Pi
    1. Overview
      1. Components Included
      2. Are There Alternatives?​
    2. Example Project:​ A Simple Sensor
      1. Required Components
      2. Set up the Hardware
      3. Write the Code
      4. Deploy and Execute
    3. Summary
  10. Chapter 10:​ Project 1:​ Building an LED Power Meter
    1. Overview
    2. Required Components
    3. Set up the Hardware
    4. Write the Code
      1. Debug Output
      2. New Project
      3. Initialize GPIO
      4. Controlling the LEDs
      5. Code for the MCP3008
    5. Deploy and Execute
    6. Summary
  11. Chapter 11:​ Project 2:​ Measuring Light
    1. Overview
    2. Required Components
    3. Set up the Hardware
    4. Write the Code
      1. New Project
      2. Lighting Providers
      3. User Interface
      4. Controlling the LED
      5. Completing the Main Class
      6. Code for the MCP3008
      7. Code for the PWM
    5. Deploy and Execute
    6. Summary
  12. Chapter 12:​ Project 3:​ Using Weather Sensors
    1. Overview
    2. Required Components
    3. Setup the Hardware
    4. Write the Code
      1. New Project
      2. Add a C# Runtime Component Project
      3. BMP280 Class
      4. User Interface
      5. Add References
      6. Reading the Weather Data
    5. Deploy and Execute
    6. Summary
  13. Chapter 13:​ Project 4:​ Using MySQL to Store Data
    1. What Is MySQL?​
    2. Getting Started with MySQL
      1. How and Where MySQL Stores Data
      2. The MySQL Configuration File
      3. How to Get and Install MySQL
      4. How to Start, Stop, and Restart MySQL
      5. Creating Users and Granting Access
    3. Overview
    4. Set up the Database
    5. Required Components
    6. Set up the Hardware
    7. Write the Code
      1. New Project
      2. Glovebox.​IoT.​Devices
      3. Units.​NET
      4. Connector/​Net
      5. Windows 10 IoT Extensions
      6. Connecting to MySQL
      7. Reading the Weather Data
      8. Writing the Data to the Database
    8. Deploy and Execute
    9. Summary
  14. Chapter 14:​ Project 5:​ Using a Web Server to Control Hardware
    1. Overview
    2. Required Components
    3. Set up the Hardware
    4. Write the Code
      1. New Project
      2. Web Interface
      3. Web Server Code
      4. Initializing the GPIO and Starting the Web Server
      5. Completing the Code
    5. Deploy and Execute
    6. Prototyping the Out of Office Sign Enclosure
      1. Assembling the Circuit Board
      2. Making the Enclosure
      3. Tuning the Servo Trigger
      4. Testing the Prototype
      5. Taking it a Step Further
    7. Summary
  15. Chapter 15:​ Project 6:​ Windows IoT and Arduino
    1. What Is an Arduino?​
      1. Arduino Models
      2. So, Which Do I Buy?​
      3. Where to Buy
    2. Getting Started with Arduino
      1. Learning Resources
      2. The Arduino IDE
    3. Arduino Wiring and UWP Lightning Providers
      1. Required Components
      2. Set up the Hardware
      3. Write the Code
      4. Deploy and Execute
    4. Windows Remote Arduino
      1. Required Components
      2. Set up the Hardware
      3. Prepare the Arduino
      4. Prepare Your PC
      5. Running the Remote Arduino Application
    5. Windows Virtual Shields for Arduino
      1. Required Components
      2. Set up the Hardware
      3. Prepare the Arduino
      4. Prepare Your PC
      5. Running the Virtual Shields Application
    6. Summary
  16. Chapter 16:​ Azure IoT Solutions:​ Cloud Services
    1. What Is Microsoft Azure?​
    2. Getting Started with Microsoft Azure
      1. Sign Up for an Azure Account
      2. Azure IoT Hub
      3. Azure IoT Suite
      4. Device Explorer
      5. Building IoT Solutions with Azure
      6. Hello, World! Azure Style
    3. Overview
    4. Required Components
    5. Set up the Hardware
    6. Set up a New Azure Remote Monitoring Solution
    7. Write the Code
      1. New Project
      2. Adding References for the Hardware
      3. Create a Class for the Weather Data
      4. Reading the Weather Data and Sending it to the Azure IoT Hub
      5. Writing the Data to the IoT Hub
    8. Deploy and Execute
    9. Summary
  17. Chapter 17:​ Where to Go from Here?​
    1. More Projects to Explore
      1. Microsoft Windows 10 IoT Samples
      2. Hackster.​io
    2. Join the Community
      1. Why Contribute?​
      2. How We Share
      3. Suggested Communities
    3. Become a Maker
      1. What’s a Maker?​
      2. Share Your Ideas
      3. Attend an Event
    4. Summary
  18. Appendix
  19. Hardware by Chapter
  20. Consolidated Hardware List
  21. Suggestions for Purchasing the Hardware
  22. Index

About the Author and About the Technical Reviewer

About the Author

Charles Bell

A416714_1_En_BookFrontmatter_Figb_HTML.jpg

conducts research in emerging technologies. He is a member of the Oracle MySQL Development team as a senior developer working on a variety of database administration and high-availability projects. He lives in a small town in rural Virginia with his loving wife. He received his doctorate of philosophy in engineering from Virginia Commonwealth University in 2005. His research interests include database systems, software engineering, sensor networks, and 3D printing. He spends his limited free time as a practicing maker, focusing on microcontroller and 3D printers and printing projects.

About the Technical Reviewer

Reggie Burnett

A416714_1_En_BookFrontmatter_Figc_HTML.jpg

is currently employed as senior software development manager for Oracle Corp., where he is in charge of development projects spanning many different platforms and architectures. Specializing in Windows and .NET technologies, Reggie has written articles for publications such as the .NET Developers Journal .

Reggie is married and has four children. He lives in central Tennessee where he plays golf and pool and works on his next geeky project.

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

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