add service to gatt database

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi Guys,

Here you can find a piece of my code

I did update the gatt database with incremental "Handle"

#define HANDLE_DEVICE_SN_UUID               0x54
#define HANDLE_DEVICE_SN_VALUE               0x55
#define HANDLE_DEVICE_SOFT_VERSION_UUID             0x56
#define HANDLE_DEVICE_SOFT_VERSION_VALUE            0x57

          ......

PRIMARY_SERVICE_UUID16 (0x004d, UUID_SERVICE_DEVICE_INFORMATION),

CHARACTERISTIC_UUID16 (0x004e, 0x004f, UUID_CHARACTERISTIC_MANUFACTURER_NAME_STRING, LEGATTDB_CHAR_PROP_READ, LEGATTDB_PERM_READABLE, 13),

        '...',

CHARACTERISTIC_UUID16 (0x0050, 0x0051, UUID_CHARACTERISTIC_MODEL_NUMBER_STRING, LEGATTDB_CHAR_PROP_READ, LEGATTDB_PERM_READABLE, 8),

        '....',

CHARACTERISTIC_UUID16 (0x0052, 0x0053, UUID_CHARACTERISTIC_SYSTEM_ID, LEGATTDB_CHAR_PROP_READ, LEGATTDB_PERM_READABLE, 8),      0x93,0xb8,0x63,0x80,0x5f,0x9f,0x91,0x71,

/*

CHARACTERISTIC_UUID16 (HANDLE_DEVICE_SN_UUID, HANDLE_DEVICE_SN_VALUE, UUID_CHARACTERISTIC_SERIAL_NUMBER_STRING,

                           LEGATTDB_CHAR_PROP_READ | LEGATTDB_CHAR_PROP_WRITE,

                           LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITABLE, 15),

                           0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

    CHARACTERISTIC_UUID16 (HANDLE_DEVICE_SOFT_VERSION_UUID, HANDLE_DEVICE_SOFT_VERSION_VALUE, UUID_CHARACTERISTIC_FIRMWARE_REVISION_STRING,

                           LEGATTDB_CHAR_PROP_READ,

                           LEGATTDB_PERM_READABLE, 9),

                           0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

*/

    // Handle 0x61: Battery service

    // This is an optional service which allows peer to read current battery level.

    PRIMARY_SERVICE_UUID16 (0x0061, UUID_SERVICE_BATTERY),

    // Handle 0x62: characteristic Battery Level, handle 0x63 characteristic value

    CHARACTERISTIC_UUID16 (HANDLE_BATTERY_UUID, HANDLE_BATTERY_VALUE, UUID_CHARACTERISTIC_BATTERY_LEVEL,

                           LEGATTDB_CHAR_PROP_READ, LEGATTDB_PERM_READABLE, 1),

        0x64,

Here I have two questions :

first : why when I comment both "HANDLE_DEVICE_SN_UUID " et "HANDLE_DEVICE_SOFT_VERSION" battery service works, and when I uncomment "HANDLE_DEVICE_SN_UUID" the battery service isn't working anymore ?

second :

Why when I uncomment the "HANDLE_DEVICE_SOFT_VERSION" and I give a length bigger than "9" (with the corresponding array following the init)  my device doesn't "start" properly ?

I say it's not starting propertly because of the data I receive on Putty (Uart), I get only number following each other and not getting my program to work.

Thanks

Yannick

0 Likes
3 Replies
Anonymous
Not applicable

Hi Yannick,

I feel your pain.  They really don't make it easy on us, do they?  You are experiencing the reason, or one of the reasons, why object oriented programming was invented; specifically the data encapsulation part of object oriented programming.

The problem is that this data block that you are tinkering with has a structure where the location and value of each successive item is somehow determined by or dependent on some or everything that was defined before  it. Not only that, but there seems to be invisible data items that are not defined here but nevertheless need to have space reserved for them in some sense.

The pattern I see here is that the so called "Handle" of the Battery service (0x0061) is also being used as an "offset" into some table.

When you uncomment the preceding items, you are pushing the declaration of the battery service downward in the table and 0x061 is no longer valid.  It looks to me, without testing this, that you should try to change the Battery Service "handle" to a larger number...

Another more direct approach to answer your question might be to ask one: What are you trying to accomplish in all of this tinkering, and then we ask what is the "right" way to do it.

I'll take a stab at a wild guess as to a possible answer below:

CHARACTERISTIC_UUID16 (0x0052, 0x0053, UUID_CHARACTERISTIC_SYSTEM_ID, LEGATTDB_CHAR_PROP_READ, LEGATTDB_PERM_READABLE, 8),      0x93,0xb8,0x63,0x80,0x5f,0x9f,0x91,0x71,

CHARACTERISTIC_UUID16 (HANDLE_DEVICE_SN_UUID, HANDLE_DEVICE_SN_VALUE, UUID_CHARACTERISTIC_SERIAL_NUMBER_STRING,

                           LEGATTDB_CHAR_PROP_READ | LEGATTDB_CHAR_PROP_WRITE,

                           LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITABLE, 15),

                           0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

    CHARACTERISTIC_UUID16 (HANDLE_DEVICE_SOFT_VERSION_UUID, HANDLE_DEVICE_SOFT_VERSION_VALUE, UUID_CHARACTERISTIC_FIRMWARE_REVISION_STRING,

                           LEGATTDB_CHAR_PROP_READ,

                           LEGATTDB_PERM_READABLE, 10),  <<--- Changed 9 to 10 because I'm guessing you want to for some reason.

                           0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00  <<-- Added another byte of characteristic to fill out 10 bytes

    // Handle Was - 0x61: Battery service - CHANGE to 0x007A to accommodate 25 bytes of characteristic added above

    // This is an optional service which allows peer to read current battery level.

    PRIMARY_SERVICE_UUID16 (0x007A, UUID_SERVICE_BATTERY),

    // Handle (was 0x62 now 0x7B): characteristic Battery Level, handle (was 0x63 now 0x7C) characteristic value

    CHARACTERISTIC_UUID16 (0x007B,0x007C, UUID_CHARACTERISTIC_BATTERY_LEVEL,

                           LEGATTDB_CHAR_PROP_READ, LEGATTDB_PERM_READABLE, 1),

        0x64,

Don't forget to adjust anything that is defined below this point in the same block.

Hope this works for you..  anyway it shouldn't take long to try it.

Eric

P.s.  I have no idea if this will work - it just looks like the right thing to do - and by the way, attempting to answer this question I believe has shown me the light as to why my own battery service is not working, and so now I have something to try also.  So thanks for asking.

0 Likes
Anonymous
Not applicable

I did try your suggestion, no improvement.

I do have other characteristic that they follow each other, and I dont get any problem.

I also try to comment other characetistc, my battery doesn't works either.

First I was really motivated using this component getting a good time to market without the need to get my own stack, but the time I consum now to solve bug is somehow loosing all the time I save with this component. I know it's not constructive ...

0 Likes
Anonymous
Not applicable

Hello YF,

The order of listing your Services and Characteristics is important.

Try to use the Smart Designer to list your characteristics and they will appear in the correct order.

pastedImage_0.png

You database is probably not well-formatted.

You may also want to dump the database to the debug UART - See wiced_sense.c file:

   // dump the database to debug uart.

#ifndef BLE_TRACE_DISABLE

     legattdb_dumpDb();

#endif

Hope this helps,

JT