1| Supported Targets | ESP32 | ESP32-C3 |
2| ----------------- | ----- | -------- |
3
4# ESP-IDF iBeacon demo
5
6From welcoming people as they arrive at a sporting event to providing information about a nearby museum exhibit, iBeacon opens a new world of possibilities for location awareness, and countless opportunities for interactivity between iOS devices and iBeacon hardware.
7
8## How to Use Example
9
10Before project configuration and build, be sure to set the correct chip target using:
11
12```bash
13idf.py set-target <chip_name>
14```
15
16**Note:** *iBeacon is a trademark of Apple Inc.*
17
18Before building devices which use iBeacon technology, visit [Apple iBeacon](https://developer.apple.com/ibeacon/) to obtain a license.
19
20### iBeacon Mode
21
22This example demonstrates iBeacon-compatible BLE advertising, and scanning of iBeacons:
23
24- **IBEACON_SENDER**: demo to send iBeacon-compatible advertising data.
25
26- **IBEACON_RECEIVER**: demo to receive and resolve iBeacon advertising data.
27
28Which demo will be run depends on the menuconfig, developers can set it in `iBeacon Example Configuration`.
29
30The default mode is iBeacon Sender.
31
32### Configure the project
33
34Open the project configuration menu:
35
36```bash
37idf.py menuconfig
38```
39
40And then enter `Component config --> Bluetooth --> Bluedroid Enable`
41
42Because the number of peripherals may be very large, developers can enable the **BLE Scan Duplicate Options**, the maximum number of devices in scan duplicate filter depends on the free heap size, when the cache is full, it is cleared.
43
44### Event Processing
45In the iBeacon receiver demo, the scan result will be posted to `ESP_GAP_SEARCH_INQ_RES_EVT` event:
46
47```c
48switch (scan_result->scan_rst.search_evt) {
49    case ESP_GAP_SEARCH_INQ_RES_EVT:
50    /* Search for BLE iBeacon Packet */
51    ......
52    break;
53    default:
54    break;
55}
56```
57### Build and Flash
58
59Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.
60
61(To exit the serial monitor, type ``Ctrl-]``.)
62
63See the [Getting Started Guide](https://idf.espressif.com/) for full steps to configure and use ESP-IDF to build projects.
64
65## Example Output
66
67The iBeacon sender will broadcast iBeacon packet after initializing the Bluetooth protocol stack, and the iBeacon receiver will scan the iBeacon packet.
68
69### iBeacon Sender
70
71```
72I (384) boot: Loaded app from partition at offset 0x10000
73I (384) boot: Disabling RNG early entropy source...
74I (386) cpu_start: Pro cpu up.
75I (389) cpu_start: Starting app cpu, entry point is 0x40081010
76I (0) cpu_start: App cpu up.
77I (400) heap_init: Initializing. RAM available for dynamic allocation:
78I (406) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
79I (413) heap_init: At 3FFCCCA8 len 00013358 (76 KiB): DRAM
80I (419) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
81I (425) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
82I (431) heap_init: At 40090E58 len 0000F1A8 (60 KiB): IRAM
83I (438) cpu_start: Pro cpu start user code
84I (120) cpu_start: Starting scheduler on PRO CPU
85I (0) cpu_start: Starting scheduler on APP CPU
86I (244) BTDM_INIT: BT controller compile version [44d04c1]
87
88I (244) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
89I (624) phy: phy_version: 3910, c0c45a3, May 21 2018, 18:07:06, 0, 0
90I (654) IBEACON_DEMO: register callback
91```
92
93### iBeacon Receiver
94
95```
96I (384) boot: Loaded app from partition at offset 0x10000
97I (384) boot: Disabling RNG early entropy source...
98I (385) cpu_start: Pro cpu up.\0x1b[0m
99I (389) cpu_start: Starting app cpu, entry point is 0x40081010
100I (0) cpu_start: App cpu up.
101I (400) heap_init: Initializing. RAM available for dynamic allocation:
102I (406) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
103I (412) heap_init: At 3FFCCC88 len 00013378 (76 KiB): DRAM
104I (418) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
105I (425) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
106I (431) heap_init: At 40090E58 len 0000F1A8 (60 KiB): IRAM
107I (437) cpu_start: Pro cpu start user code\0x1b[0m
108I (120) cpu_start: Starting scheduler on PRO CPU.
109I (0) cpu_start: Starting scheduler on APP CPU.
110I (243) BTDM_INIT: BT controller compile version [44d04c1]
111
112I (243) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
113I (633) phy: phy_version: 3910, c0c45a3, May 21 2018, 18:07:06, 0, 0
114I (663) IBEACON_DEMO: register callback
115I (329203) IBEACON_DEMO: ----------iBeacon Found----------
116I (329203) IBEACON_DEMO: Device address:: 30 ae a4 00 42 82
117I (329203) IBEACON_DEMO: Proximity UUID:: fd a5 06 93 a4 e2 4f b1 af cf c6 eb 07 64 78 25
118```
119
120## Troubleshooting
121
122For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
123