Xbee Data Loss

Hello. I’m transmitting two ADC channels with a baud rate of 9600, 8bit, in unicast mode. The XBee system is set up to collect data from the ADC channels at 50Hz (IR=14 (Hex for 20ms sampling), TX=1).

I lose a very consistent amount of data when recording both in Matlab and Labview. For example 10s of recording results in 490 data points (instead of 500) and 20s of recording results in 980 data points (instead of 1,000) for each ADC channel. The buffer is never overloaded (max size at time of read in example below is 96 bytes), although the size is a bit variable (Stdev = 2.98 bytes). While I understand there is transmission time, the data is still being recorded into the buffer at 50Hz and thus I should still get the correct amount of data, right? Checking the buffer after close shows about 3 bytes so it isn’t just missing end data. Additionally the data lag seems to increase with time (see attached figure) suggesting that the sample rate is < 50Hz.

I would greatly appreciate any feedback or suggestions! Thank you.

Example of Matlab Collection Code

s = serial(‘COM5’);

fopen(s);

A=;

i=1;

fread(s,s.BytesAvailable); % Clear buffer

tic;

while toc<10;

pause(0.1); % Changing this changes buffer size but not the resulting data size.

Atemp=fread(s,s.BytesAvailable);

l(i)=length(Atemp); % So I can check if the buffer reached capacity

A= [A;Atemp];

i=i+1;

clear Atemp

end

toc % Check that run time is correct

fclose(s);

Try just using a terminal program that can save the data to a file and see if you still have data loss.

I wrote up a python program and obtained similar results (487 points in 10s and 975 in 20s). Any thoughts?

Try decreasing the sampling rate from 50Hz to maybe 10Hz but read below first.

Here is something I found on Digi Int’s forum about unicast:

http://www.digi.com/support/forum/34755 … -broadcast

So set the DL, DH parameters so the XBee sends the data to the receiving XBee instead of on unicast.

This then requires the sending XBee to get an ACK and it will re-send if its doesn’t.

unicast mode does not have any error checking or ACK of received data packets. If the packet get RF interference and is not received then it disappears into the aether.

Are the XBee’s series 1s or 2s?

choice of channel might affect things… choose one to minimize competition with nearby 802.11.

XBee 802.15.4 (both S1 and S2) are 2MHz wide channels. WiFi 802.11 is usually 20MHz. Look at a channel chart to see overlaps.

XBee S1 have an ACK (MAC ACK) on/off setting in the config. Should be on.

I have series 2 Xbees. I’ve switched to broadcast mode with no effect of data. Switching to 10Hz sampling rate decreases the amount of loss but there is still loss with higher collection times. For example 10s pretty consistently results in 100 data points for one channel, 20s in ~199, 40s in~397, and 60s in ~595. I would ideally like to use a higher frequency. Does this help diagnose the problem? Am I wrong to think I shouldn’t have any loss? Is there an expected amount of loss with the XBee system?

The sample loss is very consistent so I do not feel that it is likely to be transmission interference. I tried most of the other channel options. None of them resulted in an improvement, although some were certainly worse in terms of data loss and variability.

Thank you for your help.

I recall there’s a way to use the XBee internal firmware to pack several samples in one transmission packet. Can you tolerate that?

1 sample per transmission packet (frame), 10 frames per second, with the XBee series 1 in 802.15.4 mode is no problem I routinely do 16 per second, with each frame having about 50 bytes (half the 100 byte max).

Xbee series 2 using ZigBee will have a lower rate due to the Zigbee overhead.

(ZigBee is not a synonym for 802.15.4 much like TCP/IP is not a synonym for Ethernet 802.3. Many don’t know this).