OpenThread

Javier Sanchez edited this page Mar 21, 2017 · 27 revisions

OpenThread

OpenThread is an open-source implementation of the Thread networking protocol. With OpenThread, Nest is making the technology used in Nest products more broadly available to accelerate the development of products for the connected home.

The Thread specification defines an IPv6-based reliable, secure and low-power wireless device-to-device communication protocol for home applications. More information about Thread can be found on threadgroup.org.

The Firefly platform has been widely used to test and develop with OpenThread, thus although the RE-Mote is a great choice as well, we focus on the Firefly as the de-facto choice for OpenThread due to:

  • Its simple form factor and more pins available for generic use
  • Dual radio enabled as default with on-board antennas (no need for external ones to start working)
  • Works at 3VDC, it can be powered over 2xAA or 2xAAA batteries, even a coin-cell!
  • The USB-A connector allows to easily plug and play to any host (Raspberry Pi, laptop, etc), event connect multiple devices in a single USB hub to easily deploy a testbed on your own

Install

The #148 Pull Request added support for the CC2538 system-on-chip, the same used in the RE-Mote or the Firefly, hurray!

The following instructions assume you are using Linux and alike, in a nutshell we will first clone the OpenThread repository, the toolchain to compile the examples and the necessary scripts to flash the Zolertia RE-Motes.

sudo apt-get update
sudo apt-get install gcc-arm-none-eabi gdb-arm-none-eabi
sudo apt-get install python-pip
pip install intelhex
pip install python-magic

Get the base code and flash installer:

cd $HOME
git clone --recursive https://github.com/openthread/openthread
git clone --recursive https://github.com/JelmerT/cc2538-bsl
cd openthread

The next steps are platform-dependent to the Firefly, if you want to test the OpenThread as it is you can safely omit the following instructions, and jump to the next section.

git remote add zolertia https://github.com/Zolertia/openthread
git fetch zolertia
git checkout pull/zolertia-firefly

The pull/zolertia-firefly branch will add support for the following peripherals:

And the following sensors:

We will expand this list and add more sensors and actuators.

These peripherals and resources has been added to the CLI example (command line interface), allowing to control and command the Firefly over command line.

Compile and program a Zolertia Firefly

To compile the Firefly (CC2538-based)` example:

./bootstrap
make -f examples/Makefile-cc2538 clean && make -f examples/Makefile-cc2538
arm-none-eabi-objcopy -O binary output/bin/arm-none-eabi-ot-cli-ftd output/bin/arm-none-eabi-ot-cli-ftd.bin

To flash the binary to the Firefly:

Connect the Firefly to an USB port:

There's no need to manually unlock the bootloader, the on-board PIC on the Firefly will automatically handle this.

And run the following command:

python $HOME/cc2538-bsl/cc2538-bsl.py -e -w -v -p /dev/ttyUSB0 -a 0x00200000  output/bin/arm-none-eabi-ot-cli-ftd.bin

Note the /dev/ttyUSB0 is the USB port to which the Firefly is connected, to find out you can run this command:

dmesg | grep ttyUSB
[ 1390.565238] usb 3-2: *cp210x converter now attached to ttyUSB0*

Running the CLI and your first OpenThread application

The OpenThread CLI exposes configuration and management APIs via a command line interface. This CLI may be used to play with OpenThread and may be used along side additional application code. The OpenThread test scripts use this CLI to execute test cases.

A comprehensive list of the available commands in available at:

https://github.com/Zolertia/openthread/blob/pull/zolertia-firefly/src/cli/README.md

Firefly custom commands

The following are specific CLI commands implemented for the Firefly in the pull/zolertia-firefly branch:

ADC

Retrieve a reading from any of the available ADC channels. Note: The ADC0 and ADC1 channels are reserved for the serial-to-USB communication to the device, thus are restricted and the application will return an error if selected.

The command has the following syntax:

adc <pin>

Whereas pin can be any pin from 2 to 7. See the Firefly pin-out for more information on the location of the pins.

The command will return something as shown below:

> adc 5
5: 2280
Done

The result is 228.0 mV as the reading has one-digit precision.

Moisture Sensor

Also using the ADC channel the moisture sensor have to connected on ADC 5

First need enable the channel:

> moisture enable 
moisture enable
Done

Now can be read the value

> moisture value
moisture: 0
Done

The sensor send '0' when the soil is completely dry or is on the air.

And when the soil is wet the values is similar than:

> moisture value
moisture: 15792
Done

TEMPERATURE AND HUMIDITY

To measure the temperature and humidity, you can use the DHT22 sensor to give the temperature and/or humidity data writing in CLI dht22 :

> dht22 enable
Done

> dht22 readall
Temp: 25.0
Humidity 43.2
Done

Temperature range of -40 and 80ºC, and Humidity between 0-100% RH.

LEDS

The Firefly has RGB leds (red, blue and green), you can turn the leds on and off using the CLI.

The command has the following syntax:

leds <color> <state>

Where color could be either blue, red or green; and state is on or off.

The output should be similar to:

> leds red on
Done

Light sensor

To use this command a light sensor is required. As default the sensor is assumed to be connected to PC2 (SDA) and PC3 (SCL), check the Firefly pin-out to locate these pins.

You can change the pin configuration at the following line.

The command to request a light reading is shown below:

> light
214
Done

Relay

For actuate on high currents or voltages is possible use a relay this actuator have to connect on Firefly ADC pin

First it's need configure a pin as an output

> relay enable
relay enable
done

And now we can play using the following syntax:

relay <state>

Where state can be on or off

> relay off
relay off

Done

Configure the devices and network parameters

For this example you will need at least 2 x Firefly. Flash both devices as shown above and connect over USB.

You can use any serial console program like Putty or Minicom, using 115200 8/N/1 as configuration.

To test the CLI first retrieve the current channel

channel

This should return something like:

> channel
11
Done

Change the channel to 26 as follows:

channel 26

Read back the channel parameter to check it has been set.

Repeat the above for the second Firefly and also set/read the following parameters in both devices to be used later:

> extaddr
fd7fdbf2624f1f25
Done

> panid 1234
Done

> extpanid
dead00beef00cafe
Done

> ipaddr
fdde:ad00:beef:0:0:ff:fe00:0
fe80:0:0:0:0:ff:fe00:0
fdde:ad00:beef:0:3b99:9bab:4d1f:ac08
fe80:0:0:0:ff7f:dbf2:624f:1f25
Done

> networkname
OpenThread
Done

If you want to change the default values such as the channel number or PAN ID, src/core/mac/mac.cpp is the file to do so.

Create a wireless OpenThread network

We are assuming we have two Zolertia Fireflies, one connected in /dev/ttyUSB0 and the other in /dev/ttyUSB1. Let us start OpenThread by running the start command, wait a few seconds and check if we are the network leader using the state command.

> start
start
Done
> state
state
leader
Done

Now start the second node (the one connected in /dev/ttyUSB1 in our example):

> start
start
Done
> state
router
Done

Do an IEEE 802.15.4 Active Scan for available networks using the scan command, on the router device console should yield:

> scan
| J | Network Name     | Extended PAN     | PAN  | MAC Address      | Ch | dBm | LQI |
+---+------------------+------------------+------+------------------+----+-----+-----+
| 0 | OpenThread       | dead00beef00cafe | 04d2 | fd7fdbf2624f1f25 |  0 | -90 | 107 |
Done

Ping the leader device using the ping command

> ping fdde:ad00:beef:0:3b99:9bab:4d1f:ac08
> 16 bytes from fdde:ad00:beef:0:3b99:9bab:4d1f:ac08: icmp_seq=0 hlim=64

And likewise on the leader device console:

scan
| J | Network Name     | Extended PAN     | PAN  | MAC Address      | Ch | dBm | LQI |
+---+------------------+------------------+------+------------------+----+-----+-----+
| 0 | OpenThread       | dead00beef00cafe | 04d2 | 0001020304050607 |  0 | -96 | 101 |
Done

> ping fdde:ad00:beef:0:96fe:c89:516:282d
> 16 bytes from fdde:ad00:beef:0:96fe:c89:516:282d: icmp_seq=1 hlim=64
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.