Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper shutdown #149

Closed
mickeyl opened this issue Mar 19, 2024 · 2 comments
Closed

Proper shutdown #149

mickeyl opened this issue Mar 19, 2024 · 2 comments

Comments

@mickeyl
Copy link

mickeyl commented Mar 19, 2024

In my application for ESP32S3, we offer similar services both through BLE/L2CAP and WiFi. In order to make things smoothly coexist, upon connection setup, we want to shutdown the respective "other" service.

What's the preferred way to shutdown the stack using esp-nimble-cpp? Here is how I set it up:

// L2CAP
    auto cocServer = new BLEL2CapServer();
    auto l2capServiceCallbacks = new L2CAPServiceCallbacks();
    auto canCoc = cocServer->createService(DeviceInformation::shared().psmForCan(), 5000, l2capServiceCallbacks);
    auto server = BLEDevice::createServer();
    auto gattServerCallbacks = new GATTServerCallbacks();
    server->setCallbacks(gattServerCallbacks);

    // FFF1 for detection & info
    auto service = server->createService(SERVICE_UUID);
    auto psmForCanCharacteristics = service->createCharacteristic(DeviceInformation::shared().psmForCan(), NIMBLE_PROPERTY::READ);
    psmForCanCharacteristics->setValue("L2CAP PSM for CANController");
    auto psmForEnetCharacteristics = service->createCharacteristic(DeviceInformation::shared().psmForEnet(), NIMBLE_PROPERTY::READ);
    psmForEnetCharacteristics->setValue("L2CAP PSM for ENET");
    service->start();

    // 180A for device information
    auto deviceInformationService = server->createService(DEVICE_INFORMATION_SERVICE_UUID);
    auto manufacturerNameCharacteristics = deviceInformationService->createCharacteristic(MANUFACTURER_NAME_UUID, NIMBLE_PROPERTY::READ);
    manufacturerNameCharacteristics->setValue(DeviceInformation::shared().manufacturerName());
    auto modelNumberCharacteristics = deviceInformationService->createCharacteristic(MODEL_NUMBER_UUID, NIMBLE_PROPERTY::READ);
    modelNumberCharacteristics->setValue(DeviceInformation::shared().modelName());
    auto serialNumberCharacteristics = deviceInformationService->createCharacteristic(SERIAL_NUMBER_UUID, NIMBLE_PROPERTY::READ);
    serialNumberCharacteristics->setValue(DeviceInformation::shared().serialNumber());
    auto hardwareRevisionCharacteristics = deviceInformationService->createCharacteristic(HARDWARE_REVISION_UUID, NIMBLE_PROPERTY::READ);
    hardwareRevisionCharacteristics->setValue(DeviceInformation::shared().hardwareRevision());
    auto firmwareRevisionCharacteristics = deviceInformationService->createCharacteristic(FIRMWARE_REVISION_UUID, NIMBLE_PROPERTY::READ);
    firmwareRevisionCharacteristics->setValue(DeviceInformation::shared().firmwareRevision());
    deviceInformationService->start();

    // Enable Advertising
    auto advertising = BLEDevice::getAdvertising();
    advertising->addServiceUUID(SERVICE_UUID);
    advertising->setScanResponse(true);
    BLEDevice::startAdvertising();

Do I need to remove the callbacks and do I need to keep the handles for the services around so I can stop them?

Or is there a more simple way to cleanup where all the registered services are shut down automatically?

Update: I have found BLEDevice::deinit -- is that a coordinated shutdown?

@mickeyl
Copy link
Author

mickeyl commented Mar 21, 2024

It looks like this is it. There's a problem with l2cap servers, but this I'm trying to address upstream.

@mickeyl mickeyl closed this as completed Mar 21, 2024
@h2zero
Copy link
Owner

h2zero commented Mar 24, 2024

Sorry for the delay, looks like you found the solution though. Interesting issue with the l2cap servers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants