1

I'm trying to use my Raspberry Pi B+ as a gateway so others sensors, also with xbee, can send data and get a few kind of commands by it. The problem is that i can only read the data with the simplest code:

import time
import serial
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(23,GPIO.OUT)
ser = serial.Serial(
    port='/dev/ttyS0',
    baudrate = 115200,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1             
 )
while 1:
    x=ser.readline()    
    print(x)

but i want to use the xbee-api to have access to write options and another read stuffs. The problem is that i get this error:

pi@raspberrypi:~ $ sudo python3 Desktop/testePython.py 
Traceback (most recent call last):
  File "Desktop/testePython.py", line 5, in <module>
    local_xbee.open()
  File "/usr/local/lib/python3.5/dist-packages/digi/xbee/devices.py", line 1259, in open
    raise InvalidOperatingModeException("Could not determine operating mode")
digi.xbee.exception.InvalidOperatingModeException: Could not determine operating mode

when i use this code:

from digi.xbee.devices import XBeeDevice

# Instantiate an XBee device object.
local_xbee = XBeeDevice("/dev/ttyS0", 115200)
local_xbee.open()

More details:
Xbee-api library
Xbee model: XBO09-DM
Already went to "raspi-config" to enable the serial interface
Already tried Xbee API Options with =1 and with =2.

SWoto
  • 117
  • 1
  • 1
  • 9

1 Answers1

1

It worked with the following steps:
API=2
systemctl stop
DigiMeshDevice instead of XBeeDevice


from digi.xbee.devices import DigiMeshDevice, RemoteXBeeDevice
from digi.xbee.models.address import XBee64BitAddress
import os

os.system("sudo systemctl stop serial-getty@ttyS0.service")

# Instantiane an XBee device object
device = DigiMeshDevice('/dev/ttyS0',115200)
device.open()

while True:
    try:
        xbee_message = device.read_data()
        print(xbee_message.data.decode("utf-8"))
    except Exception as e:
        device.close()
        print(e)
        exit(1)
SWoto
  • 117
  • 1
  • 1
  • 9