We have been testing our XBee Pro SX Modules for communication and we were looking to connect two and retrieve some useful data. In order to accomplish this goal, we attempted on using the xbee-python library provided by digi. However, this was not executable in the FCU (Linux environment) due to unknown reasons.
- digi.xbee.exception.InValidOperatingModeException: Could not determine operating mode
- In Windows Environment (Python 3.10.8), after fixing import from device to DigiMeshDevice, we were able to make the xbee-python work.
We looked for alternative methods and settled on PySerial. However, although sending and receiving was well and done. We couldn’t decode the messages that were coming from the transmitter. We suspected that it would be either in the format of hexadeicmal or utf-8, but these weren’t the format.
- The data received were in this format: �vV6���������ֶ�vV6���������ֶ�vV6
And couldn’t be decoded using any other methods.
We were hoping to get guidance in regards to this problem and any potential solutions or advice would be appreciated. If you require further details regarding this problem. Please let me know.
import serial
import time
# Replace with the serial port where your local module is connected to.
PORT = "/dev/ttyTHS1" # Linux
# Replace with the baud rate of your local module.
BAUD_RATE = 9600
DATA_TO_SEND = "hello"
def main():
# Open the serial port.
with serial.Serial(PORT, BAUD_RATE) as ser:
# Allow time for the device to connect.
time.sleep(1)
hex_data = DATA_TO_SEND.encode().hex()
# Write the data.
ser.write(bytes.fromhex(hex_data))
print(f"Sent data: {DATA_TO_SEND}")
print(f"Encoded Data: {hex_data}")
if __name__ == "__main__":
main()