Filter results by

ZigBee

ARTIK 5/7/10 and ARTIK 030 modules offer as standard the ZigBee®/Thread personal area network interface, using a built-in IEEE 802.15.4 radio. ZigBee is used primarily for control and monitoring of lights, sensors, switches, appliances, etc. and can be applied to both home and commercial/industrial automation.

The low-power ZigBee system allows devices within range of each other to autonomously form a "mesh" network that may include "star" grouping for endpoints.

Sleepy End Devices
Simple, battery-operated devices (like temperature sensors) form a star around a central parent device that routes their messages into the main mesh. These end devices wake up on their own schedule, check messages from / send status to their parent, and go back to sleep.
Powered End Devices
Line-powered devices or devices with higher-capacity or rechargeable batteries are used when immediate reaction is required (a controllable light, for example). These devices are typically router-capable.
Router capability
Router-capable devices can take part in a mesh and can be dynamically coordinated to select routes. Routers must stay active all the time and therefore are often line-powered.
Coordinator
One of these router devices becomes the Coordinator for the system and orchestrates forming / maintaining the network. The Coordinator can reorganize and reroute message travel paths as needed to adapt to changing conditions (device addition/removal, radio disturbances).

By using this hybrid topology, the range of the network between the most distant endpoints is extended considerably, with communication packets travelling by "hops" along the best route.

Nearly all ZigBee devices on the market (even "end" devices) act as routers. You'll also see that they'll often surprise you with their route choices!

ZigBee Application Tutorial

This tutorial makes use of the ZigBee software stack that is part of the Simplicity Studio® 4.0 development installation (see Prerequisites). The Simplicity tool generates custom source code according to the features you select. The code stack is the same across all ARTIK module ZigBee circuits, so you can expect consistent ZigBee programming.

When it comes to actually compiling the generated files, the approach differs depending on whether the application is Linux-based.

ARTIK 030 applications. Being designed for low-cost and CPU-efficient applications, the ARTIK 030 is not Linux-based. Its memory and processing capabilities are not sufficient for native compilation of code, so cross-compilation takes place on a separate PC.

  • To simply explore the device capabilities discussed in this tutorial, you can use pre-compiled images we have prepared for you to upload.

  • When you're ready to create custom ARTIK 030 applications, you'll use Simplicity Studio. You'll also need to license the IAR Embedded Workbench® ARM IDE tool to cross-compile the code on your development PC. Go to Custom A030 Applications for details.

ARTIK 520, 530, 710, and 1020 applications. The EM3587 ZigBee/Thread radio on the ARTIK module works with the Linux main processor on the module as a network co-processor (NCP), connected by a simple serial interface.

The NCP on the modules arrives with its "identity" pre-flashed as a ZigBee command processor. ZigBee application programs then run from the ARTIK main processor itself. The testing described in this article uses zigbee-test and zigbee-cli utility programs, based on the ZigBee API supported by starting zigbee-daemon.

To create and run custom applications of your own, you'll use the API just like the -test and -cli programs do. Network form and join operations are taken care of at your command, and you can easily turn lights on/off or dim them. The ZigBee API complements the ARTIK API, but one does not depend on installation of the other.

Optionally, you can code projects using the Simplicity Studio ZigBee stacks, similar to what you do for the ARTIK 030. In this case, you use your ARTIK 5/7/10 platform to compile the code natively (no compiler license is required), and install a pre-written NCP program. You won't use the ZigBee daemon, the API, or the utility programs.

Prerequisites

This tutorial works with a mix of ARTIK 030, 520, 530, 710, and 1020 boards. You'll need at least two. Once the devices are joined on the network, they will be able to send messages to each other.

  • Obtain any combination of the following boards: ARTIK 030, 520, 530, 710, or 1020.

  • If you intend to develop using the ZigBee software stack, you must register an ARTIK 030 development kit with Silicon Labs. The kit comes with three boards, so one kit is sufficient for testing.

  • For developing software using the stack, install Simplicity Studio 4.0 on your host PC. Have your ARTIK 030 board ready to plug in when you install the software, so that it is automatically recognized and the appropriate drivers installed.

