Skip to content
This repository was archived by the owner on Feb 14, 2024. It is now read-only.

Commit bd7a87c

Browse files
add initial example applications
1 parent a7f266a commit bd7a87c

14 files changed

Lines changed: 865 additions & 1 deletion

File tree

.gitignore

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Object files
2+
*.o
3+
# Target files
4+
*.elf
5+
# Documentation artifacts
6+
doc/doxygen/html
7+
doc/doxygen/latex
8+
doc/doxygen/man
9+
doc/doxygen/*.log
10+
doc/doxygen/*.db
11+
doc/doxygen/*.tmp
12+
# bin (e.g.:build directory) and .bin files
13+
bin
14+
*.bin
15+
# Build directory
16+
/build
17+
# AFL findings
18+
fuzzing/**/findings/
19+
# Backup files
20+
*~
21+
*.orig
22+
.*.swn
23+
.*.swo
24+
.*.swp
25+
*.save
26+
*.rej
27+
\#*\#
28+
cachegrind.out*
29+
# Eclipse workspace files
30+
.project
31+
.cproject
32+
.settings
33+
.idea
34+
# KDevelop4 project files
35+
.kdev4
36+
*.kdev4
37+
# Codelite (among others) project files
38+
*.project
39+
# Visual Studio Code user settings
40+
.vscode/
41+
# ctags index files
42+
tags
43+
# GDB initialization scripts
44+
.gdbinit
45+
46+
# Eclipse symbol file (output from make eclipsesym)
47+
eclipsesym.xml
48+
/toolchain
49+
# Ignore created Arduino sketch files
50+
_sketches.cpp
51+
52+
# local override files
53+
Makefile.local
54+
55+
# Vagrant
56+
.vagrant
57+
58+
# clang-complete command line argument lists (Vim: clang-complete, Atom: linter-clang, autocomplete-clang addons)
59+
.clang_complete
60+
# YouCompleteMe (https://github.com/Valloric/YouCompleteMe)
61+
.ycm_extra_conf.py
62+
63+
# Python compiled files
64+
*.pyc
65+
66+
# Ignore download cache
67+
.dlcache
68+
69+
# scan-build artifacts
70+
scan-build/
71+
72+
# compile_and_test_for_boards default "results" directory
73+
results/
74+
75+
# mypy artifacts
76+
.mypy_cache/
77+
78+
# Clangd compile flags (language server)
79+
compile_commands.json
80+
compile_flags.txt
81+
82+
# cache files of clangd (and probably other tools)
83+
.cache/
84+
85+
# generated by clang-check for C++ code
86+
*.plist
87+
88+
# suit manifest keys
89+
keys/
90+
91+
# clangd language server
92+
.clangd/
93+
94+
# custom clang-tidy flags, also used when using clangd language server
95+
.clang-tidy

01-hello-world/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# name of your application
2+
APPLICATION = hello-world
3+
4+
# If no BOARD is found in the environment, use this default:
5+
BOARD ?= nrf52840dk
6+
7+
# This has to be the absolute path to the RIOT base directory:
8+
RIOTBASE ?= $(CURDIR)/../RIOT
9+
10+
# Comment this out to disable code in RIOT that does safety checking
11+
# which is not needed in a production environment but helps in the
12+
# development process:
13+
DEVELHELP ?= 1
14+
15+
# Change this to 0 show compiler invocation lines by default:
16+
QUIET ?= 1
17+
18+
include $(RIOTBASE)/Makefile.include

01-hello-world/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Hello World!
2+
3+
This is a basic example how to use RIOT in your embedded application.
4+
It prints out the famous text `Hello World!`.
5+
6+
This example should foremost give you an overview how to use the Makefile system:
7+
8+
* First you must give your application a name, which is commonly the same as the name of the directory it resides in.
9+
Then you can define a default BOARD for which the application was written.
10+
By using e.g. `make BOARD=nrf52840dk` you can override the default board.
11+
12+
* The variable `RIOTBASE` contains an absolute or relative path to the directory where you have checked out RIOT.
13+
If your code resides in a subdirectory of RIOT, then you can use `$(CURDIR)` as it's done in here.
14+
15+
* The variable `QUIET`, which is either `1` or `0`, defines whether to print verbose compile information, or hide them, respectively.
16+
17+
* The last line of your Makefile must be `include $(RIOTBASE)/Makefile.include`.
18+
19+
The code itself may look like your usual *C* beginners hello-world example.

