How does ibeacon work ?)

Source: Internet
Author: User
Tags macbook


Ibeacon is a hot topic recently. This technology enables indoor positioning, allowing your mobile phone to know if it is within the beacon range. Using this technology can produce many applications, such as helping you find your car in the parking lot, or providing coupons or location-related services in retail stores. There are many applications that we cannot imagine now.


There are many explanations about what ibeacon is and how we can use it. However, from a technical point of view, how do they work? The underlying technology uses Bluetooth le, so...


What is Bluetooth le? (What is Bluetooth le, abbreviated as BLE)


Bluetooth Low Energy (BLE) is part of the Bluetooth 2010 specifications released in 4.0. It originated from Nokia's wibree technology in 2006, but was eventually integrated into Bluetooth. This is a set of protocols different from traditional Bluetooth, and the devices used are not backward compatible. Therefore, you can see three types of devices on the market:

1. Bluetooth devices: only traditional Bluetooth devices are supported.

2. Bluetooth Smart ready device: supports both traditional Bluetooth and Le-mode devices.

3. Bluetooth Smart devices: Only devices in le mode are supported.


The latest mobile phones (iPhone 4 S +, SG3 +), laptops, tablets, and so on, basically support Bluetooth 4.0, that is, the Bluetooth Smart ready device. Beacon, on the other hand, this type of device only supports low energy protocols (Le Low Power Protocol) and belongs to the above-mentioned "Bluetooth Smart" device, this is why they have been running for a long time with a button battery. Older devices, such as peripherals, automobile systems, and old mobile phones, usually only support the traditional Bluetooth protocol.


The most important feature of BLE is its low energy consumption. For example, some beacon devices rely on a micro-battery to continuously send a signal for about two years (such battery is generally not detachable, you may need to replace a new beacon after beacon stops working ). Traditional Bluetooth and Le Bluetooth use the same band (2.4 GHz-2.4835 GHz ). The ble Protocol has a low transmission rate. Therefore, apart from discovering devices and performing some simple communications, it is not suitable for transmitting a large amount of data streams. In terms of the agreement, both le and traditional bluetooth signals can cover the range of 100 meters.


How does ble communication work? (How to communicate with ble devices)


Ble communication includes two main parts: advertising and connecting ).


Advertising is a one-way transmission mechanism. Devices that want to be searched can send packets at intervals of 20 ms to 10 seconds. The shorter the time interval, the faster the battery consumes, but the faster the device is detected. A data packet consists of a maximum of 47 bytes. It consists of the following parts:


1 byte preamble (1 byte header)

4 byte access address (4 byte address)

39 bytes Advertising channel PDU (39 bytes for PDU packets)

3 bytes CRC (3 bytes for CRC data verification)



For advertising communication channels, the addresses are always0x8E89BED6. For other data channels, the addresses are determined by different connections.


The returned PDU data also has its own data header (2 bytes: declare the length and type of the payload data-whether the device supports connection, etc) and the current payload data (up to 37 bytes ).


In the end, the first six bytes of the payload data are the MAC address of the device, so the actual information data can occupy up to 31 bytes.


Ble devices can run in a single unconnected ad mode (In this mode, all information is included in the ad package ), however, devices can also run In connectable mode (usually in this mode ).


When a device is found, a connection is established. Then you can read the services provided by the ble device and the characteristic (attributes, similar to the GATT profile instance) of each service ). Each characteristic provides values that can be read or modified. For example, a small thermostat can open a service to get the current temperature or humidity readings (equivalent to the characteristic service), and other services and characteristic can also be opened to set the expected temperature. Here, because Beacon does not use the connection mode, I will skip these details. For more information about connecting to the ble device, see the Apple's core Bluetooth guide, although you may not be an iOS developer. For more technical articles, refer to introduction to Ble, making the most out of BLE advertising mode.


How do beacons use ble? (How to Use ble for beacon devices)


Beacon devices only use ad communication channels. As beacon (beacon, beacon) literally means, such devices send data packets at a certain interval, and the data sent can be obtained by devices like mobile phones. That is to say, ibeacon is only a simple use of BLE advertising mode, and provides additional support for IOS.


If you try to intercept an ibeacon advertisement packet, for example, the packet intercepted from estimote beacon below:


02 01 06 1A FF 4C 00 02 15 B9 40 7F 30 F5 F8 46 6E AF F9 25 55 6B 57 FE 6D 00 49 00 0A C5

(The above data is intercepted. If you are using a Mac device, you can refer to additional xcode download to add a Bluetooth scan and data packet printing tool for xcode. For Windows devices, refer to here)


The preceding data has removed the header of the AD packet, the corrected address, the header of the ad pdu packet, and the MAC address, that is to say, this part of data only contains the actual information data-a total of 30 bytes, which meets the limit of up to 31 bytes of actual information data.


How is the ble advertisement data of an ibeacon device made up? The following is the data format corrected by Apple. For details, refer to the following ):


02 01 06 1A FF 4C 00 02 15: iBeacon prefix (fixed)B9 40 7F 30 F5 F8 46 6E AF F9 25 55 6B 57 FE 6D: proximity UUID (here: Estimote’s fixed UUID)00 49: major00 0A: minorC5: 2’s complement of measured TX power



Based on these principles, if you want to experiment with beacon functions, you do not need a real beacon device. If you have the latest mobile phone (such as iPhone 4S +, SG3 +) or a laptop with Bluetooth 4 (such as retina MacBook), you can convert these devices into ibeacon sending devices and receiving devices. Take the iPhone as an example. You can download the "locate IB" app from the appstore. For MacOS, refer to here. Of course you can use Raspberry Pi.


Breaking down the ibeacon format (parse the ibeacon Data Format)


In addition to the corrected ibeacon prefix data (02 01... 15), what does the other data represent?


Proximity UUID(B9... 6D in the above example): This is the ID that distinguishes all your beacon devices from other beacon devices! For example, multiple beacon nodes are distributed in a certain area of the store to form a "chain belt", which is used to provide specific services to customers, beacon that belongs to the same "chain" will be allocated to the same proximity UUID. The dedicated application designed for this chain belt will use this UUID in the background to scan the beacon device in this chain belt.


MajorNumber (2 bytes, 0x0049 in the preceding example, that is, 73): used to identify the related beacon as a group. For example, all beacon in a store will be assigned the same major number. In this way, the application can know the store where the customer is located.


MinorLabel (also 2 bytes, 0x000a in the preceding example, that is, 10): used to identify a specific beacon device. For example, each beacon device in a store has a unique minor number, so that you can know where the customer is located.


Measuring distance)


Last value,TX powerTo determine the distance between you and beacon. Based on this value, not only can rough information be obtained (for example, close to/away from/out of the range ), you can also get the distance accurate to the meter (of course, you can also convert it to the distance in the unit of STEP ). So how to implement it?


TX power(In the preceding example, 0xc5 = 197, and 256-197 =-59dbm is measured based on the 2's complement code.) It is the signal strength value measured 1 meters from the device (received-signal ed signal strength indication, signal strength indicators received ). If the received signal strength decreases, we may be away from it. As long as you know the 1-meter-distance relationship between the source and the current (we can obtain this information from one of the received signals), it is possible to calculate the current distance. IOS has implemented this function. For other platforms that require manual coding, refer to here.


Note: Java code rough distance calculation code:

protected static double calculateAccuracy(int txPower, double rssi) {  if (rssi == 0) {    return -1.0; // if we cannot determine accuracy, return -1.  }  double ratio = rssi*1.0/txPower;  if (ratio < 1.0) {    return Math.pow(ratio,10);  }  else {    double accuracy =  (0.89976)*Math.pow(ratio,7.7095) + 0.111;        return accuracy;  }}   

However, in practice, the distance is only an estimate because the human body or other communication barrier may weaken the signal.


IOS Integration)


IOS has integrated ibeacon. When you enter the beacon scope, your application can receive notifications even if your application is in the background. An application can register an entry or exit event for a region, so it can be awakened even if the application is not running. In response to these events, applications can send notifications such as local push, prompting users to open the application to view the sales promotion ads of the store (these sales promotion ads can be obtained from the Internet ), or other related content.


More accurately, when the mobile phone is not active, that is, when IOS enters the low-power monitoring mode, only the ibeacon zone entry/exit event can be received. When mobile phones and applications are active, you can enter the ranging mode, which makes the signal strength and estimated distance you detect more accurate.


Note that it takes some time for your mobile phone to detect beacon. First, the beacon device sends an advertisement at a certain interval. Second, if your mobile phone is in inactive mode, it will only detect bluetooth signals in some cases. To detect a beacon device, there must be an intersection between the above two periods of work. It may take 15 minutes to detect a beacon device.


For details about how to develop an iOS ibeacon application, refer to here. Beacon manufacturers usually also provide sdks to help develop beacon applications. Refer to the ios sdk and Android SDK of estimote.


How can I get some beacons? (How to obtain beacon devices)


Beacon device resources are currently relatively scarce. You usually need to wait a few weeks to get the goods, but it is certain that this situation will improve in the future.


Therefore, the fastest choice is to create a beacon simulator: Convert iPhone/Android/MacBook/other laptops/Raspberry Pi into a beacon simulator.


The second option is to try to order some beacon devices:


Pre-order estimote beacons; 3 for $99

Kontakt beacons come in a couple of packages; 4 for $99, 10 for $279.

Raspberrypi kits from radiusnetworks: 1 for $99

Redbearlab offers ble shields for Arduino for $30

Bleu sells USB-ibeacon dongles. 1 for $40, 5 for $150


Alternatives (alternative)


Ibeacon is not the only device developed based on ble close-up technology. Qualcomm is also developing its own beacon-gimbal, which integrates iOS and Android sdks. They provide similar functions, but ble Ads may have different data formats. My development tool is still being shipped, so I haven't tested it yet, but this beacon must be interesting, especially because it costs only $5 at the lowest price.


What's next? (What is next ?)


What we haven't done yet is to develop some beacon-based applications. To achieve this, remember softwaremill: We often look for interesting projects for development.


Address: http://www.warski.org/blog/2014/01/how-ibeacons-work/



How does ibeacon work ?)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.