Add serial BLE scan and BMS selection
This commit is contained in:
@@ -355,6 +355,77 @@ void handleDebugSerial() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (command == "scan ble") {
|
||||
int count = scanBleDevices(10);
|
||||
|
||||
if (count == 0) {
|
||||
Serial.println("No BLE devices found.");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println("BLE devices:");
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
const BleScanResult* result = getBleScanResult(i);
|
||||
|
||||
if (!result) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Serial.print(i + 1);
|
||||
Serial.print(") ");
|
||||
|
||||
if (result->name.length() > 0) {
|
||||
Serial.print(result->name);
|
||||
} else {
|
||||
Serial.print("(no name)");
|
||||
}
|
||||
|
||||
Serial.print(" | ");
|
||||
Serial.print(result->address);
|
||||
Serial.print(" | RSSI ");
|
||||
Serial.println(result->rssi);
|
||||
}
|
||||
|
||||
Serial.println("Use: select bms <number>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.startsWith("select bms ")) {
|
||||
int selected = command.substring(11).toInt();
|
||||
|
||||
if (selected < 1 || selected > getBleScanResultCount()) {
|
||||
Serial.println("Invalid BMS selection. Run: scan ble");
|
||||
return;
|
||||
}
|
||||
|
||||
const BleScanResult* result = getBleScanResult(selected - 1);
|
||||
|
||||
if (!result) {
|
||||
Serial.println("Invalid BMS selection. Run: scan ble");
|
||||
return;
|
||||
}
|
||||
|
||||
appConfig.bms.enabled = true;
|
||||
appConfig.bms.address = result->address;
|
||||
appConfig.bms.addressType = "public";
|
||||
|
||||
if (result->name.length() > 0) {
|
||||
appConfig.bms.name = result->name;
|
||||
} else {
|
||||
appConfig.bms.name = "BMS";
|
||||
}
|
||||
|
||||
saveConfig();
|
||||
|
||||
Serial.print("OK selected BMS: ");
|
||||
Serial.print(appConfig.bms.name);
|
||||
Serial.print(" / ");
|
||||
Serial.println(appConfig.bms.address);
|
||||
Serial.println("BMS will reconnect on next update cycle.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.length() > 0) {
|
||||
Serial.print("Unknown command: ");
|
||||
Serial.println(command);
|
||||
|
||||
Reference in New Issue
Block a user