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