#include <ProsecCoAP.h>
Public Member Functions | |
| Coap (UDP &udp, size_t coapBufferSize=COAP_BUF_MAX_SIZE) | |
| Construct a CoAP instance using the given UDP transport. | |
| ~Coap () | |
| Destroy the CoAP instance and free buffers. | |
| int | notifyObservers (const char *observed_endpoint, const char *payload, int payload_len, COAP_CONTENT_TYPE type) |
| Notify all observers of a specific endpoint. | |
| int | addObserver (Observer **observer_out, const char *endpoint, IPAddress ip, int port, const uint8_t *token, uint8_t tokenLength) |
| Add a new observer for a specific URL. | |
| bool | removeObserver (const char *endpoint, IPAddress ip, int port, const uint8_t *token, uint8_t tokenLength) |
| Remove an observer for a specific endpoint. | |
| bool | start () |
| Start the server on the default port. | |
| bool | start (int port) |
| Start the server on a custom port. | |
| void | response (CoapCallback c) |
| Set the response callback for acknowledgements. | |
| void | server (CoapCallback c, String url) |
| Register a server callback for a URI. | |
| uint16_t | sendResponse (IPAddress ip, int port, uint16_t messageId) |
| Send a basic acknowledgment with empty payload. | |
| uint16_t | sendResponse (IPAddress ip, int port, uint16_t messageId, const char *payload) |
| Send a text acknowledgment response. | |
| uint16_t | sendResponse (IPAddress ip, int port, uint16_t messageId, const char *payload, size_t payloadLength) |
| Send a typed acknowledgment response with explicit length. | |
| uint16_t | sendResponse (IPAddress ip, int port, uint16_t messageId, const char *payload, size_t payloadLength, COAP_RESPONSE_CODE code, COAP_CONTENT_TYPE type, const uint8_t *token, int tokenLength) |
| Send a fully customized acknowledgment response. | |
| uint16_t | get (IPAddress ip, int port, const char *url) |
| Send a confirmable GET request. | |
| uint16_t | put (IPAddress ip, int port, const char *url, const char *payload) |
| Send a confirmable PUT with null-terminated payload. | |
| uint16_t | put (IPAddress ip, int port, const char *url, const char *payload, size_t payloadLength) |
| Send a confirmable PUT with explicit payload length. | |
| uint16_t | post (IPAddress ip, int port, const char *url, const char *payload) |
| Send a confirmable POST with null-terminated payload. | |
| uint16_t | post (IPAddress ip, int port, const char *url, const char *payload, size_t payloadLength) |
| Send a confirmable POST with explicit payload length. | |
| uint16_t | send (IPAddress ip, int port, const char *url, COAP_TYPE type, COAP_METHOD method, const uint8_t *token, uint8_t tokenLength, const uint8_t *payload, size_t payloadLength) |
| Send a CoAP request with optional payload. | |
| uint16_t | send (IPAddress ip, int port, const char *url, COAP_TYPE type, COAP_METHOD method, const uint8_t *token, uint8_t tokenLength, const uint8_t *payload, size_t payloadLength, COAP_CONTENT_TYPE contentType) |
| Send a CoAP request specifying the content format. | |
| uint16_t | send (IPAddress ip, int port, const char *url, COAP_TYPE type, COAP_METHOD method, const uint8_t *token, uint8_t tokenLength, const uint8_t *payload, size_t payloadLength, COAP_CONTENT_TYPE contentType, uint16_t messageId) |
| Send a CoAP request with explicit message ID. | |
| bool | loop () |
| Process incoming packets and dispatch handlers. | |
| Coap::Coap | ( | UDP & | udp, |
| size_t | coapBufferSize = COAP_BUF_MAX_SIZE ) |
Construct a CoAP instance using the given UDP transport.
| udp | The UDP transport to use for sending and receiving CoAP packets. |
| coapBufferSize | The size of the internal CoAP buffers. Default is COAP_BUF_MAX_SIZE. |
| Coap::~Coap | ( | ) |
Destroy the CoAP instance and free buffers.
| int Coap::addObserver | ( | Observer ** | observer_out, |
| const char * | endpoint, | ||
| IPAddress | ip, | ||
| int | port, | ||
| const uint8_t * | token, | ||
| uint8_t | tokenLength ) |
Add a new observer for a specific URL.
If the observer is already registered, the existing observer is returned.
| observer_out | Pointer to an Observer pointer that will be set to the newly added observer, or to the existing observer if already registered. |
| endpoint | The endpoint to observe. |
| ip | The IP address of the observer. |
| port | The port of the observer. |
| token | The token used by the observer. |
| tokenLength | The length of the token. |
| uint16_t Coap::get | ( | IPAddress | ip, |
| int | port, | ||
| const char * | url ) |
Send a confirmable GET request.
| bool Coap::loop | ( | ) |
Process incoming packets and dispatch handlers.
| int Coap::notifyObservers | ( | const char * | observed_endpoint, |
| const char * | payload, | ||
| int | payload_len, | ||
| COAP_CONTENT_TYPE | type ) |
Notify all observers of a specific endpoint.
This method sends a notification to all registered observers for the given endpoint. As per specifications, the notification includes the Observe option with a sequential number. The notification will be a non-confirmable message (COAP_NONCON).
| observed_endpoint | The endpoint being observed. |
| payload | The payload to send to observers. |
| payload_len | The length of the payload. |
| type | The content type of the payload. |
| uint16_t Coap::post | ( | IPAddress | ip, |
| int | port, | ||
| const char * | url, | ||
| const char * | payload ) |
Send a confirmable POST with null-terminated payload.
| uint16_t Coap::post | ( | IPAddress | ip, |
| int | port, | ||
| const char * | url, | ||
| const char * | payload, | ||
| size_t | payloadLength ) |
Send a confirmable POST with explicit payload length.
| uint16_t Coap::put | ( | IPAddress | ip, |
| int | port, | ||
| const char * | url, | ||
| const char * | payload ) |
Send a confirmable PUT with null-terminated payload.
| uint16_t Coap::put | ( | IPAddress | ip, |
| int | port, | ||
| const char * | url, | ||
| const char * | payload, | ||
| size_t | payloadLength ) |
Send a confirmable PUT with explicit payload length.
| bool Coap::removeObserver | ( | const char * | endpoint, |
| IPAddress | ip, | ||
| int | port, | ||
| const uint8_t * | token, | ||
| uint8_t | tokenLength ) |
Remove an observer for a specific endpoint.
|
inline |
Set the response callback for acknowledgements.
| uint16_t Coap::send | ( | IPAddress | ip, |
| int | port, | ||
| const char * | url, | ||
| COAP_TYPE | type, | ||
| COAP_METHOD | method, | ||
| const uint8_t * | token, | ||
| uint8_t | tokenLength, | ||
| const uint8_t * | payload, | ||
| size_t | payloadLength ) |
Send a CoAP request with optional payload.
| uint16_t Coap::send | ( | IPAddress | ip, |
| int | port, | ||
| const char * | url, | ||
| COAP_TYPE | type, | ||
| COAP_METHOD | method, | ||
| const uint8_t * | token, | ||
| uint8_t | tokenLength, | ||
| const uint8_t * | payload, | ||
| size_t | payloadLength, | ||
| COAP_CONTENT_TYPE | contentType ) |
Send a CoAP request specifying the content format.
| uint16_t Coap::send | ( | IPAddress | ip, |
| int | port, | ||
| const char * | url, | ||
| COAP_TYPE | type, | ||
| COAP_METHOD | method, | ||
| const uint8_t * | token, | ||
| uint8_t | tokenLength, | ||
| const uint8_t * | payload, | ||
| size_t | payloadLength, | ||
| COAP_CONTENT_TYPE | contentType, | ||
| uint16_t | messageId ) |
Send a CoAP request with explicit message ID.
| uint16_t Coap::sendResponse | ( | IPAddress | ip, |
| int | port, | ||
| uint16_t | messageId ) |
Send a basic acknowledgment with empty payload.
| uint16_t Coap::sendResponse | ( | IPAddress | ip, |
| int | port, | ||
| uint16_t | messageId, | ||
| const char * | payload ) |
Send a text acknowledgment response.
| uint16_t Coap::sendResponse | ( | IPAddress | ip, |
| int | port, | ||
| uint16_t | messageId, | ||
| const char * | payload, | ||
| size_t | payloadLength ) |
Send a typed acknowledgment response with explicit length.
| uint16_t Coap::sendResponse | ( | IPAddress | ip, |
| int | port, | ||
| uint16_t | messageId, | ||
| const char * | payload, | ||
| size_t | payloadLength, | ||
| COAP_RESPONSE_CODE | code, | ||
| COAP_CONTENT_TYPE | type, | ||
| const uint8_t * | token, | ||
| int | tokenLength ) |
Send a fully customized acknowledgment response.
|
inline |
Register a server callback for a URI.
| bool Coap::start | ( | ) |
Start the server on the default port.
| bool Coap::start | ( | int | port | ) |
Start the server on a custom port.