Use CoAP with RIOT on A8-M3 nodes

 

Level: Medium

Duration: 45 minutes

Prerequisites: Configure SSH Access / Understand IPv6 subnetting / Experiment CLI client / Public IPv6/6LoWPAN network with A8-M3 nodes

Description: The goal of this tutorial is to discover the basics of CoAP with RIOT on IoT-LAB. You will reserve 2 A8 nodes on the Saclay site, build and flash the required firmwares on the A8-M3 nodes, create a simple IPv6 network in IoT-LAB. Finally, from the saclay 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).

  1. Connect to Saclay site host:
    my_computer$ ssh <login>@saclay.iot-lab.info
    
  2. Start an experiment called riot_a8 that contains 2 A8 nodes.
    <login>@saclay:~$ auth-cli -u <login> 
    <login>@saclay:~$ experiment-cli submit -n riot_a8 -d 60 -l 2,archi=a8:at86rf231+site=saclay

    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.

  3. 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 we obtain a8-1.saclay.iot-lab.info and a8-2.saclay.iot-lab.info nodes.
     <login>@saclay:~$ experiment-cli get -i <exp_id> -s
     <login>@saclay:~$ experiment-cli get -i <exp_id> -r
  4. Get the code of the 2016.10 release of RIOT from GitHub:
    <login>@saclay:~$ mkdir -p ~/A8/riot
    <login>@saclay:~$ cd ~/A8/riot
    <login>@saclay:~/A8/riot$ git clone https://github.com/RIOT-OS/RIOT.git
    <login>@saclay:~/A8/riot$ git checkout -b 2016.10-branch origin/2016.10-branch

    Note that you can also use the RIOT development code (e.g the master branch) at your own risk : this tutorial may not fully work.

    Important note: to minimize radio interferences with other experiments you can build the firmwares below 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.

  5. Build the required firmware for the border router node. The node node-a8-1 will act as the border router in this experiment. The border firmware is built using the RIOT gnrc_border_router example.
    <login>@saclay:~/A8/riot$ cd RIOT/examples/gnrc_border_router
    <login>@saclay:~/A8/riot/RIOT/examples/gnrc_border_router$ make BOARD=iotlab-a8-m3 clean all
    <login>@saclay:~/A8/riot/RIOT/examples/gnrc_border_router$ cp bin/iotlab-a8-m3/gnrc_border_router.elf ~/A8/.
  6. Build the required firmware for the node running the CoAP server. RIOT nanocoap_server example will be used for this purpose. You could also use the microcoap_server example which takes more space in memory.
    <login>@saclay:~$ cd ~/A8/riot/RIOT/examples/nanocoap_server
    <login>@saclay:~/A8/riot/RIOT/examples/nanocoap_server$ make BOARD=iotlab-a8-m3 clean all
    <login>@saclay:~/A8/riot/RIOT/examples/nanocoap_server$ cp bin/iotlab-a8-m3/nanocoap_server.elf ~/A8/.
  7. Connect to the A8 of the M3 border router: node-a8-1.
    <login>@saclay:~$ ssh root@node-a8-1

    Then flash the BR firmware on the M3 and build the required RIOT configuration tools: uhcpd (Micro Host Configuration Protocol) and ethos (Ethernet Over Serial).

    root@node-a8-1:~# flash_a8_m3 A8/gnrc_border_router.elf
    root@node-a8-1:~# cd ~/A8/riot/RIOT/dist/tools/uhcpd 
    root@node-a8-1:~/A8/riot/RIOT/dist/tools/uhcpd# make clean all
    root@node-a8-1:~/A8/riot/RIOT/dist/tools/uhcpd# cd ../ethos
    root@node-a8-1:~/A8/riot/RIOT/dist/tools/ethos# make clean all

    On the border router, the network can finally be configured automatically using the following commands:

    root@node-a8-1:~/A8/riot/RIOT/dist/tools/ethos# ./start_network.sh /dev/ttyA8_M3 tap0 2001:660:3207:401::/64
    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:401::/64. You can find informations about IPv6 subnetting forA8-M3 nodes here. You can also get this subnet directly on the A8 node

    root@node-a8-1:~# printenv
    INET6_PREFIX_LEN=64
    INET6_PREFIX=2001:0660:3207:401
    INET6_ADDR=2001:0660:3207:0400::1/64
  8. Now, in another terminal, log on the remaining A8 node, node-a8-2, and flash the nanocoap_server firmware on the M3:
    my_computer$ ssh <login>@saclay.iot-lab.info
    <login>@saclay:~$ ssh root@node-a8-2
    root@node-a8-2:~# flash_a8_m3 A8/nanocoap_server.elf
    root@node-a8-2:~# exit
  9. On the border router shell with the command routers you can find the IPv6 of the node running nanocoap server. (type enter in the terminal of node-a8-1 where you launched the start_network.sh 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
    ifconfig             Configure network interfaces
    txtsnd               Sends a custom string as is over the link layer
    fibroute             Manipulate the FIB (info: 'fibroute [add|del]')
    ncache               manage neighbor cache by hand
    routers              IPv6 default router list
    6ctx                 6LoWPAN context configuration tool
    > routers
    routers
    if  Router                          state      type
    ---------------------------------------------------
     6  2001:660:3207:401:3432:4833:46df:a902  STALE       REG
  10. 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>@saclay:~$ coap get coap://[2001:660:3207:401:3432:4833:46df:a902]/riot/board
    (2.05)	iotlab-a8-m3
    

If everything works as described, you can use CoAP with RIOT on IoT-Lab. Congratulations !