MQTT-SN with public IPv6 network and A8-M3 nodes

 

Level: High

Duration: 45 minutes

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

Description: The goal of this tutorial is to discover the MQTT procotol and its contrained variant called MQTT-SN with RIOT on IoT-LAB. You will reserve 3 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 SSH frontend host, you’ll publish MQTT messages to the test/riot topic. The messages will be displayed by the MQTT-SN client running on the RIOT node.

The first node will be used as a border router for propagating an IPv6 prefix through its wireless interface, the second node will be used a as MQTT broker (using the mosquitto.rsmb application) and the third node will run a RIOT application containing a shell and a MQTT-SN client to connect to the brober.

 

    1. Connect to Saclay site host:
      my_computer$ ssh <login>@saclay.iot-lab.info
      
    2. BEFORE any experiment submission, verify that you add ssh public key of your local user on the ssh frontend to your global User profile. You can get this key as below and follow this tutorial.
      <login>@saclay:~$ cat ~/.ssh/id_rsa.pub
    3. Start an experiment with 3 A8 nodes called riot_mqtt.
      <login>@saclay:~$ iotlab-auth -u <login> 
      <login>@saclay:~$ iotlab-experiment submit -n riot_mqtt -d 60 -l 3,archi=a8:at86rf231+site=saclay
      <login>@saclay:~$ iotlab-experiment wait
      

      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.

    4. Wait a moment until all nodes are up:
      <login>@saclay:~$ iotlab-ssh --verbose wait-for-boot
    5. During this tutorial we suppose that we obtain a8-1.saclay.iot-lab.info, a8-2.saclay.iot-lab.info and a8-3.saclay.iot-lab.info nodes.
       <login>@saclay:~$ iotlab-experiment get -i <exp_id> -s
       <login>@saclay:~$ iotlab-experiment get -i <exp_id> -r
    6. Get the code of the 2019.01 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 -b 2019.01-branch
      <login>@saclay:~/A8/riot$ cd RIOT

      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.

    7. Build and flash 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/RIOT$ source /opt/riot.source
      <login>@saclay:~/A8/riot/RIOT$ make ETHOS_BAUDRATE=500000 BOARD=iotlab-a8-m3 clean all -C examples/gnrc_border_router
      <login>@saclay:~/A8/riot/RIOT$ iotlab-ssh flash-m3 examples/gnrc_border_router/bin/iotlab-a8-m3/gnrc_border_router.elf -l saclay,a8,1
      
    8. Connect to the A8 of the M3 border router: node-a8-1.
      <login>@saclay:~$ ssh root@node-a8-1

      Then uild the required RIOT configuration tools: uhcpd (Micro Host Configuration Protocol) and ethos (Ethernet Over Serial) for propagating the public IPv6 network.

      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 500000
      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 for A8-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
    9. Now, in a second terminal, connect to the SSH frontend and then log on the second A8 node, node-a8-2. We are going to configure and start the MQTT-SN broker as follows:
      my_computer$ ssh <login>@saclay.iot-lab.info
      <login>@saclay:~$ ssh root@node-a8-2

      Edit a file config.conf (vim config.conf) with the following content:

      # add some debug output
      trace_output protocol
      
      # listen for MQTT-SN traffic on UDP port 1885
      listener 1885 INADDR_ANY mqtts
        ipv6 true
      
      # listen to MQTT connections on tcp port 1886
      listener 1886 INADDR_ANY
        ipv6 true
      

      Important, note the global IPv6 address of this node, since we’ll use it to connect to the MQTT broker from the node:

      root@node-a8-2:~# ip -6 -o addr show eth0
      2: eth0    inet6 2001:660:3207:400::66/64 scope global        valid_lft forever preferred_lft forever
      2: eth0    inet6 fe80::fadc:7aff:fe01:98fc/64 scope link        valid_lft forever preferred_lft forever
      

      And finally start the broker:

      root@node-a8-2:~# broker_mqtts config.conf
      20170715 001526.077 CWNAN9999I Really Small Message Broker
      20170715 001526.084 CWNAN9998I Part of Project Mosquitto in Eclipse
      (http://projects.eclipse.org/projects/technology.mosquitto)
      20170715 001526.088 CWNAN0049I Configuration file name is config.conf
      20170715 001526.099 CWNAN0053I Version 1.3.0.2, Jul 11 2017 14:55:20
      20170715 001526.102 CWNAN0054I Features included: bridge MQTTS 
      20170715 001526.104 CWNAN9993I Authors: Ian Craggs (icraggs@uk.ibm.com), Nicholas O'Leary
      20170715 001526.111 CWNAN0300I MQTT-S protocol starting, listening on port 1885
      20170715 001526.115 CWNAN0014I MQTT protocol starting, listening on port 1886
      

      You now have a running MQTT/MQTT-SN broker running on node-a8-2.

      This broker is reachable :

      • from the SSH frontend using MQTT on port 1886
      • from any M3 nodes behind the border router using MQTT-SN on port 1885 (in our case, node-a8-3, see below)
    10. Finally, in a third terminal, log on the SSH frontend, build and flash the RIOT MQTT-SN example firmware on the M3:
      my_computer$ ssh <login>@saclay.iot-lab.info
      <login>@saclay:~$ source /opt/riot.source
      <login>@saclay:~$ cd ~/A8/riot/RIOT
      <login>@saclay:~/A8/riot/RIOT$ make BOARD=iotlab-a8-m3 -C examples/emcute_mqttsn
      <login>@saclay:~/A8/riot/RIOT$ iotlab-ssh flash-m3 examples/emcute_mqttsn/bin/iotlab-a8-m3/emcute_mqttsn.elf -l saclay,a8,3
      

      You can now login to the A8 and connect to the M3 via the serial port to access the shell:

      <login>@saclay:~$ ssh root@node-a8-3
      root@node-a8-2:~# miniterm.py /dev/ttyA8_M3 500000 -e
      > help
      Command        
            Description
      ---------------------------------------
      con                  connect to MQTT broker
      discon               disconnect from the current broker
      pub                  publish something
      sub                  subscribe topic
      unsub                unsubscribe from topic
      will                 register a last will
      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
      ncache               manage neighbor cache by hand
      routers              IPv6 default router list
      

      Use the con command to connect to the MQTT-SN broker on node-a8-2 and subscribe to the test/riot topic using command sub.

      > con 2001:660:3207:400::66 1885
      > sub test/riot
      
    11. In a fourth terminal, connect to the SSH frontend and use the preinstalled mosquitto client CLI to publish and subscribe to topics on the MQTT broker running on node-a8-2.
      <login>@saclay:~$ mosquitto_pub -h 2001:660:3207:400::66 -p 1886 -t test/riot -m iotlab

On the RIOT shell (node-a8-3, third terminal), you get the following message:

### got publication for topic 'test/riot' [1] ###
iotlab

If everything works as described, you are able to use MQTT-SN with RIOT on IoT-Lab. Congratulations !

Now play with mosquitto_sub on the frontend side (fourth terminal) and pub on the RIOT node side (third terminal) to exchange messages from the node to the frontend.