CoAP

This module includes functions that control CoAP communication.

Summary

The functions in this module are available when CoAP API feature (OPENTHREAD_CONFIG_COAP_API_ENABLE) is enabled.

Enumerations

otCoapBlockSzx enum
CoAP Block Size Exponents.
otCoapCode{
  OT_COAP_CODE_EMPTY = (((( 0 )&0x7) << 5) | (( 0 )&0x1f)),
  OT_COAP_CODE_GET = (((( 0 )&0x7) << 5) | (( 1 )&0x1f)),
  OT_COAP_CODE_POST = (((( 0 )&0x7) << 5) | (( 2 )&0x1f)),
  OT_COAP_CODE_PUT = (((( 0 )&0x7) << 5) | (( 3 )&0x1f)),
  OT_COAP_CODE_DELETE = (((( 0 )&0x7) << 5) | (( 4 )&0x1f)),
  OT_COAP_CODE_RESPONSE_MIN = (((( 2 )&0x7) << 5) | (( 0 )&0x1f)),
  OT_COAP_CODE_CREATED = (((( 2 )&0x7) << 5) | (( 1 )&0x1f)),
  OT_COAP_CODE_DELETED = (((( 2 )&0x7) << 5) | (( 2 )&0x1f)),
  OT_COAP_CODE_VALID = (((( 2 )&0x7) << 5) | (( 3 )&0x1f)),
  OT_COAP_CODE_CHANGED = (((( 2 )&0x7) << 5) | (( 4 )&0x1f)),
  OT_COAP_CODE_CONTENT = (((( 2 )&0x7) << 5) | (( 5 )&0x1f)),
  OT_COAP_CODE_CONTINUE = (((( 2 )&0x7) << 5) | (( 31 )&0x1f)),
  OT_COAP_CODE_BAD_REQUEST = (((( 4 )&0x7) << 5) | (( 0 )&0x1f)),
  OT_COAP_CODE_UNAUTHORIZED = (((( 4 )&0x7) << 5) | (( 1 )&0x1f)),
  OT_COAP_CODE_BAD_OPTION = (((( 4 )&0x7) << 5) | (( 2 )&0x1f)),
  OT_COAP_CODE_FORBIDDEN = (((( 4 )&0x7) << 5) | (( 3 )&0x1f)),
  OT_COAP_CODE_NOT_FOUND = (((( 4 )&0x7) << 5) | (( 4 )&0x1f)),
  OT_COAP_CODE_METHOD_NOT_ALLOWED = (((( 4 )&0x7) << 5) | (( 5 )&0x1f)),
  OT_COAP_CODE_NOT_ACCEPTABLE = (((( 4 )&0x7) << 5) | (( 6 )&0x1f)),
  OT_COAP_CODE_REQUEST_INCOMPLETE = (((( 4 )&0x7) << 5) | (( 8 )&0x1f)),
  OT_COAP_CODE_PRECONDITION_FAILED = (((( 4 )&0x7) << 5) | (( 12 )&0x1f)),
  OT_COAP_CODE_REQUEST_TOO_LARGE = (((( 4 )&0x7) << 5) | (( 13 )&0x1f)),
  OT_COAP_CODE_UNSUPPORTED_FORMAT = (((( 4 )&0x7) << 5) | (( 15 )&0x1f)),
  OT_COAP_CODE_INTERNAL_ERROR = (((( 5 )&0x7) << 5) | (( 0 )&0x1f)),
  OT_COAP_CODE_NOT_IMPLEMENTED = (((( 5 )&0x7) << 5) | (( 1 )&0x1f)),
  OT_COAP_CODE_BAD_GATEWAY = (((( 5 )&0x7) << 5) | (( 2 )&0x1f)),
  OT_COAP_CODE_SERVICE_UNAVAILABLE = (((( 5 )&0x7) << 5) | (( 3 )&0x1f)),
  OT_COAP_CODE_GATEWAY_TIMEOUT = (((( 5 )&0x7) << 5) | (( 4 )&0x1f)),
  OT_COAP_CODE_PROXY_NOT_SUPPORTED = (((( 5 )&0x7) << 5) | (( 5 )&0x1f))
}
enum
CoAP Code values.
otCoapOptionContentFormat{
  OT_COAP_OPTION_CONTENT_FORMAT_TEXT_PLAIN = 0,
  OT_COAP_OPTION_CONTENT_FORMAT_COSE_ENCRYPT0 = 16,
  OT_COAP_OPTION_CONTENT_FORMAT_COSE_MAC0 = 17,
  OT_COAP_OPTION_CONTENT_FORMAT_COSE_SIGN1 = 18,
  OT_COAP_OPTION_CONTENT_FORMAT_LINK_FORMAT = 40,
  OT_COAP_OPTION_CONTENT_FORMAT_XML = 41,
  OT_COAP_OPTION_CONTENT_FORMAT_OCTET_STREAM = 42,
  OT_COAP_OPTION_CONTENT_FORMAT_EXI = 47,
  OT_COAP_OPTION_CONTENT_FORMAT_JSON = 50,
  OT_COAP_OPTION_CONTENT_FORMAT_JSON_PATCH_JSON = 51,
  OT_COAP_OPTION_CONTENT_FORMAT_MERGE_PATCH_JSON = 52,
  OT_COAP_OPTION_CONTENT_FORMAT_CBOR = 60,
  OT_COAP_OPTION_CONTENT_FORMAT_CWT = 61,
  OT_COAP_OPTION_CONTENT_FORMAT_COSE_ENCRYPT = 96,
  OT_COAP_OPTION_CONTENT_FORMAT_COSE_MAC = 97,
  OT_COAP_OPTION_CONTENT_FORMAT_COSE_SIGN = 98,
  OT_COAP_OPTION_CONTENT_FORMAT_COSE_KEY = 101,
  OT_COAP_OPTION_CONTENT_FORMAT_COSE_KEY_SET = 102,
  OT_COAP_OPTION_CONTENT_FORMAT_SENML_JSON = 110,
  OT_COAP_OPTION_CONTENT_FORMAT_SENSML_JSON = 111,
  OT_COAP_OPTION_CONTENT_FORMAT_SENML_CBOR = 112,
  OT_COAP_OPTION_CONTENT_FORMAT_SENSML_CBOR = 113,
  OT_COAP_OPTION_CONTENT_FORMAT_SENML_EXI = 114,
  OT_COAP_OPTION_CONTENT_FORMAT_SENSML_EXI = 115,
  OT_COAP_OPTION_CONTENT_FORMAT_COAP_GROUP_JSON = 256,
  OT_COAP_OPTION_CONTENT_FORMAT_SENML_XML = 310,
  OT_COAP_OPTION_CONTENT_FORMAT_SENSML_XML = 311
}
enum
CoAP Content Format codes.
otCoapOptionType{
  OT_COAP_OPTION_IF_MATCH = 1,
  OT_COAP_OPTION_URI_HOST = 3,
  OT_COAP_OPTION_E_TAG = 4,
  OT_COAP_OPTION_IF_NONE_MATCH = 5,
  OT_COAP_OPTION_OBSERVE = 6,
  OT_COAP_OPTION_URI_PORT = 7,
  OT_COAP_OPTION_LOCATION_PATH = 8,
  OT_COAP_OPTION_URI_PATH = 11,
  OT_COAP_OPTION_CONTENT_FORMAT = 12,
  OT_COAP_OPTION_MAX_AGE = 14,
  OT_COAP_OPTION_URI_QUERY = 15,
  OT_COAP_OPTION_ACCEPT = 17,
  OT_COAP_OPTION_LOCATION_QUERY = 20,
  OT_COAP_OPTION_BLOCK2 = 23,
  OT_COAP_OPTION_BLOCK1 = 27,
  OT_COAP_OPTION_SIZE2 = 28,
  OT_COAP_OPTION_PROXY_URI = 35,
  OT_COAP_OPTION_PROXY_SCHEME = 39,
  OT_COAP_OPTION_SIZE1 = 60
}
enum
CoAP Option Numbers.
otCoapType{
  OT_COAP_TYPE_CONFIRMABLE = 0,
  OT_COAP_TYPE_NON_CONFIRMABLE = 1,
  OT_COAP_TYPE_ACKNOWLEDGMENT = 2,
  OT_COAP_TYPE_RESET = 3
}
enum
CoAP Type values (2 bit unsigned integer).

Typedefs

otCoapBlockSzx typedef
CoAP Block Size Exponents.
otCoapBlockwiseReceiveHook)(void *aContext, const uint8_t *aBlock, uint32_t aPosition, uint16_t aBlockLength, bool aMore, uint32_t aTotalLength) typedef
Pointer is called when a CoAP message with a block-wise transfer option is received.
otCoapBlockwiseResource typedef
Represents a CoAP resource with block-wise transfer.
otCoapBlockwiseTransmitHook)(void *aContext, uint8_t *aBlock, uint32_t aPosition, uint16_t *aBlockLength, bool *aMore) typedef
Pointer is called before the next block in a block-wise transfer is sent.
otCoapCode typedef
enum otCoapCode
CoAP Code values.
otCoapOption typedef
struct otCoapOption
Represents a CoAP option.
otCoapOptionContentFormat typedef
CoAP Content Format codes.
otCoapOptionIterator typedef
Acts as an iterator for CoAP options.
otCoapOptionType typedef
CoAP Option Numbers.
otCoapRequestHandler)(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo) typedef
void(*
Pointer is called when a CoAP request with a given Uri-Path is received.
otCoapResource typedef
Represents a CoAP resource.
otCoapResponseHandler)(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aResult) typedef
void(*
Pointer is called when a CoAP response is received or on the request timeout.
otCoapTxParameters typedef
Represents the CoAP transmission parameters.
otCoapType typedef
enum otCoapType
CoAP Type values (2 bit unsigned integer).

Functions

otCoapAddBlockWiseResource(otInstance *aInstance, otCoapBlockwiseResource *aResource)
void
Adds a block-wise resource to the CoAP server.
otCoapAddResource(otInstance *aInstance, otCoapResource *aResource)
void
Adds a resource to the CoAP server.
otCoapBlockSizeFromExponent(otCoapBlockSzx aSize)
uint16_t
Converts a CoAP Block option SZX field to the actual block size.
otCoapMessageAppendBlock1Option(otMessage *aMessage, uint32_t aNum, bool aMore, otCoapBlockSzx aSize)
Appends a Block1 option.
otCoapMessageAppendBlock2Option(otMessage *aMessage, uint32_t aNum, bool aMore, otCoapBlockSzx aSize)
Appends a Block2 option.
otCoapMessageAppendContentFormatOption(otMessage *aMessage, otCoapOptionContentFormat aContentFormat)
Appends the Content Format CoAP option as specified in https://tools.ietf.org/html/rfc7252#page-92.
otCoapMessageAppendMaxAgeOption(otMessage *aMessage, uint32_t aMaxAge)
Appends a Max-Age option.
otCoapMessageAppendObserveOption(otMessage *aMessage, uint32_t aObserve)
Appends an Observe option.
otCoapMessageAppendOption(otMessage *aMessage, uint16_t aNumber, uint16_t aLength, const void *aValue)
Appends a CoAP option in a header.
otCoapMessageAppendProxyUriOption(otMessage *aMessage, const char *aUriPath)
Appends a Proxy-Uri option.
otCoapMessageAppendUintOption(otMessage *aMessage, uint16_t aNumber, uint32_t aValue)
Appends an unsigned integer CoAP option as specified in https://tools.ietf.org/html/rfc7252#section-3.2.
otCoapMessageAppendUriPathOptions(otMessage *aMessage, const char *aUriPath)
Appends a Uri-Path option.
otCoapMessageAppendUriQueryOption(otMessage *aMessage, const char *aUriQuery)
Appends a single Uri-Query option.
otCoapMessageAppendUriQueryOptions(otMessage *aMessage, const char *aUriQuery)
Appends a Uri-Query option.
otCoapMessageCodeToString(const otMessage *aMessage)
const char *
Returns the CoAP Code as human readable string.
otCoapMessageGenerateToken(otMessage *aMessage, uint8_t aTokenLength)
void
Sets the Token length and randomizes its value.
otCoapMessageGetCode(const otMessage *aMessage)
Returns the Code value.
otCoapMessageGetMessageId(const otMessage *aMessage)
uint16_t
Returns the Message ID value.
otCoapMessageGetToken(const otMessage *aMessage)
const uint8_t *
Returns a pointer to the Token value.
otCoapMessageGetTokenLength(const otMessage *aMessage)
uint8_t
Returns the Token length.
otCoapMessageGetType(const otMessage *aMessage)
Returns the Type value.
otCoapMessageInit(otMessage *aMessage, otCoapType aType, otCoapCode aCode)
void
Initializes the CoAP header.
otCoapMessageInitResponse(otMessage *aResponse, const otMessage *aRequest, otCoapType aType, otCoapCode aCode)
Initializes a response message.
otCoapMessageSetCode(otMessage *aMessage, otCoapCode aCode)
void
Sets the Code value.
otCoapMessageSetPayloadMarker(otMessage *aMessage)
Adds Payload Marker indicating beginning of the payload to the CoAP header.
otCoapMessageSetToken(otMessage *aMessage, const uint8_t *aToken, uint8_t aTokenLength)
Sets the Token value and length in a header.
otCoapNewMessage(otInstance *aInstance, const otMessageSettings *aSettings)
Creates a new CoAP message.
otCoapOptionIteratorGetFirstOption(otCoapOptionIterator *aIterator)
const otCoapOption *
Returns a pointer to the first option.
otCoapOptionIteratorGetFirstOptionMatching(otCoapOptionIterator *aIterator, uint16_t aOption)
const otCoapOption *
Returns a pointer to the first option matching the specified option number.
otCoapOptionIteratorGetNextOption(otCoapOptionIterator *aIterator)
const otCoapOption *
Returns a pointer to the next option.
otCoapOptionIteratorGetNextOptionMatching(otCoapOptionIterator *aIterator, uint16_t aOption)
const otCoapOption *
Returns a pointer to the next option matching the specified option number.
otCoapOptionIteratorGetOptionUintValue(otCoapOptionIterator *aIterator, uint64_t *aValue)
Fills current option value into aValue assuming the current value is an unsigned integer encoded according to https://tools.ietf.org/html/rfc7252#section-3.2.
otCoapOptionIteratorGetOptionValue(otCoapOptionIterator *aIterator, void *aValue)
Fills current option value into aValue.
otCoapOptionIteratorInit(otCoapOptionIterator *aIterator, const otMessage *aMessage)
Initialises an iterator for the options in the given message.
otCoapRemoveBlockWiseResource(otInstance *aInstance, otCoapBlockwiseResource *aResource)
void
Removes a block-wise resource from the CoAP server.
otCoapRemoveResource(otInstance *aInstance, otCoapResource *aResource)
void
Removes a resource from the CoAP server.
otCoapSendRequest(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, otCoapResponseHandler aHandler, void *aContext)
Sends a CoAP request.
otCoapSendRequestBlockWise(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, otCoapResponseHandler aHandler, void *aContext, otCoapBlockwiseTransmitHook aTransmitHook, otCoapBlockwiseReceiveHook aReceiveHook)
Sends a CoAP request block-wise.
otCoapSendRequestBlockWiseWithParameters(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, otCoapResponseHandler aHandler, void *aContext, const otCoapTxParameters *aTxParameters, otCoapBlockwiseTransmitHook aTransmitHook, otCoapBlockwiseReceiveHook aReceiveHook)
Sends a CoAP request block-wise with custom transmission parameters.
otCoapSendRequestWithParameters(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, otCoapResponseHandler aHandler, void *aContext, const otCoapTxParameters *aTxParameters)
Sends a CoAP request with custom transmission parameters.
otCoapSendResponse(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo)
Sends a CoAP response from the server.
otCoapSendResponseBlockWise(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, void *aContext, otCoapBlockwiseTransmitHook aTransmitHook)
Sends a CoAP response block-wise from the server.
otCoapSendResponseBlockWiseWithParameters(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, const otCoapTxParameters *aTxParameters, void *aContext, otCoapBlockwiseTransmitHook aTransmitHook)
Sends a CoAP response block-wise from the server with custom transmission parameters.
otCoapSendResponseWithParameters(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo, const otCoapTxParameters *aTxParameters)
Sends a CoAP response from the server with custom transmission parameters.
otCoapSetDefaultHandler(otInstance *aInstance, otCoapRequestHandler aHandler, void *aContext)
void
Sets the default handler for unhandled CoAP requests.
otCoapStart(otInstance *aInstance, uint16_t aPort)
Starts the CoAP server.
otCoapStop(otInstance *aInstance)
Stops the CoAP server.

Macros

OT_COAP_CODE ((((c)&0x7) << 5) | ((d)&0x1f))
Helper macro to define CoAP Code values.
OT_COAP_DEFAULT_TOKEN_LENGTH 2
Default token length.
OT_COAP_MAX_RETRANSMIT 20
Max retransmit supported by OpenThread.
OT_COAP_MAX_TOKEN_LENGTH 8
Max token length as specified (RFC 7252).
OT_COAP_MIN_ACK_TIMEOUT 1000
Minimal ACK timeout in milliseconds supported by OpenThread.
OT_DEFAULT_COAP_PORT 5683
Default CoAP port, as specified in RFC 7252.

Structs

otCoapBlockwiseResource

Represents a CoAP resource with block-wise transfer.

otCoapOption

Represents a CoAP option.

otCoapOptionIterator

Acts as an iterator for CoAP options.

otCoapResource

Represents a CoAP resource.

otCoapTxParameters

Represents the CoAP transmission parameters.

Enumerations

otCoapBlockSzx

 otCoapBlockSzx

CoAP Block Size Exponents.

otCoapOptionContentFormat

 otCoapOptionContentFormat

CoAP Content Format codes.

The full list is documented at https://www.iana.org/assignments/core-parameters/core-parameters.xhtml#content-formats

Properties
OT_COAP_OPTION_CONTENT_FORMAT_CBOR

application/cbor: [RFC7049]

OT_COAP_OPTION_CONTENT_FORMAT_COAP_GROUP_JSON

application/coap-group+json: [RFC7390]

OT_COAP_OPTION_CONTENT_FORMAT_COSE_ENCRYPT

application/cose; cose-type="cose-encrypt": [RFC8152]

OT_COAP_OPTION_CONTENT_FORMAT_COSE_ENCRYPT0

application/cose; cose-type="cose-encrypt0": [RFC8152]

OT_COAP_OPTION_CONTENT_FORMAT_COSE_KEY

application/cose-key: [RFC8152]

OT_COAP_OPTION_CONTENT_FORMAT_COSE_KEY_SET

application/cose-key-set: [RFC8152]

OT_COAP_OPTION_CONTENT_FORMAT_COSE_MAC

application/cose; cose-type="cose-mac": [RFC8152]

OT_COAP_OPTION_CONTENT_FORMAT_COSE_MAC0

application/cose; cose-type="cose-mac0": [RFC8152]

OT_COAP_OPTION_CONTENT_FORMAT_COSE_SIGN

application/cose; cose-type="cose-sign": [RFC8152]

OT_COAP_OPTION_CONTENT_FORMAT_COSE_SIGN1

application/cose; cose-type="cose-sign1": [RFC8152]

OT_COAP_OPTION_CONTENT_FORMAT_CWT

application/cwt: [RFC8392]

OT_COAP_OPTION_CONTENT_FORMAT_EXI

application/exi: ["Efficient XML Interchange (EXI) Format 1.0 (Second Edition)", February 2014]

OT_COAP_OPTION_CONTENT_FORMAT_JSON

application/json: [RFC7159]

OT_COAP_OPTION_CONTENT_FORMAT_JSON_PATCH_JSON

application/json-patch+json: [RFC6902]

OT_COAP_OPTION_CONTENT_FORMAT_LINK_FORMAT

application/link-format: [RFC6690]

OT_COAP_OPTION_CONTENT_FORMAT_MERGE_PATCH_JSON

application/merge-patch+json: [RFC7396]

OT_COAP_OPTION_CONTENT_FORMAT_OCTET_STREAM

application/octet-stream: [RFC2045][RFC2046]

OT_COAP_OPTION_CONTENT_FORMAT_SENML_CBOR

application/senml+cbor: [RFC8428]

OT_COAP_OPTION_CONTENT_FORMAT_SENML_EXI

application/senml-exi: [RFC8428]

OT_COAP_OPTION_CONTENT_FORMAT_SENML_JSON

application/senml+json: [RFC8428]

OT_COAP_OPTION_CONTENT_FORMAT_SENML_XML

application/senml+xml: [RFC8428]

OT_COAP_OPTION_CONTENT_FORMAT_SENSML_CBOR

application/sensml+cbor: [RFC8428]

OT_COAP_OPTION_CONTENT_FORMAT_SENSML_EXI

application/sensml-exi: [RFC8428]

OT_COAP_OPTION_CONTENT_FORMAT_SENSML_JSON

application/sensml+json: [RFC8428]

OT_COAP_OPTION_CONTENT_FORMAT_SENSML_XML

application/sensml+xml: [RFC8428]

OT_COAP_OPTION_CONTENT_FORMAT_TEXT_PLAIN

text/plain; charset=utf-8: [RFC2046][RFC3676][RFC5147]

OT_COAP_OPTION_CONTENT_FORMAT_XML

application/xml: [RFC3023]

otCoapType

 otCoapType

CoAP Type values (2 bit unsigned integer).

Properties
OT_COAP_TYPE_ACKNOWLEDGMENT

Acknowledgment.

OT_COAP_TYPE_CONFIRMABLE

Confirmable.

OT_COAP_TYPE_NON_CONFIRMABLE

Non-confirmable.

OT_COAP_TYPE_RESET

Reset.

Typedefs

otCoapBlockSzx

enum otCoapBlockSzx otCoapBlockSzx

CoAP Block Size Exponents.

otCoapBlockwiseReceiveHook

otError(* otCoapBlockwiseReceiveHook)(void *aContext, const uint8_t *aBlock, uint32_t aPosition, uint16_t aBlockLength, bool aMore, uint32_t aTotalLength)

Pointer is called when a CoAP message with a block-wise transfer option is received.

Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.

Details
Parameters
[in] aContext
A pointer to application-specific context.
[in] aBlock
A pointer to the block segment.
[in] aPosition
The position of aBlock in a sequence in bytes.
[in] aBlockLength
The length of the block segment in bytes.
[in] aMore
Flag if more block segments are following.
[in] aTotalLength
The total length in bytes of the transferred information (indicated by a Size1 or Size2 option).
Return Values
OT_ERROR_NONE
Block segment was stored successfully.
OT_ERROR_NO_BUFS
No more memory to store blocks.
OT_ERROR_NO_FRAME_RECEIVED
Block segment missing.

otCoapBlockwiseResource

struct otCoapBlockwiseResource otCoapBlockwiseResource

Represents a CoAP resource with block-wise transfer.

otCoapBlockwiseTransmitHook

otError(* otCoapBlockwiseTransmitHook)(void *aContext, uint8_t *aBlock, uint32_t aPosition, uint16_t *aBlockLength, bool *aMore)

Pointer is called before the next block in a block-wise transfer is sent.

Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.

By changing the value of aBlockLength, the block size of the whole exchange is renegotiated. It is recommended to do this after the first block has been received as later changes could cause problems with other CoAP implementations.

Details
Parameters
[in] aContext
A pointer to application-specific context.
[in,out] aBlock
A pointer to where the block segment can be written to.
[in] aPosition
The position in a sequence from which to obtain the block segment.
[in,out] aBlockLength
On entry, the maximum block segment length in bytes.
[out] aMore
A pointer to the flag if more block segments will follow.
Return Values
OT_ERROR_NONE
No error occurred.
OT_ERROR_INVALID_ARGS
Block at aPosition does not exist.

otCoapCode

enum otCoapCode otCoapCode

CoAP Code values.

otCoapOption

struct otCoapOption otCoapOption

Represents a CoAP option.

otCoapOptionContentFormat

enum otCoapOptionContentFormat otCoapOptionContentFormat

CoAP Content Format codes.

The full list is documented at https://www.iana.org/assignments/core-parameters/core-parameters.xhtml#content-formats

otCoapOptionIterator

struct otCoapOptionIterator otCoapOptionIterator

Acts as an iterator for CoAP options.

otCoapOptionType

enum otCoapOptionType otCoapOptionType

CoAP Option Numbers.

otCoapRequestHandler

void(* otCoapRequestHandler)(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)

Pointer is called when a CoAP request with a given Uri-Path is received.

Details
Parameters
[in] aContext
A pointer to arbitrary context information.
[in] aMessage
A pointer to the message.
[in] aMessageInfo
A pointer to the message info for aMessage.

otCoapResource

struct otCoapResource otCoapResource

Represents a CoAP resource.

otCoapResponseHandler

void(* otCoapResponseHandler)(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aResult)

Pointer is called when a CoAP response is received or on the request timeout.

Details
Parameters
[in] aContext
A pointer to application-specific context.
[in] aMessage
A pointer to the message buffer containing the response. NULL if no response was received.
[in] aMessageInfo
A pointer to the message info for aMessage. NULL if no response was received.
[in] aResult
A result of the CoAP transaction.
Return Values
OT_ERROR_NONE
A response was received successfully.
OT_ERROR_ABORT
A CoAP transaction was reset by peer.
OT_ERROR_RESPONSE_TIMEOUT
No response or acknowledgment received during timeout period.

otCoapTxParameters

struct otCoapTxParameters otCoapTxParameters

Represents the CoAP transmission parameters.

otCoapType

enum otCoapType otCoapType

CoAP Type values (2 bit unsigned integer).

Functions

otCoapAddBlockWiseResource

void otCoapAddBlockWiseResource(
  otInstance *aInstance,
  otCoapBlockwiseResource *aResource
)

Adds a block-wise resource to the CoAP server.

Details
Parameters
[in] aInstance
A pointer to an OpenThread instance.
[in] aResource
A pointer to the resource.

otCoapAddResource

void otCoapAddResource(
  otInstance *aInstance,
  otCoapResource *aResource
)

Adds a resource to the CoAP server.

Details
Parameters
[in] aInstance
A pointer to an OpenThread instance.
[in] aResource
A pointer to the resource.

otCoapBlockSizeFromExponent

uint16_t otCoapBlockSizeFromExponent(
  otCoapBlockSzx aSize
)

Converts a CoAP Block option SZX field to the actual block size.

Details
Parameters
[in] aSize
Block size exponent.
Returns
The actual size exponent value.

otCoapMessageAppendBlock1Option

otError otCoapMessageAppendBlock1Option(
  otMessage *aMessage,
  uint32_t aNum,
  bool aMore,
  otCoapBlockSzx aSize
)

Appends a Block1 option.

Details
Parameters
[in,out] aMessage
A pointer to the CoAP message.
[in] aNum
Current block number.
[in] aMore
Boolean to indicate more blocks are to be sent.
[in] aSize
Block Size Exponent.
Return Values
OT_ERROR_NONE
Successfully appended the option.
OT_ERROR_INVALID_ARGS
The option type is not equal or greater than the last option type.
OT_ERROR_NO_BUFS
The option length exceeds the buffer size.

otCoapMessageAppendBlock2Option

otError otCoapMessageAppendBlock2Option(
  otMessage *aMessage,
  uint32_t aNum,
  bool aMore,
  otCoapBlockSzx aSize
)

Appends a Block2 option.

Details
Parameters
[in,out] aMessage
A pointer to the CoAP message.
[in] aNum
Current block number.
[in] aMore
Boolean to indicate more blocks are to be sent.
[in] aSize
Block Size Exponent.
Return Values
OT_ERROR_NONE
Successfully appended the option.
OT_ERROR_INVALID_ARGS
The option type is not equal or greater than the last option type.
OT_ERROR_NO_BUFS
The option length exceeds the buffer size.

otCoapMessageAppendContentFormatOption

otError otCoapMessageAppendContentFormatOption(
  otMessage *aMessage,
  otCoapOptionContentFormat aContentFormat
)

Appends the Content Format CoAP option as specified in https://tools.ietf.org/html/rfc7252#page-92.

This must be called before setting otCoapMessageSetPayloadMarker if a payload is to be included in the message.

The function is a convenience wrapper around otCoapMessageAppendUintOption, and if the desired format type code isn't listed in otCoapOptionContentFormat, this base function should be used instead.

Details
Parameters
[in,out] aMessage
A pointer to the CoAP message.
[in] aContentFormat
One of the content formats listed in otCoapOptionContentFormat above.
Return Values
OT_ERROR_NONE
Successfully appended the option.
OT_ERROR_INVALID_ARGS
The option type is not equal or greater than the last option type.
OT_ERROR_NO_BUFS
The option length exceeds the buffer size.

otCoapMessageAppendMaxAgeOption

otError otCoapMessageAppendMaxAgeOption(
  otMessage *aMessage,
  uint32_t aMaxAge
)

Appends a Max-Age option.

Details
Parameters
[in,out] aMessage
A pointer to the CoAP message.
[in] aMaxAge
The Max-Age value.
Return Values
OT_ERROR_NONE
Successfully appended the option.
OT_ERROR_INVALID_ARGS
The option type is not equal or greater than the last option type.
OT_ERROR_NO_BUFS
The option length exceeds the buffer size.

otCoapMessageAppendObserveOption

otError otCoapMessageAppendObserveOption(
  otMessage *aMessage,
  uint32_t aObserve
)

Appends an Observe option.

Details
Parameters
[in,out] aMessage
A pointer to the CoAP message.
[in] aObserve
Observe field value.
Return Values
OT_ERROR_NONE
Successfully appended the option.
OT_ERROR_INVALID_ARGS
The option type is not equal or greater than the last option type.
OT_ERROR_NO_BUFS
The option length exceeds the buffer size.

otCoapMessageAppendOption

otError otCoapMessageAppendOption(
  otMessage *aMessage,
  uint16_t aNumber,
  uint16_t aLength,
  const void *aValue
)

Appends a CoAP option in a header.

Details
Parameters
[in,out] aMessage
A pointer to the CoAP message.
[in] aNumber
The CoAP Option number.
[in] aLength
The CoAP Option length.
[in] aValue
A pointer to the CoAP value.
Return Values
OT_ERROR_NONE
Successfully appended the option.
OT_ERROR_INVALID_ARGS
The option type is not equal or greater than the last option type.
OT_ERROR_NO_BUFS
The option length exceeds the buffer size.

otCoapMessageAppendProxyUriOption

otError otCoapMessageAppendProxyUriOption(
  otMessage *aMessage,
  const char *aUriPath
)

Appends a Proxy-Uri option.

Details
Parameters
[in,out] aMessage
A pointer to the CoAP message.
[in] aUriPath
A pointer to a NULL-terminated string.
Return Values
OT_ERROR_NONE
Successfully appended the option.
OT_ERROR_INVALID_ARGS
The option type is not equal or greater than the last option type.
OT_ERROR_NO_BUFS
The option length exceeds the buffer size.

otCoapMessageAppendUintOption

otError otCoapMessageAppendUintOption(
  otMessage *aMessage,
  uint16_t aNumber,
  uint32_t aValue
)

Appends an unsigned integer CoAP option as specified in https://tools.ietf.org/html/rfc7252#section-3.2.

Details
Parameters
[in,out] aMessage
A pointer to the CoAP message.
[in] aNumber
The CoAP Option number.
[in] aValue
The CoAP Option unsigned integer value.
Return Values
OT_ERROR_NONE
Successfully appended the option.
OT_ERROR_INVALID_ARGS
The option type is not equal or greater than the last option type.
OT_ERROR_NO_BUFS
The option length exceeds the buffer size.
See also:
otCoapMessageGetOptionUintValue

otCoapMessageAppendUriPathOptions

otError otCoapMessageAppendUriPathOptions(
  otMessage *aMessage,
  const char *aUriPath
)

Appends a Uri-Path option.

Details
Parameters
[in,out] aMessage
A pointer to the CoAP message.
[in] aUriPath
A pointer to a NULL-terminated string.
Return Values
OT_ERROR_NONE
Successfully appended the option.
OT_ERROR_INVALID_ARGS
The option type is not equal or greater than the last option type.
OT_ERROR_NO_BUFS
The option length exceeds the buffer size.

otCoapMessageAppendUriQueryOption

otError otCoapMessageAppendUriQueryOption(
  otMessage *aMessage,
  const char *aUriQuery
)

Appends a single Uri-Query option.

Details
Parameters
[in,out] aMessage
A pointer to the CoAP message.
[in] aUriQuery
A pointer to NULL-terminated string, which should contain a single key=value pair.
Return Values
OT_ERROR_NONE
Successfully appended the option.
OT_ERROR_INVALID_ARGS
The option type is not equal or greater than the last option type.
OT_ERROR_NO_BUFS
The option length exceeds the buffer size.

otCoapMessageAppendUriQueryOptions

otError otCoapMessageAppendUriQueryOptions(
  otMessage *aMessage,
  const char *aUriQuery
)

Appends a Uri-Query option.

Details
Parameters
[in,out] aMessage
A pointer to the CoAP message.
[in] aUriQuery
A pointer to a NULL-terminated string.
Return Values
OT_ERROR_NONE
Successfully appended the option.
OT_ERROR_INVALID_ARGS
The option type is not equal or greater than the last option type.
OT_ERROR_NO_BUFS
The option length exceeds the buffer size.

otCoapMessageCodeToString

const char * otCoapMessageCodeToString(
  const otMessage *aMessage
)

Returns the CoAP Code as human readable string.

@ returns The CoAP Code as string.

Details
Parameters
[in] aMessage
A pointer to the CoAP message.

otCoapMessageGenerateToken

void otCoapMessageGenerateToken(
  otMessage *aMessage,
  uint8_t aTokenLength
)

Sets the Token length and randomizes its value.

Details
Parameters
[in,out] aMessage
A pointer to the CoAP message.
[in] aTokenLength
The Length of a Token to set.

otCoapMessageGetCode

otCoapCode otCoapMessageGetCode(
  const otMessage *aMessage
)

Returns the Code value.

Details
Parameters
[in] aMessage
A pointer to the CoAP message.
Returns
The Code value.

otCoapMessageGetMessageId

uint16_t otCoapMessageGetMessageId(
  const otMessage *aMessage
)

Returns the Message ID value.

Details
Parameters
[in] aMessage
A pointer to the CoAP message.
Returns
The Message ID value.

otCoapMessageGetToken

const uint8_t * otCoapMessageGetToken(
  const otMessage *aMessage
)

Returns a pointer to the Token value.

Details
Parameters
[in] aMessage
A pointer to the CoAP message.
Returns
A pointer to the Token value.

otCoapMessageGetTokenLength

uint8_t otCoapMessageGetTokenLength(
  const otMessage *aMessage
)

Returns the Token length.

Details
Parameters
[in] aMessage
A pointer to the CoAP message.
Returns
The Token length.

otCoapMessageGetType

otCoapType otCoapMessageGetType(
  const otMessage *aMessage
)

Returns the Type value.

Details
Parameters
[in] aMessage
A pointer to the CoAP message.
Returns
The Type value.

otCoapMessageInit

void otCoapMessageInit(
  otMessage *aMessage,
  otCoapType aType,
  otCoapCode aCode
)

Initializes the CoAP header.

Details
Parameters
[in,out] aMessage
A pointer to the CoAP message to initialize.
[in] aType
CoAP message type.
[in] aCode
CoAP message code.

otCoapMessageInitResponse

otError otCoapMessageInitResponse(
  otMessage *aResponse,
  const otMessage *aRequest,
  otCoapType aType,
  otCoapCode aCode
)

Initializes a response message.

Details
Parameters
[in,out] aResponse
A pointer to the CoAP response message.
[in] aRequest
A pointer to the CoAP request message.
[in] aType
CoAP message type.
[in] aCode
CoAP message code.
Return Values
OT_ERROR_NONE
Successfully initialized the response message.
OT_ERROR_NO_BUFS
Insufficient message buffers available to initialize the response message.

otCoapMessageSetCode

void otCoapMessageSetCode(
  otMessage *aMessage,
  otCoapCode aCode
)

Sets the Code value.

Details
Parameters
[in,out] aMessage
A pointer to the CoAP message to initialize.
[in] aCode
CoAP message code.

otCoapMessageSetPayloadMarker

otError otCoapMessageSetPayloadMarker(
  otMessage *aMessage
)

Adds Payload Marker indicating beginning of the payload to the CoAP header.

Details
Parameters
[in,out] aMessage
A pointer to the CoAP message.
Return Values
OT_ERROR_NONE
Payload Marker successfully added.
OT_ERROR_NO_BUFS
Header Payload Marker exceeds the buffer size.

otCoapMessageSetToken

otError otCoapMessageSetToken(
  otMessage *aMessage,
  const uint8_t *aToken,
  uint8_t aTokenLength
)

Sets the Token value and length in a header.

Details
Parameters
[in,out] aMessage
A pointer to the CoAP message.
[in] aToken
A pointer to the Token value.
[in] aTokenLength
The Length of aToken.
Return Values
OT_ERROR_NONE
Successfully set the Token value.
OT_ERROR_NO_BUFS
Insufficient buffers to set the Token value.

otCoapNewMessage

otMessage * otCoapNewMessage(
  otInstance *aInstance,
  const otMessageSettings *aSettings
)

Creates a new CoAP message.

Details
Parameters
[in] aInstance
A pointer to an OpenThread instance.
[in] aSettings
A pointer to the message settings or NULL to set default settings.
Returns
A pointer to the message buffer or NULL if no message buffers are available or parameters are invalid.

otCoapOptionIteratorGetFirstOption

const otCoapOption * otCoapOptionIteratorGetFirstOption(
  otCoapOptionIterator *aIterator
)

Returns a pointer to the first option.

Details
Parameters
[in,out] aIterator
A pointer to the CoAP message option iterator.
Returns
A pointer to the first option. If no option is present NULL pointer is returned.

otCoapOptionIteratorGetFirstOptionMatching

const otCoapOption * otCoapOptionIteratorGetFirstOptionMatching(
  otCoapOptionIterator *aIterator,
  uint16_t aOption
)

Returns a pointer to the first option matching the specified option number.

Details
Parameters
[in] aIterator
A pointer to the CoAP message option iterator.
[in] aOption
The option number sought.
Returns
A pointer to the first matching option. If no matching option is present NULL pointer is returned.

otCoapOptionIteratorGetNextOption

const otCoapOption * otCoapOptionIteratorGetNextOption(
  otCoapOptionIterator *aIterator
)

Returns a pointer to the next option.

Details
Parameters
[in,out] aIterator
A pointer to the CoAP message option iterator.
Returns
A pointer to the next option. If no more options are present NULL pointer is returned.

otCoapOptionIteratorGetNextOptionMatching

const otCoapOption * otCoapOptionIteratorGetNextOptionMatching(
  otCoapOptionIterator *aIterator,
  uint16_t aOption
)

Returns a pointer to the next option matching the specified option number.

Details
Parameters
[in] aIterator
A pointer to the CoAP message option iterator.
[in] aOption
The option number sought.
Returns
A pointer to the next matching option. If no further matching option is present NULL pointer is returned.

otCoapOptionIteratorGetOptionUintValue

otError otCoapOptionIteratorGetOptionUintValue(
  otCoapOptionIterator *aIterator,
  uint64_t *aValue
)

Fills current option value into aValue assuming the current value is an unsigned integer encoded according to https://tools.ietf.org/html/rfc7252#section-3.2.

Details
Parameters
[in,out] aIterator
A pointer to the CoAP message option iterator.
[out] aValue
A pointer to an unsigned integer to receive the option value.
Return Values
OT_ERROR_NONE
Successfully filled value.
OT_ERROR_NOT_FOUND
No current option.
OT_ERROR_NO_BUFS
Value is too long to fit in a uint64_t.
See also:
otCoapMessageAppendUintOption

otCoapOptionIteratorGetOptionValue

otError otCoapOptionIteratorGetOptionValue(
  otCoapOptionIterator *aIterator,
  void *aValue
)

Fills current option value into aValue.

Details
Parameters
[in,out] aIterator
A pointer to the CoAP message option iterator.
[out] aValue
A pointer to a buffer to receive the option value.
Return Values
OT_ERROR_NONE
Successfully filled value.
OT_ERROR_NOT_FOUND
No current option.

otCoapOptionIteratorInit

otError otCoapOptionIteratorInit(
  otCoapOptionIterator *aIterator,
  const otMessage *aMessage
)

Initialises an iterator for the options in the given message.

Details
Parameters
[in,out] aIterator
A pointer to the CoAP message option iterator.
[in] aMessage
A pointer to the CoAP message.
Return Values
OT_ERROR_NONE
Successfully initialised.
OT_ERROR_PARSE
Message state is inconsistent.

otCoapRemoveBlockWiseResource

void otCoapRemoveBlockWiseResource(
  otInstance *aInstance,
  otCoapBlockwiseResource *aResource
)

Removes a block-wise resource from the CoAP server.

Details
Parameters
[in] aInstance
A pointer to an OpenThread instance.
[in] aResource
A pointer to the resource.

otCoapRemoveResource

void otCoapRemoveResource(
  otInstance *aInstance,
  otCoapResource *aResource
)

Removes a resource from the CoAP server.

Details
Parameters
[in] aInstance
A pointer to an OpenThread instance.
[in] aResource
A pointer to the resource.

otCoapSendRequest

otError otCoapSendRequest(
  otInstance *aInstance,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo,
  otCoapResponseHandler aHandler,
  void *aContext
)

Sends a CoAP request.

If a response for a request is expected, respective function and context information should be provided. If no response is expected, these arguments should be NULL pointers.

Details
Parameters
[in] aInstance
A pointer to an OpenThread instance.
[in] aMessage
A pointer to the message to send.
[in] aMessageInfo
A pointer to the message info associated with aMessage.
[in] aHandler
A function pointer that shall be called on response reception or timeout.
[in] aContext
A pointer to arbitrary context information. May be NULL if not used.
Return Values
OT_ERROR_NONE
Successfully sent CoAP message.
OT_ERROR_NO_BUFS
Failed to allocate retransmission data.

otCoapSendRequestBlockWise

otError otCoapSendRequestBlockWise(
  otInstance *aInstance,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo,
  otCoapResponseHandler aHandler,
  void *aContext,
  otCoapBlockwiseTransmitHook aTransmitHook,
  otCoapBlockwiseReceiveHook aReceiveHook
)

Sends a CoAP request block-wise.

Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.

If a response for a request is expected, respective function and context information should be provided. If the response is expected to be block-wise, a respective hook function should be provided. If no response is expected, these arguments should be NULL pointers.

Details
Parameters
[in] aInstance
A pointer to an OpenThread instance.
[in] aMessage
A pointer to the message to send.
[in] aMessageInfo
A pointer to the message info associated with aMessage.
[in] aHandler
A function pointer that shall be called on response reception or timeout.
[in] aContext
A pointer to arbitrary context information. May be NULL if not used.
[in] aTransmitHook
A pointer to a hook function for outgoing block-wise transfer.
[in] aReceiveHook
A pointer to a hook function for incoming block-wise transfer.
Return Values
OT_ERROR_NONE
Successfully sent CoAP message.
OT_ERROR_NO_BUFS
Failed to allocate retransmission data.

otCoapSendRequestBlockWiseWithParameters

otError otCoapSendRequestBlockWiseWithParameters(
  otInstance *aInstance,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo,
  otCoapResponseHandler aHandler,
  void *aContext,
  const otCoapTxParameters *aTxParameters,
  otCoapBlockwiseTransmitHook aTransmitHook,
  otCoapBlockwiseReceiveHook aReceiveHook
)

Sends a CoAP request block-wise with custom transmission parameters.

Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.

If a response for a request is expected, respective function and context information should be provided. If the response is expected to be block-wise, a respective hook function should be provided. If no response is expected, these arguments should be NULL pointers.

Details
Parameters
[in] aInstance
A pointer to an OpenThread instance.
[in] aMessage
A pointer to the message to send.
[in] aMessageInfo
A pointer to the message info associated with aMessage.
[in] aHandler
A function pointer that shall be called on response reception or timeout.
[in] aContext
A pointer to arbitrary context information. May be NULL if not used.
[in] aTxParameters
A pointer to transmission parameters for this request. Use NULL for defaults.
[in] aTransmitHook
A pointer to a hook function for outgoing block-wise transfer.
[in] aReceiveHook
A pointer to a hook function for incoming block-wise transfer.
Return Values
OT_ERROR_NONE
Successfully sent CoAP message.
OT_ERROR_NO_BUFS
Failed to allocate retransmission data.
OT_ERROR_INVALID_ARGS
Invalid arguments are given.

otCoapSendRequestWithParameters

otError otCoapSendRequestWithParameters(
  otInstance *aInstance,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo,
  otCoapResponseHandler aHandler,
  void *aContext,
  const otCoapTxParameters *aTxParameters
)

Sends a CoAP request with custom transmission parameters.

If a response for a request is expected, respective function and context information should be provided. If no response is expected, these arguments should be NULL pointers.

Details
Parameters
[in] aInstance
A pointer to an OpenThread instance.
[in] aMessage
A pointer to the message to send.
[in] aMessageInfo
A pointer to the message info associated with aMessage.
[in] aHandler
A function pointer that shall be called on response reception or timeout.
[in] aContext
A pointer to arbitrary context information. May be NULL if not used.
[in] aTxParameters
A pointer to transmission parameters for this request. Use NULL for defaults. Otherwise, parameters given must meet the following conditions:
  1. mMaxRetransmit is no more than OT_COAP_MAX_RETRANSMIT.
  2. mAckRandomFactorNumerator / mAckRandomFactorDenominator must not be below 1.0.
  3. The calculated exchange life time must not overflow uint32_t.
Return Values
OT_ERROR_NONE
Successfully sent CoAP message.
OT_ERROR_NO_BUFS
Failed to allocate retransmission data.
OT_ERROR_INVALID_ARGS
Invalid arguments are given.

otCoapSendResponse

otError otCoapSendResponse(
  otInstance *aInstance,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo
)

Sends a CoAP response from the server.

Details
Parameters
[in] aInstance
A pointer to an OpenThread instance.
[in] aMessage
A pointer to the CoAP response to send.
[in] aMessageInfo
A pointer to the message info associated with aMessage.
Return Values
OT_ERROR_NONE
Successfully enqueued the CoAP response message.
OT_ERROR_NO_BUFS
Insufficient buffers available to send the CoAP response.

otCoapSendResponseBlockWise

otError otCoapSendResponseBlockWise(
  otInstance *aInstance,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo,
  void *aContext,
  otCoapBlockwiseTransmitHook aTransmitHook
)

Sends a CoAP response block-wise from the server.

Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.

Details
Parameters
[in] aInstance
A pointer to an OpenThread instance.
[in] aMessage
A pointer to the CoAP response to send.
[in] aMessageInfo
A pointer to the message info associated with aMessage.
[in] aContext
A pointer to arbitrary context information. May be NULL if not used.
[in] aTransmitHook
A pointer to a hook function for outgoing block-wise transfer.
Return Values
OT_ERROR_NONE
Successfully enqueued the CoAP response message.
OT_ERROR_NO_BUFS
Insufficient buffers available to send the CoAP response.

otCoapSendResponseBlockWiseWithParameters

otError otCoapSendResponseBlockWiseWithParameters(
  otInstance *aInstance,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo,
  const otCoapTxParameters *aTxParameters,
  void *aContext,
  otCoapBlockwiseTransmitHook aTransmitHook
)

Sends a CoAP response block-wise from the server with custom transmission parameters.

Is available when OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE configuration is enabled.

Details
Parameters
[in] aInstance
A pointer to an OpenThread instance.
[in] aMessage
A pointer to the CoAP response to send.
[in] aMessageInfo
A pointer to the message info associated with aMessage.
[in] aTxParameters
A pointer to transmission parameters for this response. Use NULL for defaults.
[in] aContext
A pointer to arbitrary context information. May be NULL if not used.
[in] aTransmitHook
A pointer to a hook function for outgoing block-wise transfer.
Return Values
OT_ERROR_NONE
Successfully enqueued the CoAP response message.
OT_ERROR_NO_BUFS
Insufficient buffers available to send the CoAP response.
OT_ERROR_INVALID_ARGS
Invalid arguments are given.

otCoapSendResponseWithParameters

otError otCoapSendResponseWithParameters(
  otInstance *aInstance,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo,
  const otCoapTxParameters *aTxParameters
)

Sends a CoAP response from the server with custom transmission parameters.

Details
Parameters
[in] aInstance
A pointer to an OpenThread instance.
[in] aMessage
A pointer to the CoAP response to send.
[in] aMessageInfo
A pointer to the message info associated with aMessage.
[in] aTxParameters
A pointer to transmission parameters for this response. Use NULL for defaults.
Return Values
OT_ERROR_NONE
Successfully enqueued the CoAP response message.
OT_ERROR_NO_BUFS
Insufficient buffers available to send the CoAP response.
OT_ERROR_INVALID_ARGS
Invalid arguments are given.

otCoapSetDefaultHandler

void otCoapSetDefaultHandler(
  otInstance *aInstance,
  otCoapRequestHandler aHandler,
  void *aContext
)

Sets the default handler for unhandled CoAP requests.

Details
Parameters
[in] aInstance
A pointer to an OpenThread instance.
[in] aHandler
A function pointer that shall be called when an unhandled request arrives.
[in] aContext
A pointer to arbitrary context information. May be NULL if not used.

otCoapStart

otError otCoapStart(
  otInstance *aInstance,
  uint16_t aPort
)

Starts the CoAP server.

Details
Parameters
[in] aInstance
A pointer to an OpenThread instance.
[in] aPort
The local UDP port to bind to.
Return Values
OT_ERROR_NONE
Successfully started the CoAP server.
OT_ERROR_FAILED
Failed to start the CoAP server.

otCoapStop

otError otCoapStop(
  otInstance *aInstance
)

Stops the CoAP server.

Details
Parameters
[in] aInstance
A pointer to an OpenThread instance.
Return Values
OT_ERROR_NONE
Successfully stopped the CoAP server.

Macros

OT_COAP_CODE

 OT_COAP_CODE ((((c)&0x7) << 5) | ((d)&0x1f))

Helper macro to define CoAP Code values.

OT_COAP_DEFAULT_TOKEN_LENGTH

 OT_COAP_DEFAULT_TOKEN_LENGTH 2

Default token length.

OT_COAP_MAX_RETRANSMIT

 OT_COAP_MAX_RETRANSMIT 20

Max retransmit supported by OpenThread.

OT_COAP_MAX_TOKEN_LENGTH

 OT_COAP_MAX_TOKEN_LENGTH 8

Max token length as specified (RFC 7252).

OT_COAP_MIN_ACK_TIMEOUT

 OT_COAP_MIN_ACK_TIMEOUT 1000

Minimal ACK timeout in milliseconds supported by OpenThread.

OT_DEFAULT_COAP_PORT

 OT_DEFAULT_COAP_PORT 5683

Default CoAP port, as specified in RFC 7252.

Resources

OpenThread API Reference topics originate from the source code, available on GitHub. For more information, or to contribute to our documentation, refer to Resources.