|
| 1 | +# How to set 6lowpan communication between Raspbian and Nuttx. |
| 2 | + |
| 3 | +This guide will show how to set-up a Raspberry Pi 3 (RPI) running Raspbian and an Olimex STM32 E407 board running NuttX to have 6lowpan communication between them. |
| 4 | + |
| 5 | +## What do we need? |
| 6 | + |
| 7 | +- Raspberry Pi 3 |
| 8 | +- micro-SD card (almost 16gb) with Raspbian lite already installed. |
| 9 | +- Olimex-STM32-E407 board. |
| 10 | +- Two PMODRF2 module which are base on the MRF24J40 module. |
| 11 | +- PC with Ubuntu (It works fine with Ubuntu 16.04) |
| 12 | + |
| 13 | +## How to set-up 6lowpan RPI? |
| 14 | + |
| 15 | +First, we need to connect the PMODRF2 module to the RPI, so we need to set the next connections: |
| 16 | + |
| 17 | +| | RPI | PMODRF2 | |
| 18 | +| -- | -- | -- | |
| 19 | +| VIN | 1 | 12 | |
| 20 | +| GND | 20 | 11 | |
| 21 | +| RESET | 17 | 8 | |
| 22 | +| INT | 16 | 7 | |
| 23 | +| SDI | 19 | 2 | |
| 24 | +| SDO | 21 | 3 | |
| 25 | +| SCK | 23 | 4 | |
| 26 | +| CS | 26 | 1 | |
| 27 | + |
| 28 | +In the next links you can see the pinout of each board: |
| 29 | +[- Raspberry Pi 3 pinout.](https://i.pinimg.com/originals/84/46/ec/8446eca5728ebbfa85882e8e16af8507.png) |
| 30 | +[- PMODRF2 pionut.](https://reference.digilentinc.com/reference/pmod/pmodrf2/start) |
| 31 | + |
| 32 | +Once you've set all the wires, power-on the RPI and download the next repository inside the RPI. |
| 33 | +https://github.com/micro-ROS/micro-ROS-bridge_RPI |
| 34 | + |
| 35 | +Execute the next command: |
| 36 | +```sudo ./micro-ROS-bridge_RPI/RPI_6lowpan/script.sh``` |
| 37 | + |
| 38 | +If everything goes fine, at the end of the script, the board should restart. After the start-up, type the next command to see if the configuration and the connection are fine: |
| 39 | +```dmesg | grep mrf24j40``` |
| 40 | + |
| 41 | +And if everything is fine, it should return the next: |
| 42 | +```bash |
| 43 | +pi@raspberrypi:~ $ dmesg | grep mrf24j40 |
| 44 | +[ 4.075212] mrf24j40 spi0.0: probe(). IRQ: 169 |
| 45 | +``` |
| 46 | +The last point is to set-up the network. |
| 47 | + |
| 48 | +- Set the PAN ID: ``sudo iwpan dev wpan0 set pan_id 0xabcd`` |
| 49 | +- Set the page and channel: ``sudo iwpan phy phy0 set channel 0 26`` |
| 50 | +- Set the short address: ``sudo iwpan dev wpan0 set short_addr 0x4204`` (Each board must a different one) |
| 51 | +- Attach the phy layer to the lowpan: ``sudo ip link add link wpan0 name lowpan0 type lowpan`` |
| 52 | +- Bring up the WPAN0 interface: ``sudo ip link set wpan0 up`` |
| 53 | +- Bring up the RPI lowpan: ``sudo ip link set lowpan0 up`` |
| 54 | + |
| 55 | + |
| 56 | +Now the RPI is ready to send and receive messages from a NuttX board or another RPI. |
| 57 | + |
| 58 | + |
| 59 | +## How to set-up 6lowpan NuttX? |
| 60 | + |
| 61 | +First, we need to do the connections between the Olimex board and the PMODRF2 module. |
| 62 | + |
| 63 | +- `Board D13` -> `MRF24J40 SCLK` |
| 64 | +- `Board D12` -> `MRF24J40 MISO` |
| 65 | +- `Board D11` -> `MRF24J40 MOSI` |
| 66 | +- `Board D10` -> `MRF24J40 CS` |
| 67 | +- `Board D8` -> `MRF24J40 INT` |
| 68 | + |
| 69 | +Once the wiring is finished, we need to compile and upload the firmware. Type the next commands: |
| 70 | + |
| 71 | +o to the main folder of NuttX and type the command to configure the board: |
| 72 | +`./scripts/configure.sh olimex-stm32-e407 mrf24j40-6lowpan` |
| 73 | + |
| 74 | +Compile: |
| 75 | +`make` |
| 76 | + |
| 77 | +Upload: |
| 78 | +`./scripts/flash.sh olimex-stm32-e407` |
| 79 | + |
| 80 | +It should return somenthing like this: |
| 81 | + |
| 82 | +- Configuration: |
| 83 | +``` |
| 84 | +Copy files |
| 85 | +Refreshing... |
| 86 | +``` |
| 87 | +- Compilation: |
| 88 | +``` |
| 89 | +CP: nuttx.hex |
| 90 | +CP: nuttx.bin |
| 91 | +``` |
| 92 | +- Upload the firmware |
| 93 | +``` |
| 94 | +wrote 131072 bytes from file nuttx.bin in 3.763846s (34.008 KiB/s) |
| 95 | +Info : Listening on port 6666 for tcl connections |
| 96 | +Info : Listening on port 4444 for telnet connections |
| 97 | +``` |
| 98 | +(The number of written bytes could be different in each board) |
| 99 | + |
| 100 | + |
| 101 | +Finally, connect the mini USB cable to the USB OTG2, and the console should return the next: |
| 102 | + |
| 103 | +```bash |
| 104 | +nsh> ? |
| 105 | +help usage: help [-v] [<cmd>] |
| 106 | + |
| 107 | + [ cd df help ls mw set true |
| 108 | + ? cp echo hexdump mb ps sh uname |
| 109 | + addroute cmp exec ifconfig mkdir pwd sleep umount |
| 110 | + basename dirname exit ifdown mh rm test unset |
| 111 | + break dd false ifup mount rmdir telnetd usleep |
| 112 | + cat delroute free kill mv route time xd |
| 113 | + |
| 114 | +Builtin Apps: |
| 115 | + udp_6lowpan ping6 i8sak |
| 116 | +``` |
| 117 | +
|
| 118 | +We're going to configure the network. Execute udp_6lowpan. |
| 119 | +The program will ask you if you want to configure the network. Type **Y** to start the configuration process. |
| 120 | +**Important note:** If you don't configure the network, the connection won't be possible with other boards.** |
| 121 | +
|
| 122 | +Then will ask you if you want to set this board as a coordinator or as a node. |
| 123 | +The difference between a coordinator and a node is that the first one can work as a router, coordinating the network traffic of up to 8 nodes. |
| 124 | +On the other hand, the node is an endpoint device which only sends and receive data, it doesn't coordinate the traffic of the other devices. |
| 125 | +
|
| 126 | +For this example, we will set ``coordinator``. |
| 127 | +
|
| 128 | +Finally will ask for an ID. This ID must be unique for each board. If everything goes fine, this should return the next: |
| 129 | +
|
| 130 | +```bash |
| 131 | +Your hardware address is: i8sak set eaddr 00:fa:de:00:de:ad:be:00 |
| 132 | + |
| 133 | +i8sak: accepting all assoc requests |
| 134 | +i8sak: daemon started |
| 135 | +ifup wpan0...OK |
| 136 | +Mounting proc file system |
| 137 | +wpan0 Link encap:6LoWPAN HWaddr 00:be:ad:de:00:de:fa:00 at UP |
| 138 | + inet6 addr: fe80::2be:adde:de:fa00/64 |
| 139 | + inet6 DRaddr: ::/64 |
| 140 | + |
| 141 | + RX: Received Fragment Errors |
| 142 | + 00000000 00000000 00000000 |
| 143 | + IPv6 Dropped |
| 144 | + 00000000 00000000 |
| 145 | + TX: Queued Sent Errors Timeouts |
| 146 | + 00000000 00000000 00000000 00000000 |
| 147 | + Total Errors: 00000000 |
| 148 | + |
| 149 | + |
| 150 | + |
| 151 | + |
| 152 | +Available commands |
| 153 | + -To send a package type: write |
| 154 | + -To receive a package type: read |
| 155 | + -To exit type: quit |
| 156 | + |
| 157 | +``` |
| 158 | +
|
| 159 | +** At this point the network is ready to work!** |
| 160 | +
|
| 161 | +Finally type ``quit`` two times to close the app and come back to the main menu. |
| 162 | +
|
| 163 | +## Sending a message from NuttX to Raspbian: |
| 164 | +
|
| 165 | +### Raspberry Part: |
| 166 | +
|
| 167 | +We need to check our IP, so type in the console: ```ifconfig``` |
| 168 | +This should return something like this: |
| 169 | +
|
| 170 | +```bash |
| 171 | +eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 |
| 172 | + inet 192.168.1.173 netmask 255.255.255.0 broadcast 192.168.1.255 |
| 173 | + inet6 fe80::47b1:3e6c:17fa:a06a prefixlen 64 scopeid 0x20<link> |
| 174 | + ether b8:27:eb:69:5b:e7 txqueuelen 1000 (Ethernet) |
| 175 | + RX packets 538496 bytes 394976364 (376.6 MiB) |
| 176 | + RX errors 0 dropped 2416 overruns 0 frame 0 |
| 177 | + TX packets 358285 bytes 51814460 (49.4 MiB) |
| 178 | + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
| 179 | + |
| 180 | +lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 |
| 181 | + inet 127.0.0.1 netmask 255.0.0.0 |
| 182 | + inet6 ::1 prefixlen 128 scopeid 0x10<host> |
| 183 | + loop txqueuelen 1000 (Local Loopback) |
| 184 | + RX packets 48 bytes 7076 (6.9 KiB) |
| 185 | + RX errors 0 dropped 0 overruns 0 frame 0 |
| 186 | + TX packets 48 bytes 7076 (6.9 KiB) |
| 187 | + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
| 188 | + |
| 189 | +lowpan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1280 |
| 190 | + inet6 fe80::a9cd:ff:fe00:4204 prefixlen 64 scopeid 0x20<link> |
| 191 | + inet6 fe80::9c6e:87a5:eb60:84d0 prefixlen 64 scopeid 0x20<link> |
| 192 | + unspec 9E-6E-87-A5-EB-60-84-D0-00-00-00-00-00-00-00-00 txqueuelen 1000 (UNSPEC) |
| 193 | + RX packets 2 bytes 132 (132.0 B) |
| 194 | + RX errors 0 dropped 0 overruns 0 frame 0 |
| 195 | + TX packets 95 bytes 9480 (9.2 KiB) |
| 196 | + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
| 197 | + |
| 198 | +wlan0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 |
| 199 | + ether b8:27:eb:3c:0e:b2 txqueuelen 1000 (Ethernet) |
| 200 | + RX packets 0 bytes 0 (0.0 B) |
| 201 | + RX errors 0 dropped 0 overruns 0 frame 0 |
| 202 | + TX packets 0 bytes 0 (0.0 B) |
| 203 | + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
| 204 | + |
| 205 | +wpan0: flags=195<UP,BROADCAST,RUNNING,NOARP> mtu 123 |
| 206 | + unspec 9E-6E-87-A5-EB-60-84-D0-00-00-00-00-00-00-00-00 txqueuelen 300 (UNSPEC) |
| 207 | + RX packets 61 bytes 4775 (4.6 KiB) |
| 208 | + RX errors 0 dropped 0 overruns 0 frame 0 |
| 209 | + TX packets 107 bytes 8199 (8.0 KiB) |
| 210 | + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
| 211 | +``` |
| 212 | +
|
| 213 | +The part which is important for us, is the next fragment: |
| 214 | +
|
| 215 | +``` bash |
| 216 | +lowpan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1280 |
| 217 | + inet6 fe80::a9cd:ff:fe00:4204 prefixlen 64 scopeid 0x20<link> |
| 218 | + inet6 fe80::9c6e:87a5:eb60:84d0 prefixlen 64 scopeid 0x20<link> |
| 219 | + unspec 9E-6E-87-A5-EB-60-84-D0-00-00-00-00-00-00-00-00 txqueuelen 1000 (UNSPEC) |
| 220 | + RX packets 2 bytes 132 (132.0 B) |
| 221 | + RX errors 0 dropped 0 overruns 0 frame 0 |
| 222 | + TX packets 95 bytes 9480 (9.2 KiB) |
| 223 | + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
| 224 | +``` |
| 225 | +
|
| 226 | +As you can see there is two IP in this network interface. But you need to remember the second one. We will use later with NuttX. |
| 227 | +`fe80::9c6e:87a5:eb60:84d0`` |
| 228 | + |
| 229 | +Go to the place where lives the repo that you downloaded previously. Go to ``micro-ROS-bridge_RPI/RPI_6lowpan/Examples/6lowpan_recv`` |
| 230 | +Finally, execute recv_demo telling to open the 61616 port. Type this command: ``./recv_demo 61616`` |
| 231 | + |
| 232 | +At this point, the RPI is ready to receive incoming packages. |
| 233 | + |
| 234 | +### NuttX part: |
| 235 | + |
| 236 | +Execute ``udp_6lowpan`` application. |
| 237 | +This will ask you if you want to configure the network. Type N, because is already configured. |
| 238 | +Now you're in the main menu of the App. Type ``write`` to start the sending mode and will ask for the next data: |
| 239 | +- The destination IP: This is the IP of the RPI which we saved previously. |
| 240 | +- The destination port: For this specific example is 61617. |
| 241 | +- The origin port: This is the port that we want to open to send the message, for example, we could use 61618. |
| 242 | +
|
| 243 | +At this point it should look like this: |
| 244 | +
|
| 245 | +``` bash |
| 246 | +nsh> udp_6lowpan |
| 247 | +Do you want to execute the automatic WPAN configuration? (y/n) |
| 248 | +
|
| 249 | +Available commands |
| 250 | + -To send a package type: write |
| 251 | + -To receive a package type: read |
| 252 | + -To exit type: quit |
| 253 | +Introduce the IVP6 Destination |
| 254 | +Introduce the port destination |
| 255 | +Introduce the port origin |
| 256 | +Conection data: |
| 257 | + -Dest_IP: fe80::857:adfe:5a82:c7ac |
| 258 | + -Dest_Port: 61616 |
| 259 | + -Origin_Port: 61617 |
| 260 | +Introduce a message to send: |
| 261 | +``` |
| 262 | +Now if you type somenthing and press enter NuttX should show the next: |
| 263 | +```bash |
| 264 | +Introduce a message to send: |
| 265 | +Sending 5 characters: hello |
| 266 | +``` |
| 267 | +
|
| 268 | +And the RPI, should show the next message: |
| 269 | +```bash |
| 270 | +Received (from fe80::2be:adde:de:fa00): hello |
| 271 | +``` |
| 272 | +
|
| 273 | +## Sending a message from the Raspbian to NuttX: |
| 274 | +
|
| 275 | +**Very important note! :** |
| 276 | +The Linux 6lowpan utility needs to have a ping response before sending a data package, but the ping implementation of NuttX is not compatible. So the solution for this problem is to send a message from NuttX to Linux, just to add the NuttX direction to the neighborhood table. |
| 277 | +
|
| 278 | +If this does not work, do as follow: |
| 279 | +
|
| 280 | +Check if the Nuttx address is part within the Linux/Raspbian neighborhood table. |
| 281 | +If it is, remove it: |
| 282 | +```bash |
| 283 | + $ ip neigh # a bunch of address shall appear including yours (if you send a |
| 284 | + message already) |
| 285 | + fe80::2be:adde:de:fa00 dev lowpan0 FAILED |
| 286 | + $ sudo ip neigh delete fe80::2be:adde:de:fa00 dev lowpan0 # Remove it. |
| 287 | +``` |
| 288 | +
|
| 289 | +Then once delete add the Nuttx device it permanently (until reboot): |
| 290 | +
|
| 291 | +```bash |
| 292 | + $ sudo ip neigh add fe80::2be:adde:de:fa00 dev lowpan0 00:be:ad:de:00:de:fa:00 # Add it with the |
| 293 | +corret Hardware address. |
| 294 | +``` |
| 295 | +
|
| 296 | +### NuttX part: |
| 297 | +First we need the ip of the board, so type ``ifconfig`` in the main menu. This should return somenthing like this: |
| 298 | +```bash |
| 299 | +wpan0 Link encap:6LoWPAN HWaddr 00:be:ad:de:00:de:fa:00 at UP |
| 300 | + inet6 addr: fe80::2be:adde:de:fa00/64 |
| 301 | + inet6 DRaddr: ::/64 |
| 302 | +
|
| 303 | + RX: Received Fragment Errors |
| 304 | + 00000000 00000000 00000000 |
| 305 | + IPv6 Dropped |
| 306 | + 00000000 00000000 |
| 307 | + TX: Queued Sent Errors Timeouts |
| 308 | + 00000000 00000000 00000000 00000000 |
| 309 | + Total Errors: 00000000 |
| 310 | +
|
| 311 | + IPv6 TCP UDP ICMPv6 |
| 312 | +Received 0000 0000 0000 0000 |
| 313 | +Dropped 0000 0000 0000 0000 |
| 314 | + IPv6 VHL: 0000 |
| 315 | + Checksum ---- 0000 0000 ---- |
| 316 | + TCP ACK: 0000 SYN: 0000 |
| 317 | + RST: 0000 0000 |
| 318 | + Type 0000 ---- ---- 0000 |
| 319 | +Sent 0000 0000 0000 0000 |
| 320 | + Rexmit ---- 0000 ---- ---- |
| 321 | +``` |
| 322 | +
|
| 323 | +For us is important to remember the **inet6_addr** which is: ``fe80::2be:adde:de:fa00`` |
| 324 | +
|
| 325 | +Execute ``udp_6lowpan`` app, type ``N`` to the configuration request and finally type read, to start the receiving mode. |
| 326 | +Type the port that you want to open, for example, the 61616. And it should look like this mean is waiting for the incoming message. |
| 327 | +
|
| 328 | +```bash |
| 329 | +Available commands |
| 330 | + -To send a package type: write |
| 331 | + -To receive a package type: read |
| 332 | + -To exit type: quit |
| 333 | +Introduce the reception port |
| 334 | +Listening on 61616 for input packets |
| 335 | +``` |
| 336 | +
|
| 337 | +### Raspbian Part: |
| 338 | +
|
| 339 | +Go to the places that lives the previous download repo. Then go to this folder: ``/micro-ROS-bridge_RPI/RPI_6lowpan/Examples/66lowpan_send`` |
| 340 | +
|
| 341 | +And execute with root privileges the next app: ``send_demo``. |
| 342 | +These demos have two arguments: The first is the port to open in the destination and the second is the destination IP. An example of this specific demo could be: |
| 343 | +``sudo send_demo 61616 fe80::2be:adde:de:fa00`` |
| 344 | +
|
| 345 | +This app returns any data. |
| 346 | +
|
| 347 | +On the other hand, in the NuttX board we will see the next: |
| 348 | +```bash |
| 349 | +Received 12 bytes from 80fe:0000:0000:0000:cda9:ff00:00fe:0442 port 39464 |
| 350 | +Received packet: Hola mundo ! |
| 351 | +``` |
0 commit comments