nRF5 IoT SDK
v0.9.0
|
The CoAP block library supports encoding and decoding of block1 options (request messages) in CoAP. The application has to handle all decision making in a block transfer as the library only handles encoding and decoding of the options values into structures.
Below is an example on how to locate the option index of the block1 option, followed by decoding of the block1 option into a block1 option structure using the coap_block_opt_block1_decode function.
The example below shows how to encode a block1 structure into a uint32_t using the coap_block_opt_block1_encode function, then how to add it to the message and set the correct CoAP message code. The CoAP code will depend on whether the transaction is completed or not. In the case of a complete transaction, the more bit should also be 0 in addition to COAP_CODE_204_CHANGED CoAP message code.