Software apps and online services
Hand tools and fabrication machines
With som many connected devices cropping up in the market and engineers finding new ways to connect a thing to the internet, we are at the crossroads of every increasing SMART things and the network requirements to support them.
This tutorial would concentrate on the 6LowPAN technology. What is 6LowPAN:
6LowPAN is an acronym of IPv6 over Low-Power Wireless Personal Area Networks. 6LowPAN is the name of a concluded working group in the Internet area of the IETF.
The 6LoWPAN concept originated from the idea that "the Internet Protocol could and should be applied even to the smallest devices," and that low-power devices with limited processing capabilities should be able to participate in the Internet of Things.
The 6LoWPAN group has defined encapsulation and header compression mechanisms that allow IPv6 packets to be sent and received over IEEE 802.15.4 based networks. IPv4 and IPv6 are the work horses for data delivery for local-area networks, metropolitan area networks, and wide-area networks such as the Internet. Likewise, IEEE 802.15.4 devices provide sensing communication-ability in the wireless domain. The inherent natures of the two networks though, are different.
So essential its Ipv6 over a non-conventional radio protocol that inherently doesn't support TCP-IP. BLE is one such radio and via the IPSP profile, supports the 6LowPAN stack.
A good reading on the Nordic IPSP support:So whats the big deal ?
Okay, so we are essentially going to send TCP-IP packets over Bluetooth LE. Great. whats the user though. Well to put it short, we dont need dependence on Wifi for all our so called SMART equipment. any thing that has a 6LowPAN compatible radio and the stack support can participate in a 6LowPAN mesh and communicate with the world.
The downside though is that for such devices to actually post information to the internet, they need an intermediate base station or in terms of 6LowPAN ; a bridge. This appliance will act as a 6LowPAN network interface for your computer. It will *not* be a node of the network that you'll be able to ping or do anything, it will just convert ethernet+IPv6 frames to 802.15.5+6LowPAN frames
Now that we know some basics into 6LowPAN and its possible use cases, lets jump into the actual implementation.Enter Zephyr OS
The Zephyr™ Project is a scalable real-time operating system (RTOS) supporting multiple hardware architectures, optimized for resource constrained devices, and built with security in mind.
Some of the awesome features of the OS:
Connectivity protocols optimized for resource constrained devices
- Open Source
Neutrally governed, established and proven development model
Developers can customize for their device needs
Developed with security in mind
Well, all this makes Zephyr OS a much needed kick to the IoT OS landscape. The OS is supported by the linux foundation as well and major players in the semicondictor industry are pledging their support for the OS in their hardware.The Hardware:
The iTracker module is a very unique board. It hosts a plethora of connectivity options like:
- Nb-IoT provided by the Quectel M35 chipset
- Bluetooth provided by the nordic nrf52832 chipset
- GPS provided by the Quectel L70-R chipset
Not just that a host of on board sensors are available as well:
- Opt 3001 light sensor
- LIS3dh Triple axis accelerometer
- Lis2mdl Triple axis magnetic field sensor
- Bme280 Barometric pressure and temperature sensor
Phew !! that is a lot of connectivity and a lot of sensors for such a small module
Some of the use cases for this module are:
- Vehicle Tracker and fleet management
- Personnel positioning
- Home security
- Safety monitoring for children/elders
- Animal husbandry and protection
There will be some SKUs available for the board with on board support for NB-Iot or 4g/CAT m1 supported modules from Quectel. so make sure you decide on the model that you prefer to work on.Setting up your build environment:
I would be running this setup on a ubuntu machine running 16.04 (later versions should also work) and make sure that you have a bluetooth 4.0 dongle with you and your on the latest kernel to ensure that you can run the Bluez tools to enable a ipv6 over ble connectivity.Download the Zephyr OS source code:
Open a shell session on your ubuntu machine and inside a folder of your choice run the follwing commands:
git clone https://github.com/zephyrproject-rtos/zephyr.git
This will clone the latest zephyr OS
Zephyr currently supports the following Nordic ICs:
- nRF51822 (all variants)
Important note on custom or additional boards: If your board is similar to one of the above supported ones but does not include a 32KHz external crystal, you may have to include the following lines in your prj.conf:
First we need to obtain and install a toolchain. The following toolchains are supported as of date for developing ZephyrOS for nrf52:
- Linux: Zephyr SDK, GCC ARM Embedded
- macOS: GCC ARM Embedded
Assuming we go with GCC ARM Embedded and that you have a working native compiler and basic toolset on your machine, you can then follow the steps below:
- Download and unpack GCC ARM Embedded to the folder of your choice. In this manual we will assume you've unpacked it in ~/gccarmemb/
- Export the following environment variables:
$ export GCCARMEMB_TOOLCHAIN_PATH="~/gccarmemb/" $ export ZEPHYR_GCC_VARIANT=gccarmemb
- At the root folder of your freshly cloned repository, run:
$ source zephyr-env.sh
Now you are ready to build. Let's start with a simple beacon example:
$ cd samples/bluetooth/ipsp $ mkdir build && cd build $ cmake -DBOARD=nrf52_pca10040 .. $ make
- To flash the image into the board you will need to download and install the JLink Software and Documentation Pack and the nRF5x command-line tools. Additional information about Segger J-Link in Nordic nRF5x boards can be found in the Nordic nRF5x Segger J-Link doc page
- Now you are ready to use nrfjprog to erase and program the board:
$ nrfjprog --eraseall -f nrf52 $ nrfjprog --program outdir/nrf52_pca10040/zephyr.hex -f nrf52 $ nrfjprog --reset -f nrf52
hurray you have built the IPSP sampel for the nrf52 microcontroller. Now lets get to the interesting part. Getting ipv6 over BLE !!!Testing your firmware for ipv6 connectivity.
Once the device is flashed successfully with the firmware, it down to making your ubuntu box connect to the nrf52 IPSP service profile via BLE and send and receive ipv6 packets.
To test IPSP please take a look at samples/net/README, in addition to running echo-client you must enable 6LowPAN module in Linux with the following commands (as root):
# modprobe bluetooth_6lowpan# echo 1 > /sys/kernel/debug/bluetooth/6lowpan_enable
The itracker board does have two pins that can be converted to the UART signal for getting messages over UART but it requires slight modification to the firmware wich we will cover in the next set of tutorials. IF needed, you can use the RTT API from the nordic iot sdk and convert all your printf statements to RTT printf statements.
A good example of RTT viewer setup is provided in this tutorial:
You may scan for your board on the host. The modern way to do that is using
bluetoothctl utility (included in the recent versions of BlueZ package) and its
scan on command:
$ bluetoothctl [NEW] Controller A3:24:97:EB:D6:23 ubuntu-0 [default] [NEW] Device CC:5C:D&:19:24:91 Zephyr [bluetooth]# scan onDiscovery started [NEW] Device AB:91:FE:33:CA:34 Zephyr
bluetoothctl shows all BLE (and likely, BT/EDR) devices it knows about. As discussed above, the IPSP uses static random addresses, so entries for previously connected devices, as shown above, can accumulate and become stale. You need to be extra careful to find an entry for the active address. The best approach may be to reset your board after issuing
scan on command. This way it will reinitialize with the BLE address which will be discovered after the command.
As an alternative to
bluetoothctl, you can use the legacy
hcitool utility which talks directly to hardware and always shows fresh scan results:
$ sudo hcitool lescanLE Scan ... CC:5C:D&:19:24:91 (unknown) CC:5C:D&:19:24:91 Test IPSP node
After you have found the board's BLE address, connect to the board (as root):
# echo "connect <bdaddr> <type>" > /sys/kernel/debug/bluetooth/6lowpan_control
<bdaddr> is the BLE address and
<type> is BLE address type: 1 for public address and 2 for random address. As you can see from the IPSP sample output above, it uses a static random address. So, with the sample output above, the command will be:
# echo "connect CC:5C:D&:19:24:91 2" > /sys/kernel/debug/bluetooth/6lowpan_control
Once connected a dedicated interface will be created, usually bt0. You can verify this with the following command:
# ifconfig bt0 Link encap:UNSPEC HWaddr F8-2F-A8-FF-FE-EB-6D-8C-00-00-00-00-00-00-00-00 inet6 addr: fe80::fa2f:a8ff:feeb:6d8c/64 Scope:Link UP POINTOPOINT RUNNING MULTICAST MTU:1280 Metric:1 RX packets:2 errors:0 dropped:3 overruns:0 frame:0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:92 (92.0 B) TX bytes:233 (233.0 B)
As can be seen from the output, only a link-local IPv6 address was assigned to the interface.
At this point, you can test IPv6 connectivity (and discover your board's IPv6 address) by pinging "All local-link nodes" IPv6 address:
# ping6 -I bt0 ff02::1 PING ff02::1(ff02::1) from fe80::fa54:a8ff:feeb:218f bt0: 56 data bytes 64 bytes from fe80::fa54:a8ff:feeb:218f: icmp_seq=1 ttl=64 time=0.088 ms 64 bytes from fe80::c9af:14ff:fe57:d86e: icmp_seq=1 ttl=64 time=285 ms (DUP!)
The IPSP sample includes builtin echo server for UDP and TCP on a port 4242, which we can test with:
$ telnet 2001:db8::1 4242 Trying 2001:db8::1... Connected to 2001:db8::1. Escape character is '^]'. Hellow world Hellow world hi all hi all ^] telnet> quit Connection closed.
In the output above, first
test line was typed, next was echoed back by the board. Likewise for
test2. To quit telnet tool, type Ctrl+], then "quit" at the prompt.
As an alternative to using well-known networking tools above, and also to test both TCP and UDP echo, you can use Zephyr's helper tool in the GitHub
$ echo-client -i bt0 <ip>
There you have it guys your first venture into ipv6 over BLE territory. Our next tutorials will venture deeper into this realm, connecting other devices over this stack and creating mesh of devices communicating with each other over 6LowPAN