GSM modem module for Python
python-gsmmodem is a module that allows easy control of a GSM modem attached to the system. It also includes a couple of useful commandline utilities for interacting with a GSM modem.
Its features include:
- simple methods for sending SMS messages, checking signal level, etc
- easy-to-use API for starting and responding to USSD sessions and making voice calls
- handling incoming phone calls and received SMS messages via callback methods
- support for SMS PDU and text mode
- support for tracking SMS status reports
- wraps AT command errors into Python exceptions by default
- modular design; you easily issue your own AT commands to the modem (with error checking), or read/write directly from/to the modem if you prefer
- comprehensive test suite
Bundled utilities:
- GSMTerm: an easy-to-use serial terminal for communicating with an attached GSM modem. It features command completion, built-in help for many AT commands, history, context-aware prompt, etc.
- sendsms.py: a simple command line script to send SMS messages
- identify-modem.py: simple utility to identify attached modem. Can also be used to provide debug information used for development of python-gsmmodem.
Go to examples/ directory in this repo.
- Python 3.3 or later
- pyserial-asyncio-fast <https://github.com/home-assistant-libs/pyserial-asyncio-fast>
There are multiple ways to install python-gsmmodem-stk
package:
pip install python-gsmmodem-stk
pip will automatically download and install
all dependencies, as required. You can also utilise easy_install
in the
same manner as using pip
above.
If you are utilising python-gsmmodem-stk
as part of another project,
add it to your install_requires
section of your setup.py
file and
upon your project's installation, it will be pulled in automatically.
Download a python-gsmmodem-stk
archive from PyPI, extract it and install the package with command:
python setup.py install
Note that python-gsmmodem-stk
package relies on pySerial
for serial communications:
https://github.com/pyserial/pyserial
Clone from GitHub:
git clone https://github.com/strokovnjaka/python-gsmmodem.git cd python-gsmmodem/ python setup.py install
Note that python-gsmmodem-stk
package relies on pySerial
for serial communications:
https://github.com/pyserial/pyserial
To run all unit tests, do:
python setup.py test
Unit test code coverage information may be generated by using coverage. You can execute it directly from setup.py by doing:
python setup.py coverage
This will run all unit tests and report on code coverage statistics.
This package contains Sphinx-based documentation. To manually build or test the documentation locally, do the following:
git clone https://github.com/strokovnjaka/python-gsmmodem.git cd python-gsmmodem pip install .[doc] cd doc make html
For true isolation, you may wish to run the above commands within a virtualenv, which will help you manage this development installation.
Copyright (C) 2013 Francois Aucamp See AUTHORS for all authors and contact information.
- License: GNU Lesser General Public License, version 3 or later; see COPYING
- included in this archive for details.
You can simply list all ttyUSB devices before and after pluging the modem in.
ls /dev/ttyUSB*
On Windows, port is from COM1 to COM9, you can check using the 'mode' command in cmd.
Check running processes. The device could be occupied by another program or another instance of gsmmodem which is still running in the background. Run sudo lsof | grep tty
, try to locate the problematic process and sudo kill <PID>
.