forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: bluetooth: Add Apple iBeacon demo application
Add a simple demo implementation of an Apple iBeacon BLE broadcaster. Signed-off-by: Henrik Brix Andersen <[email protected]>
- Loading branch information
1 parent
034a11b
commit b27d968
Showing
5 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) | ||
project(NONE) | ||
|
||
target_sources(app PRIVATE src/main.c) | ||
|
||
if(IBEACON_RSSI) | ||
zephyr_compile_definitions(IBEACON_RSSI=${IBEACON_RSSI}) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.. _bluetooth-ibeacon-sample: | ||
|
||
Bluetooth: iBeacon | ||
################## | ||
|
||
Overview | ||
******** | ||
|
||
This simple application demonstrates the BLE Broadcaster role | ||
functionality by advertising an Apple iBeacon. The calibrated RSSI @ 1 | ||
meter distance can be set using an IBEACON_RSSI build variable | ||
(e.g. IBEACON_RSSI=0xb8 for -72 dBm RSSI @ 1 meter), or by manually | ||
editing the default value in the ``main.c`` file. | ||
|
||
Because of the hard-coded values of iBeacon UUID, major, and minor, | ||
the application is not suitable for production use, but is quite | ||
convenient for quick demonstrations of iBeacon functionality. | ||
|
||
Requirements | ||
************ | ||
|
||
* A board with Bluetooth LE support, or | ||
* QEMU with BlueZ running on the host | ||
|
||
Building and Running | ||
******************** | ||
|
||
This sample can be found under :file:`samples/bluetooth/ibeacon` in the | ||
Zephyr tree. | ||
|
||
See :ref:`bluetooth setup section <bluetooth_setup>` for details on how | ||
to run the sample inside QEMU. | ||
|
||
For other boards, build and flash the application as follows: | ||
|
||
.. zephyr-app-commands:: | ||
:zephyr-app: samples/bluetooth/ibeacon | ||
:board: <board> | ||
:goals: flash | ||
:compact: | ||
|
||
Refer to your :ref:`board's documentation <boards>` for alternative | ||
flash instructions if your board doesn't support the ``flash`` target. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CONFIG_BT=y | ||
CONFIG_BT_DEBUG_LOG=y | ||
CONFIG_BT_DEVICE_NAME="Zephyr iBeacon Demo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
sample: | ||
description: Sample code for Zephyr iBeacon Demo | ||
name: iBeacon | ||
tests: | ||
test: | ||
harness: bluetooth | ||
platform_whitelist: bbc_microbit qemu_x86 | ||
tags: bluetooth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) 2018 Henrik Brix Andersen <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/types.h> | ||
#include <stddef.h> | ||
#include <misc/printk.h> | ||
#include <misc/util.h> | ||
|
||
#include <bluetooth/bluetooth.h> | ||
#include <bluetooth/hci.h> | ||
|
||
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME | ||
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) | ||
|
||
#ifndef IBEACON_RSSI | ||
#define IBEACON_RSSI 0xc8 | ||
#endif | ||
|
||
/* | ||
* Set iBeacon demo advertisement data. These values are for | ||
* demonstration only and must be changed for production environments! | ||
* | ||
* UUID: 18ee1516-016b-4bec-ad96-bcb96d166e97 | ||
* Major: 0 | ||
* Minor: 0 | ||
* RSSI: -56 dBm | ||
*/ | ||
static const struct bt_data ad[] = { | ||
BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR), | ||
BT_DATA_BYTES(BT_DATA_MANUFACTURER_DATA, | ||
0x4c, 0x00, /* Apple */ | ||
0x02, 0x15, /* iBeacon */ | ||
0x18, 0xee, 0x15, 0x16, /* UUID[15..12] */ | ||
0x01, 0x6b, /* UUID[11..10] */ | ||
0x4b, 0xec, /* UUID[9..8] */ | ||
0xad, 0x96, /* UUID[7..6] */ | ||
0xbc, 0xb9, 0x6d, 0x16, 0x6e, 0x97, /* UUID[5..0] */ | ||
0x00, 0x00, /* Major */ | ||
0x00, 0x00, /* Minor */ | ||
IBEACON_RSSI) /* Calibrated RSSI @ 1m */ | ||
}; | ||
|
||
/* Set Scan Response data */ | ||
static const struct bt_data sd[] = { | ||
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN), | ||
}; | ||
|
||
static void bt_ready(int err) | ||
{ | ||
if (err) { | ||
printk("Bluetooth init failed (err %d)\n", err); | ||
return; | ||
} | ||
|
||
printk("Bluetooth initialized\n"); | ||
|
||
/* Start advertising */ | ||
err = bt_le_adv_start(BT_LE_ADV_NCONN, ad, ARRAY_SIZE(ad), | ||
sd, ARRAY_SIZE(sd)); | ||
if (err) { | ||
printk("Advertising failed to start (err %d)\n", err); | ||
return; | ||
} | ||
|
||
printk("iBeacon started\n"); | ||
} | ||
|
||
void main(void) | ||
{ | ||
int err; | ||
|
||
printk("Starting iBeacon Demo\n"); | ||
|
||
/* Initialize the Bluetooth Subsystem */ | ||
err = bt_enable(bt_ready); | ||
if (err) { | ||
printk("Bluetooth init failed (err %d)\n", err); | ||
} | ||
} |