Building a Thread Router Eligible End Device Application Part 2.

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:16 PM - edited ‎01-10-2017 01:55 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 1 by adding a handler for a CoAP message.

 

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 REED
  1. Go back to the ISC configuration file which we created in the previous exercise (ThreadReed200EFR32.isc).
  2. Navigate to the "Plugins" tab:
      a. Select "CoAP Dispatch".
        b. Remove "CoAP Debug" as there are some conflicts.
  3. Under the "Other" tab:
      a. Add a CoAP Dispatch item.
          i. Change Method to POST.
          ii. Change URI Path to "reed/toggle".
          iii. Change Handler to "reedToggleHandler".
  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 Projects in Simplicity Studio IDE
  1. In thread-callbacks.c add the following code to have the node respond to CoAP messages. This Handler will respond to "reed/toggle" URI, toggle an LED on the WSTK, and print a statement to the console.

void reedToggleHandler(void) {
  EmberCoapCode responseCode;
 
  halToggleLed(BOARD_ACTIVITY_LED);

  responseCode = EMBER_COAP_CODE_204_CHANGED;
  emberCoapRespond(responseCode, NULL, 0);
 
  emberSerialPrintf(APP_SERIAL, "\nToggled LED\n");
}

  2. Build your project and ensure that it completes with zero errors.

III. Load Application to All WSTKs
  1. In Network Analyzer perspective, click on a node for your application and disconnect from the device (for the EFR32). Then 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. Bringing Nodes Back Into the Network
  1. In Network Analyzer perspective, navigate to the node's console and use the resume command.

network-management resume

  2. Do this for all nodes.

V. Sending CoAP messages
  1. In the console send a CoAP POST message to your neighbor using their IP address and unique URI to toggle the LED using coap post <destination> <uri> <body>

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