nRF5 IoT SDK
v0.9.0
|
Use the following procedure to establish a connection between an nRF5x device and the Linux router. Depending on the Linux variant that you are using, the commands may differ slightly.
Some of the commands, like loading the 6LoWPAN module or setting the PSM value, can be called only once per Linux session. If you are not familiar with the required Linux commands, check the following sections for more information about each command.
Several of the commands require administrator credentials, so you should log in as a root user by issuing the sudo su
command.
Current versions of the Linux kernel provide support for 6LoWPAN in Bluetooth low energy in a stand-alone module. The module must be compiled and enabled. After initializing the module, you will have access to the essential debugfs files.
You must initialize the module after each reboot. Once initialized, you do not need to repeat the steps for each connection.
In most Linux distributions, the debugfs file system is mounted to /sys/kernel/debug. However, Raspbian OS does not automatically mount the debugfs file system. Therefore, you must mount it manually before 6LoWPAN can use it:
You must mount the debugfs file system once after every reboot. Alternatively, you can make the mount persistent by editing the /etc/fstab file.
To initialize the 6LoWPAN module, you must first load it:
Enable the bluetooth_6lowpan module:
To verify that the module is indeed loaded:
To use 6LoWPAN communication, both a GAP connection and an L2CAP connection oriented channel must be established. You can control both of them by issuing the debugfs command 6lowpan_control
. Use this command to connect a device to or disconnect it from the Linux router.
The parameters of this command are:
To establish a 6LoWPAN connection:
To disconnect a device from the router:
HCI commands are used to configure Bluetooth devices. The device name hciX is assigned to the device installed in the system.
To display basic status information, for example, about interface type, BD address, MTU, and flags (up, running, ...):
To check that the Bluetooth device installed in the system has low-energy support:
To reset the HCI device hciX (to ensure that it is cleared before starting):
To discover all advertising devices:
Figure 1 displays an example of the output of the hcitool
command.
To list all connected BLE devices:
You can use the ifconfig
command to display and configure Linux network interfaces that are currently active. After successfully establishing a 6LoWPAN connection, you should see a newly added btX interface on the list.
To display all active network interfaces:
Specify an interface name (for example, bt0) to display information about that interface:
Communication between Linux and the device through IPv6 can use different types of protocols. One of these protocols is ICMPv6, which has diagnostic capabilities by sending and receiving echo request and echo response messages.
Use the IPv6 link-local address (see Creating link-local IPv6 addresses) to ping a specific device:
Send an echo request to an IPv6 multicast all nodes address to discover all devices that are currently attached to the router:
In this case, not only the device will respond, but also the btX interface itself.
The device will only send an echo response message if the application supports it (for example, when using Nordic's stack).