Tram Ho

iBeacon and mechanism of action


iBeacon is a protocol developed by Apple and introduced from iOS 7. iBeacon allows handheld electronic devices to use Bluetooth Low Energy ( BLE ) to interact and receive data from wireless sensors ( often called the beacons). Imagine going to a supermarket where Beacons are located. Immediately your iPhone will identify and communicate with the beacons, thereby retrieving information on promotions, discounts … and displayed on the iPhone. In addition, employees can easily manage each customer who is present in the supermarket. The maximum data transmission distance of the beacons will depend on the location and obstacles in the environment. The standard beacons have a range of approximately 70m, some beacons can range up to 450m. This makes iBeacon an excellent way to build tracking applications on a narrow scale, requiring greater accuracy than GPS.

Mechanism of action

iBeacon uses BLE’s advertising mode (sending only one-way information) to send a universally unique identifier ( UUID ) with data bytes to compatible devices. A transmitted packet must follow the specified standards and be 47 bytes in length. The beacons can signal in cycles from 20ms to 10s, the longer the cycle, the longer the battery life.

Compatible devices

  • iOS devices with Bluetooth 4.0+ (iPhone 4S and later, iPad (3rd generation) and later, iPad Mini (1st generation) and later, and iPod Touch (5th generation) and later).
  • Macintosh computers with OS X Mavericks (10.9) or later and Bluetooth 4.0.
  • Android Devices with Bluetooth 4.0+ and Android OS 4.3+ (eg Samsung Galaxy S7 / J1 mini Prime, Samsung Galaxy Note 2/3, HTC One, Google / LG Nexus 7 2013 / Nexus 4 / Nexus 5, OnePlus One, LG G3) .
  • Windows Phone devices with Bluetooth 4.0+ and the Lumia Cyan update or above (reports suggest support is not included with Windows Phone 8.1).

What is iBeacon used for?

With a well-established beacons network, shops, buildings, zoos … can know exactly where users are. This allows users to receive useful information related to shops, items, discounts, etc. The iBeacon technology provides a solution that firms can communicate with each customer individually. more accurate way existing technologies. Currently, manufacturers have created many different types of beacons to apply iBeacon technology, in this article, Zeacon will be used.

Communicate with Zeacon

The concept

Central is the device that receives data from beacons (here is iPhone). Peripheral are Blutooth devices that will emit signals – the Zeacon itself. Advertising Packets are packets that a peripheral emits. Each packet is usually very small and cannot contain a lot of information, so to share more data, a central will need to connect to the peripheral to read data from it. The data of a peripheral is organized into services and characteristics . Service is a collection of data and related behaviors that describe a specific function of peripheral. A Peripheral can have more than one service. Characteristic provides more details about the service. For example: A smart watch device will have services: measuring heart rate, monitoring sleep, tracking sport activities … In the activity tracking service, there will be features: counting steps, calories consume…

Scan Zeacon

Import Core Bluetooth framework in MainViewController.swift . You will need to create a CBCentralManager that communicates with the peripheral

Most of the work in the Core Bluetooth framework is done through delegates. With central is CBCentralManagerDelegate and peripheral is CBPeripheralDelegate .

Function centralManagerDidUpdateState (_:) will check the bluetooth status before scanning starts. If bluetooth is off, turn it back on to make sure the status is .poweredOn . The scan results will be returned in the didDiscover function

A lot of peripheral are found, one of them with format name = VR-320 * – ****** are Zeacon.

Bind the values ​​in arrPeripheral into a UITableView and display them on the screen. Make connect when tap on any cell.

The result after making connect will be returned in the didConnect function. Here perform discoverServices to find services that peripheral has

The service found will be returned in the didDiscoverServices function. Here discover discoverCharacteristics to find the characteristics corresponding to each service

The characteristic found will be returned in the fuction didDiscoverCharacteristicsFor . Here the analysis will begin to retrieve the information sent by the peripheral. The characteristic will contain a CBCharacteristicProperties (.read or .notify) property that specifies the corresponding data fetch:

The values ​​obtained from peripheral will return in the didUpdateValueFor function. Here, save the values ​​and display them in the UI

Above is a brief introduction about iBeacon. In the future, there will probably be many applications using iBeacon especially in the field of IoT.

Share the news now

Source : Viblo