Low Power Wireless: 6LoWPAN, IEEE802.15.4 and the Raspberry Pi

What's going on here? Linux is part of the UNIX family of operating systems (including BSD, among many others). They all have quirks, and source code authors have to deal with those. There have been many tools to make this management easier, and wpan-tools uses autoreconf to build a configuration file, then configure to work out the specifics of your RPi system so that when you make your application, all of the correct pieces are in place.

The result of this is that the application iwpan is now in the /usr/bin directory for use.

You're nearly there! Remember in the kernel configuration you set the 6LoWPAN and device drivers to be dynamic modules. They won't have been installed by default like you would expect modules to be. That's what all this device tree stuff is about—bringing devices into the system when it can't detect them normally. So the next step is to load the modules:

sudo modprobe at86rf230

Then lsmod should include something like this:

Module                  Size  Used by
ieee802154_6LoWPAN     19335  0
6LoWPAN                13191  8 nhc_fragment,ieee802154_6LoWPAN
at86rf230              22211  0
mac802154              49035  1 at86rf230
ieee802154             55698  2 ieee802154_6LoWPAN,mac802154
crc_ccitt               1278  1 mac802154

And now—ta-da!—iwpan list shows something like this:

wpan_phy phy0
supported channels:
page 0: 11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26
current_page: 0
current_channel: 13,  2415 MHz
cca_mode: (1) Energy above threshold
cca_ed_level: -77
tx_power: 4
iftypes: node,monitor
page 0:
[11]  2405 MHz, [12]  2410 MHz, [13]  2415 MHz,
[14]  2420 MHz, [15]  2425 MHz, [16]  2430 MHz,
[17]  2435 MHz, [18]  2440 MHz, [19]  2445 MHz,
[20]  2450 MHz, [21]  2455 MHz, [22]  2460 MHz,
[23]  2465 MHz, [24]  2470 MHz, [25]  2475 MHz,
[26]  2480 MHz
tx_powers: 4,3.7,3.4,3,2.5,2,1,0,-1,-2,-3,-4,-6,-8,-12,-17
cca_ed_levels: -91,-89,-87,-85,-83,-81,-79,-77,-75,-73,-71,
(1) Energy above threshold
(2) Carrier sense only
(3, cca_opt: 0) Carrier sense with energy above threshold
 ↪(logical operator is 'and')
(3, cca_opt: 1) Carrier sense with energy above threshold
 ↪(logical operator is 'or')
min_be: 0,1,2,3,4,5,6,7,8
max_be: 3,4,5,6,7,8
csma_backoffs: 0,1,2,3,4,5
frame_retries: 0,1,2,3,4,5,6,7
lbt: false
Supported commands:

Your 6LoWPAN device is now known to the Linux system.

Configuring 6LoWPAN

So now you have a new kernel, you have the at86rf230 device recognized, and the 6LoWPAN networking stack is in place. The final steps are to configure networking and bring the device up. You likely are used to Wi-Fi networks having an SSID. IEEE802.15.4 networks have a similar concept, a PAN ID. Two devices will be on the same network only if they have the same PAN ID. You use iwpan to set this:

iwpan dev wpan0 set pan_id 0xbeef

The ID of 0xbeef isn't fixed, but every example seems to use it!

Then, you bring up the interface using normal networking tools:

ip link add link wpan0 name lowpan0 type lowpan
ifconfig wpan0 up
ifconfig lowpan0 up

What have you got now? ifconfig returns something like this:

lowpan0   Link encap:UNSPEC  HWaddr
inet6 addr: fe80::ec0b:fb0f:76b9:f393/64 Scope:Link
RX packets:38 errors:0 dropped:0 overruns:0 frame:0
TX packets:39 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:5205 (5.0 KiB)  TX bytes:5205 (5.0 KiB)

wpan0     Link encap:UNSPEC  HWaddr
RX packets:58 errors:0 dropped:0 overruns:0 frame:0
TX packets:55 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:300
RX bytes:4111 (4.0 KiB)  TX bytes:4904 (4.7 KiB)

The interface wpan0 is the wireless device. The interface lowpan0 is the 6LoWPAN network device, just like eth0, the loopback device and so on. Note how it has an IPv6 address, but no IPv4 address—this is next-generation IP only!


Jan Newmarch has written many books and papers about software engineering, network programming, user interfaces and artificial intelligence, and he is currently digging into the IoT.