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

[Server] Add secondary capability. #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

h2zero
Copy link
Owner

@h2zero h2zero commented Sep 12, 2021

Adds NimBLEService::createService and NimBLEService::addService which will create a secondary service under the service caller.

@justintconroy
Copy link

Were you able to get the secondary service to show up in a BLE scanner of some sort? I can't seem to get it to show up in my project. I'll try to throw together something more minimal to either repro my problem or figure out how to do it the right way if you aren't seeing the same.

@justintconroy
Copy link

I think what's missing here is adding the secondary service to the includes of the primary service in start()

@justintconroy
Copy link

My likely naïve attempt to remedy:

if (m_secSvcVec.size() > 0) {
    int i = 0;
    const ble_gatt_svc_def* incs[m_secSvcVec.size()];
    for (auto& it : m_secSvcVec) {
        incs[i] = it->m_pSvcDef;
        ++i;
    }
    m_pSvcDef->includes = incs;
}

triggers an abort() in NimBLEServer::start():

if(svc->m_removed == 0) {
    rc = ble_gatts_find_svc(&svc->getUUID().getNative()->u, &svc->m_handle);
    if(rc != 0) {
        abort();
    }
}

@h2zero
Copy link
Owner Author

h2zero commented Sep 13, 2021

Thanks for testing it, it seemed to be working for me last night but that wasn't a thorough test and I can confirm some scanners don't read it. You were on the right path I think with the "includes", I'll look at this now and see what's up.

@h2zero
Copy link
Owner Author

h2zero commented Sep 13, 2021

I've added the includes to the primary service. NimBLE reports this:

primary service
08:18:50.943 ->            uuid 0x1800
08:18:50.943 ->          handle 1
08:18:50.943 ->      end_handle 5
08:18:50.943 -> characteristic
08:18:50.943 ->            uuid 0x2a00
08:18:50.943 ->      def_handle 2
08:18:50.943 ->      val_handle 3
08:18:50.943 ->    min_key_size 0
08:18:50.943 ->           flags [READ]
08:18:50.943 -> characteristic
08:18:50.989 ->            uuid 0x2a01
08:18:50.989 ->      def_handle 4
08:18:50.989 ->      val_handle 5
08:18:50.989 ->    min_key_size 0
08:18:50.989 ->           flags [READ]
08:18:50.989 -> primary service
08:18:50.989 ->            uuid 0x1801
08:18:50.989 ->          handle 6
08:18:50.989 ->      end_handle 9
08:18:50.989 -> characteristic
08:18:50.989 ->            uuid 0x2a05
08:18:50.989 ->      def_handle 7
08:18:50.989 ->      val_handle 8
08:18:50.989 ->    min_key_size 0
08:18:50.989 ->           flags [INDICATE]
08:18:50.989 -> ccc descriptor
08:18:50.989 ->            uuid 0x2902
08:18:50.989 ->          handle 9
08:18:50.989 ->    min_key_size 0
08:18:50.989 ->           flags [READ|WRITE]
08:18:50.989 -> secondary service
08:18:50.989 ->            uuid 0000abcd-0000-1000-8000-00805f9b34fb
08:18:50.989 ->          handle 10
08:18:51.036 ->      end_handle 13
08:18:51.036 -> characteristic
08:18:51.036 ->            uuid 0x1234
08:18:51.036 ->      def_handle 11
08:18:51.036 ->      val_handle 12
08:18:51.036 ->    min_key_size 0
08:18:51.036 ->           flags [READ|WRITE|READ_ENC|WRITE_ENC]
08:18:51.036 -> descriptor
08:18:51.036 ->            uuid 0x2904
08:18:51.036 ->          handle 13
08:18:51.036 ->    min_key_size 0
08:18:51.036 ->           flags [READ]
08:18:51.036 -> primary service
08:18:51.036 ->            uuid 0000dead-0000-1000-8000-00805f9b34fb
08:18:51.036 ->          handle 14
08:18:51.036 ->      end_handle 18
08:18:51.036 -> included service
08:18:51.036 ->            uuid 0000abcd-0000-1000-8000-00805f9b34fb
08:18:51.036 ->     attr handle 15
08:18:51.036 -> characteristic
08:18:51.036 ->            uuid 0xbeef
08:18:51.083 ->      def_handle 16
08:18:51.083 ->      val_handle 17
08:18:51.083 ->    min_key_size 0
08:18:51.083 ->           flags [READ|WRITE|READ_ENC|WRITE_ENC]
08:18:51.083 -> descriptor
08:18:51.083 ->            uuid 0x2904
08:18:51.083 ->          handle 18
08:18:51.083 ->    min_key_size 0
08:18:51.083 ->           flags [READ]
08:18:51.083 -> primary service
08:18:51.083 ->            uuid 0xbaad
08:18:51.083 ->          handle 19
08:18:51.083 ->      end_handle 23
08:18:51.083 -> characteristic
08:18:51.083 ->            uuid 0xf00d
08:18:51.083 ->      def_handle 20
08:18:51.083 ->      val_handle 21
08:18:51.083 ->    min_key_size 0
08:18:51.083 ->           flags [READ|WRITE|NOTIFY]
08:18:51.083 -> ccc descriptor
08:18:51.083 ->            uuid 0x2902
08:18:51.083 ->          handle 22
08:18:51.083 ->    min_key_size 0
08:18:51.083 ->           flags [READ|WRITE]
08:18:51.130 -> descriptor
08:18:51.130 ->            uuid 0xc01d
08:18:51.130 ->          handle 23
08:18:51.130 ->    min_key_size 0
08:18:51.130 ->           flags [READ|WRITE|WRITE_ENC]

However, my scanner apps don't report it, maybe you'll have better luck.

@justintconroy
Copy link

Sorry, I won't have much time to test this today or maybe the rest of the week. My initial attempts didn't work (your rebase from master caused build errors, but I fixed those temporarily). I think what I saw yesterday was that the secondary service was showing up like a primary service in Light Blue.

How did you get NimBLE to give you that output? I can at least check if I have things setup correctly before checking what's in a scanner.

@h2zero
Copy link
Owner Author

h2zero commented Sep 14, 2021

Sorry about the rebase. You can call ble_gatts_show_local(); to get NimBLE to dump the database after starting advertising.

No hurry, I need to implement the client portion still anyway which does detect this correctly in the test code.

@finger563
Copy link

Was this ever solved? Looking to move from bluedroid to NimBLE and would like to use esp-nimble-cpp but we definitely need multiple services. If this is close and still valid w.r.t. the latest changes (given that these changes were 2 years ago) then I can try to get this finalized and tested with multiple services.

@h2zero
Copy link
Owner Author

h2zero commented Feb 21, 2024

@finger563 This is for creating secondary service types. If all you need is multiple services then that has been supported since the beginning of this repo.

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

Successfully merging this pull request may close these issues.

None yet

3 participants