You must register at least one ARTIK 030 kit to allow installation of the ZigBee stacks, even if you only use the stacks for ARTIK 5/7/10 boards.

We recommend that you read the ZigBee fundamentals document in your Simplicity Studio ZigBee installation, usually found at
C:\SiliconLabs\SimplicityStudio\v4\developer\stacks\znet\vx.x.x.x\protocol\zigbee_x.x
in the documentation folder:
\documentation\UG103-02-AppDevFundamentals-ZigBee.pdf

The time for completing the tutorial portion of this article is about an hour, including the download and installation time for necessary software. The basic steps will be:

  1. Prepare – load needed software and firmware onto the various board types
  2. Create – execute the commands to form and join the ZigBee network.
  3. Command – send ZigBee Cluster Library (ZCL) commands to try them out.

The pre-compiled A030 HaSample… images cannot act as Coordinator. For thorough testing, you'll need at least one other ARTIK 5/7/10 board.

Prepare ARTIK 5/7/10 Boards

Using one or more ARTIK 520, 530, 710, or 1020 kits, you'll build ZigBee device nodes to play with. Any of these board types can talk with any other one, as well as with ARTIK 030 boards prepared as described elsewhere.

You'll run all ZigBee utility and application programs on the ARTIK main processor, which will transfer commands to and return data from the NCP by way of the internal serial port (the same one used for flashing an NCP firmware update).

Two pre-built utility programs provide a shorthand method for testing, avoiding lengthy network form and join sequences to get right to ZCL commands. To create and compile your own application, you'll use ZigBee API calls. Refer to the artik_zigbee_test.c file in the ARTIK IDE section – it's the source for the program that we use here.

Install or update software

To prepare your board, you'll need to do some quick setup and installation checks.

Step 1. Set up repository to install/update software packages for ZigBee

Step 2. If needed, flash-update the NCP to re-establish its "identity" as ZigBee

Step 3. Verify that the internal serial port driver, called zigbee-daemon, is running.


Step 1: Install the latest ZigBee API packages

ZigBee NCP firmware is loaded to each Silicon Labs device by default at the ARTIK factory, making it "ZigBee-ready". However, the main processor firmware image may or may not include ZigBee driver and utility programs. As the latest ARTIK API release (rev. 1.2) introduces new features, you'll want to update to that revision in any case.

Module Firmware
release
Capabilities
520 A520-OS-1.0.0 ZigBee-ready but no ARTIK SDK
  A520-OS-2.0.0 daemon and rev. 1.1 utility programs built-in
530 A530-OS-1.0.0 daemon and rev. 1.1 utility programs built-in
710 A710-OS-1.0.0 daemon and rev. 1.1 utility programs built-in
  A710-OS-2.0.0 daemon and rev. 1.1 utility programs built-in
1020 A1020-OS-1.1.0 ZigBee-ready but no ARTIK SDK

If you have Ubuntu, you are already set up as required. Skip this part.

For Fedora only:

  1. Pull up the ARTIK SDK Installation article, and follow the instructions to:

    1. Set up dnf access to the ARTIK repository and its up-to-date packages

    2. Make sure you enter the last command as indicated:
         dnf makecache --refresh

    3. Install the ARTIK SDK (only if you are using an older build without it).

  2. Update to the latest SDK files (including ZigBee) by entering
       dnf update

  3. Install the latest ZigBee daemon by running:

    1. dnf remove zigbeed
    2. dnf install zigbeed

You can verify that you have the updated version (1.2) by entering:
   dnf info libartik-sdk-zigbee

If you have the rev. 1.1 API version installed and would like a reference to that older version instead, you can find the article here.

Step 2: Load the ZigBee NCP firmware if needed

