IoT Projects with Bluetooth Low Energy
eBook - ePub

IoT Projects with Bluetooth Low Energy

  1. 278 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

IoT Projects with Bluetooth Low Energy

About this book

Use the power of BLE to create exciting IoT applicationsAbout This Book• Build hands-on IoT projects using Bluetooth Low Energy and learn about Bluetooth 5 and its features.• Build a health tracking system, and indoor navigation and warehouse weather monitoring projects using smart devices.• Build on a theoretical foundation and create a practice-based understanding of Bluetooth Low Energy.Who This Book Is ForIf you're an application developer, a hardware enthusiast, or just curious about the Internet of Things and how to convert it into hands-on projects, then this book is for you. Having some knowledge of writing mobile applications will be advantageous.What You Will Learn• Learn about the architecture and IoT uses of BLE, and in which domains it is being used the most• Set up and learn about various development platforms (Android, iOS, Firebase, Raspberry Pi, Beacons, and GitHub)• Create an Explorer App (Android/iOS) to diagnose a Fitness Tracker• Design a Beacon with the Raspberry Pi and write an app to detect the Beacon• Write a mobile app to periodically poll the BLE tracking sensor• Compose an app to read data periodically from temperature and humidity sensors• Explore more applications of BLE with IoT• Design projects for both Android and iOS mobile platformsIn DetailBluetooth Low Energy, or Bluetooth Smart, is Wireless Personal Area networking aimed at smart devices and IoT applications. BLE has been increasingly adopted by application developers and IoT enthusiasts to establish connections between smart devices.This book initially covers all the required aspects of BLE, before you start working on IoT projects. In the initial stages of the book, you will learn about the basic aspects of Bluetooth Low Energy—such as discovering devices, services, and characteristics—that will be helpful for advanced-level projects. This book will guide you through building hands-on projects using BLE and IoT. These projects include tracking health data, using a mobile App, and making this data available for health practitioners; Indoor navigation; creating beacons using the Raspberry Pi; and warehouse weather Monitoring. This book also covers aspects of Bluetooth 5 (the latest release) and its effect on each of these projects.By the end of this book, you will have hands-on experience of using Bluetooth Low Energy to integrate with smart devices and IoT projects.Style and approachA practical guide that will help you promote yourself into an expert by building and exploring practical applications of Bluetooth Low Energy.

Tools to learn more effectively

Saving Books

Saving Books

Keyword Search

Keyword Search

Annotating Text

Annotating Text

Listen to it instead

Listen to it instead

Information

Building a Service Explorer App

I hear and I forget. I see and I remember. I do and I understand.
- Confucius
In the last chapter, we configured our systems so that we could build apps to gain a better understanding of Bluetooth Low Energy. In this chapter, we will build a Service Explorer app using which you can explore all kinds of Bluetooth Low Energy devices for their services. Also, as a bonus, we will simulate our very own homemade fitness tracker and explore its services and characteristics using the same app.
We hope that you remember our discussions regarding Bluetooth Low Energy architecture from the first chapter. Even if our deep discussions in the last chapter regarding the setup of our development environment has made it a little foggy, worry not, as we start with a refresher of the BLE architecture concepts in this chapter.
We will be creating a Service Explorer App by covering the following topics in this chapter:
  • Central Peripheral Architecture for BLE
  • Services and Characteristics
  • Creating a Service Explorer App

Central Peripheral Architecture for BLE

As understanding of Bluetooth Low Energy architecture in terms of Central and Peripheral roles is essential to understand how Bluetooth Low Energy devices advertise and connect to each other.
A Central is a device, which scans for Bluetooth devices to connect and utilize the information hosted by them. Usually, Central devices are richer in terms of resources such as computing power compared to the Peripheral devices. Specific to the use case that we will describe in this chapter, the role of a Central will be played by a mobile phone (Android/iOS):
Figure 1: Central and Peripheral Roles in Bluetooth Low Energy; source: developer.apple.com
Peripherals, on the other hand, are devices, which advertise their presence, and it is by virtue of this advertisement that the Central knows that a Peripheral device is nearby and it can connect to enquire about its data. For this chapter, we will be using the following to act as peripherals:
  • A fitness tracker
  • A mobile app, which will simulate a heart rate tracking device
