This commit is contained in:
James 2024-04-23 21:46:06 +01:00
parent 7dbdf8a27b
commit 8b9f384e47
2 changed files with 5 additions and 21 deletions

22
BLE.ino
View File

@ -54,15 +54,11 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks{
Serial.println(advertisedDevice.toString().c_str()); Serial.println(advertisedDevice.toString().c_str());
} }
// Check if device is advertising the specific service UUID
if (!advertisedDevice.isAdvertisingService(serviceUUID)) {
// Check if found device is the one we are looking for debug("Device does not advertise the specified service UUID.");
if( return;
strcmp(advertisedDevice.getName().c_str(), BLE_NAME)==0 && }
strcmp(advertisedDevice.getAddress().toString().c_str(), BLE_ADDRESS)==0 &&
advertisedDevice.haveServiceUUID() &&
advertisedDevice.isAdvertisingService(serviceUUID)
){
if(BLE_CALLBACK_DEBUG){ if(BLE_CALLBACK_DEBUG){
debug("BLE: target device found"); debug("BLE: target device found");
@ -70,8 +66,6 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks{
pBLEScan->stop(); pBLEScan->stop();
if(advertisedDevice.getRSSI() >= BLE_MIN_RSSI){
// delete old remote device, create new one // delete old remote device, create new one
if(pRemoteDevice != nullptr){ if(pRemoteDevice != nullptr){
delete pRemoteDevice; delete pRemoteDevice;
@ -79,12 +73,6 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks{
pRemoteDevice = new BLEAdvertisedDevice(advertisedDevice); pRemoteDevice = new BLEAdvertisedDevice(advertisedDevice);
doConnect = true; doConnect = true;
}else{
if(BLE_CALLBACK_DEBUG){
debug("BLE: RSSI of target device below minimum");
}
}
}
} }
}; };

View File

@ -52,10 +52,6 @@
#define BLE_CALLBACK_DEBUG true // send debug messages via MQTT & serial in callbacks (handy for finding your BMS address, name, RSSI, etc) #define BLE_CALLBACK_DEBUG true // send debug messages via MQTT & serial in callbacks (handy for finding your BMS address, name, RSSI, etc)
// watchdog timeout
#define WATCHDOG_TIMEOUT (BLE_TIMEOUT+10*1000) // go to sleep after x seconds
// ==== MAIN CODE ==== // ==== MAIN CODE ====
#include "datatypes.h" // for brevity the BMS stuff is in this file #include "datatypes.h" // for brevity the BMS stuff is in this file
#include <BLEDevice.h> // for BLE #include <BLEDevice.h> // for BLE