From 9ca087836c67a88473471bba28441f4a55dad5ba Mon Sep 17 00:00:00 2001 From: jessikitty Date: Thu, 27 Aug 2026 19:32:50 +1000 Subject: [PATCH] Add BLE scanner sketch for finding hub addresses --- tools/hub_scanner/hub_scanner.ino | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tools/hub_scanner/hub_scanner.ino diff --git a/tools/hub_scanner/hub_scanner.ino b/tools/hub_scanner/hub_scanner.ino new file mode 100644 index 0000000..93306f7 --- /dev/null +++ b/tools/hub_scanner/hub_scanner.ino @@ -0,0 +1,49 @@ +/* + * hub_scanner.ino -- find the BLE addresses of your LEGO hubs + * + * Board package: esp32 (the normal Espressif one) + * Libraries: NimBLE-Arduino 1.4.x (same version Legoino wants) + * + * Flash this to the receiver board, open the serial monitor at 115200, then + * press the green button on one hub at a time. Anything advertising the LEGO + * Wireless Protocol service (00001623-1212-EFDE-1623-785FEABCD123) is printed + * with its address. Copy those into receiver.ino. + * + * Created by: Jess Rogerson (yelling commands at Claude.AI) + */ + +#include + +static const char *LPF2_SERVICE = "00001623-1212-efde-1623-785feabcd123"; + +void setup() { + Serial.begin(115200); + delay(500); + Serial.println("Scanning for LEGO hubs - press a hub button to wake it up"); + + NimBLEDevice::init("hub-scanner"); + NimBLEScan *scan = NimBLEDevice::getScan(); + scan->setActiveScan(true); + scan->setInterval(100); + scan->setWindow(99); +} + +void loop() { + NimBLEScan *scan = NimBLEDevice::getScan(); + NimBLEScanResults results = scan->start(5, false); + + Serial.println("---- scan pass ----"); + for (int i = 0; i < results.getCount(); i++) { + NimBLEAdvertisedDevice dev = results.getDevice(i); + bool isLego = dev.isAdvertisingService(NimBLEUUID(LPF2_SERVICE)); + if (!isLego && dev.getName().empty()) continue; + + Serial.print(dev.getAddress().toString().c_str()); + Serial.print(" rssi "); + Serial.print(dev.getRSSI()); + Serial.print(" "); + Serial.print(dev.getName().c_str()); + Serial.println(isLego ? " <-- LEGO HUB" : ""); + } + scan->clearResults(); +}