Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET access to 802.15.4 Wireless Transceiver

Tags:

c++

python

c#

Dear Stack Overflow community,

I'm writing in hopes that you might be able to help me connect to an 802.15.4 wireless transceiver using C# or C++. Let me explain a little bit about my project. This semester, I spent some time developing a wireless sensor board that would transmit light, temperature, humidity, and motion detection levels every 8 seconds to a USB wireless transceiver. Now, I didn't develop the USB transceiver. One of the TA's for the course did, and he helped me throughout the development process for my sensor board (it was my first real PCB).

Now, I've got the sensor board programmed and I know it's sending the data to the transceiver. The reason I know this is that this TA wrote a simple python module that would pull the latest packet of information from the transceiver (whenever it was received), unpack the hex message, and convert some of the sensor data into working units (like degrees Celsius, % relative humidity, etc.)

The problem is that the python module works on his computer (Mac) but not on mine (Windows 7). Basically, he's using a library called zigboard to unpack the sensor message, as well as pyusb and pyserial libraries in the sketch. The 802.15.4 wireless transceiver automatically enumerates itself on a Mac, but runs into larger issues when running on a PC. Basically, I believe the issue lies in the lack of having a signed driver. I'm using libusb to generate the .inf file for this particular device... and I know it's working on my machine because there is an LED on my sensor board and on the transceiver which blink when a message is sent/received. However, when I run the same python module that this TA runs on his machine, I get an error message about missing some Windows Backend Binaries and thus, it never really gets to the stage where it returns the data.

But, the larger issue isn't with this python module. The bigger issue is that I don't want to have to use Python. This sensor board is going to be part of a larger project in which I'll be designing a software interface in C# or C++ to do many different things (some of which is dealing with this sensor data). So, ultimately I want to be able to work in .NET in order to access the data from this transceiver. However, all I have to go on is this python sketch (which wont even run on my machine). I know the easiest thing to do would be to ask this TA more questions about how to get this to work on my machine... but I've already monopolized a ton of his time this semester regarding this project and additionally he's currently out of town. Also, his preference is python, where as I'm most comfortable in C# or C++ and would like to use that environment for this project. Now, I would say I'm competent in electronics and programming (but certainly not an expert... my background is actually in architecture). But, if anyone could help me develop some code so I could unpack the sensor message being sent from board, it would be greatly appreciated. I've attached the Python sketch below which is what the TA uses to unpack his sensor messages on his machine (but like I said... I had issues on my windows machine). Does anyone have any suggestions?

Thanks again.

from zigboard import ZigBoard
from struct import unpack
from time import sleep, time

zb = ZigBoard()
lasttime = time()

while True:
    pkt = zb.receive()
    if pkt is None:
        sleep(0.01)
        continue
    if len(pkt.data) < 10:
        print "short packet"
        sleep(0.01)
        continue

    data = pkt.data[:10]
    cmd, bat, light, SOt, SOrh, pir = unpack("<BBHHHH", data)
    lasttime = time()

    d1 = -39.6
    d2 = 0.01 

    c1 = -2.0468
    c2 = 0.0367
    c3 = -1.5955E-6

    t1 = 0.01 
    t2 = 0.00008

    sht15_tmp = d1 + d2 * float(SOt);
    RHL = c1 + c2 * SOrh + c3 * float(SOrh)**2
    sht15_rh = (sht15_tmp - 25.0) * (t1 + t2 * float(SOrh)) + RHL

    print "address: 0x%04x" % pkt.src_addr
    print "temperature:", sht15_tmp
    print "humidity:", sht15_rh
    print "light:", light
    print "motion:", pir
    print
like image 636
andyopayne Avatar asked May 15 '12 00:05

andyopayne


1 Answers

Thanks everyone for the help. The key to everything was using LibUSBDotNet. Once I had installed and referenced that into my project... I was able to create a console window that could handle the incoming sensor data. I did need to port some of the functions from the original Zigboard library... but on

like image 60
andyopayne Avatar answered Nov 17 '22 11:11

andyopayne