The Silicon Labs chip is configured at the factory to give it a ZigBee identity. Normally you will not need to change this. But if the factory NCP image has been replaced (for Thread operation, for example), you will need to flash back the appropriate ZigBee NCP firmware before proceeding. Refer to NCP Update for details.

Step 3: Check that the ZigBee daemon is running

For all platforms, you'll need to enable the ZigBee daemon, a driver that manages the internal serial port traffic. It should start automatically with the latest packages installed.

Check whether it is running.
systemctl status zigbee-daemon

If not, you need to either:

  • Manually start it after each reset:
    systemctl start zigbee-daemon

  • Set it to start itself automatically on each reset:
    systemctl enable zigbee-daemon

If zigbee-daemon is not operating in the background, the ZigBee applications and utility programs will not work.

Completion

Your ARTIK 5/7/10 boards are now ready for ZigBee testing.

Continue below if needed to prepare ARTIK 030 boards, or jump to Create ZigBee Network if you are not using any ARTIK 030 devices.

Prepare ARTIK 030 Boards

Using the ARTIK 030 kit, you'll build a pair of ZigBee device nodes to play with. The pre-built examples we'll use are designed to form a network automatically when used with suitably prepared ARTIK 5, 7, and/or 10 boards.

Upload Images

You will first be uploading different images to two ARTIK 030 development boards. If you have already followed the ARTIK 030 Software Getting Started Guide instructions, then you'll have a better understanding of what we present here.

However, our ARTIK 5/7/10 pre-built utility programs and daemon do not support ZigBee 3.0, so you'd need to repeat the exercise using the Simplicity HaSampleSwitchSoc and HaSampleLightSoc projects instead. Or just use our pre-compiled images!

  1. Download zigbee_tutorial_17-01-15.zip; unzip and save the HaSampleSwitchSoc.s37, HaSampleLightSoc.s37, and ZBbootloader.s37 files on your PC (shown below saved in the c: root).

  2. Run the Simplicity Studio 4.0 program and go to the Simplicity IDE view.

  3. Connect both boards to your PC using their USB cables, making sure the board switches are set to 'AEM'. The devices appear on the left of the screen with identifier numbers. You'll use these numbers to distinguish between HaSampleLightSoc and HaSampleSwitchSoc applications in the following steps.

  4. Upload the HaSampleSwitchSoc.s37 image to one of the ARTIK 030 boards.
    Repeat using the HaSampleLightSoc.s37 image to the other board.

    1. Left-click to select a device.
    2. Note its number to associate with the application (light or switch).
    3. Right-click and choose Upload application… (see note below if not clickable).
    4. Browse to your downloads; select the HaSampleSwitchSoc.s37 or HaSampleLightSoc.s37 file as the main image.
    5. Click the "Bootloader" checkbox.
    6. For a bootloader, under the directory
      C:\SiliconLabs\SimplicityStudio\v4\developer\stacks\znet\
       vx.x.x.x\protocol\zigbee_x.x
      find and select
      \tool\bootloader-efr32mg1p132f256gm48\
      serial-uart-bootloader\serial-uart-bootloader.s37

    7. Click Erase chip so that the chip will be cleared before upload.
    8. Click OK.

Launch Terminal Console

  1. Open terminal emulator consoles to send commands and check status.
    1. Select both devices (Ctrl-left-click on the second one).
    2. Right-click and select Launch Console.

    Once you launch the console, Simplicity automatically connects over the J-Link serial bus. If you need to upload a different image later, hit Disconnect to again make the Upload application… selection clickable.

  2. The console windows default to a tabbed format where you can only see one at a time. Let's rearrange them and pre-select the active terminal tab we'll be using.

    1. Click on and drag one of the tabs to the top, bottom, left, or right of the window; you'll see how it will split the window depending on where you release. A side-by-side view is helpful for our purposes.

    2. Click on each main tab and select the Serial 1 sub-tab on each console window.

  3. With the cursor in the bottom command entry box of the console window, hit the Enter key to get a prompt. If you see it, you're set up now to begin testing.

