Skip to content

Commit

Permalink
Merge pull request #20 from mrdeep1/server_version
Browse files Browse the repository at this point in the history
server.cc: Add in alternative resource
  • Loading branch information
mrdeep1 authored Jun 22, 2024
2 parents b271d88 + ce49ccf commit a49829e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
LIBVER: ["v4.3.4", "develop"]
LIBVER: ["develop", "v4.3.4", "v4.3.3", "v4.3.2"]
steps:
- uses: actions/checkout@v4
- name: setup
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Minimal CoAP Client and Server Examples for libcoap
===================================================

These examples require [libcoap-3](https://github.com/obgm/libcoap) to
work.
These examples require [libcoap-3](https://github.com/obgm/libcoap) with a
minimum version of 4.3.2 to compile and execute.

`client.cc` shows a minimal libcoap client that sends a confirmable
`client.cc` is a minimal libcoap client that sends a confirmable
UDP `GET /hello` request to a pre-defined CoAP server
([coap.me](http://coap.me) in this example) and outputs a received
response. It supports an optional argument which can be a different
Expand All @@ -13,7 +13,8 @@ then this is handled by a NON-confirmable request.

`server.cc` is a minimal CoAP server that binds on
`::5683`, as well as the multicast IPs 224.0.1.187 and ff02::fd.
It has a single resource `/hello`.
It has two defined resources `/hello` and `hello/my` along with the
inbuilt resource `.well-known/core`.

Copyright (C) 2018-2024 Olaf Bergmann <bergmann@tzi.org>

Expand Down
14 changes: 14 additions & 0 deletions server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ main(void) {
});
coap_add_resource(ctx, resource);

/* Create another resource that the server can respond to with information */
resource = coap_resource_init(coap_make_str_const("hello/my"), 0);
coap_register_handler(resource, COAP_REQUEST_GET,
[](auto, auto,
const coap_pdu_t *request,
auto, coap_pdu_t *response) {
coap_show_pdu(COAP_LOG_WARN, request);
coap_pdu_set_code(response, COAP_RESPONSE_CODE_CONTENT);
coap_add_data(response, 8,
(const uint8_t *)"my world");
coap_show_pdu(COAP_LOG_WARN, response);
});
coap_add_resource(ctx, resource);

/* Handle any libcoap I/O requirements */
while (true) {
coap_io_process(ctx, COAP_IO_WAIT);
Expand Down

0 comments on commit a49829e

Please sign in to comment.