Chapter 5. Beacons with Raspberry Pi
The technology you use impresses no one. The experience you create with it is everything.
In the last chapter, we brewed our very own indoor positioning system by using nothing more than a smartphone, an iTag, and a few brilliantly written research papers. Building on our knowledge about discovering and connecting with Bluetooth Low Energy devices from the previous chapters, we discovered that apart from services and characteristics, there is much more that Bluetooth Low Energy has to offer; for instance, we used RSSI to extract relevant information from a Bluetooth Low Energy device by converting it to proximity/distance.
This chapter is a little different from the previous ones. Building on our knowledge of implementation details that we gathered in the previous chapters, rather than introducing a new implementation detail, this chapter introduces the reader to a completely new class of Bluetooth Low Energy devices, that is, Beacons.
We will...
Stating simply, a Beacon is a small wireless device, which transmits continuous radio/Bluetooth Low Energy signals. Depending on the protocol being used, these signals package contextual information, which can then be intercepted by nearby Bluetooth Low Energy devices (which in most cases are smart phones), and then depending on the context and use case, the intercepted information is either presented to the user or sent to a backend for further processing or both.
Figure 1: Various types of Beacons
Apart from the hardware itself, a protocol plays an important role and is one of the fundamental building blocks of any Beacon-related application use case. In very simple words, for the purpose of wireless communication, a protocol is a set of rules defining data transmission in a wireless channel.
Note
Do not get confused between a protocol and the Beacon itself. A Beacon is a piece of hardware whereas a protocol is the way in which data is structured and transmitted by...
Introduction to Raspberry Pi
For the purpose of introduction, Raspberry Pi is a series of small single board computers, created by Raspberry Pi Foundation in February 2012.
The vision behind these miniature computers was to teach basic computer science in the schools in and around the UK and in various developing countries, which is identified by the mission of the Raspberry Pi Foundation, that is, "To put the power of digital making into the hands of people all over the world".
However, due to their low cost and longer durability, Raspberry Pi surpassed the anticipation of its makers by becoming hugely popular with hackers and novices alike. It further went on to become the best-selling PC in the UK of all time.
The following figure shows the timeline of the release of various models of Raspberry Pi up until 2015:
Figure 5: Timeline, the advent and evolution of Raspberry Pi
February 2016 marked the advent of a...
Creating a Beacon with Raspberry Pi
We shall be creating a Beacon on top of Raspbian and we would be doing that using one of the popular tools that come bundled with the original Linux kernel. We shall begin by setting up the Raspberry Pi (Model 3B) and we are assuming that you have a Raspberry Pi essentials kit, a keyboard, a mouse and a display (monitor) to start with:
- Plug in the USB mouse and keyboard to the USB ports, also connect the monitor to the Pi via the HDMI cable. If you do not have an HDMI monitor, you can use the appropriate converter for the purpose. A port outline of the Raspberry Pi Model 3B is shown in the following image:
Figure 8: Ports on Raspberry Pi Model 3B; source: www.element14.com
- Use the NOOBS card that came bundled with the essentials kit and insert it into the MicroSD card slot. Additionally, not essentially, you can also put up the housing/case over the Pi, which came bundled with the essentials kit.
- We have hooked up all the I/O units, plus inserted the NOOBS...
Writing an App to Detect the Beacon
Our Beacon is already up and advertising. We will now write an app to detect the Beacon and the contents of the advertisement. Although Eddystone has excellent documentation provided by Google for both Android and iOS. Eddystone is originally developed by Google and in general sense has a more elaborative setup on Android. Hence, we shall start with Android first and then move on to iOS. For iOS, we shall give you a head start on the code and then expect that you do the rest as an exercise to gain a solid footing.
Prerequisites for this section:
- A Raspberry Pi 3(setup as described in the previous section)
Android:
- Latest Android Studio
- A Latest Android Device(Preferable Samsung Galaxy S8, since it has support for Bluetooth 5 otherwise Any Device with an API Level of 23(Android M) is fine)
- Basic familiarity with Java and Android
iOS:
- XCode 8.2
- A latest iOS device(Our development device uses iOS 9.3.5)
- Basic familiarity with Swift 2.3 and iOS
Beacons are a different and an important paradigm related to Bluetooth Low Energy. They are becoming increasingly popular day by day. Google and Apple already foresaw that, and defined their own standard formats for Beacon advertisements which we covered in this chapter. We also briefly discussed Physical Web, which is Google's grand plan to convert Internet of things to Internet of everything. We shall discuss Physical Web in detail in the last chapter.
As this chapter draws to a conclusion, we move on to the grand finale, our final project for this book, where we design an industrial solution for warehouse monitoring. We shall also introduce a new interesting sensor in that chapter. The project is of utmost importance, given the fact that that it is already being applied in warehouses across the US and UK. So, stay tuned!