# BC127 write custom characteristic value when in peripheral mode

**URL:** <https://forum.sierrawireless.com/t/bc127-write-custom-characteristic-value-when-in-peripheral-mode/12981>\
**Category:** WiFi and Bluetooth Modules\
**Created:** [June 27, 2018, 3:11pm UTC](https://forum.sierrawireless.com/t/bc127-write-custom-characteristic-value-when-in-peripheral-mode/12981 "2018-06-27T15:11:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![me1sdm](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@me1sdm](https://forum.sierrawireless.com/u/me1sdm)\
**Post date:** [June 27, 2018, 3:11pm UTC](https://forum.sierrawireless.com/t/bc127-write-custom-characteristic-value-when-in-peripheral-mode/12981/1 "2018-06-27T15:11:18Z")

</div>

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:

```auto
> |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:

```auto
┌──────────────┬────────────────────────────────────────────────────────────┬───────────────────────────┬───────────────┐
│ 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:

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

```

On the BC127 side, the following happens:

```auto
< |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:

```auto
> |SND test
< |OK

```

which is received on the BC127 as:

```auto
< |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 :

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

```

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

–  
David

---

<div class="post-metadata">

**Author:** ![alupienbedard](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@alupienbedard](https://forum.sierrawireless.com/u/alupienbedard)\
**Post date:** [June 27, 2018, 7:31pm UTC](https://forum.sierrawireless.com/t/bc127-write-custom-characteristic-value-when-in-peripheral-mode/12981/2 "2018-06-27T19:31:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![me1sdm](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@me1sdm](https://forum.sierrawireless.com/u/me1sdm)\
**Post date:** [June 28, 2018, 12:20pm UTC](https://forum.sierrawireless.com/t/bc127-write-custom-characteristic-value-when-in-peripheral-mode/12981/3 "2018-06-28T12:20:13Z")

</div>

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

–  
David

---

<div class="post-metadata">

**Author:** ![pmandel\_google](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@pmandel\_google](https://forum.sierrawireless.com/u/pmandel_google)\
**Post date:** [June 26, 2019, 10:23pm UTC](https://forum.sierrawireless.com/t/bc127-write-custom-characteristic-value-when-in-peripheral-mode/12981/4 "2019-06-26T22:23:17Z")

</div>

How’d you generate the custom GATT table? I’ve been trying to use the db\_gen tool from Sierra and it keeps saying it’s not a valid executable. Did you figure out how to get it to work or use something else?

Thanks!