You should not just limit yourself to these two devices. Once we have designed the app, we recommend that you use it with as many BLE Peripherals as you can lay your hands on.
If the Peripheral is responsible for advertisements, then the Central is responsible for the following:
  • Initiating a connection
  • Establishing a connection
  • Retrieving information from the peripheral (Discover Services, Characteristics, Descriptors and finally read the data)
  • Terminating a connection
These are shown in the following image:
Fig 1.1 - Bluetooth Low Energy Connection Procedure
Based on the preceding points, it is safe to say that it is always the Central which is in control of the information exchange process and of the entire connection. For a one-to-one connection, depending on whether it is connected to a Central or not, a Bluetooth Low Energy Peripheral can be in either one of the following two states:
  • Advertising
  • Connected
When the Peripheral is in an Advertising state, it broadcasts Bluetooth Low Energy advertising packets. Before delving into the details of advertising packets, it is important to understand what the general packet structure is that BLE follows.
Basic BLE packets can range from 80 bits to 376 bits in length, which include a 1-byte preamble, 4-byte access codes correlated with the RF channel number used, a PDU that can be between 2 to 39 bytes, and 3 bytes of CRC.
PDU is short for Protocol Data Unit, the term used to describe data as it moves from one layer of the OSI model to another. In this reference, PDU is often used synonymously with a packet.
An advertising PDU for the advertising channel consists of the 16-bit PDU header and depending on the type of advertising, the device address, and up to 31 bytes of information:
Figure 2: Over the air packet structure and advertisement PDU
However, although we have 31 bytes for packaging advertisement data, due to the specifications laid down by BLE, in reality, we have only 26 bytes. Puzzled? Let's see in the following points how it fits together:
  • As per the Bluetooth Low Energy specifications, any GAP broadcast must contain flags that tell the device about the type of advertisement that is being sent. The structure of these flags uses three bytes in total: one for data length, one for data type, and one for the data itself. Hence, we have 28 bytes left.
  • Now, finally we can package our own data but it also needs an indication of length and type (two bytes in total). So we have 26 bytes left to package the actual data.
Due to the Peripheral’s advertisements, once a Central is aware of the existence of a Peripheral, in most cases, both Central and the Peripheral will intend to move towards the Connected state, primarily due to the fact that the Central will be interested in further exploring the data that the Peripheral has to offer.
Opposing the preceding example are Beacons, which exist to advertise only and never try to move to a Connected state.
Once the connection has been made, a Central forms the process of discovery on the Peripheral, relying on the fact that the Peripheral has maintained its data in the form of services and their specific characteristics, as specified by the Bluetooth Low Energy specification.

Services and Characteristics

We have already covered services and characteristics in extensive detail in the first chapter; however, we will still do a quick refresher here, just in case. We will go bottom up this time starting with characteristics first.
Characteristics are the lowest and the most important echelon of the Bluetooth Low Energy technology. Encapsulated by a related service, these are the actual state variables, each of which stores a single piece of relevant measurement and information data. It is worthwhile reading about the Heart Rate Measurement characteristic, which we will be covering extensively in this chapter...

Table of contents

  1. Title Page
  2. Copyright
  3. Credits
  4. Foreword
  5. About the Author
  6. About the Reviewer
  7. www.PacktPub.com
  8. Customer Feedback
  9. Preface
  10. What is Bluetooth Low Energy?
  11. Setting Up
  12. Building a Service Explorer App
  13. Designing a Personal Tracking System
  14. Beacons with Raspberry Pi
  15. Weather Monitoring Using BLE in Warehouses
  16. Going Further

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access IoT Projects with Bluetooth Low Energy by Madhur Bhargava in PDF and/or ePUB format, as well as other popular books in Computer Science & Computer Networking. We have over one million books available in our catalogue for you to explore.