|
OpenThread_app
|
Core CoAP infrastructure for request handling, response generation, and resource management. More...
Classes | |
| struct | otapp_coap_uri_t |
Macros | |
| #define | OTAPP_COAP_PORT 5683 |
| Default CoAP port, as specified in RFC 7252. | |
| #define | OTAPP_COAP_URI_OK (-1) |
| #define | OTAPP_COAP_URI_ERROR (-2) |
| #define | OTAPP_COAP_OK OTAPP_COAP_URI_OK |
| #define | OTAPP_COAP_ERROR OTAPP_COAP_URI_ERROR |
| #define | OTAPP_COAP_OK_OBSERVER_REQUEST (-3) |
Typedefs | |
| typedef struct ot_app_devDrv_t | ot_app_devDrv_t |
| typedef struct otapp_coap_uri_t | otapp_coap_uri_t |
Enumerations | |
| enum | otapp_coap_uriIndex_t { OTAPP_URI_NO_URI_INDEX = 0 , OTAPP_URI_WELL_KNOWN_CORE , OTAPP_URI_PARING_SERVICES , OTAPP_URI_SUBSCRIBED_URIS , OTAPP_URI_TEST , OTAPP_URI_TEST_LED , OTAPP_URI_END_OF_INDEX } |
| enum | otapp_coap_messageId_t { OTAPP_MESSAGE_OK = 0 , OTAPP_MESSAGE_ERROR , OTAPP_MESSAGE_TEST } |
Functions | |
| int8_t | otapp_coap_init (ot_app_devDrv_t *devDriver) |
| Initializes the CoAP service. | |
| void | otapp_coap_sendResponse (otMessage *requestMessage, const otMessageInfo *aMessageInfo, const uint8_t *responseContent, uint16_t responseLength) |
| Sends a generic CoAP response with a payload. | |
| void | otapp_coap_sendResponseOK (otMessage *aMessage, const otMessageInfo *aMessageInfo) |
| Sends a simple "OK" response (2.04 Changed). | |
| void | otapp_coap_sendResponseERROR (otMessage *aMessage, const otMessageInfo *aMessageInfo) |
| Sends a "Not Found" error response (4.04). | |
| void | otapp_coap_printSenderIP (const otMessageInfo *aMessageInfo) |
| Prints the sender's IP address from message metadata to the log. | |
| const char * | otapp_coap_getMessage (otapp_coap_messageId_t msgID) |
| Converts an internal message ID/Type to a string representation. | |
| void | otapp_coapSendtoTestPut () |
| Sends a test PUT message (Debug function). | |
| void | otapp_coapSendtoTestGet () |
| Sends a test GET message (Debug function). | |
| void | otapp_coapSendDeviceNamePut () |
| Sends a request to update the device name on the network. | |
| void | otapp_coapSendGetUri_Well_known (const otIp6Address *ipAddr, otCoapResponseHandler responseHandler, void *aContext) |
| Sends a GET request to the standard discovery URI .well-known/core. | |
| void | otapp_coapSendPutUri_subscribed_uris (const otIp6Address *ipAddr, const uint8_t *data, uint16_t dataSize) |
| Sends a PUT request to update a resource on a remote device. | |
| void | otapp_coapSendSubscribeRequest (const otIp6Address *ipAddr, const char *aUriPath, uint8_t *tokenOut) |
| Initiates a CoAP Observe subscription (RFC 7641). | |
| void | otapp_coapSendSubscribeRequestUpdate (const otIp6Address *ipAddr, const char *aUriPath, uint8_t *tokenIn) |
| Refreshes or updates an existing subscription. | |
| void | otapp_coap_clientSendPutByte (const otIp6Address *peer_addr, const char *aUriPath, const uint8_t *payloadMsg, const uint16_t payloadMsgSize, otCoapResponseHandler responseHandler, void *aContext) |
| send coap message bytes using the PUT method | |
| void | otapp_coap_clientSendGetByte (const otIp6Address *peer_addr, const char *aUriPath, otCoapResponseHandler responseHandler, void *aContext) |
| send coap request using the GET method. Response will contain bytes | |
| const char * | otapp_coap_getUriNameFromDefault (otapp_coap_uriIndex_t uriIndex) |
| Retrieves the string name of a default URI by its index. | |
| int8_t | otapp_coapReadPayload (otMessage *aMessage, uint8_t *bufferOut, uint16_t bufferSize, uint16_t *readBytesOut) |
| Extracts the payload from an OpenThread CoAP message. | |
| int8_t | otapp_coap_processUriRequest (otMessage *aMessage, const otMessageInfo *aMessageInfo, uint8_t uriId, uint8_t *bufOut, uint16_t bufSize) |
| main function for HARDWARE DEVICE URIS. This function processing incoming request. Request can be concern adding device to subscribe list or general uri request to next processing. If it is general uri request, then the given bufOut contains data to processing. | |
Core CoAP infrastructure for request handling, response generation, and resource management.
This module wraps the OpenThread CoAP API to provide a simplified interface for application developers. It handles the low-level details of message buffer management, header parsing, and response code generation. Key Functionalities:
| #define OTAPP_COAP_ERROR OTAPP_COAP_URI_ERROR |
| #define OTAPP_COAP_OK OTAPP_COAP_URI_OK |
| #define OTAPP_COAP_OK_OBSERVER_REQUEST (-3) |
| #define OTAPP_COAP_PORT 5683 |
Default CoAP port, as specified in RFC 7252.
| #define OTAPP_COAP_URI_ERROR (-2) |
| #define OTAPP_COAP_URI_OK (-1) |
| typedef struct ot_app_devDrv_t ot_app_devDrv_t |
| typedef struct otapp_coap_uri_t otapp_coap_uri_t |
| void otapp_coap_clientSendGetByte | ( | const otIp6Address * | peer_addr, |
| const char * | aUriPath, | ||
| otCoapResponseHandler | responseHandler, | ||
| void * | aContext ) |
send coap request using the GET method. Response will contain bytes
| peer_addr | [in] ptr to device IPv6 address |
| aUriPath | [in] string ptr to uri |
| responseHandler | [in] callback to response handler |
| aContext | [in] content will be provided with responseHandler |
| void otapp_coap_clientSendPutByte | ( | const otIp6Address * | peer_addr, |
| const char * | aUriPath, | ||
| const uint8_t * | payloadMsg, | ||
| const uint16_t | payloadMsgSize, | ||
| otCoapResponseHandler | responseHandler, | ||
| void * | aContext ) |
send coap message bytes using the PUT method
| peer_addr | [in] ptr to device IPv6 address |
| aUriPath | [in] string ptr to uri |
| payloadMsg | [in] ptr to payload data |
| payloadMsgSize | [in] payload size |
| responseHandler | [in] callback to response handler |
| aContext | [in] content will be provided with responseHandler |
| const char * otapp_coap_getMessage | ( | otapp_coap_messageId_t | msgID | ) |
Converts an internal message ID/Type to a string representation.
| msgID | [in] Internal message identifier. |
| const char * otapp_coap_getUriNameFromDefault | ( | otapp_coap_uriIndex_t | uriIndex | ) |
Retrieves the string name of a default URI by its index.
Helper to map integer IDs (e.g., from config) to actual URI strings.
| uriIndex | [in] Index of the URI. |
| int8_t otapp_coap_init | ( | ot_app_devDrv_t * | devDriver | ) |
Initializes the CoAP service.
Starts the CoAP engine on the default UDP port and sets up the internal driver reference.
| devDriver | Pointer to the main device driver instance. |
| void otapp_coap_printSenderIP | ( | const otMessageInfo * | aMessageInfo | ) |
Prints the sender's IP address from message metadata to the log.
| aMessageInfo | [in] Pointer to the message info structure. |
| int8_t otapp_coap_processUriRequest | ( | otMessage * | aMessage, |
| const otMessageInfo * | aMessageInfo, | ||
| uint8_t | uriId, | ||
| uint8_t * | bufOut, | ||
| uint16_t | bufSize ) |
main function for HARDWARE DEVICE URIS. This function processing incoming request. Request can be concern adding device to subscribe list or general uri request to next processing. If it is general uri request, then the given bufOut contains data to processing.
| aMessage | [in] ptr to incoming message |
| aMessageInfo | [in] ptr to message info |
| uriId | [in] specific HARDWARE DEVICE URI ID that was passed in uriGetListSize callback |
| bufOut | [out] ptr to buffer. Incomming data will be saved there. |
| bufSize | [in] size of bufOut |
| void otapp_coap_sendResponse | ( | otMessage * | requestMessage, |
| const otMessageInfo * | aMessageInfo, | ||
| const uint8_t * | responseContent, | ||
| uint16_t | responseLength ) |
Sends a generic CoAP response with a payload.
| request | [in] The original request message (used to match Token/Message ID). |
| messageInfo | [in] Source address and port of the requester. |
| payload | [in] Pointer to the data buffer to send. |
| payload_len | [in] Length of the payload data. |
| coapResponseCode | [in] CoAP status code (e.g., OT_COAP_CODE_CONTENT). |
| coapType | [in] Message type (e.g., OT_COAP_TYPE_ACKNOWLEDGMENT). |
| void otapp_coap_sendResponseERROR | ( | otMessage * | aMessage, |
| const otMessageInfo * | aMessageInfo ) |
Sends a "Not Found" error response (4.04).
Used when the requested URI or resource does not exist.
| request | [in] The original request message. |
| aMessageInfo | [in] Source address and port. |
| void otapp_coap_sendResponseOK | ( | otMessage * | aMessage, |
| const otMessageInfo * | aMessageInfo ) |
Sends a simple "OK" response (2.04 Changed).
Typically used to acknowledge PUT/POST requests that don't require returning data.
| request | [in] The original request message. |
| aMessageInfo | [in] Source address and port. |
| int8_t otapp_coapReadPayload | ( | otMessage * | aMessage, |
| uint8_t * | bufferOut, | ||
| uint16_t | bufferSize, | ||
| uint16_t * | readBytesOut ) |
Extracts the payload from an OpenThread CoAP message.
Copies bytes from the opaque otMessage structure into a linear buffer.
| [in] | aMessage | Pointer to the incoming message. |
| [out] | bufferOut | Destination buffer. |
| [in] | bufferSize | Max size of the destination buffer. |
| [out] | readBytesOut | Pointer to store the actual number of bytes read. |
| void otapp_coapSendDeviceNamePut | ( | ) |
Sends a request to update the device name on the network.
Constructs a CoAP PUT message containing the device's current name and sends it to the default service locator or parent.
| void otapp_coapSendGetUri_Well_known | ( | const otIp6Address * | ipAddr, |
| otCoapResponseHandler | responseHandler, | ||
| void * | aContext ) |
Sends a GET request to the standard discovery URI .well-known/core.
This function is used for Service Discovery. It queries a remote device to list its available resources (URIs). The response is handled by the provided callback.
| ipAddr | [in] IPv6 address of the target device. |
| responseHandler | [in] Callback function to handle the list of resources returned. |
| aContext | [in] User context to pass to the handler. |
| void otapp_coapSendPutUri_subscribed_uris | ( | const otIp6Address * | ipAddr, |
| const uint8_t * | data, | ||
| uint16_t | dataSize ) |
Sends a PUT request to update a resource on a remote device.
Sends a Confirmable PUT message with a payload. Use this to control remote devices (e.g., turn on a light).
| ipAddr | [in] IPv6 address of the target device. |
| data | [in] Pointer to the payload data (e.g., new state). |
| dataSize | [in] Size of the payload. |
| void otapp_coapSendSubscribeRequest | ( | const otIp6Address * | ipAddr, |
| const char * | aUriPath, | ||
| uint8_t * | tokenOut ) |
Initiates a CoAP Observe subscription (RFC 7641).
Sends a GET request with the Observe option set to 0 (Register). This tells the server to send notifications whenever the resource state changes.
| ipAddr | [in] IPv6 address of the target device. |
| aUriPath | [in] URI path string to subscribe to (e.g., "light/on_off"). |
| tokenOut | [out] Buffer (min 8 bytes) where the generated subscription Token will be saved. |
| void otapp_coapSendSubscribeRequestUpdate | ( | const otIp6Address * | ipAddr, |
| const char * | aUriPath, | ||
| uint8_t * | tokenIn ) |
Refreshes or updates an existing subscription.
Similar to otapp_coapSendSubscribeRequest, but uses an existing Token instead of generating a new one. Useful for re-confirming interest without resetting state.
| ipAddr | [in] IPv6 address of the target device. |
| aUriPath | [in] URI path string. |
| tokenIn | [in] Existing token to reuse for this request. |
| void otapp_coapSendtoTestGet | ( | ) |
Sends a test GET message (Debug function).
Hardcoded test routine for verifying transmission logic during development.
| void otapp_coapSendtoTestPut | ( | ) |
Sends a test PUT message (Debug function).
Hardcoded test routine for verifying transmission logic during development.