Trying to capture USB modem AT command response

Per topic, I'm trying to capture the output of AT commands sent to an LTE modem attached to an OpenWrt 18.06.2 router to log signal data that uqmi doesn't provide. For example, this is the response I get if I issue the command "at!gstatus?" to the modem using screen or minicom.

Current Time:  561592           Temperature: 39
Reset Counter: 1                Mode:        ONLINE
System mode:   LTE              PS state:    Attached
LTE band:      B2               LTE bw:      15 MHz
LTE Rx chan:   876              LTE Tx chan: 18876
EMM state:     Registered       Normal Service
RRC state:     RRC Connected
IMS reg state: No Srv

PCC RxM RSSI:  -69              RSRP (dBm):  -97
PCC RxD RSSI:  -74              RSRP (dBm):  -100
Tx Power:      0                TAC:         (data removed)
RSRQ (dB):     -8.3             Cell ID:     (data removed)
SINR (dB):     15.0


however, when I script that same command as below, the output is very inconsistent. Sometimes it works, often it's just partial. The output is never incorrect/incomplete/inconsistent when I enter the command directly, only when I script it through chat.

chat -t5 -e '' 'at!gstatus?' 'OK' '' < /dev/ttyUSB2 > /dev/ttyUSB2`

Thoughts? Or is there a better way on OpenWrt to script AT commands and log the result?

Thanks much

I typically use Python (3) for this kind of thing, with multi-threading. One typically needs an “independent” reader and writer for robust operation. Python isn’t small. You probably would need the lite and serial packages.

Unfortunately I know next to nothing about Python. Would seem I should be able to script this simply with minicom or something designed for this, but I'm striking out.

minicom would seem to just need something like:

minicom -D /dev/ttyUSB2 -S scriptname -C capture

but for the life of me the script won't run that way, I just get a normal interactive minicom console, and my script doesn't appear to have run at all.

Thoughts? Thanks.

The tricky thing is you need:

your_script ==> | ==> /dev/ttyUSB2
                | ==> your_log

and, simultaneously

your_script <== | <== /dev/ttyUSB2
   your_log <== | 

While minicom, screen, or the like works OK for interactive input, you need to feed it from and have it feed a script. There might be some way to do it with redirecting both STDIN and STDOUT, but I've never tried to tackle that.

1 Like

In my case I think I just need the simple functionality of a capture file, I'm not really doing anything interactive. I'm dumping a single command to the local modem device and I just want to capture the output, which is exactly the scenario -S and -C in minicom seem ideal for.

Just this one-liner (and then exit) and log the output for massaging into a csv log of the signal info.

send "at!gstatus?\r"

Thoughts? Thanks.


printf "at!gstatus?\r" > /dev/ttyUSB2
sleep 1  # Or however long it takes to respond
cat /dev/ttyUSB2 >> your_log_file
1 Like

Tried that earlier, and it "almost" works, except that the cat never exits -- It basically acts like "tail -f"

Aha, prefixed the call to cat with "timeout" and it seems to do what I need.

printf "at!gstatus?\r" > /dev/ttyUSB2 && timeout 1 cat /dev/ttyUSB2 > output

Any add'l thoughts or advice? Thanks for brainstorming with me.


If cat or tail don't work, then try reading character by character, checking that the IOCTLs are set up properly, and the like. ttys can be very fickle