User Tools

Site Tools


public:protocols:python-digi-xbee

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
public:protocols:python-digi-xbee [2020/05/10 15:33] – timdv91public:protocols:python-digi-xbee [2023/02/26 04:51] (current) – external edit 127.0.0.1
Line 1: Line 1:
-Usage of digi.xbee library for wireless data communication:+====== Digi.Xbee library:======
  
 +Usage of digi.xbee library for wireless data communication:
 Source: [[https://xbplib.readthedocs.io/en/latest/getting_started_with_xbee_python_library.html]] Source: [[https://xbplib.readthedocs.io/en/latest/getting_started_with_xbee_python_library.html]]
 +<code bash Install > pip3 install digi-xbee </code>
 +<code bash fix install error> pip3 install --upgrade setuptools </code>
  
-Typical imports:  +===== Typical required imports: ===== 
-<code python>+<code python imports>
 import time import time
 import sys import sys
Line 12: Line 15:
 </code> </code>
  
-Typical instantiation of local device object:  +===== Typical instantiation of local device: ===== 
-<code python>+<code python init local devices>
 # instantiate XbeeDevice object: # instantiate XbeeDevice object:
 #device = XBeeDevice("/dev/ttyS2", 9600) #device = XBeeDevice("/dev/ttyS2", 9600)
Line 22: Line 25:
 </code> </code>
  
-Typical instantiation of a remote device & set pin DIO11 on remote device high: +===== Typical instantiation of a remote device: ===== 
-<code python>+<code python init remote-devices>
 # Instantiate a remote XBee device object. # Instantiate a remote XBee device object.
 remote_device = RemoteXBeeDevice(device, XBee64BitAddress.from_hex_string("0013A200xxxxxxxx")) remote_device = RemoteXBeeDevice(device, XBee64BitAddress.from_hex_string("0013A200xxxxxxxx"))
 +</code>
 +
 +===== remote pin control: =====
 +<code python set IO>
 remote_device.set_io_configuration(IOLine.DIO11_PWM1, IOMode.DIGITAL_OUT_HIGH) remote_device.set_io_configuration(IOLine.DIO11_PWM1, IOMode.DIGITAL_OUT_HIGH)
 </code> </code>
 +===== Typical serial data transmission: =====
 +  * Send text to remote receiver 
 +  * receive text back from remote receiver
 +<code python serial data communication>
 +# Send data using the remote object.
 +#state = device.send_data(remote_device, "Hello XBee!")
 +sendID = 0
 +while(True):
 +    if(sendID == 3):
 +        sendID = 0
 +    else:
 +        sendID += 1
  
 +    #h = hex(sendID)
 +    #v = ("\xFF".encode('Latin-1'))
 +    #state = device.send_data(remote_device, v)
  
 +    state = device.send_data(remote_device, chr(sendID))
 +
 +    if(state != None):
 +        print(state.transmit_status)
 +
 +    time.sleep(0.2)
 +
 +    # Read data.
 +    xbee_message = device.read_data()
 +    if(xbee_message != None):
 +        remote_device = xbee_message.remote_device
 +        data = xbee_message.data
 +        is_broadcast = xbee_message.is_broadcast
 +        timestamp = xbee_message.timestamp
 +
 +        print(str(data.decode()))
 +    else:
 +        print("No return message")
 +
 +</code>
 +
 +===== At end of program: =====
 +<code python close port>
 +device.close()
 +</code>
public/protocols/python-digi-xbee.1589124781.txt.gz · Last modified: (external edit)