Get Cellular Modem Signal Strength With Python
I work in the cinema sector, and as such, have encountered my fair share of poorly (or un-) documented technologies and interfaces. At least, poorly in relation to Python. SNMP was one. Custom binary communication using various KLV interfaces another. Eventually I find a way, but only after wrestling with unfamiliar protocols, ancient, unmaintained packages, and the like.
I almost never (OK, never) document what I learned, outside the internal company developer notes I deliver with completed features.
Today, I document how to write a simple cellular modem (GSM) signal strength script in Python 3. Turns out to be really simple, using the venerable PySerial
package.
Requirements
- Raspberry Pi >=3 with GSM modem module installed and configured on serial port
/dev/ttyUSB*
- Python >=3.7
- PySerial: do
pip3 install pyserial
Preparation
We will send the AT Commands via serial port, so we need to know which port to use. Run the following command in the terminal:
dmesg | grep ttyUSB
Baud rate is another important factor. The default used by the few packages I found is 115200
, so I use it too.
The Problem: Get Signal Strength
We just want to know a little thing – the signal strength – so we can just ask using [][AT Commands]
References
Not much help on the web (hence, this post). Here's what I referenced:
- PySerial documentation
- GSMTC35 Python Library: Overkill for simple things, and targeted at the TC35 GSM, but I referenced the code.
- Python-Exemplary: The only thing close to a tutorial I found
- M2MSupport Online AT Command Tester tool: Site has some general documentation about AT Commands.