Click here to Skip to main content
Click here to Skip to main content

Zena Sniffer Advanced

, 19 Jun 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
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.

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):

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:

  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)

Share

About the Author

amaletic

Croatia Croatia
No Biography provided

Comments and Discussions

 
QuestionZena Adapter c# application help PinmemberMember 1124808421-Nov-14 13:13 
GeneralMy vote of 5 PinmemberLydia Gabriella16-Jul-14 11:55 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 19 Jun 2014
Article Copyright 2014 by amaletic
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid