Sending CoAP Block-wise requests (NCS 2.0.0)

I am having difficulty getting Thread Block-wise Transfers working correctly using the API from NCS v2.0.0. It was my understanding that the otCoapSendRequestBlockWise function abstracts the process of managing block-wise transfers.

How is the otCoapSendRequestBlockWise function supposed to be used? Depending on how I set up to transmit blocks, the receiving end either does not see anything, or it see's all 00's - not the programmed payload. Before going down the rabbit hold of what I am doing wrong, I would like to understand how otCoapSendRequestBlockWise should be used since there is NO examples anywhere on the web that I am aware of. 

The following is my understanding (or misunderstanding) of the flow:

otCoapNewMessage
otCoapMessageInit
otCoapMessageGenerateToken
otCoapMessageSetToken
otCoapMessageAppendUriPathOptions
otCoapMessageAppendBlock1Option
otCoapMessageSetPayloadMarker
otMessageAppend
otCoapSendRequestBlockWise

I've tried many combinations of the above with no successful results. I have a few questions that may be clarified by a proper understanding of the expected flow.

  1. Is it necessary to set the payload marker and add payload prior to calling otCoapSendRequestBlockWise, or is the Blockwise TX Hook supposed to handle the first block?
  2. Is otCoapMessageAppendBlock1Option a required step or does otCoapSendRequestBlockWise handle this under the hood? Removing it seems to cause the receiver side to execute the response callback instead of the block-wise RX callback.
  3. Adding otCoapMessageSetPayloadMarker and otMessageAppend causes the receiver to not receive anything. 
  4. Removing otCoapMessageSetPayloadMarker and otMessageAppend causes the receiver to receive proper block sizes, but reads all 0's.
  5. I have tried many combinations of the above and have yet to get something that works.  
  • I figured out my issue. First I realized there was the CoAP CLI example (found in C:\ncs\v2.0.0\modules\lib\openthread\src\cli) which was very helpful. My bigger issue was that my block-wise callback was not properly copying memory from the local buffer into the CoAP buffer.

  • Hi,

    Glad to hear you found a sample that you could guide you. I was about to suggest the OpenThread samples we have in the SDK, while we waited for an answer from our OpenThread team, but that seems to be redundant now.

    I will mark this ticket as verified and close it by tomorrow, so let me know if you have any additional questions related to this ticket before then and I'll keep it open.

    Kind regards,
    Andreas

  • Did you get the block-wise functionality working as expected? Could you share a small example?

    Before jumping into custom firmware development, I used the ot-cli sample to evaluate the feasibility of transmitting large payloads but my server isn’t receiving any data.

    To test, I used the following command:

    $ ot coap put <synthesized IPv6 address of the CoAP server> <uri> block-64 40

    From the documentation, this command will transmit 40 data blocks of 64 bytes each to the CoAP server. However, no payload ever arrives at my CoAP server. The value 40 is intended to represent the number of blocks to send, with the actual payload consisting of random bytes. Is the block-wise implementation in OT-CLI working as expected?

    The documentation also states:

    “The block- type requires OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE to be set.”

    Do I need to enable this configuration? If so, can I do it in the prj.conf file like this?

    CONFIG_OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE=y
Related