01-hello-world/main.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2014 Freie Universität Berlin
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @ingroup examples
11+
* @{
12+
*
13+
* @file
14+
* @brief Hello World application
15+
*
16+
* @author Kaspar Schleiser <kaspar@schleiser.de>
17+
* @author Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
18+
*
19+
* @}
20+
*/
21+
22+
#include <stdio.h>
23+
24+
int main(void)
25+
{
26+
puts("Hello World!");
27+
28+
printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD);
29+
printf("This board features a(n) %s MCU.\n", RIOT_MCU);
30+
31+
return 0;
32+
}

02-timers/Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# name of the application
2+
APPLICATION = timers-example
3+
4+
# If no BOARD is found in the environment, use this default:
5+
BOARD ?= nrf52840dk
6+
7+
# This has to be the absolute path to the RIOT base directory:
8+
RIOTBASE ?= $(CURDIR)/../RIOT
9+
10+
# required modules
11+
USEMODULE += ztimer
12+
USEMODULE += ztimer_msec
13+
USEMODULE += ztimer_sec
14+
15+
# Comment this out to disable code in RIOT that does safety checking
16+
# which is not needed in a production environment but helps in the
17+
# development process:
18+
DEVELHELP ?= 1
19+
20+
# Change this to 0 show compiler invocation lines by default:
21+
QUIET ?= 1
22+
23+
include $(RIOTBASE)/Makefile.include

