You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mynewt.apache.org by James Howarth <ja...@gmail.com> on 2016/05/23 21:24:15 UTC

Respond to a write characteristic

Hi,

I am looking to issue a response to a write characteristic, and seem to be
just getting a null response.

Is there anything I need to do special with the write data, before writing
back some data.

Here's my code, it's based off the peripheral tutorial from 0.80.


Inside static const struct ble_gatt_svc_def gatt_svr_svcs[] = {

....

 [4] = {
         /*** Service: TXPWR */
         .type = BLE_GATT_SVC_TYPE_PRIMARY,
         .uuid128 = (void *)p_uuid_base,
         .characteristics = (struct ble_gatt_chr_def[]) { {
             .uuid128 = (void *)p_uuid_id,
             .access_cb = gatt_svr_chr_txpwrlvl_cb,
             .flags = BLE_GATT_CHR_F_READ,
         }, {
             .uuid128 = (void *)p_uuid_command_nonce,
             .access_cb = gatt_svr_p_command_nonce_cb,
             .flags = BLE_GATT_CHR_F_READ,
         }, {
          .uuid128 = (void *)p_uuid_command,
             .access_cb = gatt_svr_p_command_cb,
             .flags = BLE_GATT_CHR_F_WRITE,
         }, {
             0, /* No more characteristics in this service. */
         } },
     },


...


static int
gatt_svr_p_command_cb(uint16_t conn_handle, uint16_t attr_handle, uint8_t
op,
                         union ble_gatt_access_ctxt *ctxt, void *arg)
{
static uint8_t command_int = 0x05;
    ctxt->chr_access.data = &command_int;
    ctxt->chr_access.len = 1;

    return 0;
}

Cheers
James

Re: Respond to a write characteristic

Posted by Christopher Collins <cc...@apache.org>.
On Mon, May 23, 2016 at 09:22:42PM -0700, James Howarth wrote:
> Hi Chris,
> 
> Looking at the LightBlue app on my iPhone, it tells me the response is 'null'.

Hmm... I am not sure.  A write response does not contain any data of its
own; all write responses are alike.  Is it possible lightblue displays
that due to an attempt to read a characteristic (as opposed to write)?

Unfortunately I am not equipped to test this out at the moment, but I'll
take a look tomorrow.  That said, I don't believe there is anything
wrong with your code.

Chris

Re: Respond to a write characteristic

Posted by James Howarth <ja...@gmail.com>.
Hi Chris,

Looking at the LightBlue app on my iPhone, it tells me the response is 'null'.

Cheers
James


> On May 23, 2016, at 9:19 PM, Christopher Collins <cc...@apache.org> wrote:
> 
> Hi James,
> 
>> On Mon, May 23, 2016 at 02:24:15PM -0700, James Howarth wrote:
>> Hi,
>> 
>> I am looking to issue a response to a write characteristic, and seem to be
>> just getting a null response.
> [...]
>> static int
>> gatt_svr_p_command_cb(uint16_t conn_handle, uint16_t attr_handle, uint8_t
>> op,
>>                         union ble_gatt_access_ctxt *ctxt, void *arg)
>> {
>> static uint8_t command_int = 0x05;
>>    ctxt->chr_access.data = &command_int;
>>    ctxt->chr_access.len = 1;
>> 
>>    return 0;
>> }
> 
> That should do the trick. As long as the function returns 0, the write
> response should get sent.
> 
> What do you mean by null response?
> 
> Chris

Re: Respond to a write characteristic

Posted by Christopher Collins <cc...@apache.org>.
Hi James,

On Mon, May 23, 2016 at 02:24:15PM -0700, James Howarth wrote:
> Hi,
> 
> I am looking to issue a response to a write characteristic, and seem to be
> just getting a null response.
> 
[...]
> static int
> gatt_svr_p_command_cb(uint16_t conn_handle, uint16_t attr_handle, uint8_t
> op,
>                          union ble_gatt_access_ctxt *ctxt, void *arg)
> {
> static uint8_t command_int = 0x05;
>     ctxt->chr_access.data = &command_int;
>     ctxt->chr_access.len = 1;
> 
>     return 0;
> }

That should do the trick. As long as the function returns 0, the write
response should get sent.

What do you mean by null response?

Chris