This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Write Queued Characteristic with Less than 20 bytes

Good afternoon,

Following up my previous case, to which I got no reply, how can I use a queued write characteristic to write less than 20 bytes of data?

I'm using it to mainly write more than 20 bytes of data but when I write less than 20 bytes it just halts the application. How can I overcome it?

Thank you,

João

  • I'm running a peripheral BLE device using SDK15 and Softdevice6.0.0

    Thank you again,

    João

  • HI Joao, 

    I sincerely apologize for the very late reply on this question and the other QWR related question you have posted. I've been looking at the QWR module and it appears that it does not handle regular write requests with authorization, i.e. it is not replying to a write auth. request and that is why it is hanging. I added the following code to the switch-case in on_rw_authorize_request() in nrf_ble_qwr.c

        case BLE_GATTS_OP_WRITE_REQ:
                auth_reply.type                     = BLE_GATTS_AUTHORIZE_TYPE_WRITE;
                auth_reply.params.write.gatt_status = BLE_GATT_STATUS_SUCCESS;
                auth_reply.params.write.update = 1;
                ret_code_t err_code = sd_ble_gatts_rw_authorize_reply(p_qwr->conn_handle,&auth_reply);
                if (err_code != NRF_SUCCESS)
                {
                    // Report error to application.
                    p_qwr->error_handler(err_code);
                }
                break;
     

    This appears to solve the issue of the application halting when writing less than 20 bytes. I will look more into this tomorrow. 

    Bjørn 

  • Hi Bjørn,

    Thank you for your reply.

    Indeed now it doesn't halt when writing less than 20 bytes, still the write request is not executed in the end, which indicates that something is still missing to forward the write command and respective data to execution.

    Looking forward to your reply,

    Thank you,

    João

  • HI Joao, 

    I've been looking a bit more into the QWR module code and looking at a sniffer trace when you write less than 20bytes to the QWR characteristic. 

    So if you write less than 20 bytes to the QWR characteristic using nRF Connect for Android/iOS or Desktop, then it will send a regular Write Request that needs to be authorized and not a Prepare Write Request

    The code I sent you in my previous reply modifies the QWR event handler to handle a Write Request, but the Write Request is not preceeded by a User Memory Request, the SD is asking the Application for a memory section to store the incoming data in, so invoking the nrf_ble_qwrs_on_qwr_evt() handler and passing NRF_BLE_QWR_EVT_EXECUTE_WRITE as the event type is not possible as it will trigger the nrf_ble_qwr_value_get() call, which in turn will try to use a buffer that is never allocated

    So I am not sure if it is the right way to go as the module would work as it should if the less than 20 byte data is sent as a prepare write request followed by an Execute Write Now Request. 

    You could of course create a separate event type NRF_BLE_QWR_EVT_WRITE_REQ and then handle that in nrf_ble_qwrs_on_qwr_evt(), but then you would have to modify the nrf_ble_qwrs_on_qwr_evt() handler so that nrf_ble_qwr_value_get() is not called when the NRF_BLE_QWR_EVT_WRITE_REQ event is received.

    What is your use case for queued writes, are you planning on writing to multiple characteristic handles or is it just one characteristic handle? Also what are you planning on using as the central device, a smartphone or another nordic device?

    Best regards

    Bjørn 

  • Hi Bjørn,

    Thank you for your reply.

    I understand the clarified implications.

    Our peripheral is intended to interact with Smartphone central apps on both Android and iOS, and we make use of multiple services/characteristics along with the Queued Write Service and its containing Queued Write Characteristic. We can write either less or more than 20 bytes through the Queued Write Characteristic. So what would be the best way to solve this issue? Is there a way to force a "Prepare Write Request" through the Smartphone central app on both Android and iOS or should we change the nrf_ble_qwr/nrf_ble_qwrs events to deal with both types of data lengths? For the suggested solution, what exactly should we code?

    Looking forward to your reply,

    Thank you,

    João

Related