@@ -256,12 +256,6 @@ class BleGattServer : public BaseComponent {
256256 return false ;
257257 }
258258
259- client_ = NimBLEDevice::createClient ();
260- if (!client_) {
261- logger_.error (" Failed to create client" );
262- return false ;
263- }
264-
265259 // set the server callbacks
266260 server_->setCallbacks (new BleGattServerCallbacks (this ));
267261
@@ -286,8 +280,8 @@ class BleGattServer : public BaseComponent {
286280 // / @note This method will also deinitialize the device info and battery
287281 // / services.
288282 void deinit () {
289- if (!server_ || !client_ ) {
290- logger_.info (" Server / Client are nullptr; already deinitialized, not deinitializing again" );
283+ if (!server_) {
284+ logger_.info (" Server is nullptr; already deinitialized, not deinitializing again" );
291285 return ;
292286 }
293287
@@ -298,9 +292,8 @@ class BleGattServer : public BaseComponent {
298292 // invalidates any references/pointers to them
299293 bool clear_all = true ;
300294 NimBLEDevice::deinit (clear_all);
301- // clear the server and client
295+ // clear the server
302296 server_ = nullptr ;
303- client_ = nullptr ;
304297 }
305298
306299 // / Start the services
@@ -532,19 +525,14 @@ class BleGattServer : public BaseComponent {
532525 logger_.error (" Server not created" );
533526 return {};
534527 }
535- if (!client_) {
536- logger_.error (" Client not created" );
537- return {};
538- }
539528 // since this connection is handled by the server, we won't manually
540529 // connect, and instead inform the client that we are already connected
541530 // using this conn handle
542- client_->clearConnection ();
543- client_->setConnection (conn_info);
531+ auto client = server_->getClient (conn_info);
544532 // refresh the services
545- client_ ->getServices (true );
533+ client ->getServices (true );
546534 // now get Generic Access Service
547- auto gas = client_ ->getService (NimBLEUUID (" 1800" ));
535+ auto gas = client ->getService (NimBLEUUID (" 1800" ));
548536 if (!gas) {
549537 logger_.error (" Failed to get Generic Access Service" );
550538 return {};
@@ -562,8 +550,6 @@ class BleGattServer : public BaseComponent {
562550 }
563551 // and read it
564552 auto name = name_char->readValue ();
565- // unset the client connection
566- client_->clearConnection ();
567553 return name;
568554 }
569555
@@ -600,10 +586,6 @@ class BleGattServer : public BaseComponent {
600586 logger_.error (" Server not created" );
601587 return {};
602588 }
603- if (!client_) {
604- logger_.error (" Client not created" );
605- return {};
606- }
607589 if (!is_connected ()) {
608590 logger_.error (" Not connected to any devices" );
609591 return {};
@@ -613,12 +595,9 @@ class BleGattServer : public BaseComponent {
613595 // since this connection is handled by the server, we won't manually
614596 // connect, and instead inform the client that we are already connected
615597 // using this conn handle
616- client_->clearConnection ();
617- client_->setConnection (conn_info);
598+ auto client = server_->getClient (conn_info);
618599 // and read the RSSI from the client
619- auto rssi = client_->getRssi ();
620- // unset the client connection
621- client_->clearConnection ();
600+ auto rssi = client->getRssi ();
622601 logger_.info (" RSSI for connected device {}: {}" , peer_address.toString (), rssi);
623602 return rssi;
624603 }
@@ -691,7 +670,6 @@ class BleGattServer : public BaseComponent {
691670
692671 Callbacks callbacks_{}; // /< The callbacks for the GATT server.
693672 NimBLEServer *server_{nullptr }; // /< The GATT server.
694- NimBLEClient *client_{nullptr }; // /< The client.
695673 DeviceInfoService device_info_service_; // /< The device info service.
696674 BatteryService battery_service_; // /< The battery service.
697675};
0 commit comments