We are doing some prototyping with Xbee S2 modules.
We have an extremely simply test which is showing very poor results:
Sender module (configured as Router) sends 8 bytes directly (unicast) to receiver and waits for an ACK byte. The receiver module (configured as Coordinator) reads bytes and after the 8th byte is received, it sends an ACK byte.
This is wrapped in a for-loop running 50 iterations. The modules are 1 foot apart.
We have tested with various delays between successive iterations in the for-loop.
Observation:
In all cases the receiver always receives all data cleanly. However, the sender often does not receive the response ACK. I am seeing 10% on average of all responses being missed! We reversed roles of modules and saw the same results.
This is certainly showstopper for any further development.
Questions:
What are some potential causes for such a poor results for such a trivial test?
Below is my python test code.
----------------Sender.py----------------
import serial
import time
from time import sleep
ser = serial.Serial(‘COM9’, 9600, timeout=2)
NumResponsesReceived=0
#wait maximum of 2 seconds for response
ser.timeout=2
for i in range(0,50):
print "sending message, SeqNo " + str(i) + "
"
values = bytearray([2, 3, 1,4,0,0,0,i])
ser.write(values)
c2=ser.read(1)
if(c2!=‘’):
b=int(c2.encode(‘hex’),16)
print "Got response! " + str(b) + "
"
NumResponsesReceived=NumResponsesReceived+1
else:
print "Timed out
"
ser.flush()
sleep(0.1)
ser.close()
print "Total responses received: " + str(NumResponsesReceived)
----------------Receiver.py----------------
import serial
import time
from time import sleep
ser = serial.Serial(‘COM5’, 9600, timeout=None)
ser.flushInput
ACK=‘06’
NAK=‘15’
NumOfMessages=0
print “Receiver started. Waiting for data…”
while True:
ser.timeout= None
c=ser.read()
if(c!=‘’):
x=int(c.encode(‘hex’),16)
#print "encoded " + str(x)
if(x==2): #STX symbol (start sentinal)
print ":::::Record:::::
"
ser.timeout=1
print "["
NumRead=1
while(NumRead<8):
c2=ser.read(1)
if(c2!=''):
b=int(c2.encode('hex'),16)
print str(b),
NumRead=NumRead+1
else:
#print "Timed out
"
break
print “]”
sleep(0.1)
if(NumRead==8):
ser.write(ACK.decode(“hex”))
print “Got command message! Sending ACK!”
else:
ser.write(NAK.decode(“hex”))
print “Did not receive all 8 bytes! Sending NAK!”
print " "
else:
print "Unexpected preamble " + str(x)
else:
print "Timeout or something is wrong!!! Assuming no more data.
"
#print Checks
break
ser.close()