Den

Noridic nRF51822 Airtag

Intro. What is OpenHaystack?

In a world of proprietary technologies, one platform dares to offer a new wave of DIY tech freedom: OpenHaystack. This groundbreaking framework serves as a canvas for tech enthusiasts looking to create their own “AirTags” for Apple’s Find My network. Whether you’re a seasoned developer or a curious hobbyist, OpenHaystack presents an intriguing opportunity to learn, explore, and create, bypassing the restrictions of off-the-shelf solutions. This article dives into the intriguing world of OpenHaystack, breaking down its capabilities, potential, and exploring how it’s empowering a whole new generation of tech innovators. Let’s embark on this journey and discover how OpenHaystack is making waves in the realm of decentralized tracking.

I did a first prototype of OpenHaystakTracker using micro:bit development board.

First prototypes

   
Model Nordic nRF51822-QFAA-R rev 3
Core variant Arm Cortex-M0 32 bit processor
Flash ROM 256KB
RAM 16KB
Speed 16MHz
Debug SWD, jlink/OB

ESP32 vs nRF51822 Power Conumption

OpenHaystack beacon works more time on micro:bit dev board (nRF51822) in comparison witth ESP32, especially on a small battery. Because ESP32 the low power modes of the ESP32 can consume between 68mA and 5µA Reference. But nRF51822 0.6µA Reference, that at least 10 times less.

Productionisation…

But micro:bit dev board is not small, so I continued to look for the better fit. And I found this beacon module based on nRF51822 on ~10$ Aliexpress

.

Without a case just MCU costs about1.41$ Aliexpress. But to flash it you need SWD interface, like STLink V2 1.5$ Aliexpress using this script

Here is STLink v2 -> nRF51822 pinout Reference | | | |-|-| ST-Link V2 |nrf51822 3.3V |VDD GND |GND SWDIO |SWDIO SWDCLK |SCLK

And script

file=<PATH_TO_HEX>
openocd -f interface/stlink.cfg -f target/nrf51.cfg -c init -c "reset halt" ^
-c "flash write_image $file 0x1c000" -c reset -c exit

Dev Board

Ok, I ordered nrf51822 to build a second prototype on bare-metal MCU. It looks like this

Board Connected 2 Board Connected 1

I found the following pinout for my board to connect to STLink v2, you need the following pins SWDIO, SWDCLK, VDD, GND

Flashing

I found a few instruction on how to flash nrf51822 using openocd. The most relevant was at this thread. To flash an openhaystack firmware, you need to create a new devices in the app and the export Advertisement key as base64 string.

Then export PUBKEY=<advertisement key> and patch an firmware image with a new key. To patch the firmware I have used key-injector.py script.

#!/usr/bin/env python3
import sys
import re
import base64
import os

PUBKEY = os.environ.get("PUBKEY")
decoded_bytes = base64.b64decode(PUBKEY)
data = sys.stdin.buffer.read()
output_string = re.sub(b"OFFLINEFINDINGPUBLICKEYHERE!", decoded_bytes, data)
sys.stdout.buffer.write(output_string)

Install open-ocd. For macOS you can use brew install open-ocd and then flash a firmware.

export PUBKEY=4jSeYlz7GAhKYQBjXS1Ku06A5+UjV2CfvEATNw==
firmware=opnehaystack-nrf51822-firmware.bin

./key-injector.py < /Applications/OpenHaystack.app/Contents/Resources/firmware.bin > $firmware

openocd -f interface/stlink-v2.cfg -f target/nrf51.cfg -c "init; halt; nrf51 mass_erase; program $firmware verify; program $firmware; resume;"

After flashing connect a battery and mark the the “device” in openhaystack as “Deployed”.

Enjoy!

Setup openhaystack software

sudo spctl --master-disable
sudo defaults write "/Library/Preferences/com.apple.mail" EnableBundles 1

Reference