Hello and thank you for your help.
Im working on a Zephyr-based project with the nrf52840 usb dongle, and Ive hit a wall.
The dongle needs to act as a central and client, and connects over BLE to a second device. This second device has one primary service with two characteristics. Of those two characteristics, one is a notify/read, and the other is write/write w/o response.
I have successfully implemented gatt discover and then subscribe/enable notifications, and I can see the heartbeat message from the server to the client in my printk output. So far so good. Where I am having a problem is I can't seem to then go back to the discovery process, and then get the write w/o response side of things to work.
I think I need to use GATT discover to find the write characteristic, and then I can write [0x01,0x63] to it without response. I think the problem im having is in the discovery part, but welcome any advice or examples. The GATT Central example isnt very helpful, in that it writes to basically a random handle. Are there any other examples for a client-side implementation that first does bt_gatt_discover(...) and then bt_gatt_write_without_response(...)?
Here is my code if that helps:
static uint8_t SEND_discover_func(struct bt_conn *conn, const struct bt_gatt_attr *attr, struct bt_gatt_discover_params *params) { int err; if (!attr) { printk("Discover complete\n"); (void)memset(params, 0, sizeof(*params)); return BT_GATT_ITER_STOP; } //did we get to this callback after searching for the primary service? then look for write characterisitic if (0 == bt_uuid_cmp(SEND_Discover_Params.uuid, PROTEUS_PRIMARY_SERVICE_UUID)) { memcpy(&SEND_Discover_UUID, PROTEUS_SERVER_Receive_CHARACTERISTIC, sizeof(SEND_Discover_UUID)); SEND_Discover_Params.uuid = &SEND_Discover_UUID.uuid; SEND_Discover_Params.start_handle = attr->handle + 1; //why is this +1? SEND_Discover_Params.type = BT_GATT_DISCOVER_CHARACTERISTIC; err = bt_gatt_discover(conn, &SEND_Discover_Params); if (err) { printk("Discover failed (err %d)\n", err); } } //did we get to this callback after searching for the characterisitic? Write to the handle else if (0 == bt_uuid_cmp(SEND_Discover_Params.uuid,PROTEUS_SERVER_Receive_CHARACTERISTIC)) { //debug info char str1 [128]; bt_uuid_to_str(attr->uuid,str1,128); printk("[ATTRIBUTE] handle %u uuid %s %s\n", attr->handle,str1); //do the write err = bt_gatt_write_without_response(conn,attr->handle,send_data,2,false); printk("sent start to %i err %i \n",attr->handle,err); } return BT_GATT_ITER_STOP; }
Thank you all for your time and support.