CoAP server with public IPv6 network and M3 nodes
Level: Medium
Duration: 45 minutes
Prerequisites: Configure SSH Access / Understand IPv6 subnetting / Experiment CLI client / Public IPv6 network with M3 nodes
Description: The goal of this tutorial is to discover the basics of CoAP with RIOT on IoT-LAB. You will reserve 2 M3 nodes on the Grenoble site, build and flash the required firmwares on the M3 nodes, create a simple IPv6 network in IoT-LAB. Finally, from the Grenoble host (or any computer with a global IPv6 address), you’ll interact with the node running the CoAP server using the coap client available on the SSH frontend (or any other CoAP client).
- Connect to the Grenoble site host:
my_computer$ ssh <login>@grenoble.iot-lab.info
- Start an experiment with two M3 nodes called
riot_m3_coap
.<login>@grenoble:~$ iotlab-auth -u <login> <login>@grenoble:~$ iotlab-experiment submit -n riot_coap_m3 -d 60 -l 2,archi=m3:at86rf231+site=grenoble
Remember the experiment identifier returned by the last command. It’ll be used in the commands shown below,
<exp_id>
. The requested experiment duration is 60 minutes. - Wait a moment until the experiment is launched (state is Running) and get the nodes list. For the next of this tutorial we suppose that you obtained m3-1.grenoble.iot-lab.info and m3-2.grenoble.iot-lab.info nodes.
<login>@grenoble:~$ iotlab-experiment get -i <exp_id> -s <login>@grenoble:~$ iotlab-experiment get -i <exp_id> -r
- Get the code of the 2019.01 release of RIOT from GitHub:
<login>@grenoble:~$ mkdir -p ~/riot <login>@grenoble:~$ cd ~/riot <login>@grenoble:~/riot$ git clone https://github.com/RIOT-OS/RIOT.git -b 2019.01-branch <login>@grenoble:~/riot$ cd RIOT
Note: you can also use the RIOT development code (e.g the master branch) but this will be at your own risk: this tutorial may not fully work.
- Build the required firmware for the border router node. The node
m3-1
will act as the border router in this experiment. The border router firmware is built using the RIOT gnrc_border_router example.Important note 1: we build this firmware with a baudrate of 500000. This is mandatory forethos_uhcpd.py
script to work effectively since the UART baudrate of the M3 is 500000.Important note 2: to minimize radio interferences with other experiments you can build the firmwares to make them use a different 802.15.4 channel (default is 26). To do so, add
DEFAULT_CHANNEL=<channel>
option to the make commands.<login>@grenoble:~/riot/RIOT/$ source /opt/riot.source <login>@grenoble:~/riot/RIOT/$ make ETHOS_BAUDRATE=500000 DEFAULT_CHANNEL=<channel> BOARD=iotlab-m3 -C examples/gnrc_border_router clean all
- Use the CLI-Tools to flash the gnrc_border_router firmware that you have just built on the first M3 node. Here we use m3-1 but it may change in your case:
<login>@grenoble:~/riot/RIOT/$ iotlab-node --update examples/gnrc_border_router/bin/iotlab-m3/gnrc_border_router.elf -l grenoble,m3,1
- Choose an available IPv6 prefix for the site you are experimenting on. For example in Grenoble site:
- we choose 2001:660:5307:3100::/64
- Now you can configure the network of the border router on
m3-1
and propagate an IPv6 prefix withethos_uhcpd.py
.<login>@grenoble:~$ sudo ethos_uhcpd.py m3-1 tap0 2001:660:5307:3100::1/64
Important note1: Check that tap0 network interface is not already used and in this case choose another number
<login>@grenoble:~$ ip addr show | grep tap 1406: tap0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 500
Important note2: If you have an error “overlaps with routes”, it’s because another experiment is using the same ipv6 prefix (e.g. : 2001:660:5307:3100::/64).
You can view currently used IPv6 prefixes on the frontend SSH with this command
<login>@grenoble:~$ ip -6 route 2001:660:5307:30fff::/64 dev eth0 proto kernel metric 256 mtu 1500 advmss 1440 hoplimit 4294967295 2001:660:5307:3100::/64 dev tun0 proto kernel metric 256 mtu 1500 advmss 1440 hoplimit 4294967295 fe80::/64 dev eth1 proto kernel metric 256 mtu 1500 advmss 1440 hoplimit 4294967295 fe80::/64 dev eth0 proto kernel metric 256 mtu 1500 advmss 1440 hoplimit 4294967295 fe80::/64 dev tun0 proto kernel metric 256 mtu 1500 advmss 1440 hoplimit 4294967295 default via 2001:660:5307:30ff:ff:: dev eth0 metric 1 mtu 1500 advmss 1440 hoplimit 4294967295
The network is finally configured:
net.ipv6.conf.tap0.forwarding = 1 net.ipv6.conf.tap0.accept_ra = 0 ----> ethos: sending hello. ----> ethos: activating serial pass through. ----> ethos: hello reply received
Note that we propagate another subnetwork for the border router (M3 node) in our LLN,
2001:660:3207:04c1::/64
. - Now, in another terminal, SSH to the SSH frontend and build the CoAP server firmware used for the other node. RIOT microcoap_server example will be used for this purpose.
<login>@grenoble:~$ cd riot/RIOT <login>@grenoble:~/riot/RIOT/$ source /opt/riot.source <login>@grenoble:~/riot/RIOT/$ make DEFAULT_CHANNEL=<channel> BOARD=iotlab-m3 -C examples/microcoap_server clean all
Use the CLI-Tools to flash the
microcoap_server
firmware that you have just built on the second M3 node. Here we use M3-2 but it may change in your case:<login>@grenoble:~/riot/RIOT/$ iotlab-node --update examples/microcoap_server/bin/iotlab-m3/microcoap_server.elf -l grenoble,m3,2
- On the border router shell (eg. where you are running the ethos_uhcpd.py command) with the command nib neigh you can find the IPv6 of the node running nanocoap server. (type enter in the terminal of m3-1 where you launched the
ethos_uhcpd.py
script : you have access to the shell or RIOT)> > help help Command Description --------------------------------------- reboot Reboot the node ps Prints information about running threads. ping6 Ping via ICMPv6 random_init initializes the PRNG random_get returns 32 bit of pseudo randomness nib Configure neighbor information base ifconfig Configure network interfaces fibroute Manipulate the FIB (info: 'fibroute [add|del]') 6ctx 6LoWPAN context configuration toolol > nib neigh nib neigh [...] 2001:660:3207:4c1:1711:6b10:65fd:bd36 dev #6 lladdr 15:11:6b:10:65:fd:bd:36 STALE REGISTERED
- On the SSH frontend, you can now use the preinstalled CoAP client to query the CoAP server node. By default, the nanocoap server example of RIOT exposes only the board type to a CoAP
GET
request on/riot/board
, let’s try it on the CoAP server node:<login>@grenoble:~$ aiocoap-client coap://[2001:660:3207:4c1:1711:6b10:65fd:bd36]/riot/board (2.05) iotlab-m3
If everything works as described, you can use CoAP with RIOT on IoT-Lab. Congratulations !