def main(): print(" +-----------------------------------------------------+") print(" | XBee Python Library Manage Common parameters Sample |") print(" +-----------------------------------------------------+\n") device = XBeeDevice(PORT, BAUD_RATE) try: device.open() print("Cached parameters\n" + "-" * 50) print("64-bit address: %s" % device.get_64bit_addr()) print("16-bit address: %s" % device.get_16bit_addr()) print("Node Identifier: %s" % device.get_node_id()) print("Firmware version: %s" % utils.hex_to_string(device.get_firmware_version())) print("Hardware version: %s" % device.get_hardware_version().description) print("") # Configure and read non-cached parameters. device.set_pan_id(PARAM_VALUE_PAN_ID) device.set_dest_address(PARAM_DESTINATION_ADDR) device.set_power_level(PARAM_POWER_LEVEL) print("Non-Cached parameters\n" + "-" * 50) print("PAN ID: %s" % utils.hex_to_string(device.get_pan_id())) print("Dest address: %s" % device.get_dest_address()) print("Power level: %s" % device.get_power_level().description) finally: if device is not None and device.is_open(): device.close()
def main(): print(" +---------------------------------+") print(" | Get and Set Params Local/Remote |") print(" +---------------------------------+\n") local_xbee = XBeeDevice(PORT, BAUD_RATE) try: local_xbee.open() remote_xbee = RemoteXBeeDevice(local_xbee, x64bit_addr=REMOTE_DEVICE_ADDRESS) local_xbee.read_device_info() print("Read device info of local device successfully") remote_xbee.read_device_info() print("Read device info of remote device successfully") print("\nLocal:") print(local_xbee.get_node_id()) print(local_xbee.get_hardware_version()) print(hex_to_string(local_xbee.get_firmware_version())) print(local_xbee.get_protocol()) print("\nRemote:") print(remote_xbee.get_node_id()) print(remote_xbee.get_hardware_version()) print(hex_to_string(remote_xbee.get_firmware_version())) print(remote_xbee.get_protocol()) ni = ''.join( random.choice(string.ascii_letters) for i in range(random.randint(1, 20))) local_xbee.set_parameter("NI", bytearray(ni, "utf8")) param = local_xbee.get_parameter("NI") assert (param.decode() == ni) ni = ''.join( random.choice(string.ascii_letters) for i in range(random.randint(1, 20))) remote_xbee.set_parameter("NI", bytearray(ni, "utf8")) param = remote_xbee.get_parameter("NI") assert (param.decode() == ni) print("\nTest finished successfully") finally: if local_xbee is not None and local_xbee.is_open(): local_xbee.close()
from digi.xbee.devices import XBeeDevice PORT = '/dev/ttyUSB0' BAUD_RATE = 57600 device = XBeeDevice(PORT, BAUD_RATE) device.open() # Get the 64-bit address of the device. addr_64 = device.get_64bit_addr() # Get the node identifier of the device. node_id = device.get_node_id() # Get the hardware version of the device. hardware_version = device.get_hardware_version() # Get the firmware version of the device. firmware_version = device.get_firmware_version() print("MAC ADDRESS = ",addr_64) print("Node ID = ",node_id)