Yes, it seems to be an intentional mechanism to preserve battery or prevent an unauthenticated device staying connected longer than it needed to carry out the authentication. Both the smart locks I am working on have this same mechanism. The other one the characteristic discovery is basically instant though.
Here’s a slight modification of my program. The lock disconnects the master device after 30 seconds:
app-connect-and-wait.ino
#define BLE_WIRING_DEBUG_ENABLED 1
#include "Particle.h"
SYSTEM_MODE(MANUAL);
SerialLogHandler logHandler(LOG_LEVEL_ALL);
BleScanResult targetScanResult;
bool found = false;
auto targetDeviceMAC = "EC:F3:FA:F0:CF:DD";
void scanResultCallback(const BleScanResult* scanResult, void *context) {
Log.info("Scan result %s", scanResult->address.toString().c_str());
if (scanResult->address.toString() == "EC:F3:FA:F0:CF:DD") {
targetScanResult = *scanResult; // Copy
found = true;
BLE.stopScanning();
}
}
void setup() {
// Allow time for serial monitor to connect
delay(700);
while (!found) {
Log.info("Starting scan looking for %s", targetDeviceMAC);
BLE.scan(scanResultCallback, NULL);
}
BlePeerDevice device;
while (!BLE.connected()) {
Log.info("Connecting");
int connectedDuration = 0;
device = BLE.connect(targetScanResult.address, false);
if (!device.connected())
continue;
Log.info("Device connected");
delay(500);
connectedDuration += 500;
Log.info("Discover services...");
auto services = device.discoverAllServices();
Log.info("%d services discovered:", services.size());
for (auto &&s : services) {
Log.info(s.UUID().toString().c_str());
}
if (!device.connected()) // Incase remote disconnects us
continue;
BleService mainService;
bool gotMainService = device.getServiceByUUID(mainService, BleUuid("FFF0"));
Log.info("Got service? %s. UUID = %s", gotMainService ? "True" : "False", mainService.UUID().toString().c_str());
if (!BLE.connected() || !gotMainService)
continue;
while (BLE.connected()) {
Log.info("Connected for approx %dms", connectedDuration);
delay(500);
connectedDuration += 500;
}
Log.info("No longer connected");
Log.info("Exiting");
return;
}
}
void loop() {
delay(1000);
}
app-connect-and-wait.ino Output
Serial monitor opened successfully:
0000000657 [sys.power] TRACE: Battery state CHARGED -> DISCONNECTED
0000000842 [app] INFO: Starting scan looking for EC:F3:FA:F0:CF:DD
0000000843 [hal.ble] TRACE: hal_ble_stack_init().
0000000843 [hal.ble] TRACE: hal_ble_set_callback_on_periph_link_events().
0000000843 [hal.ble] TRACE: hal_ble_gap_start_scan().
0000000844 [hal.ble] TRACE: | interval(ms) window(ms) timeout(ms) |
0000000844 [hal.ble] TRACE: 160*0.625 80*0.625 5000
0000000968 [app] INFO: Scan result 5F:07:F1:36:C8:C4
0000001057 [app] INFO: Scan result F7:66:FC:2F:9F:FE
0000001090 [app] INFO: Scan result EC:F3:FA:F0:CF:DD
0000001090 [hal.ble] TRACE: hal_ble_gap_stop_scan().
0000001091 [app] INFO: Connecting
0000001091 [hal.ble] TRACE: hal_ble_gap_connect().
0000001596 [hal.ble] TRACE: BLE GAP event: connected.
0000001596 [hal.ble] TRACE: BLE role: 2, connection handle: 0
0000001597 [hal.ble] TRACE: | interval(ms) latency timeout(ms) |
0000001597 [hal.ble] TRACE: 36*1.25 0 500*10
0000001598 [hal.ble] TRACE: Attempts to exchange ATT_MTU if needed.
0000001598 [wiring.ble] TRACE: New peripheral is connected.
0000001599 [app] INFO: Device connected
0000001642 [hal.ble] TRACE: BLE GATT Server event: exchange ATT MTU request: 83, desired: 247
0000001643 [hal.ble] TRACE: Effective ATT MTU: 83.
0000002099 [app] INFO: Discover services...
0000002099 [wiring.ble] TRACE: Start discovering services.
0000002100 [hal.ble] TRACE: hal_ble_gatt_client_discover_all_services().
0000002183 [hal.ble] TRACE: BLE GATTC event: services discovered.
0000002272 [hal.ble] TRACE: BLE GATTC event: services discovered.
0000002407 [hal.ble] TRACE: BLE GATTC event: services discovered.
0000002408 [app] INFO: 4 services discovered:
0000002408 [app] INFO: 1800
0000002409 [app] INFO: 1801
0000002409 [app] INFO: 180A
0000002409 [app] INFO: FFF0
0000002410 [app] INFO: Got service? True. UUID = FFF0
0000002410 [app] INFO: Connected for approx 500ms
0000002910 [app] INFO: Connected for approx 1000ms
0000003411 [app] INFO: Connected for approx 1500ms
0000003911 [app] INFO: Connected for approx 2000ms
0000004411 [app] INFO: Connected for approx 2500ms
0000004912 [app] INFO: Connected for approx 3000ms
0000005412 [app] INFO: Connected for approx 3500ms
0000005602 [hal.ble] TRACE: BLE GAP event: connection parameter update request.
0000005912 [app] INFO: Connected for approx 4000ms
0000005917 [hal.ble] TRACE: BLE GAP event: connection parameters updated.
0000005918 [hal.ble] TRACE: | interval(ms) latency timeout(ms) |
0000005918 [hal.ble] TRACE: 8*1.25 0 300*10
0000006413 [app] INFO: Connected for approx 4500ms
0000006913 [app] INFO: Connected for approx 5000ms
0000007413 [app] INFO: Connected for approx 5500ms
0000007913 [app] INFO: Connected for approx 6000ms
0000008414 [app] INFO: Connected for approx 6500ms
0000008914 [app] INFO: Connected for approx 7000ms
0000009415 [app] INFO: Connected for approx 7500ms
0000009915 [app] INFO: Connected for approx 8000ms
0000010415 [app] INFO: Connected for approx 8500ms
0000010915 [app] INFO: Connected for approx 9000ms
0000011416 [app] INFO: Connected for approx 9500ms
0000011916 [app] INFO: Connected for approx 10000ms
0000012416 [app] INFO: Connected for approx 10500ms
0000012917 [app] INFO: Connected for approx 11000ms
0000013417 [app] INFO: Connected for approx 11500ms
0000013917 [app] INFO: Connected for approx 12000ms
0000014418 [app] INFO: Connected for approx 12500ms
0000014918 [app] INFO: Connected for approx 13000ms
0000015418 [app] INFO: Connected for approx 13500ms
0000015919 [app] INFO: Connected for approx 14000ms
0000016419 [app] INFO: Connected for approx 14500ms
0000016919 [app] INFO: Connected for approx 15000ms
0000017420 [app] INFO: Connected for approx 15500ms
0000017920 [app] INFO: Connected for approx 16000ms
0000018420 [app] INFO: Connected for approx 16500ms
0000018921 [app] INFO: Connected for approx 17000ms
0000019421 [app] INFO: Connected for approx 17500ms
0000019921 [app] INFO: Connected for approx 18000ms
0000020422 [app] INFO: Connected for approx 18500ms
0000020922 [app] INFO: Connected for approx 19000ms
0000021422 [app] INFO: Connected for approx 19500ms
0000021923 [app] INFO: Connected for approx 20000ms
0000022423 [app] INFO: Connected for approx 20500ms
0000022923 [app] INFO: Connected for approx 21000ms
0000023424 [app] INFO: Connected for approx 21500ms
0000023924 [app] INFO: Connected for approx 22000ms
0000024424 [app] INFO: Connected for approx 22500ms
0000024925 [app] INFO: Connected for approx 23000ms
0000025425 [app] INFO: Connected for approx 23500ms
0000025925 [app] INFO: Connected for approx 24000ms
0000026426 [app] INFO: Connected for approx 24500ms
0000026926 [app] INFO: Connected for approx 25000ms
0000027426 [app] INFO: Connected for approx 25500ms
0000027927 [app] INFO: Connected for approx 26000ms
0000028427 [app] INFO: Connected for approx 26500ms
0000028927 [app] INFO: Connected for approx 27000ms
0000029428 [app] INFO: Connected for approx 27500ms
0000029928 [app] INFO: Connected for approx 28000ms
0000030428 [app] INFO: Connected for approx 28500ms
0000030929 [app] INFO: Connected for approx 29000ms
0000031429 [app] INFO: Connected for approx 29500ms
0000031929 [app] INFO: Connected for approx 30000ms
0000031972 [hal.ble] TRACE: BLE GAP event: disconnected.
0000031973 [wiring.ble] TRACE: Disconnected by remote device.
0000032430 [app] INFO: No longer connected
0000032430 [app] INFO: Exiting
I also just tested without discovering services either i.e. just connect and wait and the result is the same, disconnected by the remote after exactly 30s. My other lock disconnects after 8s in both situations, but I am able to discover the characteristics and as long as I do that and then complete the locks auth procedure within the 8s it will allow the Boron to stay connected.