Example #1
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()
Example #2
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()