Skip to content

Commit

Permalink
Switch to static ipv6 addresses for the riot coap example
Browse files Browse the repository at this point in the history
  • Loading branch information
LasseRosenow committed Jan 22, 2025
1 parent 24ce057 commit 5d72075
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 116 deletions.
54 changes: 6 additions & 48 deletions examples/riot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,62 +35,20 @@ First you need to create the `tap` interfaces so that the `sender` and `receiver
sudo $RIOTBASE/dist/tools/tapsetup/tapsetup
```

#### Get IPv6 address of receiver
#### Start the Sender

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.
Start the sender with `PORT=tap0`:

```shell
cd sender
make REMOTE_ADDRESS=fe80::8cc3:33ff:febb:1b3 BOARD=native PORT=tap0 all term
make BOARD=native PORT=tap0 all term
```

##### Receiver
#### Start the Receiver

Start the receiver with `PORT=tap1`, make sure to replace `REMOTE_ADDRESS` with
the address of `tap0` that you found above.
Start the receiver with `PORT=tap1`:

```shell
cd receiver
make REMOTE_ADDRESS=fe80::44e5:1bff:fee4:dac8 BOARD=native PORT=tap1 all term
make BOARD=native PORT=tap1 all term
```
15 changes: 3 additions & 12 deletions examples/riot/coap_federated/receiver/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,8 @@ 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
# Neither is defined
$(error Either define REMOTE_ADDRESS or set ONLY_PRINT_IP=1 to print the IP-Address of this device.)
endif
# Static IPv6 address
CFLAGS += -DCONFIG_GNRC_IPV6_STATIC_LLADDR='"fe80::cafe:cafe:cafe:2"'
CFLAGS += -DCONFIG_GNRC_IPV6_STATIC_LLADDR_IS_FIXED=1

include $(CURDIR)/../../../../make/riot/riot.mk
4 changes: 1 addition & 3 deletions examples/riot/coap_federated/receiver/main.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#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_ADDRESS "fe80::cafe:cafe:cafe:1"

#define REMOTE_PROTOCOL_FAMILY AF_INET6

Expand Down
15 changes: 3 additions & 12 deletions examples/riot/coap_federated/sender/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,8 @@ 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
# Neither is defined
$(error Either define REMOTE_ADDRESS or set ONLY_PRINT_IP=1 to print the IP-Address of this device)
endif
# Static IPv6 address
CFLAGS += -DCONFIG_GNRC_IPV6_STATIC_LLADDR='"fe80::cafe:cafe:cafe:1"'
CFLAGS += -DCONFIG_GNRC_IPV6_STATIC_LLADDR_IS_FIXED=1

include $(CURDIR)/../../../../make/riot/riot.mk
4 changes: 1 addition & 3 deletions examples/riot/coap_federated/sender/main.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include "reactor-uc/reactor-uc.h"
#include "reactor-uc/platform/riot/coap_udp_ip_channel.h"

#ifndef REMOTE_ADDRESS
#define REMOTE_ADDRESS "fe80::8cc3:33ff:febb:1b3"
#endif
#define REMOTE_ADDRESS "fe80::cafe:cafe:cafe:2"

#define REMOTE_PROTOCOL_FAMILY AF_INET6

Expand Down
76 changes: 38 additions & 38 deletions examples/riot/coap_federated_lf/src/CoapFederatedLF.lf
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
target uC {
platform: RIOT,
timeout: 1sec
}

reactor Src(id: int = 0) {
output out: int
reaction(startup) -> out{=
printf("Hello from Src!\n");
lf_set(out, self->id);
=}
}

reactor Dst {
input in: int
state check: bool = false
reaction(startup) {=
printf("Hello from Dst!\n");
=}
reaction(in) {=
printf("Received %d from Src\n", in->value);
validate(in->value == 42);
self->check = true;
env->request_shutdown(env);
=}

reaction(shutdown) {=
validate(self->check);
=}
}

federated reactor {
@interface_coap(name="if1", address="fe80::44e5:1bff:fee4:dac8")
r1 = new Src(id=42)
platform: RIOT,
timeout: 1sec
}

@interface_coap(name="if1", address="fe80::8cc3:33ff:febb:1b3")
r2 = new Dst()
reactor Src(id: int = 0) {
output out: int
reaction(startup) -> out{=
printf("Hello from Src!\n");
lf_set(out, self->id);
=}
}

@link(left="if1", right="if1")
r1.out -> r2.in
}
reactor Dst {
input in: int
state check: bool = false
reaction(startup) {=
printf("Hello from Dst!\n");
=}
reaction(in) {=
printf("Received %d from Src\n", in->value);
validate(in->value == 42);
self->check = true;
env->request_shutdown(env);
=}

reaction(shutdown) {=
validate(self->check);
=}
}

federated reactor {
@interface_coap(name="if1", address="fe80::44e5:1bff:fee4:dac8")
r1 = new Src(id=42)

@interface_coap(name="if1", address="fe80::8cc3:33ff:febb:1b3")
r2 = new Dst()

@link(left="if1", right="if1")
r1.out -> r2.in
}

0 comments on commit 5d72075

Please sign in to comment.