Python rookie assistance

Hi,

I am working on a school projekt for the subjekt called Technology.

where we want to use Zigbee to make a smart wireless light switch.
our prototype of the product should enable you to control lights from a computer with a zigbee connected to a USB port and then sending a wireless signal to another Zigbee with a Latching relay and a LED

However looking through the Digi Python programming code i cannot get the examples to work.

this is the example as written in the guide


#
# This example binds to application endpoint 0xe8,
# receives a single frames at this endpoint and then
# sends the frame's payload back to the originator
# using the radio's proprietary mesh transport.
#
# include the sockets module into the namespace:
from socket import *

# Create the socket, datagram mode, proprietary transport:
sd = socket(AF_ZIGBEE, SOCK_DGRAM, ZBS_PROT_TRANSPORT)
# Bind to endpoint 0xe8 (232):
sd.bind(("", 0xe8, 0, 0))
# Block until a single frame is received, up to 72 bytes:
payload, src_addr = sd.recvfrom(72)
# Send the payload back to the source we received it from:
sd.sendto(payload, 0, src_addr)

however after running i get following error

Traceback (most recent call last):
File “C:\Python26\Zigbee projekt\read_write.py”, line 11, in
sd = socket(AF_ZIGBEE, SOCK_DGRAM, ZBS_PROT_TRANSPORT)
NameError: name ‘AF_ZIGBEE’ is not defined

why is that ?
how do i import or define
AF_ZIGBEE, SOCK_DGRAM and ZBS_PROT_TRANSPORT

I’m still only a python beginner so bear with me if it’s a little obvious.

what is the difference between

from Socket Import *
and
Import Socket ??

(i know this is general python but instead of having to inquire 2 different places)

how does address to a zigbee work?
we are only using 2 zigbee’s.

thanks in advance :smiley:

I am having your same problem :frowning:

import sys

Used for receiving samples from the nodes

Used for parsing sample data packets

from xis import XBeeIOSample

Used for discovering and configuring nodes

import zigbee
import socket # Our main function called at program start
#from socket import *
host = ‘127.0.0.1’
port = 52200
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
def main():

# First we create our socket to listen 
# for nodes joining the network
# The socket is configured to listen on the
# data endpoint (0xE8) and to time out after
# blocking for 1 second
#sd = socket.socket(socket.AF_ZIGBEE, 
                  # socket.SOCK_DGRAM, 
                   #socket.ZBS_PROT_TRANSPORT)



#sd = socket.socket(socket.AF_ZIGBEE,socket.SOCK_DGRAM, socket.ZBS_PROT_TRANSPORT)
sd = socket(AF_ZIGBEE, SOCK_DGRAM, ZBS_PROT_TRANSPORT) 
sd.bind(('', 0xe8,0,0))
sd.settimeout(1)
#Create TCP socket and connect

NameError: global name ‘AF_ZIGBEE’ is not defined

If I found anything I’ll let you know and please if you found out where is the problem please let me know as well :slight_smile:

Thank YOU

The sd = socket(AF_ZIGBEE, SOCK_DGRAM, ZBS_PROT_TRANSPORT) only works on Digi gateways. It won’t work on a PC.

Digi does have a zigbee.py which allows some limited PC to XBee comes by a serially-attached XBee (like XBIB or XStick). I am hoping someone can point out where this code is on the support site.

See MST’s reply on thread http://forums.digi.com/support/forum/viewthread_thread,898