Ejemplo n.º 1
0
def main():

    print(" +-------------------+")
    print(" | Send Data 16 Test |")
    print(" +-------------------+\n")

    local = XBeeDevice(PORT_LOCAL, BAUD_RATE_LOCAL)
    local_remote = XBeeDevice(PORT_REMOTE, BAUD_RATE_REMOTE)

    try:
        local.open()
        local_remote.open()

        remote = RemoteXBeeDevice(local,
                                  x16bit_addr=local_remote.get_16bit_addr())
        local.send_data(remote, "Test message")

        time.sleep(1)

        message = local_remote.read_data()
        assert (message is not None)
        assert (
            message.remote_device.get_16bit_addr() == local.get_16bit_addr())

        print("Test finished successfully")

    finally:
        if local is not None and local.is_open():
            local.close()
        if local_remote is not None and local_remote.is_open():
            local_remote.close()
Ejemplo n.º 2
0
class Radio:
    #commandDB where all commands will be stored
    commandDB = None

    def __init__(self):
        self.serialPort = "/dev/tty.SLAB_USBtoUART"  # port where Xbee is connected find by doing ls /dev/tty* on terminal
        self.device = XBeeDevice(self.serialPort, 9600)
        self.remote_device = RemoteXBeeDevice(
            self.device, XBee64BitAddress.from_hex_string(
                "0013A200406343f7"))  # "0013A20040XXXXXX"
        self.callback = None
        # strores a reference to the radio callback function

    def __repr__(self):
        return "Xbee Device at Port {0}\nopen = {1}".format(
            self.serialPort, self.device.is_open())

    def __str__(self):
        return "Xbee Device at Port {0}\nopen = {1}".format(
            self.serialPort, self.device.is_open())

    def openConnection(self):
        if (self.device != None and self.device.is_open() == False):
            self.device.open()

    def closeConnection(self):
        if (self.device != None and self.device.is_open()):
            self.device.close()

    def send(self, data):
        try:
            #self.openConnection()
            #self.device.send_data_broadcast(data)
            #self.device.send_data(self.remote_device,data)
            self.device.send_data_async(self.remote_device, data)  #sent async
        except (KeyboardInterrupt):
            print("something went wrong when sending data")

    def my_data_received_callback(xbee_message):
        address = xbee_message.remote_device.get_64bit_addr()
        data = xbee_message.data.decode("utf8")
        #store the XBbee into a command object for decoding etc...
        command = Command(xbee_message)
        # add this command to the command dataBase
        Radio.commandDB.addCommand(command)
        print("Received data from %s: %s" % (address, data))

    # opens the xbee device and sets the recieve call back
    # parameters: database = command database to store commands
    def setUP(self, database):
        Radio.commandDB = database
        self.openConnection()
        self.callback = Radio.my_data_received_callback
        self.device.add_data_received_callback(self.callback)

    #close xbeeconnection and delete callback
    def terminate(self):
        #self.device.del_data_received_callback(self.callback)
        self.closeConnection()
Ejemplo n.º 3
0
class ModuleSingleton:
    def __init__(self):
        self.device = XBeeDevice(LOCAL_PORT, BAUD_RATE)
        self.device.open()
        self.remote_device = None
        self.queue = None

        try:
            self.remote_device = RemoteXBeeDevice(
                self.device,
                XBee64BitAddress.from_hex_string(REMOTE_NODE_ADDRESS))
            if self.remote_device is None:
                print("Could not find the remote device")
        except XBeeException:
            print("Exception has occurred")

    def send(self, data):
        print("Testing data: " + data)
        try:
            print("Sending data to %s >> %s..." %
                  (self.remote_device.get_64bit_addr(), DATA_TO_SEND))

            logging.basicConfig(stream=sys.stdout,
                                level=logging.DEBUG,
                                format="[root] %(levelname)s - %(message)s")

            logger = logging.getLogger(self.device.get_node_id())

            self.device.send_data(self.remote_device, data)

            print("Success")

        finally:
            if self.device is not None and self.device.is_open():
                # self.device.close()
                print("Commented out close")

    def bind_queue(self, queue):
        self.queue = queue

    def receive(self):
        try:

            def data_receive_callback(msg):
                data = msg.data.decode("utf8")

                json_data = json.loads(data)

                self.queue.put(json_data)

            self.device.add_data_received_callback(data_receive_callback)

            print("Waiting for data...\n")
            input()
        finally:
            if self.device is not None and self.device.is_open():
                #self.device.close()
                print("Commented out close")
