Building a Thread Router Eligible End Device Application Part 1.

by <a href="http://community.silabs.com/t5/Welcome-and-Announcements/Community-Ranking-System-and-Recognition-Program/m-p/140490#U140490"><font color="#000000"><font size="2">Hero Employee</font></font> </a> kpszupin on ‎12-26-2016 04:08 PM - edited on ‎02-20-2017 03:20 AM by Administrator Siliconlabs

A step-by-step guide to creating, building, and running your own Router Eligible End Device (REED) application based on the Silicon Labs Thread stack. Before tackling this tutorial, please checkout "Building Silicon Labs Thread Sample Applications" tutorial first.

 

This tutorial is part of a three part series:

Building a Thread Router Eligible End Device Application Part 1.

Building a Thread Router Eligible End Device Application Part 2.

Building a Thread Router Eligible End Device Application Part 3.


Requirements:

Software:
 - Simplicity Studio v4
 - Silicon Labs Thread Stack 2.0.0
 - IAR Workbench 7.30

Hardware:
 - EFR32MG Wireless Starter Kit (WSTK)

I. Launch Simplicity Studio and start a blank application
  1. Make sure at least two nodes are present with EFR32s under Devices.
  2. Go to File -> New -> Silicon Labs AppBuilder Project.
  3. Check on "Start with a blank application". Click Next.
  4. Name your project. For example ThreadReed200EFR32.
  5. In next window (Project Setup), check if Simplicity Studio detected correct board, part, and toolchain. In this example we're using BRD4153A, EFR32MG1P132F256GM48, and IAR ARM 7.30.

II. Configuring REED
  1. Under the "General" tab:
      a. Update the "Device name" to project's name (ie ThreadReed200EFR32).
      b. Open "Device type" dialog:
          i. Select EFR32 and add device to "Selected devices and plugins".
          ii. Select SoC and add device to "Selected devices and plugins".
          iii. Select Router and add device to "Selected devices and plugins".
          iv. Close dialog by clicking OK.
  2. Under the "HAL" tab:
      a. Set Bootloader to Application type.
      b. Set the Application serial port to USART0 (Port 1).
      c. Check "USART0 (port 1)" box. This will be our communication line to the chip.
  3. Under the "Printing" tab:
      a. Make sure "Enable debug printing" is checked.
      b. Make sure under functional area Core and Application are checked in both "Compiled in" and Enabled at startup".
  4. Under the "Plugins" tab:
      a. Add CoAP Debug under the Common section. This will give us CoAP debug output in the console.
      b. Add ICMP Debug under the Common section. This will give us ICMP debug output in the console.
  5. Under the "Callbacks" tab:
      a. Select emberFormNetworkReturn - check "Is Used"; Stub should be check automatically.
      b. Select emberJoinNetworkReturn.
      c. Select emberResumeNetworkReturn.
      d. Select emberResetNetworkStateReturn.
  6. Under the "Other" tab, we do not have anything to add.
  7. Click "Generate". Notice project appeared in Project Explorer. Click OK.
  8. Save ISC file by going to File -> Save.

III. Add Code and Build Projects
  1. Go to Simplicity IDE perspective. In Project Exploror, expand your Reed project.
  2. Add the following code to thread-callbacks.c file. The functions should already be available after generating the project through AppBuilder. This will give us some useful output in the command line.

 

void emberFormNetworkReturn(EmberStatus status) {
  boolean success = (status == EMBER_SUCCESS);
  emberSerialPrintf(APP_SERIAL, "\nForm %s\n", success ? "complete" : "failed");
}
void emberJoinNetworkReturn(EmberStatus status) {
  boolean success = (status == EMBER_SUCCESS);
  emberSerialPrintf(APP_SERIAL, "\nJoin %s\n", success ? "complete" : "failed");
}
void emberResetNetworkStateReturn(EmberStatus status) {
  boolean success = (status == EMBER_SUCCESS);
  emberSerialPrintf(APP_SERIAL, "\nReset %s\n", success ? "success" : "failed");  
}
void emberResumeNetworkReturn(EmberStatus status) {
  boolean success = (status == EMBER_SUCCESS);
  emberSerialPrintf(APP_SERIAL, "\nResume %s\n", success ? "success" : "failed");
}


  3. Compile your project by right-clicking on project name and using "Build project" option.
  4. Make sure your build is successful and the compiled binary is located in project directory tree under "IAR ARM - Debug" folder.
 
IV. Load Application and Bootloader to EFR32MG module on WSTK
  1. As described in "Building Thread Sample Applications" section 7. Load the Reed application and booltoader to two available devices.

V. Adding nodes to a network using pre-commissioning
  1. In Network Analyzer perspective, in the Devices view, right-click on a node and select "Connect" then right-click again and select "Launch Console".
      a. Navigate to "Serial 1" tab and press the return key a few times to get a prompt.
      b. Find out the state of your device using the "Info" command. The output should output network status of 0x00 (EMBER_NO_NETWORK).
      c. If your device has an ip address, reset the network parameters by issuing the command:

 network-management reset

  2. For the first device on the network we will need to form the network
      a. Set the master key issuing command:       

network-management set-master-key {00112233445566778899AABBCCDDEEFF} 

      b. Set network parameters for the network using network-management form <channel:1> <power:1> <node type:1> [<network id:0--16> [<ula prefix>]

network-management form 25 3 2 "Honey Badger" "FD00:0DB8::"

      c. Check network status using the info command. Network status should be 0x03 (EMBER_JOINED_NETWORK_ATTACHED).

  3. For the second node (or any node after)
      a. In the "Serial 1" console make sure the node is not already in a network.
      b. Set Commissioning information for the device. Note the PAN ID, Extended PAN ID, and Network ID are set by the Leader (our first node on the network). Use the info command on the Leader node to get proper parameters for the network. Using network-management commission <preferred channel:1> <power:1> <network id:0--16> <ula prefix> <extended pan id:8> <key:16> <pan id:2>

network-management commission 25 0 "Honey Badger" "FD00:0DB8::" {1234ABCD1234ABCD} {00112233445566778899AABBCCDDEEFF} 0xd00d

  4. Join the pre-commissioned device to the network.
      a. Use the command network-management join-commissioned <power:1> <node type:1> [<require connectivity:1>]

network-management join-commissioned 3 2 0

  5. Check the status of the node by using the info command. Network status should be 0x03 (EMBER_JOINED_NETWORK_ATTACHED).

VI. Sending Messages
  1. In the Console ping one of the devices in the network, for example ping the Leader's IP address using icmp ping <destination>

icmp ping "fd00:db8::d9dd:b493:143b:9cbc"

  2. In the Console send a CoAP POST message using coap post <destination> <uri> <body>

coap post "fd00:db8::d9dd:b493:143b:9cbc" "reed/notice" "1"