Home/Support/Support Forum/AF_ZIGBEE Not Defined
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

AF_ZIGBEE Not Defined

0 votes
I'm writing a simple C# application to connect to an X2e ZB Ethernet module via SSH and execute a python script to act as an intermediary between my computer and a network of devices with Digi Zigbee modules in them. Whether executed from the python terminal through PuTTY or my C# application running a script uploaded to the X2e, I'm getting the same issue, so I don't think it's a problem with the SSH connection or my application. The python code I execute in either case is:

from socket import *
sd = socket(AF_ZIGBEE, SOCK_DGRAM, ZBS_PROT_TRANSPORT)

and the error I get is:

NameError: name 'AF_ZIGBEE' is not defined

Any help would be appreciated. I'm sure I'm missing something simple, but I can't figure out what it is.

Thanks,
Jeremy
asked Feb 4, 2014 in Python by CHSH New to the Community (10 points)

Please log in or register to answer this question.

2 Answers

0 votes
Figured it out in case somebody else has the same problem. This may only be an issue with the new shiny ConnectPort X2e ZB (I'm using the Ethernet model) since the older black X2 with an external antenna doesn't require this additional line of code. To interpret the AF_ZIGBEE definition another module called 'zigbee' is needed, and this must be imported before you import 'socket'.

from zigbee import *
from socket import *

sd = socket(AF_ZIGBEE, SOCK_DGRAM, XBS_PROT_TRANSPORT)

The above code will run without error (fixed the ZBS->XBS typo as well). My issue now is that it doesn't function .. at least not the same as it did before when running on the X2. The full code is:

from zigbee import *
from socket import *

sd = socket(AF_ZIGBEE, SOCK_DGRAM, XBS_PROT_TRANSPORT)

sd.bind(("", 0xe8, 0, 0))

while 1:
payload, src_addr = sd.recvfrom(128)
print payload


Previously (though without the zigbee import line) this code running on an X2 would wait until it received a message from a zigbee module in the network destined for the controller (address 0) then print the message to the console. Running on the X2e, adding the import zigbee line lets it run without error, but it doesn't do anything. If anybody has experience running a similar basic communication script on one of the new X2e's and can offer some insight, let me know!

Thanks,
Jeremy
answered Feb 5, 2014 by CHSH New to the Community (10 points)
0 votes
Hi Jeremy, in my project, I import the xbee module instead of zigbee module and it works fine.
Here is my code.
import sys, os
import xbee
from socket import *

sd = socket(AF_XBEE, SOCK_DGRAM, XBS_PROT_TRANSPORT)

sd.bind(("", 0xe8, 0, 0))
while 1:
payload, src_addr = sd.recvfrom(8192)
for i in range(len(payload)):
print ord(payload),
print ""

Hope it will be helpful for you.
answered Feb 27, 2014 by zdyang New to the Community (1 point)
...