Cell Signal Strength Monitoring
This summer, AT&T's cell tower servicing my house became extremely unreliable. The cell signal regularly completely disappeared for hours at a time. AT&T made various excuses about maintenance, etc., but none were believable. (Would they really be doing maintenance when the signal dropped at 11PM? In a rainstorm?)
It seemed like even they really had no idea what was going on with their cell tower. As an experiment, I wrote some code to log the signal level. I think I was doing more to monitor AT&T's tower than they were.
It turns out that most phones have a terminal interface based on the AT command set typically used for modems. Commands are available to do exactly what I need. Even if you don't have a need to log the signal strength, this might be something fun to play around with.
Connect to the phone over bluetooth using the command
sudo rfcomm bind 0 MAC
. The MAC address is probably on a label under the battery,
or can be found in the output of sudo hcitool scan
after setting your phone to be
discoverable. The serial port of the phone appears as the /dev/rfcomm0
device.
USB is also an option. My phone (Motorola RAZR V3re) appears as /dev/ttyACM0
when connected, but
yours may differ.
For testing and experimentation, open gtkterm
and connect to the serial terminal device (probably /dev/rfcomm0
or /dev/ttyACM0
).
You may have to change permissions if you don't have access as your user.
The init string AT S7=45 S0=0 V1 X4 &c1 E0
puts the phone in a mode where it can receive the extended
AT commands. I took this line from the configuration of KMobileTools.
AT+CIND?
reads the "indicators" from the phone. On my phone
these include the # of bars of signal, whether the phone is connected to the
network, whether there are voicemails, and whether the phone is on a call.
Example output is +CIND: 0,1,0,0,2,0,0
.
AT+CIND=?
lists the values and their possible ranges.
My phone returns
+CIND: ("Voice Mail",(0,1)),("service",(0,1)),("call",(0,1)),("Roam",(0-2)),("signal",(0-5)),("callsetup",(0-3)),("smsfull",(0,1))
.
AT+CSQ
displays the signal quality. Example output: +CSQ: 9,99
It seems to vary with # of bars, but is
less meaningful to me than the output of AT+CIND?
. My script records it
anyway.
Many more commands can be found in the GSM documentation [PDF link]. There are several that may be very useful for manipulating phonebook entries and sending/receiving text messages.
My monitoring script connects to the phone and runs the AT+CIND?
and AT+CSQ
commands every 30 seconds, logging the results to a file.
Run python cell-strength.py /dev/rfcomm0 out.log
.
Another script reads the log file and computes statistics. You can run
python cell-stats.py day FILENAME
for a hour-by-hour summary of a day's log file, or
file=FILENAME; tail -f $file | python cell-stats.py live $file
for a live display.
AT&T's tower has remained stable for over a month, and let's hope it stays that way. However, this may be an experiment you'd like to replicate if you're having a similar problem, or just for the fun of experimenting with it.