02-timers/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Simple timer example
2+
3+
In this example we see to fundamental ways of using the timers of your hardware.
4+
First, we configure a timer to trigger an event that gets executed in the future.
5+
Second, we use the timer to sleep (block the thread) for a known amount of time.
6+
7+
In order to interact with timers, we need to use the `ztimer` module. To make it
8+
available to us, we add it to the list of used modules in the application's
9+
Makefile: `USEMODULE += ztimer`. Depending on the granularity that we want when
10+
handling time, we can specify different extra modules:
11+
12+
```Makefile
13+
USEMODULE += ztimer_usec # microsecond precision
14+
USEMODULE += ztimer_msec # millisecond precision
15+
USEMODULE += ztimer_sec # second precision
16+
```
17+
18+
To learn more about the `ztimer` module, visit the [documentation page](https://doc.riot-os.org/group__sys__ztimer.html).
19+
20+
## Task
21+
22+
Add a new timer to turn LED1 on after 1 second. For this you will need to:
23+
1. Define a new callback function to execute the task:
24+
```C
25+
void led_callback(void *argument)
26+
{
27+
(void) argument; /* we don't use the argument */
28+
LED1_ON; /* turn LED 1 on */
29+
}
30+
```
31+
32+
2. Instantiate and configure a new `ztimer_t`. The callback should be `led_callback`. As the
33+
argument is not used, you can set it to `NULL`.
34+
35+
3. Set the timer to fire in 1 second.

02-timers/main.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (C) 2022 HAW Hamburg
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
#include <stdio.h>
10+
11+
#include "ztimer.h"
12+
/* needed to manipulate the LEDs */
13+
#include "board.h"
14+
15+
void message_callback(void *argument)
16+
{
17+
char *message = (char *)argument;
18+
puts(message);
19+
}
20+
21+
int main(void)
22+
{
23+
puts("This is a timers example");
24+
25+
/* we can configure an event to occur in the future by setting a timer */
26+
ztimer_t timeout; /* create a new timer */
27+
timeout.callback = message_ callback; /* set the function to execute */
28+
timeout.arg = "Timeout!"; /* set the argument that the function will receive */
29+
ztimer_set(ZTIMER_SEC, &timeout, 2); /* set the timer to trigger in 2 seconds */
30+
31+
/* in parallel, we can perform other tasks on this thread */
32+
while (1) {
33+
/* this blinks an LED twice a second */
34+
LED0_TOGGLE;
35+
ztimer_sleep(ZTIMER_MSEC, 500);
36+
}
37+
38+
return 0;
39+
}

04-coap/Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# name of your application
2+
APPLICATION = coap-example
3+
4+
# If no BOARD is found in the environment, use this default:
5+
BOARD ?= nrf52840dk
6+
7+
# This has to be the absolute path to the RIOT base directory:
8+
RIOTBASE ?= $(CURDIR)/../RIOT
9+
10+
# enable default networking devides in the platform
11+
USEMODULE += netdev_default
12+
13+
# automatically initialize network interfaces for enabled devices
14+
USEMODULE += auto_init_gnrc_netif
15+
16+
# add minimal IPv6 support
17+
USEMODULE += gnrc_ipv6_default
18+
19+
# add ICMPv6 support (ping)
20+
USEMODULE += gnrc_icmpv6_echo
21+
22+
# add CoAP module
23+
USEMODULE += gcoap
24+
25+
# object dump allows use to print streams of bytes
26+
USEMODULE += od
27+
28+
# fmt allows use to format strings
29+
USEMODULE += fmt
30+
31+
USEMODULE += netutils
32+
# Add also the shell, some shell commands
33+
USEMODULE += shell
34+
USEMODULE += shell_commands
35+
USEMODULE += ps
36+
37+
# Comment this out to disable code in RIOT that does safety checking
38+
# which is not needed in a production environment but helps in the
39+
# development process:
40+
DEVELHELP ?= 1
41+
42+
# Change this to 0 show compiler invocation lines by default:
43+
QUIET ?= 1
44+
45+
include $(RIOTBASE)/Makefile.include

04-coap/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
## About
2+
3+
This application provides command line access to gcoap, a high-level API for
4+
CoAP messaging. See the [CoAP spec][1] for background, and the
5+
Modules>Networking>CoAP topic in the source documentation for detailed usage
6+
instructions and implementation notes.
7+
8+
We support two setup options for this example:
9+
10+
### Native networking
11+
12+
Build with the standard `Makefile`. Follow the setup [instructions][2] for
13+
the gnrc_networking example.
14+
15+
### SLIP-based border router
16+
17+
Build with `Makefile.slip`. Follow the setup instructions in README-slip.md,
18+
which are based on the [SLIP instructions][3] for the gnrc_border_router
19+
example. We also plan to provide or reference the ethos/UHCP instructions,
20+
but we don't have it working yet.
21+
22+
23+
## Example Use
24+
25+
This example uses gcoap as a server on RIOT native. Then we send a request
26+
from a libcoap example client on the Linux host.
27+
28+
### Verify setup from RIOT terminal
29+
30+
> coap info
31+
32+
Expected response:
33+
34+
CoAP server is listening on port 5683
35+
CLI requests sent: 0
36+
CoAP open requests: 0
37+
38+
### Query from libcoap example client
39+
40+
gcoap does not provide any output to the CoAP terminal when it handles a
41+
request. We recommend use of Wireshark to see the request and response. You
42+
also can add some debug output in the endpoint function callback.
43+
44+
./coap-client -N -m get -p 5683 coap://[fe80::1843:8eff:fe40:4eaa%tap0]/.well-known/core
45+
46+
Example response:
47+
48+
v:1 t:NON c:GET i:0daa {} [ ]
49+
</cli/stats>
50+
51+
The response shows the endpoint registered by the gcoap CLI example.
52+
53+
### Send query to libcoap example server
54+
55+
Start the libcoap example server with the command below.
56+
57+
./coap-server
58+
59+
Enter the query below in the RIOT CLI.
60+
61+
> coap get fe80::d8b8:65ff:feee:121b%6 5683 /.well-known/core
62+
63+
CLI output:
64+
65+
gcoap_cli: sending msg ID 743, 75 bytes
66+
> gcoap: response Success, code 2.05, 105 bytes
67+
</>;title="General Info";ct=0,</time>;if="clock";rt="Ticks";title="Internal Clock";ct=0;obs,</async>;ct=0
68+
69+
70+
## Other available CoAP implementations and applications
71+
72+
RIOT also provides package imports and test applications for other CoAP
73+
implementations:
74+
75+
* [Nanocoap](../nanocoap_server): a very lightweight CoAP server based on the
76+
[nanocoap library](https://github.com/kaspar030/sock/tree/master/nanocoap)
77+
implementation
78+
79+
* [Microcoap](../../tests/pkg_microcoap): another lightweight CoAP server based
80+
on the [microcoap library](https://github.com/1248/microcoap) implementation
81+
82+
83+
[1]: https://tools.ietf.org/html/rfc7252 "CoAP spec"
84+
[2]: https://github.com/RIOT-OS/RIOT/tree/master/examples/gnrc_networking "instructions"
85+
[3]: https://github.com/RIOT-OS/RIOT/tree/master/examples/gnrc_border_router "SLIP instructions"

0 commit comments

Comments
 (0)