Create ZigBee Network

You'll need to pick one of your ARTIK 5/7/10 boards to be Coordinator. All other ARTIK 030/5/7/10 boards will be joiners.

ARTIK 030: The pre-built images have a built-in network join feature. Just press PB0!

The ARTIK 030 HA application as written defines the buttons like this:

PB0 if not joined: JOIN
  if joined: PERMIT JOINING
PB1 if not joined: FORM (if the device is capable of forming)
  if joined: BIND (send ZDO end device bind request)

ARTIK 5/7/10: Operation is by console using zigbee-test, which is menu-driven and has three menu levels.

MENU 1

Select the functionality
the ARTIK module
will exhibit, then

[0] to go to next menu.
<pre>1: On/Off Switch
2: Level Control Switch   
3: On/Off Light
4: Dimmable Light
5: Light Sensor
6: Remote Control
0: ADD DEVICE DONE </pre>
<pre>





—–» to MENU 2</pre>

MENU 2

Create the network

[5] leave
[1] form + permit join
  »  join each device
then

[8] to begin testing.
<pre>1: Form network
2: Form network (advance)
3: Join network
4: Join network (advance)
5: Leave network
6: Get network state
7: Discover device
8: Start testing
9: Network permit join
10: Network find and join
11: Network stop scan</pre>
<pre>« as COORDINATOR

« as END DEVICE




—–» to MENU 3
« as COORDINATOR</pre>

MENU 3

Test devices in the
network

[1] verify join list
[3] devices blink/beep
<pre>1: Get device information
2: Auto test
3: Identify
4: On/off
5: Level control
6: Illuminance measurement
7: Remote Control
8: Commissioning target start
9: Commissioning target stop
10: Commissioning initiator start
11: Commissioning initiator stop</pre>


Type [0]
to return
to MENU 2

Get up and running quickly

Entries like [1] indicate keyboard numbers only (do not type the brackets).

  1. Set up each ARTIK 5/7/10 board. On the terminal console, type:
    1. systemctl start zigbee-daemon [Enter]
    2. zigbee-test [Enter]
    3. [1] [Enter] for on/off switch (you could also choose on/off light)
    4. [Enter] by itself, to accept the default endpoint assignment
    5. [0] [Enter] to finish.

    You will now be on Menu 2.

  2. Leave any pre-existing networks.
    • On each ARTIK 5/7/10 console, type [5] [Enter]
    • On each ARTIK 030 console, type network leave
  3. Establish one of the ARTIK 5/7/10 boards as Coordinator. On its console, type:
    1. [1] [Enter] to form a network
    2. Wait
    3. When you see 'FIND FORM', it's done forming and is in the pjoin phase.
  4. From other devices, join the network within 60s:
    • A030 – Press PB0
    • A5/7/10 – Type [3] [Enter]
    • Any other ZigBee device you may have – follow its joining procedure.

That's it! You've set up a network. All devices can communicate now. Type [8] [Enter] on the Coordinator console to move to Menu 3, and then [1] [Enter] to see the Node ID ('device id'), EUI (MAC address), and cluster information of each connected device.

Connect step-by-step

You've seen how to quickly connect devices. Now we'll try it one step at a time with the command line interface (CLI). You'll later send ZCL light on-off commands this way.

Start with boards prepared as follows.

ARTIK 030 boards Launch consoles in Simplicity. You've pre-loaded each device function as either HaSampleSwitchSoc or HaSampleLightSoc.
ARTIK 5/7/10 boards Use the terminal emulator to start the daemon and then run
zigbee-cli ON_OFF_SWITCH or zigbee-cli ON_OFF_LIGHT

