Monthly Archives: November 2014

iBeacon & Bluetooth LE

What is Bluetooth Smart and Bluetooth LE?

Bluetooth Low Energy (Bluetooth LE) is also known as Bluetooth Smart. It is designed to provide Bluetooth based functionality without draining the battery power of your device.

Bluetooth LE is part of Bluetooth 4.0 specification. You can download the specification from Bluetooth.org. You would find three kinds of bluetooth devices. One is based on Classic Bluetooth; not supporting the low energy specification. The other are Bluetooth Smart Ready; which support both classic and low energy specifications. The last are Bluetooth Smart devices; which only support 4.0 specification.

Bluetooth LE use the same spectrum as classic Bluetooth i.e. 2.4 GHz – 2.4835 GHz.

There are two central roles of Bluetooth LE devices. They are central and peripheral roles. In peripheral role, they can send advertisement broadcast messages for their presence. These messages can be picked up by another LE device in central mode. They can then connect with peripheral and request the GATT services supported by the device in peripheral role.

Each Bluetooth LE device can support a list of services. The details of these services can be discovered from the devices in the form of GATT (Generic ATTribute) profiles. You can display those services in an app to be displaoyed to the user. These services give the details of what the device is able to do.

iBeacons and Bluetooth LE

iBeacons implement the low energy part of Bluetooth 4.0 specification. They are Bluetooth LE devices in peripheral mode. They just support advertisement. You can’t really connect to an iBeacon. The presence of an iBeacon assumes proximity to a particular thing or place. It is your app’s responsibility to use the presence of an iBeacon into something useful for your customers.

iBeacon Hardware

There are a number of iBeacon providers. Just make sure that they have a configuration app for your device, otherswise, you might end up with a hardware but couldn’t just configure that. The app should also be compatible with the OS version you are running. Android is great in telling you the details of compatibility. You can also look at the details for indoor / outdoor usage. The plastic might be burned in the sun.

SticknFindCompatible

The most popular iBeacons are definitely Estimote iBeacons. They are cute little stone like structures which stick themselves to surfaces.

estimoteBeacons

Estimote are generally powered with a battery. So they can be placed at the places of your choice without ever needing an power outlet. But for your testing, you might not want to buy a lot of batteries. The iBeacons from radius network look perfect. Just hook them with your USB power adapter and they would be providing all the necessary advertisements you need for testing your app. Radius network also provides beacon tags.

radbeacon

Virtual iBeacons

Technically, we can turn any device supporting Bluetooth 4.0 specification into an iBeacon. All it needs is to run it in peripheral mode with the same intervals. Please remember that this is not possible for a windows machine to turn into an ibeacon yet (discussed below in detail). Android has added support for peripheral mode starting with Lollipop (5.0 – API 21). Apple devices support running in peripheral mode but some recent changes in Yosemite OSX have caused some issues with the existing beacon app for Mac. There are a number of iOS apps available with this functionality (using Core Location API). Just remember that in order to transmit these advertisement, the app has to be in front-most with the screen turned-on and device unlocked.

macbeacon_issues

iBeacon Advertisement Packet

An iBeacon has to advertise itself for the receivers. The receivers can use this advertisement to determine which iBeacon they are closed to. The configurable portion of an iBeacon advertisement packet consists of three parts. They are UUID, major and minor numbers.

  1. UUID (Universally Unique IDentifier): This is a 128 bit value. iOS allows scanning for iBeacon with particular UUID. As an example, a store chain owner can keep the same UUID for all iBeacons for his stores. He can also assign a unique ID for all iBeacons in a particular store.
  2. Major Number: This is a 16 bit value. Major and minor numbers are provided to uniquely identify a beacon within your device. If you are a store owner, you can use major number to identify the unique section.
  3. Minor Number: This is also a 16 bit value. A developer can use this to further identify a beacon. For the example of the store, you can use it to identify a particular aisle within the same section.

Frequency of iBeacon Advertisement

Since an iBeacon has to broadcast advertisement to announce its presence, the question is how often these announcements are transmitted. Advertising too often would drain the battery of the hardware, similarly, far apart advertisements would not be useful for most of the applications. So there has to be a balance between these two. The specification has a fixed value for the interval. This is 100ms i.e. the device would transmit advertisement packets after every 100 ms. This is not configurable.

iBeacon Functions

