From 2780174203b4bd1a554a1186207e62c53400495a Mon Sep 17 00:00:00 2001 From: uvok Date: Mon, 21 Jul 2025 12:06:24 +0200 Subject: Check BLE connected count before sleep otherwise we'll get disconnects. --- include/badge/ble.h | 2 +- src/ble.cpp | 12 ++++++------ src/main.cpp | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/badge/ble.h b/include/badge/ble.h index b3a65dc..231b103 100644 --- a/include/badge/ble.h +++ b/include/badge/ble.h @@ -12,7 +12,7 @@ namespace de::uvok::badge void ble_init(void); void ble_advertise(void); - bool ble_is_advertising(void); + bool ble_is_active(void); ble_poll_result_t ble_poll(void); void ble_set_image(uint8_t image); } // namespace de::uvok::badge diff --git a/src/ble.cpp b/src/ble.cpp index f6f03ab..5cf8b00 100644 --- a/src/ble.cpp +++ b/src/ble.cpp @@ -85,15 +85,14 @@ void de::uvok::badge::ble_init(void) // get pictures auto call = service->createCharacteristic("ca260002-b4bb-46b2-bd06-b7b7a61ea990", NIMBLE_PROPERTY::READ); - // needs to be on heap??? - String *s = new String(); + String s{}; for (int i = 0; i < ARRAY_SIZE(templates); i++) { char tmp[32]; snprintf(tmp, sizeof(tmp), "%d-%s;", i, templates[i]); - s->concat(tmp); + s.concat(tmp); } - call->setValue(s->c_str()); + call->setValue(s.c_str()); service->start(); @@ -103,9 +102,10 @@ void de::uvok::badge::ble_init(void) pAdvertising->setName("NimBLE"); } -bool de::uvok::badge::ble_is_advertising(void) +bool de::uvok::badge::ble_is_active(void) { - return pAdvertising->isAdvertising(); + return pAdvertising->isAdvertising() || server->getConnectedCount() > 0; + // ???? NimBLEDevice::getConnectedClients().size() > 0; } void de::uvok::badge::ble_advertise(void) diff --git a/src/main.cpp b/src/main.cpp index 2495c1e..af388bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -90,7 +90,7 @@ void loop() } } - if (millis() - lastActivity > SLEEP_TIME && !de::uvok::badge::ble_is_advertising()) + if (millis() - lastActivity > SLEEP_TIME && !de::uvok::badge::ble_is_active()) { // RTC watchdog might reset ??? - not sure when/how this happens... // (Happened with CPU@240MHz, not at 80 MHz yet?) -- cgit v1.2.3