Here we manually create a network and join it. The software stacks are still doing most of the work, but you have to use the somewhat wordy CLI interface to get things going.

  1. To find out whether any devices are already connected, type
      info
    on each console, and look to see whether panID values match. (Note: This won't show any output on zigbee-cli unless you have enabled a journal.)

  2. We want to start fresh, so we want them to not match. In each console, type
      network leave

  3. Verify, using a subsequent info command, that the panID value for any one device no longer matches that of another.

  4. On the device you have chosen to be Coordinator, type
      network find unused
    Remember that this won't work on an A030 with the pre-built images, which were built without Coordinator capability enabled.

  5. Again on the Coordinator, type
      network pjoin 90
    to permit joining for 90 seconds by other devices.

  6. On each of the other devices, type
      network find joinable
    You should see the "Device Announce" message on each console.

It's worth trying this exercise several times in different configurations to make sure you understand how it works. If you're on top of it and want to skip the additional details below, jump right to entering a ZCL command.

Compare code methods

Let's review how this all works. You can use various combinations of ARTIK 030, 5, 7, and 10 devices, along with other ZigBee-compatible devices, for a ZigBee network. Interacting with the different devices is mostly the same aside from some "shortcut" differences.

All ARTIK ZigBee devices use the same command line interface (CLI), although you could choose to remove this extension in your own custom code.

  • The ARTIK 030 code for HaSwitch and HaLight enables the CLI through the Simplicity console, which is very interactive and provides a lot of feedback. The code also configures the buttons on the board for shortcut methods as explained below.

  • The ARTIK 5/7/10 support is provided by an API, which we interact with using two utility programs:

    • zigbee-test provides shortcut methods similar to the A030 board, but uses the console numeric keys instead
    • zigbee-cli implements the same CLI as the Simplicity console, but requires a journal to be enabled if you want to see its output.

The A030 HaSampleLightSoc and HaSampleSwitchSoc pre-built images have the Coordinator feature disabled. If you want your ARTIK 030 to have the ability to form a network as Coordinator, just modify, regenerate, and recompile the code to enable the Coordinator role.

Here's how the applications compare. If you're wondering where the ARTIK 5/7/10 list comes from, it's in the ZigBee API example code that you'll work with here.

ACTIVITY ARTIK 5/7/10
zigbee-test
ARTIK 030
Initialize as Light select [3] upload HaLight or press RESET
Initialize as Switch select [1] upload HaSwitch or press RESET
Initialize as
Dimmable Light
select [4] *
Initialize as
Level Control Switch
select [2] *

* Not available in the ARTIK 030 pre-built binary files, but you can generate it in Simplicity Studio

Here are the steps to form and join the network. Remember, the A030 code we're using is not enabled to be Coordinator, but as a Router, so the PB1 functions are not available.

# Coordi
nator
End Dev/
router
CLI method
(all ARTIK)
ARTIK 5/7/10
'test' shortcut
ARTIK 030
shortcut
1. Leave existing network Leave existing network network leave type [5] none
2. Form a new network   network form (ch) (pwr) (PAN ID) * type [1] and wait for form complete push PB1 *
3. Permit joining   network pjoin (sec) starts automatically after form complete
or type [9]
push PB1 *
4.   Join the network network find joinable type [3] push PB0

* Not available in the pre-built program, but can be included before you generate it in Simplicity Studio

Note that the ARTIK 5/7/10 shortcut key [1] first forms the network, and then does a one-time pjoin. If you later want to let more devices join, use [9] to start another pjoin or do it manually in zigbee-cli.

Channel and Power. Networks can be formed on different IEEE 802.15.4 frequency channels, and at a specified transmission power.

PAN ID. The Personal Area Network (PAN) ID has to match for all devices. Multiple ZigBee networks can be overlaid, each with a different PAN ID, and there will be no "eavesdropping" possible between networks.

CLI Example

Using the CLI, have the Switch on ARTIK 5/7/10 form a network on channel 25, power 3, PAN ID of 0xabcd, and give the ARTIK 030 Light 15 seconds to join.

On ARTIK 5/7/10 Switch:

zigbee-cli ON_OFF_SWITCH
network leave
network form 25 3 0xabcd
network pjoin 15

On ARTIK 030 Light:

network leave
network find joinable

You should see an indication on the ARTIK 030 console that it has joined PAN 0xabcd.

If you were successful, feel free to jump right to entering a ZCL command.

Hardware Example

In the example above, the ARTIK 5/7/10 Switch is the Coordinator and the ARTIK 030 Light is a simple router. Even though the router cannot form a network, it can become a parent to local end devices.

Let's say you have a smart button that you want to add to the existing network. The button uses all the same commands as you've seen above, but implements them using hardware "tricks" since it has no connection to a terminal console.

Leave network

  1. Force the smart button to leave any existing network.

    1. Pry out battery drawer
    2. Hold down on button
    3. Reinsert battery (you'll get a steady red LED)
    4. Keep button held for 2 seconds ("network leave")

Join button to network

  1. Set the ARTIK 030 Light to permit joining.
    1. Press PB0 ("network pjoin 30")
  2. Command the smart button to join.

    1. Pry out battery drawer again
    2. Hold down on button
    3. Reinsert battery again but RELEASE button just after LED turns red
      ("network find joinable")
    4. Observe that the LED turns a dim blue and blinks
    5. Verify that it finds the network and the LED turns green to indicate NETWORK_JOINED

Bind button to light

  1. Put the ARTIK 030 Light into EZ-Mode commissioning.

    1. Press PB1 ("enable ez-mode commissioning" for 10s)
    2. Press PB0 ("permit join")
  2. Command the smart button to send a join request and identify query.

    1. Tap the button three times rapidly
  3. Watch the action on the ARTIK 030 console.

    1. Observe the identify payload message.

The button is now bound to the light. It may take a few tries for you to understand the sequence. Note also that some of these buttons have known battery contact issues. But once you get around those you'll find this sequence is reliably reproducible.

When you click the button, you'll now see a message like this on the ARTIK 030 console to indicate ON:

Rx len 3 ep 01 clus 0x0006 (on/off) FC 01 seq 72 cmd 01

and one like this to indicate OFF:

Rx len 3 ep 01 clus 0x0006 (on/off) FC 01 seq 73 cmd 00

For your convenience, we summarize the example smart button controls in this table. Some are undocumented, we report only what we have seen during testing.

Prior State Action Smart Button Function
Joined to previous network Insert battery with button held 2s
(make sure no devices are permitting joining at this time)
network leave
(LED steady red)
Not joined Insert battery with button held; release immediately on seeing red network find joinable
(LED flashes blue )
Joining Coordinator permits join Joined but not bound
(LED steady green then off)
Joined but not bound Tap button 3x zcl identify query
Joined but not bound Tap button 5x issues "rejoin request", "update device", and "device announce"
Joined and bound Press button zcl on-off ON
Joined and bound Release button zcl on-off OFF

Troubleshooting

If you have trouble getting ZigBee networks set up, make sure you have used network leave (or a known hardware equivalent) on all devices to tear down previous networks before starting a fresh one. Pressing a device reset button alone is generally not sufficient.

Before starting the zigbee-test or zigbee-cli program, you can run this command to provide debug output that "follows" events live, as they occur.
   journalctl -f | grep zigbeed &

You'll get messaging to help track down issues.

  • Running the journal is the only way to see output from the zigbee-cli program.

  • You may find that the On/Off test of the zigbee-test program will incorrectly report "there is no endpoint to send on/off command" unless you run the journal.

  • An alternative use of the command:
    journalctl -f -o"cat" &
    strips off the date stamp for cleaner output. You can't pipe this one to grep since it strips off the sort term "zigbeed", so you will also see other system events.

You can instead simply dump the output of journalctl to a file to review it at any time (not following it live).

Last updated on: