|
| 1 | +--- |
| 2 | +title: 6LoWPAN Guide |
| 3 | +permalink: /docs/tutorials/advanced/nuttx/6lowpan/ |
| 4 | +--- |
| 5 | + |
| 6 | +In this guide, we will show how to use micro-ROS over 6LoWPAN communication. |
| 7 | + |
| 8 | +# What is 6LoWPAN? |
| 9 | + |
| 10 | +6LoWPAN is an acronym o IPv6 over Low-Power Wireless Personal Area Networks. |
| 11 | +This communication protocol allows wireless communication over IEEE 802.15.4 based networks using IPv6. Some of the main advantages are: |
| 12 | +- Easy to route from radio devices to the Internet, thanks to the usage of the IP packets. |
| 13 | +- Easy to use on UDP and TCP server/clients. |
| 14 | +- A protocol designed for low power and constrained devices, perfect or micro-ROS remote sensors. |
| 15 | + |
| 16 | +# Needed hardware |
| 17 | + |
| 18 | +At present, 6LoWPAN is only available for the NuttX RTOS. |
| 19 | +In order to implement the steps highlighted in this guide, you need the following devices: |
| 20 | + |
| 21 | +- Raspberry Pi. |
| 22 | +- [Olimex-STM32-E407 board](https://www.olimex.com/Products/ARM/ST/STM32-E407/open-source-hardware). |
| 23 | +- [PmodRF2 Radio](https://store.digilentinc.com/pmod-rf2-ieee-802-15-rf-transceiver/). |
| 24 | +- micro-ROS-bridge-RPI. |
| 25 | + |
| 26 | +**Important!** |
| 27 | +You can find a guide of how to setup the micro-ROS-bridge_RPI at its [repository](https://github.com/micro-ROS/micro-ROS-bridge_RPI/blob/new_bridge_tools/Readme.md). |
| 28 | +In the micro-ROS-bridge-RPI guide, you can find everything that you need to set-up this device base. |
| 29 | + |
| 30 | +# Configure the board |
| 31 | + |
| 32 | +The configuration of the board is divided into two parts: hardware and software set-up. |
| 33 | + |
| 34 | +## Hardware set-up |
| 35 | + |
| 36 | +First we are going to connect the PmodRF2 radio. |
| 37 | + |
| 38 | +| | RPi | Olimex | PmodRF2 | |
| 39 | +| ----- | --- | ------ | ------- | |
| 40 | +| VIN | 1 | D13 | 12 | |
| 41 | +| GND | 20 | GND | 11 | |
| 42 | +| RESET | 17 | - | 8 | |
| 43 | +| INT | 16 | D8 | 7 | |
| 44 | +| SDI | 19 | D12 | 2 | |
| 45 | +| SDO | 21 | D11 | 3 | |
| 46 | +| SCK | 23 | D13 | 4 | |
| 47 | +| CS | 26 | D10 | 1 | |
| 48 | + |
| 49 | +To ease the set-up process, you can use the [RPi pinout](https://pinout.xyz/#) and [PmodRF2 pinout](https://reference.digilentinc.com/reference/pmod/pmodrf2/start). |
| 50 | + |
| 51 | +The last step is to connect a mini-USB cable to the OTG2 USB port (this USB port next to the Ethernet port). |
| 52 | + |
| 53 | +## Software set-up |
| 54 | + |
| 55 | +To create and flash the firmware, we are going to use the micro-ROS build system. |
| 56 | +You can find the instructions at the micro-ros-build's [README](https://github.com/micro-ROS/micro-ros-build/blob/dashing/micro_ros_setup/README.md). |
| 57 | +For this particular guide, it is necessary yo use the branch `dashing` and the configuration profile `uros_6lowpan`. |
| 58 | + |
| 59 | +Once you follow all the instructions in the build system and flash the board, everything is ready. |
| 60 | + |
| 61 | +# How to use it? |
| 62 | + |
| 63 | +- Turn on the Olimex board and open the NSH console on a terminal. |
| 64 | +- Check if all the applications are ready by typing `?` on the console. It should return the following: |
| 65 | + |
| 66 | +```bash |
| 67 | +help usage: help [-v] [<cmd>] |
| 68 | + |
| 69 | + [ cd df help ls mw set true |
| 70 | + ? cp echo hexdump mb ps sh uname |
| 71 | + addroute cmp exec ifconfig mkdir pwd sleep umount |
| 72 | + basename dirname exit ifdown mh rm test unset |
| 73 | + break dd false ifup mount rmdir telnetd usleep |
| 74 | + cat delroute free kill mv route time xd |
| 75 | + |
| 76 | +Builtin Apps: |
| 77 | + ping6 i8sak uros_6lowpan |
| 78 | +``` |
| 79 | +- Now turn-on the RPi and execute the micro-ROS-bridge-RPI tool by typing the next command: |
| 80 | +
|
| 81 | +```bash |
| 82 | +./ ~/micro-ROS-HB.sh |
| 83 | +``` |
| 84 | +- Once everything is configured, it will return the connection data of the 6LoWPAN network: |
| 85 | +
|
| 86 | +```bash |
| 87 | +lowpan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1280 |
| 88 | + inet6 fe80::b482:ca65:743b:b6bd prefixlen 64 scopeid 0x20<link> |
| 89 | + unspec B6-82-CA-65-74-3B-B6-BD-00-00-00-00-00-00-00-00 txqueuelen 1000 (UNSPEC) |
| 90 | + RX packets 0 bytes 0 (0.0 B) |
| 91 | + RX errors 0 dropped 0 overruns 0 frame 0 |
| 92 | + TX packets 21 bytes 2242 (2.1 KiB) |
| 93 | + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
| 94 | + |
| 95 | +1) Add new 6LoWPAN micro-ROS device 3) Create UDP micro-ROS Agent 5) Create Serial micro-ROS Agent server |
| 96 | +2) Create UDP 6LoWPAN micro-ROS Agent 4) Create TCP micro-ROS Agent 6) Quit |
| 97 | +#? |
| 98 | +``` |
| 99 | +- The value **inet6** is the IPv6 direction of the RPi over the 6LoWPAN interface. Copy it because is necessary for the subsequent steps. |
| 100 | +- Execute the micro-ROS 6LoWPAN application on the Olimex typing the next command: |
| 101 | +
|
| 102 | +```bash |
| 103 | +uros_6lowpan <Agent_IP> <Agent_Port> <pub/sub> |
| 104 | +``` |
| 105 | + where `Agent_IP` is the IPv6 copied previously, `Agent_PORT` is the port selected for the Agent and `pub/sub` controls the application behavior: in case of `pub` it will act as publisher and as in case of `sub`, it will act as a subscriber. |
| 106 | +
|
| 107 | +- Once you execute the app, ti will ask you if you want to configure the 6LoWPAN network. |
| 108 | + - This will return connection data, you should save the `inet_6_addr` and `HWaddr`. |
| 109 | + - Note: if you want to change the ID of the radio, you can do it on the `menuconfig` of NuttX on the example configuration. |
| 110 | +
|
| 111 | +```bash |
| 112 | +nsh> uros_6lowpan fe80::bc81:c3b9:5c14:1ab 8888 pub |
| 113 | +Do you want to configure the 6lowpan network? (Y/N) |
| 114 | +ifdown wpan0...OK |
| 115 | +i8sak: resetting MAC layer |
| 116 | +i8sak: starting PAN |
| 117 | +Introduce your 6LowPan ID (It must between 00 and FF (Hex)) |
| 118 | +i8sak: accepting all assoc requests |
| 119 | +i8sak: daemon started |
| 120 | +ifup wpan0...OK |
| 121 | +Connection data |
| 122 | +wpan0 Link encap:6LoWPAN HWaddr 00:be:ad:de:00:de:fa:00 at UP |
| 123 | + inet6 addr: fe80::2be:adde:de:fa00/64 |
| 124 | + inet6 DRaddr: ::/64 |
| 125 | +
|
| 126 | + RX: Received Fragment Errors |
| 127 | + 00000000 00000000 00000000 |
| 128 | + IPv6 Dropped |
| 129 | + 00000000 00000000 |
| 130 | + TX: Queued Sent Errors Timeouts |
| 131 | + 00000000 00000000 00000000 00000000 |
| 132 | + Total Errors: 00000000 |
| 133 | +``` |
| 134 | +
|
| 135 | +- After this step, the application on the Olimex board will be blocked waiting for a user input confirming that the Agent on the bridge is ready to receive data. |
| 136 | +
|
| 137 | +- Go back to the bridge, now we are going to add a new 6LoWPAN device. Push `1 + enter`. (Note: this step is only necessary if you are attaching for the first time a new device). |
| 138 | + - First, introduce the IPv6 of the Olimex board (`inet6_addr`). |
| 139 | + - Introduce the hardware address of the Olimex board (HWaddr). |
| 140 | + - Now the device is registered and ready to establish communication. |
| 141 | +- The final step on the bridge is to execute the micro-ROS-Agent, to do so, push `2 + enter` and introduce the port to use. |
0 commit comments