Home/Support/Support Forum/XBee successfully transmits four times then fails

XBee successfully transmits four times then fails

0 votes
I'm running the standard sample code below modified with a for loop. The result is four successful transmissions, and five unsuccessful transmissions. What am I missing here? Thank you!




import sys
import xbee


# TODO: replace with the node identifier of your target device.
TARGET_NODE_ID = "Router"
MESSAGE = "Hello XBee!"


def find_device(node_id):

for dev in xbee.discover():
if dev == node_id:
return dev
return None


print(" +
+")
print(" | XBee MicroPython Transmit Data (NI) Sample |")
print(" +
+\n")

# Find the device with the configure node identifier.
device = find_device(TARGET_NODE_ID)
if not device:
print("Could not find the device with node identifier '%s'" % TARGET_NODE_ID)
sys.exit(-1)

addr16 = device
addr64 = device
for x in range (0,9):
print("Sending data to %s >> %s" % (TARGET_NODE_ID, MESSAGE))
try:
# Some protocols do not have 16-bit address. In those cases, use the 64-bit one.
xbee.transmit(addr16 if addr16 else addr64, MESSAGE)
print("Data sent successfully")
except Exception as e:
print("Transmit failure: %s" % str(e))
x += 1




Results:
Sending data to Router >> Hello XBee!
Data sent successfully
Sending data to Router >> Hello XBee!
Data sent successfully
Sending data to Router >> Hello XBee!
Data sent successfully
Sending data to Router >> Hello XBee!
Data sent successfully
Sending data to Router >> Hello XBee!
Transmit failure: [Errno 7107] ENOTCONN
Sending data to Router >> Hello XBee!
Transmit failure: [Errno 7107] ENOTCONN
Sending data to Router >> Hello XBee!
Transmit failure: [Errno 7107] ENOTCONN
Sending data to Router >> Hello XBee!
Transmit failure: [Errno 7107] ENOTCONN
Sending data to Router >> Hello XBee!
Transmit failure: [Errno 7107] ENOTCONN
asked Oct 6 in MicroPython by elizabeth.farrell New to the Community (2 points)

Please log in or register to answer this question.

2 Answers

0 votes
Try importing time and then add a time.sleep.s(1) to your code.
answered Oct 6 by mvut Veteran of the Digi Community (13,472 points)
Where would you put it? No matter where I put it, I get 9 transmission failures.
I would put the time.sleep just after the x+1
That was my initial thought as well. 9 transmission failures, then I had to power cycle the units to get them back to communicating at all.
0 votes
This is interesting. Could you update your program to report the value of ATAI (using xbee.atcmd('AI')) on transmit failure? What if you have an infinite loop with a 1 second delay between each send?

The ENOTCONN should only come up when ATAI is non-zero, indicating that you aren't on a network.
answered Oct 7 by TomCollins Veteran of the Digi Community (2,051 points)
Sending data to Router >> Hello XBee!
Data sent successfully
Sending data to Router >> Hello XBee!
Data sent successfully
Sending data to Router >> Hello XBee!
Data sent successfully
Sending data to Router >> Hello XBee!
Data sent successfully
Sending data to Router >> Hello XBee!
0
Transmit failure: [Errno 7107] ENOTCONN
Sending data to Router >> Hello XBee!
0
Transmit failure: [Errno 7107] ENOTCONN
Sending data to Router >> Hello XBee!
0
Transmit failure: [Errno 7107] ENOTCONN
Sending data to Router >> Hello XBee!
0
Transmit failure: [Errno 7107] ENOTCONN
Sending data to Router >> Hello XBee!
0
Transmit failure: [Errno 7107] ENOTCONN


Updated to report ATAI - I'll tackle the infinite loop next. I appreciate the thoughts.
...