iBeacon provides two functions. They are monitoring and ranging. Monitoring is the task of getting notified when an iBeacon receiver enters or exits an iBeacon region. Ranging provides the details how close we are to a particular iBeacon.

In an organization using iBeacon proximity technology, there would be a number of iBeacons installed in the facility. Their coverage area might also overlap. As an app provider, we need to determine which iBeacon is closest to show some features to the users, hence ranging. The proximity information is not part of advertising packet but it is determined by a receiving device based on the strength of the signal. The API provides this information as RSSI (Received Signal Strength Indication)

iBeacon Configuration

An iBeacon needs to be configured before it is deployed. There are various apps to configure iBeacons. Generally, iBeacon hardware provider provide the configuration tool as well. This allows the developers to assign the values in the advertising packet of an individual iBeacon.

iBeaconConfig

iPhone and Bluetooth LE

iBeacons is really an Apple’s baby. There were a lot of talks when apple didn’t add support for NFC. They have been working on iBeacons all this time to come up with iBeacon technology. With iBeacons they don’t seem to add support for it anymore. Apple introduced the support for Bluetooth LE in iOS 7. Starting with iOS 7.1, monitoring can be used to launch an app which is not running. Apple has the best support for iBeacons, plus the iOS version of apps from hardware iBeacon providers are a lot better than their android counterpart.

estimoteiBeacondetails

Android and iBeacons

Android added support for Bluetooth LE in Android 4.3 in central role, which allows an android device to scan and receive advertisements sent by iBeacon trasmitters. The peripheral mode is announced for Anrdoid Lollipop, so it is part of Android 5.0 API (API Level – 21). In peripheral mode, an android device can be emulated as an iBeacon transmitter.

There is a special issue with Anroid BLE around some beacon hardwares specially Qualcomm’s Gimbal beacons. They have a security feature, which changes the MAC address of the hardware every 0.8 seconds. Android Bluetooth service can hold MAC addresses close to 1,990. After that it crashes. After that number is reached, as soon as you get close to a bluetooth device, it sees a new MAC address and just crashes. The only solution is to turn off the bluetooth or factory reset the hardware. Apparently Radius Network has a solution to this problem. You can download the app on your android.

crash_resolver

Microsoft & iBeacon

Microsoft introduced support for Bluetooth LE with Win 8.1. Your app needs to have permissions, so you add it in package.appmanifest file [blog post].

BluetoothLEEnumeratorWin81

Although there is support for pairing up with a Bluetooth LE device, an app cannot scan for iBeacons. OS can only scan for connectable Bluetooth devices providing GATT services and pair with them. So we need to wait until Windows 10 is out in the market. It should be expected some time in 2015. Stay tight!

Running Redis Server On Windows

Redis is a high performance key / value store. It is a NoSQL database. It supports various types of values including scalar and complex data structures including list, set, sorted set and hashset. We can just serialize our (e.g. JSON or XML) and just push it to Redis.

In this post we are going to learn how we can setup Redis on a Windows machine. In some later posts, we should see how we can build some example applications using Redis.

Downloading Redis

The download links are available on the following page. As we will be running on windows, let’s download the Win64 version. As mentioned on the download page, this is not an official redis version but supported by MS Open Tech group.

redisDownload

This takes us to its GitHub repository. Since we are not planning to do any development, let’s just download the release version, available in compressed ZIP format.

redismsopentech

Installing Redis

Win64 Redis is xcopy deployable. We should be able to run it as we download it. Just make sure that you have unblocked the zip file.

Redis can be installed and run as a Windows Service using the following commands:

Although you can install multiple instances of Redis Server (both console & window service), but you can not listen on the same port. So if you cannot start another instance of the server just check the configuration or just specify a different port in the start-up argument when you install the service.

Running Redis

Redis Server can run as console application or windows service. Just run redis-server executable from the download folder. It should launch the console as follows:

redisServerConsole

It can also be run as a Windows Service. There can be multiple instances of the server on the same machine. They can have different names and configured with requests on different ports. The complete documentation for running Redis server as a windows service is available in the download folder.

redis_service

You can use the following commands to install, uninstall, start and stop the service.

Verifying Server

In order to verify that redis server is successfully running, we can just use any redis client. Let’s just use redis-cli available in the same download folder:

redisCli

We can’t learn all redis commands in one blog psot but there is a very good interactive tutorial for learning redis commands.

tryredis