-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RIOT federated CoAP example and fix CoapUdpIp channel implementation #142
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5c96445
Add RIOT federated CoAP example and fix CoAP channel
LasseRosenow b3cb4b8
Fix after merging main
LasseRosenow b17d4d8
Improve coap channel
LasseRosenow d61f319
Add connection thread to keep channels connected
LasseRosenow 67c7007
Fix riot critical section?
LasseRosenow 328eafb
Remove critical section in LF_ENTRY_POINT_FEDERATED for now
LasseRosenow c815f90
Print ip address if channel is not found
LasseRosenow da65839
Add readme explaining how to run RIOT examples
LasseRosenow 3a462ea
Fix readme example paths
LasseRosenow 6554503
Improve the readme for the examples
LasseRosenow 7b861ed
Rename only_get_ip to only_print_ip env variable
LasseRosenow 23ed0a9
Update examples/riot/coap_federated/receiver/Makefile
LasseRosenow 21c99c8
Also remove tcp_ip from sender
LasseRosenow 975375f
Make makefile more readable
LasseRosenow e319886
Rewrite make again
LasseRosenow 2410b62
Add explanation on what ip address to choose
LasseRosenow cd28fc8
Update README
erlingrj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# RIOT Examples | ||
|
||
This doc explains how to compile and run the various RIOT OS examples. | ||
|
||
## Setup RIOT Environment | ||
|
||
Make sure that the environment variable `RIOTBASE` points to a `RIOT` codebase. | ||
|
||
## Build and Run | ||
|
||
### Blinky | ||
|
||
```shell | ||
cd blinky | ||
make BOARD=native all term | ||
``` | ||
|
||
### Hello | ||
|
||
```shell | ||
cd hello | ||
make BOARD=native all term | ||
``` | ||
|
||
### CoAP Federated | ||
|
||
The federated example using CoAP channels needs to be run using 2 terminals. | ||
Make sure to set the `PORT` environment variable to the correct `tap` interface such as `tap0` or `tap1` as can be seen in the code below. | ||
|
||
#### Preparation | ||
|
||
First you need to create the `tap` interfaces so that the `sender` and `receiver` application can communicate through the (linux) host. | ||
|
||
```shell | ||
sudo $RIOTBASE/dist/tools/tapsetup/tapsetup | ||
``` | ||
|
||
#### Get IPv6 address of receiver | ||
|
||
Enter the directory of the `sender` application: | ||
|
||
```shell | ||
cd coap_federated/sender | ||
``` | ||
|
||
Get the IP address of the `receiver` by specifying the `PORT=tap1` and `ONLY_PRINT_IP=1` environment variables: | ||
|
||
*If the program returns more than one IP-Address then select the one that starts with `fe80`*. | ||
|
||
```shell | ||
make ONLY_PRINT_IP=1 BOARD=native PORT=tap1 all term | ||
``` | ||
|
||
The resulting program will print out the IPv6 address of `tap1` and terminate. | ||
This address must be used when starting the sender below. | ||
|
||
|
||
#### Get IPv6 address of sender | ||
|
||
Enter the directory of the `receiver` application: | ||
|
||
```shell | ||
cd coap_federated/receiver | ||
``` | ||
|
||
Get the IP address of the `sender` by specifying the `PORT=tap0` and `ONLY_PRINT_IP=1` environment variables: | ||
|
||
*If the program returns more than one IP-Address then select the one that starts with `fe80`*. | ||
|
||
```shell | ||
make ONLY_PRINT_IP=1 BOARD=native PORT=tap0 all term | ||
``` | ||
|
||
The resulting program will print out the IPv6 address of `tap0` and terminate. | ||
This address must be used when starting the receiver below. | ||
|
||
#### Start the applications | ||
|
||
##### Sender | ||
Start the sender with `PORT=tap0`, make sure to replace `REMOTE_ADDRESS` with | ||
the address of `tap1` that you found above. | ||
|
||
```shell | ||
cd sender | ||
make REMOTE_ADDRESS=fe80::8cc3:33ff:febb:1b3 BOARD=native PORT=tap0 all term | ||
``` | ||
|
||
##### Receiver | ||
|
||
Start the receiver with `PORT=tap1`, make sure to replace `REMOTE_ADDRESS` with | ||
the address of `tap0` that you found above. | ||
|
||
```shell | ||
cd receiver | ||
make REMOTE_ADDRESS=fe80::44e5:1bff:fee4:dac8 BOARD=native PORT=tap1 all term | ||
``` |
LasseRosenow marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# name of your application | ||
APPLICATION = lf-coap-federated-receiver | ||
|
||
# This has to be the absolute path to the RIOT base directory: | ||
RIOTBASE ?= $(CURDIR)/../../../../../RIOT | ||
|
||
# If no BOARD is found in the environment, use this default: | ||
BOARD ?= native | ||
|
||
# Comment this out to disable code in RIOT that does safety checking | ||
# which is not needed in a production environment but helps in the | ||
# development process: | ||
DEVELHELP ?= 1 | ||
|
||
# Change this to 0 show compiler invocation lines by default: | ||
QUIET ?= 1 | ||
|
||
# Enable reactor-uc features | ||
CFLAGS += -DNETWORK_CHANNEL_COAP_RIOT | ||
REACTION_QUEUE_SIZE = 32 | ||
EVENT_QUEUE_SIZE = 32 | ||
|
||
CFLAGS += -DTHREAD_STACKSIZE_DEFAULT=10000 | ||
CFLAGS += -DTHREAD_STACKSIZE_MAIN=10000 | ||
CFLAGS += -DISR_STACKSIZE=10000 | ||
|
||
# Configure CoAP retransmission timeout | ||
CFLAGS += -DCONFIG_GCOAP_NO_RETRANS_BACKOFF=1 | ||
CFLAGS += -DCONFIG_COAP_ACK_TIMEOUT_MS=400 | ||
CFLAGS += -DCONFIG_COAP_MAX_RETRANSMIT=4 | ||
|
||
# Check if ONLY_PRINT_IP is defined | ||
# If ONLY_PRINT_IP is defined the REMOTE_ADDRESS is not needed | ||
ifdef ONLY_PRINT_IP | ||
# ONLY_PRINT_IP is defined => Set CFLAGS for it | ||
CFLAGS += -DONLY_PRINT_IP=$(ONLY_PRINT_IP) | ||
else ifdef REMOTE_ADDRESS | ||
# REMOTE_ADDRESS is defined => Set CFLAGS for it | ||
CFLAGS += -DREMOTE_ADDRESS=\"$(REMOTE_ADDRESS)\" | ||
else | ||
LasseRosenow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Neither is defined | ||
$(error Either define REMOTE_ADDRESS or set ONLY_PRINT_IP=1 to print the IP-Address of this device.) | ||
endif | ||
|
||
include $(CURDIR)/../../../../make/riot/riot.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include "reactor-uc/platform/riot/coap_udp_ip_channel.h" | ||
#include "reactor-uc/reactor-uc.h" | ||
|
||
#ifndef REMOTE_ADDRESS | ||
#define REMOTE_ADDRESS "fe80::44e5:1bff:fee4:dac8" | ||
#endif | ||
|
||
#define REMOTE_PROTOCOL_FAMILY AF_INET6 | ||
|
||
typedef struct { | ||
int size; | ||
char msg[512]; | ||
} lf_msg_t; | ||
|
||
lf_ret_t deserialize_msg_t(void *user_struct, const unsigned char *msg_buf, size_t msg_size) { | ||
(void)msg_size; | ||
|
||
lf_msg_t *msg = user_struct; | ||
memcpy(&msg->size, msg_buf, sizeof(msg->size)); | ||
memcpy(msg->msg, msg_buf + sizeof(msg->size), msg->size); | ||
|
||
return LF_OK; | ||
} | ||
|
||
LF_DEFINE_REACTION_STRUCT(Receiver, r, 0) | ||
LF_DEFINE_REACTION_CTOR(Receiver, r, 0) | ||
LF_DEFINE_INPUT_STRUCT(Receiver, in, 1, 0, lf_msg_t, 0) | ||
LF_DEFINE_INPUT_CTOR(Receiver, in, 1, 0, lf_msg_t, 0) | ||
|
||
typedef struct { | ||
Reactor super; | ||
LF_REACTION_INSTANCE(Receiver, r); | ||
LF_PORT_INSTANCE(Receiver, in, 1); | ||
int cnt; | ||
LF_REACTOR_BOOKKEEPING_INSTANCES(1, 1, 0); | ||
} Receiver; | ||
|
||
LF_DEFINE_REACTION_BODY(Receiver, r) { | ||
LF_SCOPE_SELF(Receiver); | ||
LF_SCOPE_ENV(); | ||
LF_SCOPE_PORT(Receiver, in); | ||
printf("Input triggered @ %" PRId64 " with %s size %d\n", env->get_elapsed_logical_time(env), in->value.msg, | ||
in->value.size); | ||
} | ||
|
||
LF_REACTOR_CTOR_SIGNATURE_WITH_PARAMETERS(Receiver, InputExternalCtorArgs *in_external) { | ||
LF_REACTOR_CTOR_PREAMBLE(); | ||
LF_REACTOR_CTOR(Receiver); | ||
LF_INITIALIZE_REACTION(Receiver, r); | ||
LF_INITIALIZE_INPUT(Receiver, in, 1, in_external); | ||
|
||
// Register reaction as an effect of in | ||
LF_PORT_REGISTER_EFFECT(self->in, self->r, 1); | ||
} | ||
|
||
LF_DEFINE_FEDERATED_INPUT_CONNECTION(Receiver, in, lf_msg_t, 5, MSEC(100), false) | ||
|
||
typedef struct { | ||
FederatedConnectionBundle super; | ||
CoapUdpIpChannel channel; | ||
LF_FEDERATED_INPUT_CONNECTION_INSTANCE(Receiver, in); | ||
LF_FEDERATED_CONNECTION_BUNDLE_BOOKKEEPING_INSTANCES(1, 0) | ||
} LF_FEDERATED_CONNECTION_BUNDLE_NAME(Receiver, Sender); | ||
|
||
LF_FEDERATED_CONNECTION_BUNDLE_CTOR_SIGNATURE(Receiver, Sender) { | ||
LF_FEDERATED_CONNECTION_BUNDLE_CTOR_PREAMBLE(); | ||
CoapUdpIpChannel_ctor(&self->channel, parent->env, REMOTE_ADDRESS, REMOTE_PROTOCOL_FAMILY); | ||
LF_FEDERATED_CONNECTION_BUNDLE_CALL_CTOR(); | ||
LF_INITIALIZE_FEDERATED_INPUT_CONNECTION(Receiver, in, deserialize_msg_t); | ||
} | ||
|
||
typedef struct { | ||
Reactor super; | ||
LF_CHILD_REACTOR_INSTANCE(Receiver, receiver, 1); | ||
LF_FEDERATED_CONNECTION_BUNDLE_INSTANCE(Receiver, Sender); | ||
LF_FEDERATE_BOOKKEEPING_INSTANCES(1); | ||
LF_CHILD_INPUT_SOURCES(receiver, in, 1, 1, 0); | ||
} MainRecv; | ||
|
||
LF_REACTOR_CTOR_SIGNATURE(MainRecv) { | ||
LF_REACTOR_CTOR(MainRecv); | ||
LF_FEDERATE_CTOR_PREAMBLE(); | ||
LF_DEFINE_CHILD_INPUT_ARGS(receiver, in, 1, 1); | ||
LF_INITIALIZE_CHILD_REACTOR_WITH_PARAMETERS(Receiver, receiver, 1, _receiver_in_args[i]); | ||
LF_INITIALIZE_FEDERATED_CONNECTION_BUNDLE(Receiver, Sender); | ||
LF_BUNDLE_REGISTER_DOWNSTREAM(Receiver, Sender, receiver, in); | ||
} | ||
|
||
LF_ENTRY_POINT_FEDERATED(MainRecv, SEC(1), true, true, 1, false) | ||
|
||
void print_ip_addresses(void) { | ||
gnrc_netif_t *netif = gnrc_netif_iter(NULL); | ||
char addr_str[IPV6_ADDR_MAX_STR_LEN]; | ||
|
||
while (netif) { | ||
size_t max_addr_count = 4; | ||
ipv6_addr_t addrs[max_addr_count]; | ||
gnrc_netif_ipv6_addrs_get(netif, addrs, max_addr_count * sizeof(ipv6_addr_t)); | ||
|
||
for (size_t i = 0; i < 2; i++) { | ||
if (ipv6_addr_to_str(addr_str, &addrs[i], sizeof(addr_str))) { | ||
LF_INFO(NET, "IPv6 address: %s", addr_str); | ||
} | ||
} | ||
|
||
netif = gnrc_netif_iter(netif); | ||
} | ||
} | ||
|
||
int main() { | ||
#ifdef ONLY_PRINT_IP | ||
print_ip_addresses(); | ||
#else | ||
lf_start(); | ||
#endif | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# name of your application | ||
APPLICATION = lf-coap-federated-sender | ||
|
||
# This has to be the absolute path to the RIOT base directory: | ||
RIOTBASE ?= $(CURDIR)/../../../../../RIOT | ||
|
||
# If no BOARD is found in the environment, use this default: | ||
BOARD ?= native | ||
|
||
# Comment this out to disable code in RIOT that does safety checking | ||
# which is not needed in a production environment but helps in the | ||
# development process: | ||
DEVELHELP ?= 1 | ||
|
||
# Change this to 0 show compiler invocation lines by default: | ||
QUIET ?= 1 | ||
|
||
# Enable reactor-uc features | ||
CFLAGS += -DNETWORK_CHANNEL_COAP_RIOT | ||
REACTION_QUEUE_SIZE = 32 | ||
EVENT_QUEUE_SIZE = 32 | ||
|
||
CFLAGS += -DTHREAD_STACKSIZE_DEFAULT=10000 | ||
CFLAGS += -DTHREAD_STACKSIZE_MAIN=10000 | ||
CFLAGS += -DISR_STACKSIZE=10000 | ||
|
||
# Configure CoAP retransmission timeout | ||
CFLAGS += -DCONFIG_GCOAP_NO_RETRANS_BACKOFF=1 | ||
CFLAGS += -DCONFIG_COAP_ACK_TIMEOUT_MS=400 | ||
CFLAGS += -DCONFIG_COAP_MAX_RETRANSMIT=4 | ||
|
||
# Check if ONLY_PRINT_IP is defined | ||
# If ONLY_PRINT_IP is defined the REMOTE_ADDRESS is not needed | ||
ifdef ONLY_PRINT_IP | ||
# ONLY_PRINT_IP is defined => Set CFLAGS for it | ||
CFLAGS += -DONLY_PRINT_IP=$(ONLY_PRINT_IP) | ||
else ifdef REMOTE_ADDRESS | ||
# REMOTE_ADDRESS is defined => Set CFLAGS for it | ||
CFLAGS += -DREMOTE_ADDRESS=\"$(REMOTE_ADDRESS)\" | ||
else | ||
LasseRosenow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Neither is defined | ||
$(error Either define REMOTE_ADDRESS or set ONLY_PRINT_IP=1 to print the IP-Address of this device) | ||
endif | ||
|
||
include $(CURDIR)/../../../../make/riot/riot.mk |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This did not work for me:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be
ONLY_GET_IP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still confused by the output:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oups I have renamed it to
ONLY_PRINT_IP
everywhere now.This is very strange. On my computer it only prints the IP Address if
ONLY_PRINT_IP
is enabled.I have rewritten the makefile code again, but it should not change the logic, but is more readable now. Not sure how your system is able to print the IP and the lf_start() code. it should only print the one or the other:
As can be seen in the main.c file of the sender and receiver examples. Is your main.c maybe outdated for whatever reason?