Using ZigBee Transmit Request (Frame Type: 0x10)

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:

    
    # Set destination 
    DEST_ZDO=("[00:13:a2:00:40:52:dc:51]!", 0xe8, 0xc105, 0x11)      
    

    # create socket
    sdtx = socket(AF_ZIGBEE, SOCK_DGRAM, ZBS_PROT_TRANSPORT)
    sdrx = socket(AF_ZIGBEE, SOCK_DGRAM, ZBS_PROT_TRANSPORT) 

    # bind sockets
    sdtx.bind(("", 0xe8, 0, 0))
    sdrx.bind(("", 0x00, 0, 0))
    
    # AT command frame
    data = struct.pack('BBBBBHBB',0x7E,0x00,0x05,0x08,0x01,0x4E4A,0xFF,0x5F)
    # send data
    sdtx.sendto(data, 0, DEST_ZDO)
    
    

    r,w,e = select.select([sdrx],[],[],10)

    
    if sdrx in r:
        
        payload, src_addr = sdrx.recvfrom(72)  
        
    else:
        sdtx.close()
        sdrx.close()
        raise Timeout("Request fail: ") 
    
    sdtx.close()
    sdrx.close()


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.

You probably want to look at this page and the ddo_get_param/ddo_set_param functions:
http://www.digi.com/wiki/developer/index.php/Module:xbee

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.

So I use 255 always.

I dont want to send an AT command, i tryed to send a ZigBee Transmit Request Frame but this failed.

I get an exception when i try to use the ZigBee Transmit Request Frame from the API.

To Send the Remote as well as local AT Commands to the ZigBee Module use ddo_get_param and ddo_set_param, rather than binding two zigbee nodes.

Try to go through the following Wikipedia Link:
http://www.digi.com/wiki/developer/index.php/Module:xbee

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



You repeat yourself - I’ll repeat myself.

I have no clue what you are trying to acomplish.

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.