Click here to Skip to main content
15,885,059 members
Articles
Tip/Trick
(untagged)

Zena Sniffer Advanced

Rate me:
Please Sign up or sign in to vote.
3.00/5 (2 votes)
19 Jun 2014CPOL2 min read 13.2K   10   7   4
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)


Written By
Croatia Croatia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionWhat I am looking for but where is the code? Pin
slelong28-Oct-18 1:45
slelong28-Oct-18 1:45 
QuestionWhere can i download`the code? Pin
Member 1153787718-Mar-15 22:46
Member 1153787718-Mar-15 22:46 
I cant find the download link oO?
QuestionZena Adapter c# application help Pin
Member 1124808421-Nov-14 12:13
Member 1124808421-Nov-14 12:13 
GeneralMy vote of 5 Pin
Lydia Gabriella16-Jul-14 10:55
Lydia Gabriella16-Jul-14 10:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.