Constrained Application Protocol (CoAP) server/client library for Arduino IDE/PlatformIO, ESP32, ESP8266.

Documentation is available at https://decadenza.github.io/ProsecCoAP/.
Details
This library is an implementation of CoAP protocol (RFC-7252). The aim is to provide all the compulsory functionalities, maintaining the execution lightweight and clearly documenting its API.
Please open an issue to request missing functionalities or report bugs.
How to install
Install from Arduino IDE Library Manager
- Open the Sketch menu in the IDE.
- Navigate to Include Library > Manage Libraries.
- Search for "ProsecCoAP" and install.
Install from PlatformIO CLI
pio pkg install --library "ProsecCoAP"
Manual install
- Download this source code branch as a zip file.
- In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library. At the top of the drop down list, select the option to "Add .ZIP Library".
Getting started
A simple server can be started as:
#include <Ethernet.h>
#include <EthernetUdp.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD};
{
}
}
{
{
}
}
Main header file for the ProsecCoAP library.
A CoAP message.
Definition ProsecCoAP.h:164
MessageCode getCode() const
Get the message code.
Definition ProsecCoAP.cpp:243
ErrorCode addPayload(const uint8_t *payload, size_t length)
Add a payload to the message.
Definition ProsecCoAP.cpp:802
ErrorCode buildResponse(MessageCode code, Message &response) const
Build a response message based on a request message.
Definition ProsecCoAP.cpp:86
The CoAP node that runs on this device.
Definition ProsecCoAP.h:834
ErrorCode loop()
Perform a single iteration of the CoAP event loop.
Definition ProsecCoAP.cpp:1094
ErrorCode start()
Start the CoAP instance.
Definition ProsecCoAP.cpp:1081
ErrorCode sendMessage(const Message &message, IPAddress ip, uint16_t port)
Send a CoAP message to the specified IP address and port.
Definition ProsecCoAP.cpp:1195
ErrorCode serve(const char *path, Callback callback)
Serve a given URI path with the specified callback.
Definition ProsecCoAP.cpp:1076
void setup()
Definition client.ino:30
IPAddress deviceIp(192, 168, 0, 99)
EthernetUDP Udp
Definition client.ino:27
byte mac[]
Definition client.ino:19
void loop()
Definition client.ino:48
IPAddress ip(192, 168, 0, DEVICE_ID)
Navigate to File > Examples > ProsecCoAP in Arduino IDE or check the example folder for more examples.
Run the examples
For the examples to compile and work correctly, please ensure to have all the necessary boards installed. The examples need standard libraries, like:
Ethernet by Arduino
WiFi by Arduino
Refer to the comments in each example for details.
How to test
Verify compile errors and warnings for multiple boards
To quickly verify a successful build process for multiple boards:
- Install Arduino CLI.
- Ensure the core for the supported boards are installed:
arduino-cli core install arduino:avr
arduino-cli core install esp32:esp32
arduino-cli core install esp8266:esp8266 --additional-urls http://arduino.esp8266.com/stable/package_esp8266com_index.json
- Run
make.
Functional tests through the examples
The examples need another CoAP node to be executed. You can, alternatively:
- Use two devices and check serial monitor of each.
- Use one device and a CoAP tool on your computer for testing. For example, libcoap by compiling it yourself or use the example binaries available as Debian package libcoap3-bin. In this case, you can test with
coap-client-notls and coap-server-notls.
Documentation
Documentation is available at: https://decadenza.github.io/ProsecCoAP/. It points to the main branch.
Building the documentation
To manually build documentation in your current working directory, run:
The documentation will be accessible from ./html/index.html.
Credits
This library was inspired by CoAP-simple-library. Credits for the original code go to the original contributors. This project maintains the original MIT License and continues the spirit of open-source IoT development.