I
I
Ivan Zhuravlev2021-03-23 17:45:02
linux
Ivan Zhuravlev, 2021-03-23 17:45:02

How to send AT command from python script to modem and get response?

Good day to all. Please tell me how it would be most correct and efficient to solve the following problem:

  1. We have a Linux device running a Python script.
  2. We have an LTE router on a manufacturer-modified OpenWRT. Model IRZ RL-01 (just in case). As part of the router there is a modem with which you can communicate with AT commands.
  3. The router is connected to the Linux device with a patch cord. The device in this case acts as a client and receives ip via DHCP from the router.
  4. There is a need to send AT commands to the router modem from a Python script and receive responses for further processing in the script.

I know that there are various utilities like Minicom, but this tool is more for interactively entering AT commands on a modem directly connected to a computer. But I need certain commands to be sent automatically (moreover, via TCP / IP, since the modem is on the router, which in turn is connected to the target device), and then analyzed by the script.

Are there any adequate ways to implement the behavior I need? The script on the router is not an option at all. there are very limited iron resources.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-03-23
@NeiroNx

Turn on the "TCP Converter - Serial Port" and communicate with it over the network via sockets.

s = socket(AF_INET, SOCK_STREAM)
s.connect((ip, port))
s.sendall(bytes("AT?\n","ASCII"))
sleep(1.0)
st = ""
while st[-1]!="\n":
    st+=s.recv(1)

you can also try telnet bib https://docs.python.org/3/library/telnetlib.html
there is a read_until with a timeout

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question