parsing data from multiple xbees

Hi all,

I just want to double check what I think I’ve already found out. I have a little mini network of several xbees (series 1). 1 is set as the coordinator, the other two as end devices. I’m sending quite a bit of data (~100 bytes / end device xbee). All the xbees are set up in transparent mode (AP = 0).

Here’s my problem: before the packet gets to the xbee (packet coming from an Arduino, FYI), I assign it a unique header so I can identify it when reaches my computer. Running just one end device is fine, but when two run…I’m having issues. The xbees take my big packet and break it up into smaller chunks. These smaller chunks, however, do not have the header. Combine this with data streaming in from the other end device (which has also been broken up into smaller chunks), and well…it’s pretty much impossible to reassemble the messages. I’ve read a bit about the API mode. It seems to add the device header to every packet, which would be very helpful. However setting up the API mode seems like a non-trivial task. I don’ t suppose this could be done another way?

Thanks in advance for any pointers.

Best,

David

From what I can tell, transparent mode is really for use with a pair of devices. As you have seen, using more than two creates problems because the data which would indicate the sender is discarded. Using API mode takes more effort to get working properly, but its much more flexible than transparent mode. You can control how much data to send in a single packet (up to the packet limit), the sender information is provided to the receivers, and since the packet is structured, you can include your own packet header data. I use API mode in an automation system of 4 XBees and it works great. Very easy to determine who is sending to who, even with simultaneous sends.

Hi Vraz,

Thanks for the reply. That’s what I was afraid of. I know API mode seems to make the most sense wrt other aspects of my setup as well. Now to learn how to do this…on an arduino…should provide for a festive weekend.

Please holler if you have any pointers other than what’s referenced in the manual :slight_smile:

Cheers,

David

A few hints that might help based on my own use of API mode. Here is the setup process for API mode 2 (transparent):

To enter API mode:

Wait 1.2 secs

Send +++

Wait 1.2 secs

Send ATAP2,CN

Wait 0.2 secs

Here is the assembly code I use to build the API frame:

; setup an xbee api frame
; exit: zl/zh=buffer pointer
XBeeApiBeg:	ENTRY
		ldi	zl,low(XBeeOutBuf+2)
		ldi	zh,high(XBeeOutBuf+2)
		clr	r16
		st	z+,r16		; length=0
		dec	r16
		st	z+,r16		; checksum=$ff
		ret

; setup for broadcast packet
XBeeApiBrd:	ENTRY
		ldi	r16,$01
		rcall	XBeeApiAdd		; tx16
		ldi	r16,$00
		rcall	XBeeApiAdd		; no ack
		ser	r16
		rcall	XBeeApiAdd
		rcall	XBeeApiAdd		; dest=broadcast
		ldi	r16,$04
		rcall	XBeeApiAdd		; broadcast mode
		ret

; append a byte to the frame
; entry: r16=byte
XBeeApiAdd:	ENTRY
		push	r17
		lds	r17,XBeeOutBuf+2
		inc	r17			; count the byte
		sts	XBeeOutBuf+2,r17

		lds	r17,XBeeOutBuf+3
		sub	r17,r16		; add byte to checksum
		sts	XBeeOutBuf+3,r17

		mov	r17,r16
		cpi	r17,$7e
		breq	xbeeapiadd2
		cpi	r17,$7d
		breq	xbeeapiadd2
		cpi	r17,$13
		breq	xbeeapiadd2
		cpi	r17,$11
		brne	xbeeapiadd3

xbeeapiadd2:ldi	r17,$7d		; append escape character
		st	z+,r17
		ldi	r17,$20
		eor	r17,r16		; escape the data byte

xbeeapiadd3:st	z+,r17
		pop	r17
		ret

; complete the frame
; exit: zl/zh=buffer pointer, r16=length
XBeeApiEnd:	ENTRY
		lds	r16,XBeeOutBuf+3
		rcall	XBeeApiAdd		; append the checksum

		push	zl
		push	zh			; save encoded buffer end

		ldi	zl,low(XBeeOutBuf+4)
		ldi	zh,high(XBeeOutBuf+4)

		lds	r16,XBeeOutBuf+2	; get raw count
		dec	r16			; exclude checksum
		cpi	r16,$7e
		breq	xbeeapiend2
		cpi	r16,$7d
		breq	xbeeapiend2
		cpi	r16,$13
		breq	xbeeapiend2
		cpi	r16,$11
		brne	xbeeapiend3

xbeeapiend2:ldi	r17,$20
		eor	r16,r17
		st	-z,r16		; save escaped low-length
		ldi	r16,$7d
xbeeapiend3:st	-z,r16		; save low-length
		clr	r16
		st	-z,r16		; save high-length
		ldi	r16,$7e
		st	-z,r16		; save frame marker

		pop	r17
		pop	r16			; get back end pointer
		sub	r16,zl
		sbc	r17,zh		; r16=length, zl/zh=buffer pointer
		ret

To build an API frame, call the begin function, the broadcast header function (you can replace with a unicast destination) and then the data add function. After adding all data, call the end function which will return with zl/zh pointing to the completed packet (length in r16). Send it as-is to the XBee and you are good to go.

		rcall	XBeeApiBeg		; build a frame
		rcall	XBeeApiBrd		; broadcast data

		ldi	r16,'D'
		rcall	XBeeApiAdd		; data
		lds	r16,SetupNode
		rcall	XBeeApiAdd		; node-id
		lds	r16,SetupGroup
		rcall	XBeeApiAdd		; group-id
		ldi	r16,'F'
		rcall	XBeeApiAdd		; type=feeder
		lds	r16,FeederStop
		rcall	XBeeApiAdd		; data=duration
		rcall	XBeeApiEnd

i have project to send API fream,i install the end device(ZIGBEE end deviceAPI) & the corrdinator(ZIGBEE corrdinator API) with API mode,I can send character data from end device to coordinator but can not see it come out of the UART.

do you install your xbee module as AT or API? i do not know if i need to To enter API mode by this way:

Wait 1.2 secs

Send +++

Wait 1.2 secs

Send ATAP2,CN

Wait 0.2 secs

or already my modules in API mode

any help

I use the XBee (series 1) in API mode - all in C so it ports to PC or microprocessor easily. I do peer to peer - no coordinator, no ZigBee.