Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Zena Sniffer Advanced

3.00/5 (2 votes)
19 Jun 2014CPOL2 min read 13.7K   10  
This tip solves the problem of filtering and getting correct date time information on zigbee package with ZENA sniffer.

Introduction

Microchip zena sniffer for zigbee network has user interface with couple of disadvantages:

  • Can’t filter saved messages
  • Can’t see current date time of package (you can get only relative timestamp of package arrival from start of program and that is only in micro seconds)
  • Can't export packages in format suitable for custom processing and analyzing

These disadvantages make zena software very hard to use on a large amount of messages. It is practically inusable for analyzing huge amount of data.

So I decided to fix this problem by creating Windows application that can communicate with USB ZENA driver, parse captured messages and then put it in database. This enables you to analyze stored data in database using SQL, create reports, etc.

Background

Windows ZENA driver (MPLABComm) is based on Linux port of libusb to Windows (libusb-win32 ) driver. To communicate with driver, I used LibUSBDotNet USB library.

How to communicate to Zena using libusb I found online in these articles:

I adopted the upper functionality and source code from Linux c to .NET C#

LibUsbDotNetLibrary can be found at:

Driver and ZENA description can be found at:

Using the Code

To be as simple as possible, in the project I attached with this tip, I removed functionality to store data in database. Message arrival from ZENA device is indicated by message box, you can easily change that code to store data to database, file, etc.

The main limitation of project attached is that I parsed only subset of zigbee messages (only messages that my end device and coordinator are using) but you will get the idea how it is done. I used standard ZENA tool to figure out structure off each zigbee message that I use.

Code Snippets

First thing you have to do is to get a list of available ZENA devices connected to your computer. You can do it like this.

C#
List<USBDeviceDescriptor> devices = UsbZenaAccess.GetAllDevices();

Then you must start sniffer like this (third argument of function is zigbee channel byte value between 11 and 26):

C#
USBDeviceDescriptor selected = (USBDeviceDescriptor)devices[0];
ZenaAccesss = new UsbZenaAccess(selected.Pid, selected.Vid, (byte)26));
ZenaPackageProcess.StartProcessing(ZenaAccesss);

Parsing of arrived zigbee massages is in this code:

C#
public static void StartProcessing(UsbZenaAccess usbZenaAccess)
      {
          ZenaPackage zd;
          ZenaData current;
          Thread t = (new Thread(() =>
                                     {
                                         while (true)
                                         {
                                             current = usbZenaAccess.CollectedPackages.FirstOrDefault();
                                             if (current != null)
                                             {
                                                 zd = Populate(current);
                                                 MessageBox.Show("Message arrived " + zd.CommandType);

                                                 usbZenaAccess.CollectedPackages.RemoveAt(0);
                                             }
                                             else
                                             {
                                                 System.Threading.Thread.Sleep(5000);
                                             }
                                         }
                                     }));
          t.IsBackground = true;
          t.Priority = ThreadPriority.Lowest;
          t.Start();
      }

History

  • First version of this article

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)