I get an exception when i try to use the ZigBee Transmit Request Frame from the API.
To find the source of the error i tryed to use an example frame (0x08) from the digi documentation (XBee®/XBee-PRO® ZB RF Modules, site: 104).
Here is my code:
I do not understand why you would use 2 sockets (seems to be a rash of such questions in the forum). Sockets are naturally bi-directional. Plus you will never receive anything on end-point 0x00, since the remote Zigbee/Xbee should repond on end-point 0xE8, which is your sdtx.
So elimiate all reference to sdrx and just use one socket to send on and receive from.
Do remember that in some situations (but not command 0x08) you’ll get 2 responses - the first is when the attached XBee ‘hands off the mesaage’ to another node, and the second would be any response from a remote node.
Thank you for the fast answer. I tryed this but now i have an other problem. When i send a frame the reply just contains the frame i sent.
It astonishes me that i have to set the destination two times. The first time in DEST_ZDO for the socket an than in the frame. correct ?
DEST_ZDO=("[00:00:00:00:00:00:00:00]!", 0xe8, 0xc105, 0x11)
sd = socket(AF_ZIGBEE, SOCK_DGRAM, ZBS_PROT_TRANSPORT)
sd.bind(("", 0xe8, 0, 0))
#Remote AT Command Request
data = struct.pack('BBBBBBBBBBBBBBBBBBB',0x7E,0x00,0x0F,0x17,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,0x02,0x53,0x48,0x4C)
sd.sendto(data, 0, DEST_ZDO)
r,w,e = select.select([sd],[],[],primaryTimeout)
payload=""
if sd in r:
payload, src_addr = sd.recvfrom(maxRxSize)
paylor=""
if (len(payload) > 0 ):
for c in payload : paylor += '%02X'%ord(c) + " "
print paylor
sd.close()
The socket interface is NOT optimized for sending remote AT commands - but for sending data. It is designed to mimic a UDP socket as closely as possible. For example, when I send a Modbus/RTU serial request all I have to do is:
data = ‘{my modbus request with CRC16’)
sd.sendto(data, 0, DEST_ZDO)
If you just send your command like that, the remote node will ignore it, dumping it out the remote xbee’s serial port. Not what you want.
WARNING: You should recvfrom (255), not 72 as Zigbee can move up to 82 bytes in certain cases. So although old documents call 72 the max, you can also receive 75, 82 or a few more bytes. Since the recvfrom mimics UDP, if you received 82 bytes and only used recvfrom(72), the final 10 bytes would be silently discarded. Using recvfrom (5000) doesn’t really hurt anything - you’ll never see more than about 82 for ZigBee, 100 for 802.15.4, and around 230 some for DigiMesh. It is UDP-like after all.
I get an exception when i try to use the ZigBee Transmit Request Frame from the API.
To find the source of the error i tryed to use an example frame (0x08) from the digi documentation (XBee®/XBee-PRO® ZB RF Modules, site: 104).
Here is my code:
DEST_ZDO=("[00:00:00:00:00:00:00:00]!", 0xe8, 0xc105, 0x11)
sd = socket(AF_ZIGBEE, SOCK_DGRAM, ZBS_PROT_TRANSPORT)
sd.bind(("", 0xe8, 0, 0))
#Remote AT Command Request
data = struct.pack('BBBBBBBBBBBBBBBBBBB',0x7E,0x00,0x0F,0x17,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,0x02,0x53,0x48,0x4C)
sd.sendto(data, 0, DEST_ZDO)
r,w,e = select.select([sd],[],[],primaryTimeout)
payload=""
if sd in r:
payload, src_addr = sd.recvfrom(maxRxSize)
paylor=""
if (len(payload) > 0 ):
for c in payload : paylor += '%02X'%ord(c) + " "
print paylor
sd.close()
As many people have told you, you cannot send API frames this way. The above code should not work. It may not give an error, but it will not accomplish anything useful.