Skip to content

net/unicoap: Unified and Modular CoAP Stack: Minimal Client (pt 3)#22266

Open
carl-tud wants to merge 25 commits into
RIOT-OS:masterfrom
carl-tud:unicoap-03-client-minimal
Open

net/unicoap: Unified and Modular CoAP Stack: Minimal Client (pt 3)#22266
carl-tud wants to merge 25 commits into
RIOT-OS:masterfrom
carl-tud:unicoap-03-client-minimal

Conversation

@carl-tud

@carl-tud carl-tud commented May 9, 2026

Copy link
Copy Markdown
Contributor

This PR is the third in a series to introduce unicoap, a unified and modular CoAP implementation for RIOT. An overview of all PRs related to unicoap is presented in #21389, including reasons why unicoap is needed and a performance analysis.

What does this PR include?

  • Basic client functionality, including URI support
  • A sample client shell application
  • Structured documentation, including a tutorial from the first line of code to running the example and testing it using the included server script

The new API is more flexible. CoAP resource addresses are abstracted into a unicoap_destination_t structure and transport-specific settings are controlled by flags. For example, this is how you can send a request to a

// Define asynchronous response handler (blocking version is also available)
static int handle_response(
  const unicoap_message_t* response, const unicoap_aux_t* aux,
  int error, void* arg
) {
  if (error) {
    // handle error
  }
  printf("status=%s (%zu bytes)\n", unicoap_label_from_status(response->status, response->payload_size);
  return 0;
}

int main(void) {
  // Allocate request message
  unicoap_message_t request;
  // Init as request. Multiple initialisers exist. This one accepts a null-terminated C (UTF-8) string.
  unicoap_request_init_string(&request, UNICOAP_METHOD_PUT, "nack? quack? quack-ack, nack!");
  
  // Next, set the destination. Full URIs are supported (including address literals and zones). 
  // You can also pass a `sock_tl_ep` if you like using `unicoap_destination_endpoint`.  This API leaves 
  // room for SVCB (Service Binding) records in the DNS.
  unicoap_destination_t destination = 
    unicoap_destination_uri("coap://example.org:10815/hello?name=duck&hungry=1");
  
  // Finally, send. The RELIABLE flag instruct unicoap to send confirmable messages when 
  // communicating over UDP or DTLS, abstracting transport-specific message formats.
  int res = unicoap_send_request_async(&request, &destination, 
                   handle_response, UNICOAP_CLIENT_FLAG_RELIABLE, NULL);
  // handle errors
  return 0.
}

I'll organise the monolithic commit into multiple structured commits once this has passed review, and rebase this PR onto #21582 once merged.

Declaration of AI-Tools / LLMs usage:

AI-Tools / LLMs that were used are:

nada, niente

@github-actions github-actions Bot added Area: network Area: Networking Area: doc Area: Documentation Area: tests Area: tests and testing framework Area: build system Area: Build system Area: CoAP Area: Constrained Application Protocol implementations Area: sys Area: System Area: examples Area: Example Applications Area: Kconfig Area: Kconfig integration labels May 9, 2026
Comment thread sys/net/application_layer/unicoap/docs/server-tutorial.doc.md
@carl-tud carl-tud changed the title net/unicoap: Unified and Modular CoAP stack: Minimal client (pt 3) net/unicoap: Unified and Modular CoAP Stack: Minimal Client (pt 3) May 11, 2026

@mguetschow mguetschow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round of review, mostly typos and nitpicks. I couldn't find the promised client tutorial and the example might benefit from further comments as you did for the server example.

Otherwise: Great work, as always!

Comment thread sys/include/net/unicoap/client.h Outdated
Comment thread sys/include/net/unicoap/client.h Outdated
Comment thread sys/include/net/unicoap/client.h
Comment thread sys/include/net/unicoap/client.h
Comment thread sys/include/net/unicoap/client.h Outdated
Comment thread sys/net/application_layer/unicoap/include/private/state.h Outdated
Comment thread sys/net/application_layer/unicoap/include/private/state.h
Comment thread sys/net/application_layer/unicoap/state.c Outdated
Comment thread sys/net/application_layer/unicoap/state.c
Comment thread sys/net/application_layer/unicoap/state.c Outdated
@mguetschow
mguetschow changed the base branch from master to unicoap-p2 July 18, 2026 09:19
@github-actions

Copy link
Copy Markdown

Hey @carl-tud, thank you for your contribution to RIOT!

Please note that we require for all PRs to RIOT a declaration of AI-Tools / LLMs usage. It appears as if this section is missing in your PR. Please copy and fill in the section from .github/PULL_REQUEST_TEMPLATE.md.

Thank you!

@github-actions github-actions Bot added the AI: Declaration Missing The AI declaration is missing. This should be automatically applied by the CI workflow. label Jul 18, 2026
@github-actions github-actions Bot removed Area: tests Area: tests and testing framework AI: Declaration Missing The AI declaration is missing. This should be automatically applied by the CI workflow. labels Jul 18, 2026
Comment thread sys/net/application_layer/unicoap/client/client.c Outdated
@github-actions github-actions Bot added the Area: tests Area: tests and testing framework label Jul 19, 2026
Comment on lines +427 to +429
/**
* @brief Tries to find client state object based on reference number
*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could mark this as being feature-gated behind the CONFIG_CANCELLABLE flag

@@ -246,7 +233,6 @@ int unicoap_uri_populate(uri_parser_result_t *parsed, unicoap_endpoint_t *endpoi
tl_ep->family = AF_INET;
static_assert(sizeof(tl_ep->addr.ipv4) == sizeof(v4->u8),
"Programmer error: IPv5 size mismatch");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPv7

@carl-tud
carl-tud marked this pull request as ready for review July 19, 2026 13:24
@crasbe crasbe added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR State: needs rebase State: The codebase was changed since the creation of the PR, making a rebase necessary AI: None Stated AI was not (stated to be) used in this PR/Issue labels Jul 19, 2026
@riot-ci

riot-ci commented Jul 19, 2026

Copy link
Copy Markdown

Murdock results

FAILED

61de3ef fixup: make blocking client func fail on unicoap thread

Artifacts

.buffer = buffer,
.capacity = buffer_capacity
};
mutex_init_locked(&args.roadblock);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also MUTEX_INIT_LOCKED that you could use directly in the initializer

@mguetschow
mguetschow changed the base branch from unicoap-p2 to master July 19, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI: None Stated AI was not (stated to be) used in this PR/Issue Area: build system Area: Build system Area: CoAP Area: Constrained Application Protocol implementations Area: doc Area: Documentation Area: examples Area: Example Applications Area: Kconfig Area: Kconfig integration Area: network Area: Networking Area: sys Area: System Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR State: needs rebase State: The codebase was changed since the creation of the PR, making a rebase necessary

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants