Building a Thread Router Eligible End Device Application Part 3.

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 ‎12-26-2016 04:23 PM - edited ‎01-10-2017 01:57 PM

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. This tutorial expands on Part 2 by adding a button event for the LED toggle and capturing the associated network traffic.

 

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
 - Generated project for Router Eligible End Device.

Hardware:
 - EFR32MG Wireless Starter Kit (WSTK)

I. Updating Configuration for the Reed
  1. Go back to the ISC configuration file we have been working on (ThreadReed200EFR32).
  2. Navigate to the "Callbacks" tab.
      a. Select "halButtonIsr".
  3. Under the "Other" tab:
      a. Add an Event item under Event Configuration section. This will link an event to a button press.
          i. Set Command to "eventToggle".
          ii. Set Callback to "eventToggleHandler".
  4. Click "Generate". AppBuilder will ask you to validate the generation to make sure which files can be overwritten. Make sure thread-callbacks.c is UNCHECKED. Click OK.
  5. In the "Generation successful" window click OK.
  6. Save the ISC file.

II. Add Code and Build Project in Simplicity Studio IDE
  1. In thread-callbacks.c add the following code to have the node send out a CoAP Broadcast message.

static const EmberIpv6Address allMeshNodes = {
  {0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,}
};

static const uint8_t reedToggleUri[] = "reed/toggle";
EmberEventControl eventToggle;

void eventToggleHandler(EmberStatus status) {
  emberEventControlSetInactive(eventToggle);
 
  halToggleLed(BOARD_ACTIVITY_LED);
 
  emberAfCorePrintln("Broadcast to ");
  emberAfCoreDebugExec(emberAfPrintIpv6Address(&allMeshNodes));
  emberAfCorePrintln("");  
 
  status = emberCoapPostNonconfirmable(&allMeshNodes,
                                       reedToggleUri,
                                       NULL, // body
                                       0);   // body length
}

 2. In thread-callbacks.c add interrupt service routine for the button state.

void halButtonIsr(uint8_t button, uint8_t state) {
 if ((state == BUTTON_PRESSED) && (button == BUTTON0)) {
   emberEventControlSetDelayMS(eventToggle, 10);
 }
}

 3. Compile your project and Ensure that the build completes with zero errors.

III. Load Application to All WSTKs
  1. In Network Analyzer perspective, click on a node for your application and select "Flash/Upload".
  2. Upload only the updated application. This time DO NOT erase the chip because we want to keep the network parameters saved in non-volatile memory.
  3. Repeat for all nodes.

IV. Capture Network Traffic
  1. Set Network Analyzer decode to the appropriate Thread stack by going to Window -> Preferences -> Network Analyzer -> Decoding -> Stack Versions. (Please note, there is an auto-detection decoder stack however, if you have multiple protocols in the air in your space, then we recommend selecting the specific stack).
  2. Make sure your master-key is available in Window -> Preferences -> Network Analyzer -> Decoding -> Security Keys. If it is not there add a new security key by clicking on the "Add" button.
  3. In Network Analyzer perspective, in the Device view, right-click on a node and select "Start capture with options"
      a. May need to select "Connect" first if icon beside node name is not showing green.
  4. In capture options specify PAN ID. This allows you to narrow the data captured to the specific PAN ID.

V. Bringing the Reed Back into Network
  1. In console bring the node back up by using the resume command.

network-management resume

  2. Do this for all nodes. Management traffic should start showing in the network capture.

VI. Sending Messages
  1. Press Button0 on WSTK board. Console will print when the node is broadcasting. Nodes with URI "reed/toggle", will toggle their LEDs. The network capture will show CoAP messages.