Last active
December 26, 2019 19:09
-
-
Save jgornick/2e910f40e162d2afe9954c91a8fe796a to your computer and use it in GitHub Desktop.
Bash: Get Cell Signal Strength
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
. /usr/bin/pdivt-funcs | |
pipe="$(mktemp -u)" | |
log info "Logging cell signal level..." | |
log info "Creating fifo at $pipe..." | |
mkfifo $pipe | |
# Start cat /dev/ttyUSB0 in the background and send its output to fifo | |
log info "Listening to /dev/ttyUSB0 and redirecting to $pipe..." | |
cat /dev/ttyUSB0 > $pipe & | |
catPid=$! | |
trap "kill -9 $catPid >& /dev/null; rm -rf $pipe >& /dev/null;" 0 | |
# Send the signal query command to the device | |
( | |
sleep 1 | |
log info "Sending cell signal query to /dev/ttyUSB0..." | |
echo 'AT+CSQ' > /dev/ttyUSB0 | |
) & | |
# Read the output from the device line by line until one line contains OK | |
log info "Waiting for cell signal query response..." | |
while read line; do | |
case "$line" in | |
*OK*) | |
break | |
;; | |
"") | |
;; | |
*) | |
line="${line// /}" | |
line=( ${line//,/ } ) | |
log info "Cell signal level is ${line[1]}." | |
echo "${line[1]}" > /tmp/cell-signal | |
log info "Cell signal level saved to /tmp/cell-signal." | |
;; | |
esac | |
done < $pipe | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment