1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/examples/nanocoap_server
bors[bot] 46af92d3a0
Merge #18620 #19296 #19504 #19506
18620: core: add core_mutex_debug to aid debugging deadlocks r=maribu a=maribu

### Contribution description

Adding `USEMODULE += core_mutex_debug` to your `Makefile` results in
on log messages such as

    [mutex] waiting for thread 1 (pc = 0x800024d)

being added whenever `mutex_lock()` blocks. This makes tracing down
deadlocks easier.

### Testing procedure

Run e.g.

```sh
USEMODULE=core_mutex_debug BOARD=nucleo-f767zi make -C tests/mutex_cancel flash test
```

which should provide output such as

```
Welcome to pyterm!
Type '/exit' to exit.
READY
s
[mutex] waiting for thread 1 (pc = 0x8000f35)
START
main(): This is RIOT! (Version: 2022.10-devel-841-g5cc02-core/mutex/debug)
Test Application for mutex_cancel / mutex_lock_cancelable
=========================================================

Test without cancellation: OK
Test early cancellation: OK
Verify no side effects on subsequent calls: [mutex] waiting for thread 1 (pc = 0x800024d)
OK
Test late cancellation: [mutex] waiting for thread 1 (pc = 0x0)
OK
TEST PASSED
```

```sh
$ arm-none-eabi-addr2line -a 0x800024d -e tests/mutex_cancel/bin/nucleo-f767zi/tests_mutex_cancel.elf 
0x0800024d
/home/maribu/Repos/software/RIOT/tests/mutex_cancel/main.c:51
```

### Issues/PRs references

Depends on and includes https://github.com/RIOT-OS/RIOT/pull/18619

19296: nanocoap: allow to define CoAP resources as XFA r=maribu a=benpicco



19504: cpu/cc26xx_cc13xx: Fix bogus array-bound warning r=maribu a=maribu

### Contribution description

GCC 12 create a bogus array out of bounds warning as it assumes that because there is special handling for `uart == 0` and `uart == 1`, `uart` can indeed be `1`. There is an `assert(uart < UART_NUMOF)` above that would blow up prior to any out of bounds access.

In any case, optimizing out the special handling of `uart == 1` for when `UART_NUMOF == 1` likely improves the generated code and fixes the warning.

    /home/maribu/Repos/software/RIOT/cc2650/cpu/cc26xx_cc13xx/periph/uart.c:88:8: error: array subscript 1 is above array bounds of 'uart_isr_ctx_t[1]' [-Werror=array-bounds]
       88 |     ctx[uart].rx_cb = rx_cb;
          |     ~~~^~~~~~
    /home/maribu/Repos/software/RIOT/cc2650/cpu/cc26xx_cc13xx/periph/uart.c:52:23: note: while referencing 'ctx'
       52 | static uart_isr_ctx_t ctx[UART_NUMOF];
          |                       ^~~
    /home/maribu/Repos/software/RIOT/cc2650/cpu/cc26xx_cc13xx/periph/uart.c:89:8: error: array subscript 1 is above array bounds of 'uart_isr_ctx_t[1]' [-Werror=array-bounds]
       89 |     ctx[uart].arg = arg;
          |     ~~~^~~~~~
    /home/maribu/Repos/software/RIOT/cc2650/cpu/cc26xx_cc13xx/periph/uart.c:52:23: note: while referencing 'ctx'
       52 | static uart_isr_ctx_t ctx[UART_NUMOF];
          |                       ^~~

### Testing procedure

The actual change is a pretty obvious one-liner, so that code review and a green CI should be sufficient. If not, running any UART example app without regression should do.

### Issues/PRs references

None

19506: tools/openocd: Fix handling of OPENOCD_CMD_RESET_HALT r=maribu a=maribu

### Contribution description

The OPENOCD_CMD_RESET_HALT was not longer correctly passed to the script. This fixes the issue.

### Testing procedure

Flashing of e.g. the `cc2650-launchpad` with upstream OpenOCD should work again.

### Issues/PRs references

The change was added to https://github.com/RIOT-OS/RIOT/pull/19050 after testing the PR and before merging. I'm not sure if the fix never worked because of this, or if behavior of `target-export-variables` or GNU Make changed.

Co-authored-by: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
Co-authored-by: Benjamin Valentin <benjamin.valentin@bht-berlin.de>
Co-authored-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
2023-04-25 15:46:11 +00:00
..
coap_handler.c examples/nanocoap_server: enable fileserver for large boards 2023-03-09 14:09:15 +01:00
main.c examples/nanocoap_server: use netifs_print_ipv6() 2022-06-06 20:46:48 +02:00
Makefile examples/nanocoap_server: enable fileserver for large boards 2023-03-09 14:09:15 +01:00
Makefile.ci examples,tests: Update Makefile.cis 2023-02-27 12:31:04 +01:00
README.md examples/nanocoap_server: Add echo resource and fix README 2019-03-17 14:26:11 +01:00

