The CoAP node that runs on this device. More...
#include <ProsecCoAP.h>
Public Member Functions | |
| Node (UDP &udp) | |
| Build a CoAP node using the given UDP instance. | |
| Node (UDP &udp, uint16_t port) | |
| Build a CoAP node using the given UDP instance and port. | |
| uint16_t | getPort () const |
| Get the local port used by this CoAP node. | |
| ErrorCode | start () |
| Start the CoAP instance. | |
| void | setResponseHandler (Callback handler) |
| Set the response callback. | |
| ErrorCode | serve (const char *path, Callback callback) |
| Serve a given URI path with the specified callback. | |
| ErrorCode | loop () |
| Perform a single iteration of the CoAP event loop. | |
| ErrorCode | sendMessage (const Message &message, IPAddress ip, uint16_t port) |
| Send a CoAP message to the specified IP address and port. | |
The CoAP node that runs on this device.
It uses an underlying UDP instance for communication. It provides methods to send and receive CoAP messages,
|
inline |
Build a CoAP node using the given UDP instance.
This instance will use the default CoAP port (COAP_DEFAULT_PORT).
| udp | The UDP instance to use for communication. |
|
inline |
Build a CoAP node using the given UDP instance and port.
| udp | The UDP instance to use for communication. |
| port | The local UDP port to use for communication. |
|
inline |
Get the local port used by this CoAP node.
| ErrorCode Coap::Node::loop | ( | ) |
Perform a single iteration of the CoAP event loop.
This method MUST be called in the main loop() of your application.
It is responsible for processing incoming messages, handling retransmissions, and invoking the response handler for received messages.
Send a CoAP message to the specified IP address and port.
If the message is of type COAP_CONFIRMABLE, it is added to the retransmission queue. The retransmission queue behaves as per RFC 7252 and is processed in the loop() method. Its behaviour can be configured via COAP_CONFIRMABLE_MESSAGE_QUEUE_SIZE, COAP_MAX_RETRANSMIT and COAP_ACK_TIMEOUT_MS.
| message | The CoAP message to send. |
| ip | The destination IP address. |
| port | The destination UDP port. This may be different from the local or the default port. |
Serve a given URI path with the specified callback.
The callback is invoked when a request message targeting the given path is received.
| path | The URI path to serve with no leading slash, no trailing slash and no other special characters. If the path already exists, the callback is updated. Paths are *case-sensitive. Examples of valid paths are:
|
| callback | The callback function to handle requests to the given path. |
|
inline |
Set the response callback.
The response handler is invoked when a message of type MessageType::ACK or MessageType::RST is received, allowing the application to handle the response. The callback is unique for all the responses sent to this Coap instance.
Note that transmission ACK are also received internally by the retrasmission queue, so that retransmission can be stopped.
Responses to different requests must be differentiated by matching the message ID.
| handler | The callback function to handle acknowledgements. |
| ErrorCode Coap::Node::start | ( | ) |
Start the CoAP instance.
It starts the underlying UDP instance, enabling communication. The UDP instance is bound to the local port specified at construction time.