BC127 write custom characteristic value when in peripheral mode


#1

Hi,

TLDR; how can I write a custom characteristic value with a Melody6-enabled chip, when in peripheral mode?

I have been working on a BLE setup with a BC127 in peripheral mode and a BC118 in central mode.
I’d like to use the BC SmartMelody service, but use a custom service too in addition to it.
In a first attempt I generated and loaded a custom GATT db with only the BC SmartMelody.

Note: in the traces below, > means from the terminal to the chip and < the opposite,
20FABBXXXXXX is the MAC address of the BC127 and 20FABBYYYYYY the address of the BC118.

First, on the BC127 side, I configure the chip as I need:

> |SET BLE_CONFIG=0 OFF 40 OFF
< |OK
> |ADVERTISING OFF
< |OK
> |BLE_SET_DB 3d
< |PENDING
> |0002 0118 3005 2003 0005
< |PENDING
> |2a00 dc00 6c00 0002 0018
< |PENDING
> |3005 0207 0000 2a00 d00a
< |PENDING
> |5465 7374 4465 7669 6365
< |PENDING
> |3005 0209 0001 2a00 d002
< |PENDING
> |0000 0010 f028 e368 62d6
< |PENDING
> |3490 5143 efaa c64c 2fbc
< |PENDING
> |3013 180c 003c d9f7 8937
< |PENDING
> |37aa 8f71 4aad 79e7 e5d1
< |PENDING
> |0600 cc00 6c00 3013 140f
< |PENDING
> |004d 315d 6add 7a1a b58d
< |PENDING
> |445b 9c06 e38a 8100 cc00
< |PENDING
> |6c00
< |OK
> |SET BLE_CONFIG=0 ON 40 OFF
< |OK

The device services are:

┌──────────────┬────────────────────────────────────────────────────────────┬───────────────────────────┬───────────────┐
│ Handles      │ Service > Characteristics                                  │ Properties                │ Data          │
├──────────────┼────────────────────────────────────────────────────────────┼───────────────────────────┼───────────────┤
│ 0001 -> 0004 │ Generic Attribute ( 00001801-0000-1000-8000-00805f9b34fb ) │                           │               │
│ 0003         │   Service Changed ( 00002a05-0000-1000-8000-00805f9b34fb ) │ INDICATE                  │               │
│              │                                                            │                           │               │
│ 0005 -> 0009 │ Generic Access ( 00001800-0000-1000-8000-00805f9b34fb )    │                           │               │
│ 0007         │   Device Name ( 00002a00-0000-1000-8000-00805f9b34fb )     │ READ                      │ u'TestDevice' │
│ 0009         │   Appearance ( 00002a01-0000-1000-8000-00805f9b34fb )      │ READ                      │ Unknown       │
│              │                                                            │                           │               │
│ 000a -> ffff │ bc2f4cc6-aaef-4351-9034-d66268e328f0                       │                           │               │
│ 000c         │   06d1e5e7-79ad-4a71-8faa-373789f7d93c                     │ NOTIFY WRITE              │               │
│ 000f         │   818ae306-9c5b-448d-b51a-7add6a5d314d                     │ NOTIFY WRITE NO RESPONSE  │               │
│              │                                                            │                           │               │
└──────────────┴────────────────────────────────────────────────────────────┴───────────────────────────┴───────────────┘

Which seems to be similar as when no custom GATT db is set up.

Then, on the BC118 side, I connect the device to the peripheral BC127:

< |CON 20FABBXXXXXX 0
< |OK
< |CON=OK 20FABBXXXXXX 0
< |CONP=0010 0000 04E2
< |FTRS=0104

On the BC127 side, the following happens:

< |OPEN_OK 14 BLE 20FABBYYYYYY
< |BLE_READ 14 000D
> |BLE_READ_RES 14 d 2
< |PENDING
> |{0x00}{0x00}
< |OK
< |BLE_READ 14 0010
> |BLE_READ_RES 14 10 2
< |PENDING
> |{0x00}{0x00}
< |OK
< |BLE_WRITE 14 000D 2 0100

When I write the characteristic whose handle is C from the central BC118,
everything seems fine:

> |SND test
< |OK

which is received on the BC127 as:

< |BLE_WRITE 14 000C 4 74657374

However when I try to write the same data on the same characteristic with the BLE_WRITE command
(as the documentation seems to indicate), from the peripheral BC127, I’m met with an error:

|BLE_WRITE 14 000C 4
< |ERROR 0x0011
Error: command sequence failed with status ‘error_not_allowed_in_current_config’

I tried using the characteristic value + 1 as mentionned in the documentation, but to no avail either:

|BLE_WRITE 14 000D 4
< |ERROR 0x0011
Error: command sequence failed with status ‘error_not_allowed_in_current_config’

Note: when I do the equivalent without a custom GATT db, with the SEND command, it works as it is supposed to.

The version of the BC127 firmware is :

< |Melody Audio V6.1.4
< |Build: 1493828294

Could someone please tell me what I did wrong ?
Thanks in advance.


David


#2

You cannot do a BLE_WRITE from a BC127 in BLE peripheral mode, it must be in central mode.

If you want to send unsolicited data from a BC127 BLE peripheral to a BC118 BLE central, you can use BLE_NOTIFICATION. You must subscribe to notifications of this characteristic handle on the central device.


#3

Yes, that command seems to do the trick.
Thanks a lot.


David