|
| 1 | +# FindMyAdv |
| 2 | + |
| 3 | +Reusable Apple Find My and Google Find Hub BLE advertising for Arduino on |
| 4 | +BLE-capable ESP32 chips. Add one `begin()` call to an existing firmware; the |
| 5 | +library runs its scheduler in a private FreeRTOS task and does not require code |
| 6 | +in `loop()`. |
| 7 | + |
| 8 | +`begin()` may be called from `setup()` or later, after the host application has |
| 9 | +loaded credentials or completed its own initialization. `end()` stops the |
| 10 | +module, and a later `begin()` starts it again. |
| 11 | + |
| 12 | +FindMyAdv is an unofficial, open-source interoperability project. It is not |
| 13 | +affiliated with or endorsed by Apple, Google, or Espressif. |
| 14 | + |
| 15 | +Italian documentation: [`docs/README.it.md`](docs/README.it.md) |
| 16 | +Complete API reference: [`docs/API.md`](docs/API.md) |
| 17 | + |
| 18 | +Additional references: |
| 19 | + |
| 20 | +- [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) |
| 21 | +- [`docs/TROUBLESHOOTING.md`](docs/TROUBLESHOOTING.md) |
| 22 | +- [`docs/RELEASING.md`](docs/RELEASING.md) |
| 23 | +- [`CONTRIBUTING.md`](CONTRIBUTING.md) |
| 24 | +- [`SECURITY.md`](SECURITY.md) |
| 25 | + |
| 26 | +## Supported hardware |
| 27 | + |
| 28 | +| Chip | Bluetooth | Backend | Status | |
| 29 | +| --- | --- | --- | --- | |
| 30 | +| ESP32 | BLE 4.2 | Bluedroid | Supported | |
| 31 | +| ESP32-C3 | BLE 5 | Bluedroid | Supported | |
| 32 | +| ESP32-S3 | BLE 5 | Bluedroid | Supported | |
| 33 | +| ESP32-C6 | BLE 5 | NimBLE | Supported | |
| 34 | +| ESP32-C2 | BLE 5 | Selected from Arduino core | Compatible; not yet in the release build matrix | |
| 35 | +| ESP32-C5 / ESP32-C61 | BLE | Selected from Arduino core | Compatible; requires a supporting Arduino core | |
| 36 | +| ESP32-H2 | BLE 5 | NimBLE | Compatible; build with a supporting Arduino core | |
| 37 | +| ESP8266 / ESP32-S2 / ESP32-P4 | No Bluetooth radio | — | Not possible | |
| 38 | + |
| 39 | +The current standalone firmware validates the ESP32, C3, S3, and C6 targets. |
| 40 | +Backend selection uses `CONFIG_BT_NIMBLE_ENABLED` or |
| 41 | +`CONFIG_BT_BLUEDROID_ENABLED`, rather than a hard-coded chip list. New ESP32 |
| 42 | +variants therefore work when their Arduino core exposes one of those supported |
| 43 | +BLE hosts. |
| 44 | + |
| 45 | +## Installation |
| 46 | + |
| 47 | +### PlatformIO project |
| 48 | + |
| 49 | +After the first public Registry release, installation is a single dependency: |
| 50 | + |
| 51 | +```ini |
| 52 | +lib_deps = mattbox03/FindMyAdv@^1.0.0 |
| 53 | +``` |
| 54 | + |
| 55 | +The GitHub source can also be used directly: |
| 56 | + |
| 57 | +```ini |
| 58 | +lib_deps = https://github.com/mattbox03/FindMyAdv.git |
| 59 | +``` |
| 60 | + |
| 61 | +For a local checkout, copy the complete `FindMyAdv` directory into the |
| 62 | +project's `lib` directory: |
| 63 | + |
| 64 | +```text |
| 65 | +your-project/ |
| 66 | +|-- lib/ |
| 67 | +| `-- FindMyAdv/ |
| 68 | +| |-- library.json |
| 69 | +| `-- src/ |
| 70 | +`-- src/ |
| 71 | + `-- main.cpp |
| 72 | +``` |
| 73 | + |
| 74 | +### Arduino IDE |
| 75 | + |
| 76 | +Put the `FindMyAdv` directory in the Arduino libraries directory, or create a |
| 77 | +ZIP whose root directory is named `FindMyAdv` and use **Sketch > Include |
| 78 | +Library > Add .ZIP Library**. |
| 79 | + |
| 80 | +## Minimal integration |
| 81 | + |
| 82 | +```cpp |
| 83 | +#include <Arduino.h> |
| 84 | +#include <FindMyAdv.h> |
| 85 | + |
| 86 | +void setup() { |
| 87 | + FindMyAdvConfig tracking; |
| 88 | + tracking.appleAdvertisementKeyBase64 = "APPLE_BASE64_KEY_OR_EMPTY"; |
| 89 | + tracking.googleAdvertisementEidHex = "GOOGLE_40_HEX_EID_OR_EMPTY"; |
| 90 | + tracking.advertisingIntervalMs = 2000; |
| 91 | + tracking.txPowerDbm = 0; |
| 92 | + |
| 93 | + if (!FindMyAdv.begin(tracking)) { |
| 94 | + Serial.println(FindMyAdv.lastError()); |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +void loop() { |
| 99 | + // Existing application code: FindMyAdv needs no calls here. |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +Either key may be empty. With both keys configured, the library time-slices |
| 104 | +the Apple and Google legacy advertising frames. With one key, it advertises |
| 105 | +only that provider. |
| 106 | + |
| 107 | +## Change keys or settings at runtime |
| 108 | + |
| 109 | +The library copies all input strings, so temporary `String` values and values |
| 110 | +read from a web form, MQTT, Preferences/NVS, or a configuration file are safe: |
| 111 | + |
| 112 | +```cpp |
| 113 | +String appleFromWeb = request->arg("apple_key"); |
| 114 | +String googleFromWeb = request->arg("google_eid"); |
| 115 | + |
| 116 | +if (!FindMyAdv.setKeys(appleFromWeb.c_str(), googleFromWeb.c_str())) { |
| 117 | + Serial.println(FindMyAdv.lastError()); |
| 118 | +} |
| 119 | +``` |
| 120 | +
|
| 121 | +To change intervals, TX power, accelerometer settings, and keys together: |
| 122 | +
|
| 123 | +```cpp |
| 124 | +FindMyAdvConfig updated; |
| 125 | +updated.appleAdvertisementKeyBase64 = appleFromWeb.c_str(); |
| 126 | +updated.googleAdvertisementEidHex = googleFromWeb.c_str(); |
| 127 | +updated.advertisingIntervalMs = 1000; |
| 128 | +updated.txPowerDbm = 3; |
| 129 | +FindMyAdv.reconfigure(updated); |
| 130 | +``` |
| 131 | + |
| 132 | +Persistence deliberately remains under application control. Save the values |
| 133 | +with `Preferences`, your existing settings manager, or another secure storage |
| 134 | +mechanism, then pass them to `begin()` at boot. This avoids imposing a Wi-Fi |
| 135 | +portal, filesystem, network service, or credential format on the host firmware. |
| 136 | + |
| 137 | +## Optional motion-based advertising |
| 138 | + |
| 139 | +LIS3DH, LIS2DH, and LIS2DH12 accelerometers are supported at I2C address `0x18` |
| 140 | +or `0x19`. Set address `0` to probe both automatically: |
| 141 | + |
| 142 | +```cpp |
| 143 | +tracking.accelerometerEnabled = true; |
| 144 | +tracking.accelerometerWire = &Wire; // use &Wire1 for a separate application bus |
| 145 | +tracking.initializeAccelerometerBus = true; |
| 146 | +tracking.accelerometerSda = 8; |
| 147 | +tracking.accelerometerScl = 9; |
| 148 | +tracking.accelerometerAddress = 0; |
| 149 | +tracking.motionIntervalMs = 200; |
| 150 | +tracking.motionHoldMs = 30000; |
| 151 | +tracking.motionThreshold = 320; |
| 152 | +``` |
| 153 | + |
| 154 | +If the host firmware already initialized that I2C bus, set |
| 155 | +`initializeAccelerometerBus = false` so the library does not change its pins or |
| 156 | +clock configuration. |
| 157 | + |
| 158 | +Any other motion sensor is supported through a callback, without modifying the |
| 159 | +library: |
| 160 | + |
| 161 | +```cpp |
| 162 | +bool moved() { |
| 163 | + return myImu.motionInterruptActive(); |
| 164 | +} |
| 165 | + |
| 166 | +tracking.motionDetectedCallback = moved; |
| 167 | +``` |
| 168 | + |
| 169 | +## Integration limits |
| 170 | + |
| 171 | +- Wi-Fi, sensors, displays, MQTT, web servers, and normal application tasks can |
| 172 | + run alongside FindMyAdv. |
| 173 | +- The library owns the controller's legacy BLE advertising while running. An |
| 174 | + application that already advertises a BLE GATT service must coordinate that |
| 175 | + advertising explicitly; two independent modules cannot transparently own the |
| 176 | + same legacy advertising set. |
| 177 | +- BLE connections may interrupt or alter advertising depending on the chip, |
| 178 | + controller resources, and application stack. |
| 179 | +- No radio can advertise during ESP deep sleep. Stop the library before sleep |
| 180 | + and call `begin()` again after wake-up. |
| 181 | +- Advertising two providers is time-slicing, not two simultaneous legacy radio |
| 182 | + packets. `providerWindowMs` controls the rotation window. |
| 183 | + |
| 184 | +## Security |
| 185 | + |
| 186 | +Apple advertisement keys and Google EIDs identify a tracker. Do not publish |
| 187 | +real keys in source control, logs, examples, issue reports, or public binaries. |
| 188 | +The library never sends keys over Wi-Fi and does not persist them by itself. |
| 189 | + |
| 190 | +## Examples |
| 191 | + |
| 192 | +- `Minimal`: one-call integration. |
| 193 | +- `DynamicKeys`: load keys from Preferences and replace them at runtime. |
| 194 | +- `ManualPolling`: disable the FreeRTOS scheduler task and call `poll()` from |
| 195 | + an existing cooperative loop. |
| 196 | +- `CustomMotionSource`: use any IMU, GPIO, or application event for dynamic |
| 197 | + advertising speed. |
| 198 | + |
| 199 | +## License |
| 200 | + |
| 201 | +MIT. See [`LICENSE`](LICENSE). |
0 commit comments