I was unable to communicate with my Huawei E3372h-158 with @hlovdal's solution, so I rolled my own using expect
and screen
, in this case for reading the temperature sensors via ^CHIPTEMP?
:
output=$(sudo expect <<EOF
set timeout 5
log_user 0 spawn sudo screen /dev/ttyUSB0-
sleep 1
send "AT\x5ECHIPTEMP?\r"
expect "OK"
puts "\n-->\$expect_out(buffer)<--"
# Send C-a \ to end the session
send "\x01"
send "\x5C"
EOF
)
# Strip non-printable control characters
output=$(printf "$output" | tr -dc '[:print:]\n' )
printf "$output\n" | grep -P "^\^CHIPTEMP"
Hints and caveats: Set log_user 1
to get the output of screen
. Not sure screen
works in all cases as it produces some non-printing characters and perhaps repeating output.
socat
orminicom
to establish a serial connection with the modem. See: How to send AT commands to a modem in Linux? – Aciniform