Ejemplo n.º 4
0
def main():
    print(" +-------------+")
    print(" | Calculating |")
    print(" +-------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)
    device1 = XBeeDevice(PORT1, BAUD_RATE)
    device2 = XBeeDevice(PORT2, BAUD_RATE)

    try:
        device.open()
        device1.open()
        device2.open()
        with open('web/data.csv', 'w') as csv_file:
            csv_writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
            csv_writer.writeheader()

        # Obtain the remote XBee device from the XBee network.
        xbee_network = device.get_network()
        xbee_network1 = device1.get_network()
        xbee_network2 = device2.get_network()
        remote_device = xbee_network.discover_device(REMOTE_NODE_ID)
        remote_device1 = xbee_network1.discover_device(REMOTE_NODE_ID)
        remote_device2 = xbee_network2.discover_device(REMOTE_NODE_ID)
        if remote_device and remote_device1 and remote_device2 is None:
            print("Could not find the remote device")
            exit(1)
        while True:
            # Calculating the rssi of each node from DB rigester in the XBee module .
            device.send_data(remote_device, 'a')
            device1.send_data(remote_device1, 'c')
            device2.send_data(remote_device2, 'b')
            rssi = device.get_parameter("DB")
            rssi1 = device1.get_parameter("DB")
            rssi2 = device2.get_parameter("DB")
            res = int.from_bytes(rssi, byteorder='big')
            res1 = int.from_bytes(rssi1, byteorder='big')
            res2 = int.from_bytes(rssi2, byteorder='big')

            R1 = (f"-{res}dbm")
            R2 = (f"-{res1}dbm")
            R3 = (f"-{res2}dbm")
            with open('web/data.csv', 'a') as outfile:
                csv_writer = csv.DictWriter(outfile, fieldnames=fieldnames)

                info = {"R1": res, "R2": res1, "R3": res2}

                csv_writer.writerow(info)
            print([R1, R2, R3])
            time.sleep(1)

    finally:
        if device and device1 and device2 is not None and device.is_open(
        ) and device1.is_open() and device2.is_open():
            device.close() and device1.close() and device2.close()
def main():

    print(" +-----------------------------+")
    print(" | Add Remote Device by Reader |")
    print(" +-----------------------------+\n")

    device_a = XBeeDevice(PORT_A, BAUD_RATE_A)
    device_b = XBeeDevice(PORT_B, BAUD_RATE_B)

    try:
        device_a.open()
        device_b.open()

        network = device_a.get_network()

        remote = RemoteXBeeDevice(device_b, device_a.get_64bit_addr())

        # Send a message from B to A.
        device_b.send_data(remote, "Test")

        # Give some time to device A to receive the packet.
        time.sleep(1)

        # Check that B is in the network of A.
        assert (len(network.get_devices()) == 1)
        try:
            assert (network.get_device_by_64(
                device_b.get_64bit_addr()) == device_b)
        except AssertionError:
            assert (network.get_device_by_16(
                device_b.get_16bit_addr()).get_16bit_addr() ==
                    device_b.get_16bit_addr())

        # Send another message from B to A.
        device_b.send_data(remote, "Test")

        # Check that B is not duplicated.
        assert (len(network.get_devices()) == 1)
        try:
            assert (network.get_device_by_64(
                device_b.get_64bit_addr()) == device_b)
        except AssertionError:
            assert (network.get_device_by_16(
                device_b.get_16bit_addr()).get_16bit_addr() ==
                    device_b.get_16bit_addr())

        print("Test finished successfully")

    finally:
        if device_a is not None and device_a.is_open():
            device_a.close()
        if device_b is not None and device_b.is_open():
            device_b.close()
Ejemplo n.º 6
0
class Radio:
    def __init__(self):
        self.serialPort = "COM3"
        self.device = XBeeDevice(self.serialPort, 9600)
        self.remote_device = RemoteXBeeDevice(
            self.device, XBee64BitAddress.from_hex_string(
                "0013A2004068CC5D"))  # "0013A20040XXXXXX"
        self.callback = None

    def __repr__(self):
        return "Xbee Device at Port".format(self.serialPort,
                                            self.device.is_open())

    def __str__(self):
        return "Xbee Device at Port".format(self.serialPort,
                                            self.device.is_open())

    def openConnection(self):
        if (self.device != None and self.device.is_open() == False):
            self.device.open()

    def closeConnection(self):
        if (self.device != None and self.device.is_open()):
            self.device.close()

    def send(self, data):
        try:
            self.device.send_data_async(self.remote_device, data)
        except (KeyboardInterrupt):
            print("something went wrong when sending data")

    def data_received_callback(xbee_message):
        address = xbee_message.remote_device.get_64bit_addr()
        data = xbee_message.data.decode("utf8")
        f = open("Balloon_Data.txt", "a")
        f.write(data + "\n")  #writing data to text file
        print("Received data from %s: %s" % (address, data))

# opens the XBEE device and sets the receive call back
# parameters

    def setUP(self):
        self.openConnection()
        self.callback = Radio.data_received_callback
        self.device.add_data_received_callback(self.callback)

    #terminate XBEE connection and delete callback
    def terminate(self):
        self.device.del_data_received_callback(self.callback)
        self.closeConnection()
Ejemplo n.º 7
0
def main():
    print(" +-----------------------------------------+")
    print(" | XBee Python Library Receive Data Sample |")
    print(" +-----------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        device.open()

        def data_receive_callback(xbee_message):
            print("From %s >> %s" %
                  (xbee_message.remote_device.get_64bit_addr(),
                   xbee_message.data.decode()))
            message = xbee_message.data.decode()
            if message == "cutdown":
                return CUTDOWN_VALUE
            else:
                return SAFE_VALUE

        device.add_data_received_callback(data_receive_callback)

        print("Waiting for data...\n")
        input()

    finally:
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 8
0
def main():

    print(" +-----------------------+")
    print(" | Discover Network Test |")
    print(" +-----------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        device.open()

        network = device.get_network()

        devices_callback = []

        def device_discovered_callback(remote):
            devices_callback.append(remote)

        network.add_device_discovered_callback(device_discovered_callback)

        network.start_discovery_process()

        while network.is_discovery_running():
            time.sleep(0.1)

        assert(devices_callback == network.get_devices())

        print("Test finished successfully")

    finally:
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 9
0
def main():

    #Define your xbee device with the defined port and baudrate
    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        #open the xbee device
        device.open()
        #set the io pins on the xbee board itself
        #in this example, we are using the DIO_AD0 pin on the board
        #refrence the datasheet for other availible pins
        device.set_io_configuration(IOLine.DIO0_AD0, IOMode.ADC)
        # Obtain the remote XBee device from the XBee network.
        xbee_network = device.get_network()
        remote_device = xbee_network.discover_device(REMOTE_NODE_ID)
        if remote_device is None:
            print("Could not find the remote device")
            exit(1)

        # a simple while loop to read the adc sample, convert it and send to the main reciever
        while True:
            raw_val = device.get_adc_value(IOLine.DIO0_AD0)
            voltage = ((raw_val / 1024)) * 2.5
            p = ((voltage - .3333) / 1.32000) - 1.00
            string = str(p)
            print(string)
            time.sleep(0.05)
            device.send_data(remote_device, string)

    # close the device if any error occurs
    finally:
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 10
0
def main():
    print(" +--------------------------------------+")
    print(" | XBee Python Library Send Data Sample |")
    print(" +--------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        device.open()
        print("open device")
        
        # Obtain the remote XBee device from the XBee network.
        xbee_network = device.get_network()
        remote_device = xbee_network.discover_device(REMOTE_NODE_ID)
        if remote_device is None:
            print("Could not find the remote device. We will try 5 second")
            time.sleep(5)
            #exit(1)
        numero = 300
        count = 0
        #numero = int(input("Escriba un número positivo: "))
        while (count < numero):
            DATA_TO_SEND = "Fecha: " + dt.datetime.now().strftime('%Y-%m-%d  Hora: %H:%M:%S') + " Temperatura: 24.7 Humedad: 33% Presion 44mb Co2: 674.5" + "\n"
            time.sleep(2)
            count = count + 1
            print("Sending data to %s >> %s..." % (remote_device.get_64bit_addr(), DATA_TO_SEND))
            device.send_data(remote_device, DATA_TO_SEND)
            print("Success")

    finally:
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 11
0
def main():
    Number = 0
    while (1):
        try:
            Port = "/dev/ttyUSB" + str(Number)
            device = XBeeDevice(Port, Baud_Rate)
            device.open()

            # Obtain the remote XBee device from the XBee network.
            xbee_network = device.get_network()
            remote_device = xbee_network.discover_device(REMOTE_NODE_ID)
            if remote_device is None:
                print("Could not find the remote device")
                exit(1)
            time_string = strftime('%H:%M')
            if time_string == "14:26":  # Set up time
                device.send_data(remote_device, "1/80")
                sleep(1)
                device.send_data(remote_device, "2/50")
                sleep(10)
            if time_string == "14:27":
                device.send_data(remote_device, "1/30")
                sleep(1)
                device.send_data(remote_device, "2/20")
                sleep(10)
            if time_string == "14:28":
                device.send_data(remote_device, "1/0")
                sleep(1)
                device.send_data(remote_device, "2/0")
                sleep(10)
        except:
            Number = Number + 1
        finally:
            if device is not None and device.is_open():
                device.close()
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()
Ejemplo n.º 13
0
def main():
    print(" +-------------------------------------------+")
    print(" | XBee Python Library List Directory Sample |")
    print(" +-------------------------------------------+\n")

    local_xbee = XBeeDevice(PORT, BAUD_RATE)
    fs_xbee = local_xbee

    try:
        local_xbee.open()

        if REMOTE_NODE_ID:
            # Obtain the remote XBee from the network.
            xbee_network = local_xbee.get_network()
            fs_xbee = xbee_network.discover_device(REMOTE_NODE_ID)
            if not fs_xbee:
                print("Could not find remote device '%s'" % REMOTE_NODE_ID)
                exit(1)

        filesystem_manager = fs_xbee.get_file_manager()

        path_to_list = PATH_TO_LIST
        if not path_to_list:
            path_to_list = "/flash"
        files = filesystem_manager.list_directory(path_to_list)
        print("Contents of '%s' (%s):\n" %
              (path_to_list, fs_xbee if fs_xbee.is_remote() else "local"))
        for file in files:
            print(file)
    except (XBeeException, FileSystemException) as e:
        print("ERROR: %s" % str(e))
        exit(1)
    finally:
        if local_xbee and local_xbee.is_open():
            local_xbee.close()
Ejemplo n.º 14
0
def main():
    print(" +--------------------------------------+")
    print(" | XBee Python Library Send Data Sample |")
    print(" +--------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)
    data_to_send = "this be the data homie"

    try:
        device.open()

        # Obtain the remote XBee device from the XBee network.
        # xbee_network = device.get_network()
        # remote_device = xbee_network.discover_device(REMOTE_NODE_ID)
        # if remote_device is None:
        #    print("Could not find the remote device")
        #    exit(1)

        # print("Sending data to %s >> %s..." % (remote_device.get_64bit_addr(), DATA_TO_SEND))

        # device.send_data(remote_device, DATA_TO_SEND)
        i = 0
        while i < 5:
            i = i + 1
            device.send_data_broadcast(data_to_send)
            print("Success on iteration: ", i)

    finally:
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 15
0
def main():

    print(" +---------------------+")
    print(" | PWM Duty Cycle Test |")
    print(" +---------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        device.open()

        device.set_io_configuration(IOLine.DIO10_PWM0, IOMode.PWM)
        device.set_io_configuration(IOLine.DIO11_PWM1, IOMode.PWM)

        device.set_pwm_duty_cycle(IOLine.DIO10_PWM0, 50)
        device.set_pwm_duty_cycle(IOLine.DIO11_PWM1, 100)

        dc1 = device.get_pwm_duty_cycle(IOLine.DIO10_PWM0)
        dc2 = device.get_pwm_duty_cycle(IOLine.DIO11_PWM1)

        assert (dc1 == 50)
        assert (dc2 == 100)

        print("Test finished successfully")

    finally:
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 16
0
def main():
    print(" +-----------------------------------------+")
    print(" |       Wireless Sleep Monitoring         |")
    print(" |         \"No Strings Attached!\"          |")
    print(" +-----------------------------------------+\n")
    inp = input("Press enter to start!\nPress enter a second time to stop!")

    #declaring device and grapher
    device = XBeeDevice(PORT, BAUD_RATE)
    try:
        #Opening device
        device.open()
        device.flush_queues()

        def data_receive_callback(xbee_message):
            print(xbee_message.data.decode())

        device.add_data_received_callback(data_receive_callback)

        print("Waiting for data...\n")
        input()

    #For some reason python 3.8 causes delay here
    finally:
        if device is not None and device.is_open():
            #Closing device stops callbacks
            device.close()
Ejemplo n.º 17
0
def main():
    print(" +-------------------------------------------+")
    print(" | XBee Python Library List Directory Sample |")
    print(" +-------------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)
    filesystem_manager = LocalXBeeFileSystemManager(device)

    try:
        device.open()
        filesystem_manager = LocalXBeeFileSystemManager(device)
        print("Starting file system manager...", end=" ")
        filesystem_manager.connect()
        print("OK\n")
        current_directory = filesystem_manager.get_current_directory()
        print("Current directory: %s" % current_directory)
        path_to_list = PATH_TO_LIST
        if path_to_list is None:
            path_to_list = current_directory
        files = filesystem_manager.list_directory(path_to_list)
        print("Contents of '%s':" % path_to_list)
        for file in files:
            print(str(file))
    except (XBeeException, FileSystemException) as e:
        print("ERROR: %s" % str(e))
        exit(1)
    finally:
        if filesystem_manager.is_connected:
            print("\nStopping file system manager...", end=" ")
            filesystem_manager.disconnect()
            print("OK")
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 18
0
def main():
    print("Libelium Waspmote data receiver\n")

    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        device.open()
        device.flush_queues()
        print("Waiting for data...\n")

        while True:
            xbee_message = device.read_data(300)
            if xbee_message is not None:
                # print("From %s >> %s" % (xbee_message.remote_device.get_64bit_addr(),
                #                          xbee_message.data))
                if b"<=>" in xbee_message.data:
                    data = xbee_message.data[5:]
                    print(data.decode())

    except KeyboardInterrupt:
        print("Exit")

    finally:
        if device is not None and device.is_open():
            device.close()
def main():
    print(" +------------------------------------------------------+")
    print(" | XBee Python Library Apply XBee Profile Remote Sample |")
    print(" +------------------------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)
    try:
        device.open()

        # Obtain the remote XBee device from the XBee network.
        xbee_network = device.get_network()
        remote_device = xbee_network.discover_device(REMOTE_NODE_ID)
        if remote_device is None:
            print("Could not find the remote device")
            exit(1)

        print("Updating profile '%s'...\n" % PROFILE_PATH)
        remote_device.apply_profile(PROFILE_PATH,
                                    progress_callback=progress_callback)
        print("\nProfile updated successfully!")
    except Exception as e:
        print(str(e))
        exit(1)
    finally:
        if device.is_open():
            device.close()
def main():
    print(" +---------------------------------------------------+")
    print(" | XBee Python Library Remote Firmware Update Sample |")
    print(" +---------------------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)
    try:
        device.open()

        # Obtain the remote XBee device from the XBee network.
        xbee_network = device.get_network()
        remote_device = xbee_network.discover_device(REMOTE_NODE_ID)
        if remote_device is None:
            print("Could not find the remote device")
            exit(1)

        print("Starting firmware update process...")
        remote_device.update_firmware(
            XML_FIRMWARE_FILE,
            xbee_firmware_file=OTA_FIRMWARE_FILE,
            bootloader_firmware_file=OTB_FIRMWARE_FILE,
            progress_callback=progress_callback)
        print("Firmware updated successfully!")
    except (XBeeException, FirmwareUpdateException,
            OperationNotSupportedException) as e:
        print("ERROR: %s" % str(e))
        exit(1)
    finally:
        if device is not None and device.is_open():
            device.close()
def main():
    print(" +-------------------------------------------------+")
    print(" | XBee Python Library Send User Data Relay Sample |")
    print(" +-------------------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        device.open()

        for i in range(10):
            data = (DATA_TO_SEND % (i + 1))

            print("Sending User Data Relay to %s >> '%s'... " %
                  (DEST_INTERFACE.name, data),
                  end="")

            device.send_user_data_relay(DEST_INTERFACE, data.encode("utf-8"))

            print("Success")

            time.sleep(1)
    finally:
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 22
0
def main():
    print(" +-------------------------------------------+")
    print(" | XBee Python Library Read Local ADC Sample |")
    print(" +-------------------------------------------+\n")

    th = None

    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        device.open()

        device.set_io_configuration(IOLINE_IN, IOMode.ADC)

        stop = False

        def polling_adc():
            while not stop:
                # Read the analog value from the input line.
                value = device.get_adc_value(IOLINE_IN)
                print("%s: %d" % (IOLINE_IN, value))
                time.sleep(1)

        th = threading.Thread(target=polling_adc)
        th.start()

        input()

    finally:
        stop = True
        if th is not None and th.isAlive():
            th.join()
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 23
0
def main():
    print(" +-----------------------------------------------+")
    print(" | XBee Python Library Set/Get parameters Sample |")
    print(" +-----------------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        device.open()

        # Set parameters.
        device.set_parameter(PARAM_NODE_ID, bytearray(PARAM_VALUE_NODE_ID, 'utf8'))
        device.set_parameter(PARAM_PAN_ID, PARAM_VALUE_PAN_ID)
        device.set_parameter(PARAM_DEST_ADDRESS_H, PARAM_VALUE_DEST_ADDRESS_H)
        device.set_parameter(PARAM_DEST_ADDRESS_L, PARAM_VALUE_DEST_ADDRESS_L)

        # Get parameters.
        print("Node ID:                     %s" % device.get_parameter(PARAM_NODE_ID).decode())
        print("PAN ID:                      %s" % utils.hex_to_string(device.get_parameter(PARAM_PAN_ID)))
        print("Destination address high:    %s" % utils.hex_to_string(device.get_parameter(PARAM_DEST_ADDRESS_H)))
        print("Destination address low:     %s" % utils.hex_to_string(device.get_parameter(PARAM_DEST_ADDRESS_L)))

        print("")
        print("All parameters were set correctly!")

    finally:
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 24
0
def main():

    print(" +---------------------+")
    print(" | Read IO Sample Test |")
    print(" +---------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        device.open()

        device.set_io_configuration(IOLine.DIO1_AD1, IOMode.DIGITAL_IN)

        sample = device.read_io_sample()
        assert (sample.has_digital_value(IOLine.DIO1_AD1))

        remote = RemoteXBeeDevice(device, x64bit_addr=REMOTE_DEVICE_ADDRESS)

        remote.set_io_configuration(IOLine.DIO1_AD1, IOMode.DIGITAL_IN)
        sample = remote.read_io_sample()
        assert (sample.has_digital_value(IOLine.DIO1_AD1))

        print("Test finished successfully")

    finally:
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 25
0
def main():
    coord = XBeeDevice('COM7', 9600) #create Xbeedevice Coord at COM7 & baud rate 9600 
    try:
        coord.open() #calling method to open communication with Xbee device
        coord.flush_queues()

        xbee_network = coord.get_network() #getting a newtwork and assigning it to the xbee
        router2 = xbee_network.discover_device('R3') # find the remote device on the network at R1

        if router2 is None:
            print("Could not find the remote device")
        else :
            print("Remote device found")

        while True:
            xbee_message = coord.read_data()
            if xbee_message is not None:
                timestamp = round(time.time())
                data_raw = xbee_message.data.decode().split(",")
                data = [float(element) for element in data_raw]
                # Temperature
                print("At {0} Temperature is {1}".format(timestamp, data[0]), end=": ")
                if data[0] > 23.7:
                    print("Unsafe")
                    if router2 is not None:
                        coord.send_data(router2, "T1")
                else:
                    print("Safe")
                    if router2 is not None:
                        coord.send_data(router2, "T0")
    finally:
        if coord is not None and coord.is_open():
            coord.close()
Ejemplo n.º 26
0
def main():
    print(" +----------------------------------------------+")
    print(" | XBee Python Library Format Filesystem Sample |")
    print(" +----------------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        device.open()
        filesystem_manager = LocalXBeeFileSystemManager(device)
        print("Starting file system manager...", end=" ")
        filesystem_manager.connect()
        print("OK\n")

        get_fs_info(filesystem_manager)

        print("\nFormatting filesystem...", end=" ")
        filesystem_manager.format_filesystem()
        print("OK\n")

        get_fs_info(filesystem_manager)

    except (XBeeException, FileSystemException) as e:
        print("ERROR: %s" % str(e))
        exit(1)
    finally:
        if filesystem_manager.is_connected:
            print("\nStopping file system manager...", end=" ")
            filesystem_manager.disconnect()
            print("OK")
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 27
0
def main():
    print(" +--------------------------------------+")
    print(" |           Sender (Station)           |")
    print(" +--------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)
    try:
        device.open()
        # Obtain the remote XBee device from the XBee network.
        xbee_network = device.get_network()
        remote_device = xbee_network.discover_device(REMOTE_NODE_ID)

        commActive = True
        if remote_device is None:
            print("Could not find the remote device")
            exit(1)

        while commActive:
            print(remote_device)
            action = input("action: ")
            device.send_data_async(remote_device, action)
            print("Success")
            if action == "exit":
                commActive = False

    finally:
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 28
0
def main():
    print(" +--------------------------------------+")
    print(" | XBee Python Library Send Data Sample |")
    print(" +--------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        device.open()

        # Obtain the remote XBee device from the XBee network.
        xbee_network = device.get_network()
        remote_device = xbee_network.discover_device(REMOTE_NODE_ID)
        if remote_device is None:
            print("Could not find the remote device")
            exit(1)

        # send data to the remote node id
        while True:
            raw_val = device.get_adc_value(IOLine.DIO0_AD0)
            voltage = (raw_val/1024) *3.3
            p = ((voltage - .33)/1.32) - 1
            string = str(p)
            device.send_data(remote_device, string)

       
    #device will close if there is a error
    finally:
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 29
0
def main():
    print(" +--------------------------------------+")
    print(" | XBee Python Library Send Data Sample |")
    print(" +--------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)

    # 这部分可选,传输Timeout
    # Retrieving the configured timeout for synchronous operations.
    print("Current timeout: %d seconds" % device.get_sync_ops_timeout())
    # 默认是4s
    # Configuring the new timeout (in seconds) for synchronous operations.
    device.set_sync_ops_timeout(NEW_TIMEOUT_FOR_SYNC_OPERATIONS)

    try:
        device.open()

        # Obtain the remote XBee device from the XBee network.
        xbee_network = device.get_network()
        remote_device = xbee_network.discover_device(REMOTE_NODE_ID)
        if remote_device is None:
            print("Could not find the remote device")
            exit(1)

        print("Sending data to %s >> %s..." % (remote_device.get_64bit_addr(), DATA_TO_SEND))

        device.send_data(remote_device, DATA_TO_SEND)

        print("Success")

    finally:
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 30
0
def main():
    print(" +--------------------------------------+")
    print(" | XBee Python Library Send Data Sample |")
    print(" +--------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        device.open()

        # Obtain the remote XBee device from the XBee network.
        xbee_network = device.get_network()
        remote_device = xbee_network.discover_device(REMOTE_NODE_ID)
        if remote_device is None:
            print("Could not find the remote device")
            exit(1)

        print("Sending data to %s >> %s..." %
              (remote_device.get_64bit_addr(), DATA_TO_SEND))

        device.send_data(remote_device, DATA_TO_SEND)

        print("Success")

    finally:
        if device is not None and device.is_open():
            device.close()
Ejemplo n.º 31
0
def main():

    print(" +------------+")
    print(" | Reset Test |")
    print(" +------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        device.open()

        def modem_status_callback(status):
            if status == ModemStatus.COORDINATOR_STARTED:
                return
            assert (status in [ModemStatus.HARDWARE_RESET, ModemStatus.WATCHDOG_TIMER_RESET])

        device.add_modem_status_received_callback(modem_status_callback)

        for i in range(10):
            device.reset()
            time.sleep(1)

        print("Test finished successfully")

    finally:
        if device is not None and device.is_open():
            device.close()