bt_gatt_notify returning -ENOTCONN

I am trying to send a notification in a new device we are developing, something which I have done many times before. I am using Zephyr 1.4.1

Here is how I set up the service

//Vendor Primary Service Declaration
BT_GATT_SERVICE_DEFINE(vnd_svc,
BT_GATT_PRIMARY_SERVICE(&vnd_uuid), //0

//force characteristic
BT_GATT_CHARACTERISTIC(&force_uuid.uuid, BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_WRITE, //1
BT_GATT_PERM_WRITE,
NULL, write_force, force_value),

BT_GATT_CCC(force_ccc_cfg_changed, BT_GATT_PERM_WRITE), //2

//ROM characteristic
BT_GATT_CHARACTERISTIC(&rom_uuid.uuid, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_WRITE, //3
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
read_rom, write_rom, rom_value),

BT_GATT_CCC(rom_ccc_cfg_changed, BT_GATT_PERM_WRITE), //4
);

To send a notification for the ROM characteristic I am using this code:

uint8_t temp = 50;

int result = bt_gatt_notify(NULL, &vnd_svc.attrs[3], &temp, sizeof(temp ));
printk("notify result %d %02X\n", result, result);

For some reason I am receiving -128 or -0x80, which is -ENOTCONN if I look at errno.h

Now if I change the above line and use vnd_svc.attrs[1], there is no problem.  Everything works fine.  But I cannot figure out why.  I am connected to the device

Parents
  • Hi, 

    Have a look bt_gatt_notify (structbt_conn*conn, conststruct bt_gatt_attr*attr, constvoid*data, uint16_tlen)

    Notify attribute value change.

    Send notification of attribute value change, if connection is NULL notify all peer that have notification enabled via CCC otherwise do a direct notification only the given connection.

    The attribute object on the parameters can be the so called Characteristic Declaration, which is usually declared with BT_GATT_CHARACTERISTIC followed by BT_GATT_CCC, or the Characteristic Value Declaration which is automatically created after the Characteristic Declaration when using BT_GATT_CHARACTERISTIC.

    Parameters
    • conn – Connection object.

    • attr – Characteristic or Characteristic Value attribute.

    • data – Pointer to Attribute data.

    • len – Attribute value length.

    Returns

    0 in case of success or negative value in case of error.

     --

    struct bt_gatt_attr
    #include <gatt.h>

    GATT Attribute structure.

    Public Members

    conststructbt_uuid*uuid

    Attribute UUID

    ssize_t(*read)(structbt_conn*connconststructbt_gatt_attr*attrvoid*bufuint16_tlenuint16_toffset)

    Attribute read callback.

    The callback can also be used locally to read the contents of the attribute in which case no connection will be set.

    Parameters
    • conn – The connection that is requesting to read

    • attr – The attribute that’s being read

    • buf – Buffer to place the read result in

    • len – Length of data to read

    • offset – Offset to start reading from

    Returns

    Number fo bytes read, or in case of an error BT_GATT_ERR() with a specific ATT error code.

    Regards, 
    Amanda

  • Hi Amanda,

    Thanks for the function signatures, but I am not sure how that will help me.

    I forgot to mention there is no problem reading and writing to the characteristic in question.  Only notifications for this characteristic have an issue.

    I can keep all my code the same, but change which characteristic I use to notify and there is no issue.

  • I have the same issue using Zephyr 3.1, would be great if Nordic could provide some input!

Reply Children
Related