Automatic Detection of iBeacon Failure Using Raspberry Pi
Join the DZone community and get the full member experience.Join For Free
the emergence of ibeacons as a micro location provider has created a number of solutions provided by different vendors in this space. given the quantity of beacons involved in each implementation, monitoring and maintaining the beacons have become time consuming and effort intensive increasing the maintenance & operational costs. this paper discusses about igate’s solution to detect the ibeacon failure using raspberry pi and the probable challenges that could be faced during the implementation.
2. problem statement
recent trends show that ibeacons, small battery powered bluetooth low energy (ble) devices, are being extensively used in retail stores for pushing promotions and indoor positioning. each of these beacons has a typical battery life of 6-8 months depending on the type of battery used. with a relatively huge setup that needs managing at least 500-600 beacons, manually monitoring the health of each beacon is time consuming and increases maintenance costs significantly. also if any one of the beacons has malfunctioned, detecting it might take more time which can result in loss of revenue to the retailer.
3. about raspberry pi
the raspberry pi is a credit card-sized single-board computer developed in the uk by the raspberry pi foundation with the intention of promoting the teaching of basic computer science in schools.
figure 1: raspberry pi
in 2014, the raspberry pi foundation launched the compute module, which packages a raspberry pi model b into module for use as a part of embedded systems, to encourage their use.
the raspberry pi is based on the broadcom bcm2835 system on a chip (soc), which includes an arm1176jzf-s 700 mhz processor, videocore iv gpu, and was originally shipped with 256 megabytes of ram, later upgraded (model b & model b+) to 512 mb. the system has secure digital (sd) or microsd (model a+ and b+) sockets for boot media and persistent storage.
the foundation provides debian and arch linux arm distributions for download. tools available are python as the main programming language, with support for bbc basic , c, c++, java, perl and ruby.
5.components of the system
figure 2: components of the system
6.1 preparing the raspberry pi
installing the bluez sdk, will add bluetooth capability to the pi.
once the usb bluetooth adapter is connected to the pi, the device status can be checked using the shell command
sudo hciconfig hci0 status
if the status shows “down”, the device has to be started using the command
sudo hciconfig hci0 up
once the device is up and running the shell script to detect the beacons can be run through command line or added as a cron-job that will run continuously for every 10 minutes
ibeacons are placed around the raspberry pi for it to be detected
6.2 shell script:
the shell script uses the hcitool to read the bluetooth packets near its vicinity and the script is used to filter the ibeacon packets in the list.
sudo hcitool lescan –duplicates &
the shell script, in turn, processes the ibeacon packets to retrieve the uuid, major id, minor id, rssi, and power which will be uploaded using curl to the server using a web service.
one major challenge was that the hcitool scan sniffed the packets at a higher rate than the script could process, which resulted in the readings getting processed very slowly. as the script runs continuously to scan bluetooth packets, there was a major delay in processing by the script which will led to delayed messages sent to server. to avoid this the script is run as a cron-job every 5 minutes and will last for 20 seconds every time.
timeout 20 ./ibeacon_scan.sh
this will make sure that there would be minimal delay in sending the bluetooth scan readings to the server for processing, and the server can, in turn, detect the ibeacon failure with a maximum delay of 10 minutes.
6.3 server application:
the server application consists of a web service and also a web based front end to show the beacon status on a store layout. the web service gets the data from the raspberry such as the ibeacon’s uuid, major id, minor id, rssi, and also the time stamp of the ibeacon packet reading. this data is updated on the database for the beacon table with the last updated time stamp for the beacon. a cron scheduler will check the current server time with the last updated timestamp for the beacon, and if this difference is more than 10 minutes, the beacon status will be updated as not working. the web based front end that shows the beacon status as red/ green will get updated accordingly.
7.challenges in implementation
some of the challenges faced during the implementation is listed below
the raspberry pi itself can fail for multiple reasons like power failure or some other reasons. this can be taken care by maintaining the last updated date of the raspberry pi.
detecting multiple beacons with the same uuid on the raspberry pi will fail as the ibeacon packet read by the raspberry pi will not have the mac address of the beacon
absence of any http framework on raspberry pi for handling web service calls to server for data exchange ended up in using a lot of low level functions on the raspberry pi.
as 500-600 beacons are involved in an implementation, beacon failure detection will be time consuming and expensive, if done manually. a raspberry pi combined with a bluetooth adapter and a server application can be used to detect ibeacon failure with a maximum delay of 10 minutes as given by the solution given in this paper. this solution eliminates the need for manual checking of the beacons failures.
Published at DZone with permission of Ashok Yalamanchili. See the original article here.
Opinions expressed by DZone contributors are their own.
Cypress Tutorial: A Comprehensive Guide With Examples and Best Practices
How Agile Works at Tesla [Video]
Which Is Better for IoT: Azure RTOS or FreeRTOS?
RAML vs. OAS: Which Is the Best API Specification for Your Project?