How can I know if the other device received my message with bt_gatt_write() and its time?

I am sending messages from device A to device B via Nordic's nus_client service, and in the method:

bt_nus_client_send(struct bt_nus_client *nus_c, const uint8_t *data, uint16_t len)

it calls bt_gatt_write(nus_c->conn, &nus_c->rx_write_params).

I checked that these two methods exist on the platform: bt_gatt_write() and also the bt_gatt_write_without_response(),

so I ask, if it uses bt_gatt_write() which is with response,

How can I get in the code of device A the confirmation that the device B received the message sent by device A?

How can I get the time it took for this message to go from device A to device B?

How can I get the time this message took from device A to device B plus the response confirmation time?

Thanks

Parents
  • Hello,

    It should be possible to get a callback when the bt_gatt_write() packet has been ACKed. In the central_uart sample, this is the on_sent() callback in nus_client.c.

    This means that the packet has been ACKed by the peripheral, but it doesn't mean that the application has handled it. If that is what you need, then you either need to write a custom protocol in your application, something like sending a notification back from the peripheral when a message was received. Alternatively, you can use indications, instead of notifications, which basically does the same thing. It depends on application ACKs, rather than link layer ACK. 

    This, however, is intended for a different kind of applications, as it heavily reduces the throughput. It can be useful in applications like doorlocks, where you would send a message saying "lock the door", and the door can physically be locked, and send an ACK on this, to make sure that the doorlock is not e.g. jammed before sending the ACK. 

    But the short answer is that the on_sent() callback is triggered when the packet is acknowledged. This means that the packet is received on the other side, and that the CRC was correct, and the application will handle the packet as soon as possible.

    Best regards,

    Edvin

Reply
  • Hello,

    It should be possible to get a callback when the bt_gatt_write() packet has been ACKed. In the central_uart sample, this is the on_sent() callback in nus_client.c.

    This means that the packet has been ACKed by the peripheral, but it doesn't mean that the application has handled it. If that is what you need, then you either need to write a custom protocol in your application, something like sending a notification back from the peripheral when a message was received. Alternatively, you can use indications, instead of notifications, which basically does the same thing. It depends on application ACKs, rather than link layer ACK. 

    This, however, is intended for a different kind of applications, as it heavily reduces the throughput. It can be useful in applications like doorlocks, where you would send a message saying "lock the door", and the door can physically be locked, and send an ACK on this, to make sure that the doorlock is not e.g. jammed before sending the ACK. 

    But the short answer is that the on_sent() callback is triggered when the packet is acknowledged. This means that the packet is received on the other side, and that the CRC was correct, and the application will handle the packet as soon as possible.

    Best regards,

    Edvin

Children
No Data
Related