Add BLE scanner sketch for finding hub addresses
This commit is contained in:
@@ -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 <NimBLEDevice.h>
|
||||
|
||||
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();
|
||||
}
|
||||
Reference in New Issue
Block a user