Hello everyone,
I am currently working on a project to send automated SMS messages using a GL-Inet Spitz AX router (model: GL-X3000) through Python scripts. I aim to control a 5G modem connected via the MHI interface (/dev/mhi_DUN
).
I’ve been able to successfully send AT commands using the echo
command in the shell (e.g., echo -e "AT\r" > /dev/mhi_DUN
), and I receive expected responses from the modem. However, I am encountering issues when trying to replicate this functionality in Python using the PySerial library.
Here are the methods and tools I’ve tried so far:
- Minicom:
minicom -D /dev/mhi_DUN -b 115200
I can read responses from the modem but am unable to type or send commands directly within Minicom. - Screen:
screen /dev/mhi_DUN 115200
Attempts to use this tool resulted in a/dev/null/utmp: Not a directory
error, and it terminates immediately. - Picocom:
picocom -b 115200 /dev/mhi_DUN
Similar to Screen, Resulted inFATAL: failed to add port: Filedes is not a tty
- Python (PySerial): I wrote a script to send commands and read responses. Commands like
ser.write(b'AT\r')
are used to write to the modem. However, when I try to read the response withser.read_all()
, I encounter anOSError: [Errno 22] Invalid argument
.
Here’s a snippet of my Python code:
import serial
import time
ser = serial.Serial('/dev/mhi_DUN', 115200, timeout=1)
ser.write(b'AT\r')
time.sleep(1)
response = ser.read_all()
print(response)
ser.close()
The error occurs specifically at the ser.read_all()
call. I’ve tried adjusting various serial port settings (baud rate, timeouts) but to no avail.
Has anyone experienced similar issues or have suggestions on how to resolve these communication problems with MHI devices in Python? Any help or guidance would be greatly appreciated as my goal is to automate SMS sending via this setup.
Thank you in advance!