Add ESP32 alarms system status and debug commands
This commit is contained in:
@@ -64,9 +64,19 @@ static void handleNotify(
|
||||
|
||||
static bool connectBms() {
|
||||
if (client && client->isConnected()) {
|
||||
bmsData.connected = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (client && !client->isConnected()) {
|
||||
Serial.println("BMS: Disconnected, resetting client");
|
||||
NimBLEDevice::deleteClient(client);
|
||||
client = nullptr;
|
||||
notifyChar = nullptr;
|
||||
writeChar = nullptr;
|
||||
bmsData.connected = false;
|
||||
}
|
||||
|
||||
Serial.println("BMS: Connecting...");
|
||||
|
||||
NimBLEAddress address(std::string(BMS_ADDRESS), BLE_ADDR_PUBLIC);
|
||||
@@ -76,6 +86,8 @@ static bool connectBms() {
|
||||
if (!client->connect(address)) {
|
||||
Serial.println("BMS: Connect failed");
|
||||
bmsData.connected = false;
|
||||
NimBLEDevice::deleteClient(client);
|
||||
client = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -116,6 +128,9 @@ static bool requestPacket(uint8_t* command, size_t commandLength) {
|
||||
if (!ok) {
|
||||
Serial.println("BMS: Write failed");
|
||||
bmsData.connected = false;
|
||||
if (client) {
|
||||
client->disconnect();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user