Home/Support/Support Forum/Get frame data from connectport X4
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Get frame data from connectport X4

0 votes
I have a xbee network consisting of a ConnectPort X4 and several routers and end-devices.
Now I want to get xbee frame raw data from CP X4 (such as,
7E XX XX XX .. XX)
Is there a way to extract these data from CP X4 using the python interface? I have search the forum and google the Internet but still feel helpless.
My xbee module is series 2 and working in api mode.
Thank you in advance.
asked Jan 24, 2014 in Python by zdyang New to the Community (1 point)

Please log in or register to answer this question.

1 Answer

0 votes

I have used following approach with my XBee AIO, XBee DIO and XBee 1-wire adapters (end devices) to get the raw data. Coordinator of the XBee network has been ConnectPort X4 or ConnectPort X5.

I create XBeeListener which listens XBee network traffic and puts it in to the queue for handling and processing. There is much to do to develop the code, but for my needs they have worked just fine.

Of course my end device adapters are configured to send data periodically to XBee network and rest of the time they are sleeping. Otherwise my XbeeListener would not see any traffic.

Hope this helps you somehow.
def XbeeListener (threadName,param): print timing.getTime()+" "+threadName+": Running..." try: sd = socket(AF_ZIGBEE, SOCK_DGRAM, ZBS_PROT_TRANSPORT) sd.bind(("", 0xe8, 0, 0)) sd.setblocking(0) except: print timing.getTime()+ " "+threadName+": Initializing XBee socket...FAILED" print timing.getTime()+ " "+threadName+":+ Unexpected error:", sys.exc_info()[0] else: print timing.getTime()+ " "+threadName+": Initializing XBee socket...OK" try: payload = "" src_addr = () while True: rlist,wlist = ([],[]) if len(payload) == 0: rlist=[sd] else: wlist=[sd] print timing.getTime()+ " "+threadName+": payload != 0" # Block on select: #print timing.getTime()+" "+threadName+": Waiting..." rlist, wlist, xlist = select(rlist, wlist, []) #print timing.getTime()+" "+threadName+": Processing..." # Is the socket readable? if sd in rlist: payload, src_addr = sd.recvfrom(255) xbee_frame_queue.put([payload,src_addr]) #print timing.getTime()," ",payload, " ", src_addr payload="" if sd in wlist: print timing.getTime()+ " "+threadName+": sd in wlist" payload = "" except: print timing.getTime()+" "+threadName+": Unexpected error: ",sys.exc_info()[0] pass

def XbeeDataHandler (threadName): print timing.getTime()+" "+threadName+": Running..." while True: try: xbee_frame = xbee_frame_queue.get() #print timing.getTime()," ",bytes, " ", xbee_frame[1] print "\n" print timing.getTime()+" "+threadName+": src_addr: ", xbee_frame[1] print timing.getTime()+" "+threadName+": payload: ", xbee_frame[0] frame_type = xbee_frame[1][3] if frame_type == 148: #1-Wire adapter data frame print timing.getTime()+" "+threadName+": XBee Sensor Read Indicator frame received..." bytes = list() for index, byte in enumerate(xbee_frame[0]): bytes.append(ord(byte)) print timing.getTime()+" "+threadName+": ",bytes AD0 = utility.toU16(bytes[2], bytes[1], 1) AD1 = utility.toU16(bytes[4], bytes[3], 1) AD2 = utility.toU16(bytes[6], bytes[5], 1) AD3 = utility.toU16(bytes[8], bytes[7], 1) temperature = round(utility.toI16(bytes[10], bytes[9], 0.0625),2) print timing.getTime()+" "+threadName+": AD0: ",((AD0 * 5.1) / 255) print timing.getTime()+" "+threadName+": AD1: ",((AD1 * 5.1) / 255) v_supply = (AD2 * 5.1) / 255 print timing.getTime()+" "+threadName+": v_supply: ",v_supply v_output = (AD3 * 5.1) / 255 print timing.getTime()+" "+threadName+": v_output: ",v_output sensor_rh = (1 / 0.0062) * ((v_output / v_supply) - 0.16) true_rh = round(sensor_rh / (1.0546 - (0.00216 * temperature)),2) sensor_rh = round(sensor_rh,2) print timing.getTime()+" "+threadName+": Temp: ",temperature print timing.getTime()+" "+threadName+": sensor_rh: ",sensor_rh print timing.getTime()+" "+threadName+": true_rh: ",true_rh #elif frame_type == ??? #do something #elif frame_type == ??? #do something else: print timing.getTime()+" "+threadName+": Unknown frame..." except: print timing.getTime()+" "+threadName+": Unexpected error: ",sys.exc_info()[0] pass

answered Jan 24, 2014 by juha.autioniemi New to the Community (23 points)
Thank you very much.
hi Juha.. as im quite new in Python,can u please explain more about this code (how i want to execute this code).. as currently im having problem with xbee adapter sleep mode. i've set my adapter to sleep for 20s but connectport tries to pull data from the adapter all the time which makes failure in communication.thanks.