nanocoap server example

This application is meant to get you started with implementing a CoAP server on RIOT. It uses the GNRC network stack through RIOT's sock API.

Usage

To try out the server on native, compile it with

$ make all

Then, create a tap interface (to which RIOT will connect):

$ sudo ip tuntap add tap0 mode tap user ${USER}
$ sudo ip link set tap0 up

Run the resulting RIOT binary by invoking:

$ make term

The application is now listening on all it's configured IP addresses.

Now find out its link_layer address:

$ make term
/home/aabadie/riot/examples/nanocoap_server/bin/native/nanocoapcoap_server.elf tap0
RIOT native interrupts/signals initialized.
LED_GREEN_OFF
LED_RED_ON
RIOT native board initialized.
RIOT native hardware initialization complete.

main(): This is RIOT! (Version: 2015.12-devel-632-g8f451-booze-master)
RIOT nanocoap example application
Waiting for address autoconfiguration...
Configured network interfaces:
Iface  5   HWaddr: 96:3c:18:1e:26:f7

           MTU:1500  HL:64  RTR  RTR_ADV
           Source address length: 6
           Link type: wired
           inet6 addr: ff02::1/128  scope: local [multicast]
           inet6 addr: fe80::e42a:1aff:feca:10ec/64  scope: local
           inet6 addr: ff02::1:ffca:10ec/128  scope: local [multicast]
           inet6 addr: ff02::2/128  scope: local [multicast]
           inet6 addr: 2001:db8:1:0:e42a:1aff:feca:10ec/64  scope: global

The link-layer address in this case is "fe80::e42a:1aff:feca:10ec", the only "scope: local" address set.

Testing

The CoAP server exposes 6 different resources:

  • /.well-known/core: returns the list of available resources on the server. This is part of the CoAP specifications. It works only with GET requests.
  • /echo/: will match any request that begins with '/echo/' and will echo the remaining part of the URI path. Meant to show how the prefix works. It works only with GET requests.
  • /riot/board: returns the name of the board running the server. It works only with GET requests.
  • /riot/value: returns the value of an internal variable of the server. It works with GET requests and also with PUT and POST requests, which means that this value can be updated from a client.
  • /riot/ver: returns the current RIOT version. Meant to show a block2 reply. It works only with GET requests.
  • /sha256: creates a hash with the received payloads. It is meant to show block1 support. It returns the hash when no more blocks are pending. Only works with POST.

There are multiple external CoAP clients you can use to easily test the server running on native.

libcoap CLI

(replace "fe80::e42a:1aff:feca:10ec" with your link-layer address)

  • Get the name of the board:
    # coap-client -m get coap://[fe80::e42a:1aff:feca:10ec%tap0]/riot/board
  • Update and get the internal value:
    # coap-client -m put coap://[fe80::e42a:1aff:feca:10ec%tap0]/riot/value -e 42
    # coap-client -m get coap://[fe80::e42a:1aff:feca:10ec%tap0]/riot/value

Copper (Firefox Plugin)

The Copper plugin for Firefox provides you with a nice graphical interface, but getting it to work with RIOT requires a little setup.

Make sure you've installed

And build the application again using make.

Enter the following into your /etc/radvd.conf (if it doesn't exist yet, create one):

interface tap0
{
    AdvSendAdvert on;

    MinRtrAdvInterval 3;
    MaxRtrAdvInterval 10;

    AdvDefaultPreference low;

    prefix 2001:db8:1:0::/64
    {
        AdvOnLink on;
        AdvAutonomous on;
        AdvRouterAddr off;
    };
};

(you can use radvd -c to check for syntax errors)

and run

sudo radvd

Then, run the RIOT binary as usual:

make term

Note that the output listing all configured interfaces contains a globally scoped address, which you can now use to reach the RIOT instance via Copper. To do so, enter this:

coap://[2001:db8:1:0:e42a:1aff:feca:10ec]/riot/board

into your Firefox address bar, where you should replace 2001:db8:1:0:e42a:1aff:feca:10ec with your RIOT instance's address marked as "scope: global". If you click the big green GET button, the word native should appear in the Payload text box at the center of the GUI.

If this doesn't work, try manually adding a Global address to the tap0 interface:

sudo service radvd start
sudo ip address add 2001:db8:1::a/64 dev tap0
make term