Hi Everyone,
I have seen some people in the community (including myself) struggle to get the IRK for the Private BLE integration.
In the documentation, the documented way is using Keychain on a MacOS device. But not everyone that has an iPhone has access to a MacOS device.
After searching around on the internet I found a way to get the IRK without using MacOS, but with a ESP32.
What do you need?
- ESP32 (the M5STACK ATOM LITE does also work!)
- The Bluetooth Terminal app (Bluetooth Terminal on the App Store)
- The Arduino IDE
1. Setting up Arduino IDE
First, download and install the Arduino IDE (Download link).
After installing you want to add support for the ESP32 boards or the M5STACK boards.
ESP32
- Open the Arduino IDE and click the second icon down in the left hand bar.
- Search for “esp32” and install the one by “Espressif Systems”.
- The IDE is now ready for your device.
M5STACK ATOM
- Open the Arduino IDE and click “File” in the top left corner and click on “Preferences”.
- Paste the following URL in the “Additional boards managers URLs” and click OK: (https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json)
- Click the second icon down in the left hand bar.
- Search for M5STACK and click install.
- The IDE is now ready for your device.
2. Installing the software on the device
I found the following code online, This is not my code, i am not responsable if you run this code!
- Download the code from Github by pressing the green “Code” button and clicking “download Zip”
- Extract the zip, open the folder and rename the folder “get_irk” to “esp32_irk”
- Open the “esp32_irk” folder and open the “esp32_irk.ino” file
- Connect the ESP32 (or M5STACK atom) to the computer
- In the top bar, click on the dropdown and select the port the device is connected to.
You will now get a prompt to select a board type, for most people it wil be ESP32 Dev Module, otherwise search for the M5STACK Atom. - Click the arrow button in the top left corner, the IDE will start compiling and uploading to your device.
If the IDE fails, check the instructions for your device on how to upload new code.
3. Getting the IRK
- In the top right corner, clck on the magnifying glass, this will open the serial monitor.
- Change the baud rate to 115200
- Download the Bluetooth Terminal app App Store link
- Open the app and connect to “ESP_BLE_SECURITY”
- In the serial monitor you wil get the IRK key in the following format:
IRK:,0x1A,0x1B,0x1C,0x5E,0x87,0xD2,0x1D,0x57,0x27,0x14,0x4B,0x19,0xAD,0x58,0xCF,0x41 - If you want to get the key for you Apple Watch too, restart the ESP or Atom Stack, open the serial monitor and connect through the Apple Watch app.
4. Converting the value to the correct format
- Copy the value from the terminal to a text editor and remove every “,0x” and “IRK:”. You will end up with something like this: “1A1B1C5E87D21D5727144B19AD58CF41”.
If you want to use the key for ESPrensence reverse the order of the key in pairs of 2, with the example given you will end up with “41CF58AD194B1427571DD2875E1C1B1A”. (Thank you @sota!) - This value is the decimal value of the IRK key, but Home Assistant expects the base64 encoded version of this key. Use the following website to encode the key Base64 encoder
- Congratulations, this key can be used in Home Assistant as the Private BLE IRK key!