diff --git a/components/ble_gatt_server/example/main/ble_gatt_server_example.cpp b/components/ble_gatt_server/example/main/ble_gatt_server_example.cpp index b6f4b06cc6..c0e94da181 100644 --- a/components/ble_gatt_server/example/main/ble_gatt_server_example.cpp +++ b/components/ble_gatt_server/example/main/ble_gatt_server_example.cpp @@ -67,15 +67,8 @@ extern "C" void app_main(void) { // you can create a service and add it to the server using // ble_gatt_server.server().addService() - // now start the services - ble_gatt_server.start_services(); // starts the device info service and battery service - // NOTE: we could also directly start them ourselves if we wanted to - // control the order of starting the services - // e.g.: - // ble_gatt_server.battery_service().start(); - // ble_gatt_server.device_info_service().start(); - - // now start the gatt server + // now start the gatt server; this also starts every service that has + // been added to it (the built-in device info / battery services included) ble_gatt_server.start(); // let's set some of the service data diff --git a/components/ble_gatt_server/include/battery_service.hpp b/components/ble_gatt_server/include/battery_service.hpp index 72a2c9a3ce..2e5cd19418 100644 --- a/components/ble_gatt_server/include/battery_service.hpp +++ b/components/ble_gatt_server/include/battery_service.hpp @@ -49,17 +49,9 @@ class BatteryService : public BaseComponent { } /// Start the service - /// \note This must be called after the service has been initialized - void start() { - if (!service_) { - logger_.error("Service not created"); - return; - } - if (!service_->start()) { - logger_.error("Failed to start service"); - return; - } - } + /// \note Kept for API compatibility: NimBLE starts every service when the + /// server starts (esp-nimble-cpp 2.x), so there is nothing to do here. + [[deprecated("no-op: services start with BleGattServer::start()")]] void start() {} /// Get the service /// \return The Battery Service diff --git a/components/ble_gatt_server/include/ble_gatt_server.hpp b/components/ble_gatt_server/include/ble_gatt_server.hpp index 44462f1423..e991c67842 100644 --- a/components/ble_gatt_server/include/ble_gatt_server.hpp +++ b/components/ble_gatt_server/include/ble_gatt_server.hpp @@ -294,11 +294,9 @@ class BleGattServer : public BaseComponent { } /// Start the services - /// This method starts the device info and battery services. - void start_services() { - device_info_service_.start(); - battery_service_.start(); - } + /// \note Kept for API compatibility: NimBLE starts every service when the + /// server starts (start()), so there is nothing to do here. + [[deprecated("no-op: services start with start()")]] void start_services() {} /// Start the server /// This method starts the GATT server. diff --git a/components/ble_gatt_server/include/device_info_service.hpp b/components/ble_gatt_server/include/device_info_service.hpp index 3d3dfb87ed..335d905544 100644 --- a/components/ble_gatt_server/include/device_info_service.hpp +++ b/components/ble_gatt_server/include/device_info_service.hpp @@ -86,17 +86,9 @@ class DeviceInfoService : public BaseComponent { } /// Start the service - /// \note This must be called after the service has been initialized - void start() { - if (!service_) { - logger_.error("Service not created"); - return; - } - if (!service_->start()) { - logger_.error("Failed to start service"); - return; - } - } + /// \note Kept for API compatibility: NimBLE starts every service when the + /// server starts (esp-nimble-cpp 2.x), so there is nothing to do here. + [[deprecated("no-op: services start with BleGattServer::start()")]] void start() {} /// Get the service object /// \return The service object diff --git a/components/ble_gatt_server/include/generic_access_service.hpp b/components/ble_gatt_server/include/generic_access_service.hpp index 3a552a80f1..a3b9db4a4b 100644 --- a/components/ble_gatt_server/include/generic_access_service.hpp +++ b/components/ble_gatt_server/include/generic_access_service.hpp @@ -72,17 +72,9 @@ class GenericAccessService : public BaseComponent { } /// Start the service - /// \note This must be called after the service has been initialized - void start() { - if (!service_) { - logger_.error("Service not created"); - return; - } - if (!service_->start()) { - logger_.error("Failed to start service"); - return; - } - } + /// \note Kept for API compatibility: NimBLE starts every service when the + /// server starts (esp-nimble-cpp 2.x), so there is nothing to do here. + [[deprecated("no-op: services start with BleGattServer::start()")]] void start() {} /// Get the service object /// \return The service object diff --git a/components/gfps_service/example/main/gfps_service_example.cpp b/components/gfps_service/example/main/gfps_service_example.cpp index b44b9714b8..39f808cd00 100644 --- a/components/gfps_service/example/main/gfps_service_example.cpp +++ b/components/gfps_service/example/main/gfps_service_example.cpp @@ -51,16 +51,11 @@ extern "C" void app_main(void) { gfps_service.set_log_level(espp::Logger::Verbosity::DEBUG); gfps_service.init(ble_gatt_server.server()); - // now that we've made the input characteristic, we can start the service + // set the nearby-framework advertisement mode (the GATT service itself is + // started with the server below) gfps_service.start(); - ble_gatt_server.start_services(); // starts the device info service and battery service - // NOTE: we could also directly start them ourselves if we wanted to - // control the order of starting the services - // e.g.: - // ble_gatt_server.battery_service().start(); - // ble_gatt_server.device_info_service().start(); - - // now start the gatt server + + // now start the gatt server; this also starts every service added to it ble_gatt_server.start(); // let's set some of the service data diff --git a/components/gfps_service/include/gfps_service.hpp b/components/gfps_service/include/gfps_service.hpp index f5de444980..30b6bfb5c0 100644 --- a/components/gfps_service/include/gfps_service.hpp +++ b/components/gfps_service/include/gfps_service.hpp @@ -190,19 +190,14 @@ class GfpsService : public espp::BaseComponent { } /// Start the service - /// \note This function will start the service - /// \note This function will also set the advertisement mode for the nearby - /// framework + /// \note The GATT service itself is started with the server + /// (BleGattServer::start()); this sets the advertisement mode for the + /// nearby framework, which must still be called. void start() { if (!service_) { logger_.error("Service not created"); return; } - if (service_->start()) { - logger_.info("Service started"); - } else { - logger_.error("Failed to start service"); - } int advertisement_mode = NEARBY_FP_ADVERTISEMENT_DISCOVERABLE | NEARBY_FP_ADVERTISEMENT_PAIRING_UI_INDICATOR; logger_.info("Setting advertisement mode to {}", advertisement_mode); diff --git a/components/hid_service/example/main/hid_service_example.cpp b/components/hid_service/example/main/hid_service_example.cpp index 6b1b6f29b5..d4a392f9c9 100644 --- a/components/hid_service/example/main/hid_service_example.cpp +++ b/components/hid_service/example/main/hid_service_example.cpp @@ -488,12 +488,6 @@ extern "C" void app_main(void) { ps4_feature_f2->setValue(feature_f2_data); #endif // CONFIG_EXAMPLE_AS_XBOX - // now that we've made the input characteristic, we can start the service - hid_service.start(); - // starts the device info service and battery service, see - // hid_service_example for more info - ble_gatt_server.start_services(); - // now start the gatt server ble_gatt_server.start(); diff --git a/components/hid_service/include/hid_service.hpp b/components/hid_service/include/hid_service.hpp index 3e7dd10726..1a98813f41 100644 --- a/components/hid_service/include/hid_service.hpp +++ b/components/hid_service/include/hid_service.hpp @@ -80,11 +80,9 @@ class HidService : public espp::BaseComponent { } /// @brief Start the HID service. - void start() { - if (service_) { - service_->start(); - } - } + /// @note Kept for API compatibility: NimBLE starts every service when the + /// server starts (BleGattServer::start()), so there is nothing to do. + [[deprecated("no-op: services start with BleGattServer::start()")]] void start() {} /// @brief Get the HID service. /// @return The HID service. diff --git a/components/wdi/README.md b/components/wdi/README.md index 5f1b9e7507..9e668d7b7f 100644 --- a/components/wdi/README.md +++ b/components/wdi/README.md @@ -118,15 +118,13 @@ dev.poll(); // keepalive if due `wdi_ble.hpp` wraps `WdiDevice` with the WDI GATT service (service `10A50001-…`, characteristics `10A5000{6..A}`) on `espp::BleGattServer` (esp-nimble-cpp). After -`BleGattServer::init()`, create the service, start it, advertise, and poll: +`BleGattServer::init()`, create the service, start the server, advertise, and poll: ```cpp espp::WdiBlePeripheral wdi({.on_feedback = [](const espp::wdi::FeedbackReport &f){ /*...*/ }}); espp::BleGattServer ble; ble.init("espp WDI"); wdi.make_service(ble.server()); -ble.start_services(); -wdi.start(); ble.start(); espp::BleGattServer::AdvertisedData adv; adv.setName("espp WDI"); diff --git a/components/wdi/ble_example/main/wdi_ble_example.cpp b/components/wdi/ble_example/main/wdi_ble_example.cpp index 17b73d0f5e..7a9145d1a1 100644 --- a/components/wdi/ble_example/main/wdi_ble_example.cpp +++ b/components/wdi/ble_example/main/wdi_ble_example.cpp @@ -43,8 +43,6 @@ extern "C" void app_main(void) { const std::string device_name = "espp WDI"; ble.init(device_name); wdi.make_service(ble.server()); - ble.start_services(); - wdi.start(); ble.start(); espp::BleGattServer::AdvertisedData adv; diff --git a/components/wdi/include/wdi_ble.hpp b/components/wdi/include/wdi_ble.hpp index 2648aa6a73..072869ef74 100644 --- a/components/wdi/include/wdi_ble.hpp +++ b/components/wdi/include/wdi_ble.hpp @@ -115,10 +115,9 @@ class WdiBlePeripheral : public BaseComponent { keepalive_resp_->setCallbacks(&keepalive_resp_cb_); } - /// @brief Kept for API symmetry with make_service(); NimBLE starts every - /// service when the server starts (NimBLEService::start() is a - /// deprecated no-op), so there is nothing to do here. - void start() {} + /// @brief Kept for API compatibility: NimBLE starts every service when the + /// server starts (BleGattServer::start()), so there is nothing to do. + [[deprecated("no-op: services start with BleGattServer::start()")]] void start() {} NimBLEService *get_service() { return service_; }