digidotcom / xbee-python

Python library to interact with Digi International's XBee radio frequency modules.
Mozilla Public License 2.0
185 stars 93 forks source link

InvalidOperatingModeException(op_mode=self._operating_mode) #262

Closed turriert closed 3 years ago

turriert commented 3 years ago

Hello everybody,

I have a problem with the xbee-python librairy. When I execute my script I have this result :

$ python xbee.py +--------------------------------------+ | XBee Python Library Send Data Sample | +--------------------------------------+ Traceback (most recent call last): File "xbee.py", line 172, in main() File "xbee.py", line 151, in main device.open() File "/home/pi/.local/lib/python3.7/site-packages/digi/xbee/devices.py", line 2454, in open raise exc File "/home/pi/.local/lib/python3.7/site-packages/digi/xbee/devices.py", line 2451, in open self._do_open() File "/home/pi/.local/lib/python3.7/site-packages/digi/xbee/devices.py", line 2495, in _do_open raise InvalidOperatingModeException(op_mode=self._operating_mode) digi.xbee.exception.InvalidOperatingModeException: Unsupported operating mode: AT mode (0)

My python script :

from digi.xbee.devices import XBeeDevice
PORT = "/dev/ttyUSB0"
BAUD_RATE = 9600
DATA_TO_SEND = "Hello XBee!"
REMOTE_NODE_ID = "REMOTE"
def main():
    print(" +--------------------------------------+")
    print(" | XBee Python Library Send Data Sample |")
    print(" +--------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        device.open()
        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()

if __name__ == '__main__':
    main()

My configuration :

$ python --version Python 3.7.3

To install my device I did the following operations :

sudo apt-get install python3 sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 3 update-alternatives: utilisation de « /usr/bin/python3.7 » pour fournir « /usr/bin/python » (python) en mode automatique sudo apt-get install python3-pip sudo apt-get update sudo apt-get upgrade pip install digi-xbee

My Xbee Device : Xbee série 3 XB3-24Z8PT-J on USB with Module Xbee Explorer USB WRL-11812

My device configuration :

Digi Xbee3 802.15.4 TH firmware version 200D Channel : C ID : 3332 Mac mode : 802.15.4 + Digi header w/ACKS [0] Baud Rate : 9600 Data Bits : 8 Parity : None Stop Bits : 1

Can you help me please !!

tatianaleon commented 3 years ago

Hi @turriert,

Could you verify the operation mode of your local XBee? From the exception message it seems it is in transparent mode.

Unsupported operating mode: AT mode (0)

The library only supports API communication with local XBee nodes. This means its AO must be configured to use an API mode, generally AP=1. You can configure it using XCTU or you can use force_settings when opening the connection with the local XBee in your code:

device.open(force_settings=True)

Best Regards

turriert commented 3 years ago

Hi @tatianaleon,

Thank you so much ! Indeed AT was at 0 I changed it to 1.

Now I have the following message:

$ python xbee.py +--------------------------------------+ | XBee Python Library Send Data Sample | +--------------------------------------+ Could not find the remote device

But I don't understand why he gets in there. Do I have to enter the name of the destination device? If yes, how ?

Thank you !

Best regards

tatianaleon commented 3 years ago

Hi @turriert,

The method discover_device(REMOTE_NODE_ID) is not discovering a node in your network with REMOTE as node identifier (NI). You must ensure you have another node in the same network with NI=REMOTE.

I encourage you read the readme.txt file of the "Send Data Sample" to setup and launch it successfully.

Best Regards