• Stars
    star
    132
  • Rank 274,205 (Top 6 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created over 15 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Send and receive SMS via a GSM modem in Python
class GsmModem(__builtin__.object)
 |  pyGSM is a Python module which uses pySerial to provide a nifty
 |  interface to send and receive SMS via a GSM Modem. It was ported
 |  from RubyGSM, and provides (almost) all of the same features. It's
 |  easy to get started:
 |
 |    # create a GsmModem object:
 |    >>> modem = pygsm.GsmModem(port="/dev/ttyUSB0")
 |
 |    # harass Evan over SMS:
 |    # (try to do this before 11AM)
 |    >>> modem.send_sms(*REDACTED*, "Hey, wake up!")
 |
 |    # check for incoming SMS:
 |    >>> print modem.next_message()
 |    <pygsm.IncomingMessage from *REDACTED*: "Leave me alone!">
 |
 |  pyGSM is distributed via GitHub:
 |  http://github.com/adammck/pygsm
 |
 |  Bug reports (especially for
 |  unsupported devices) are welcome:
 |  http://github.com/adammck/pygsm/issues
 |
 |
 |
 |
 |  Methods defined here:
 |
 |
 |  __init__(self, *args, **kwargs)
 |      Create a GsmModem object. All of the arguments are passed along
 |      to serial.Serial.__init__ when GsmModem.connect is called. For
 |      all of the possible configration options, see:
 |
 |      http://pyserial.wiki.sourceforge.net/pySerial#tocpySerial10
 |
 |      Alternatively, a single 'device' kwarg can be passed, which
 |      overrides the default proxy-args-to-pySerial behavior. This is
 |      useful when testing, or wrapping the serial connection with some
 |      custom logic.
 |
 |      NOTE: The serial connection isn't created until GsmModem.connect
 |      is called. It might still fail (but should raise GsmConnectError
 |      when it does so.)
 |
 |
 |  boot(self, reboot=False)
 |      (Re-)Connect to the modem and configure it in an (often vain)
 |      attempt to standardize the behavior of the many vendors and
 |      models. Should be called before reading or writing.
 |
 |      This method isn't called during __init__ (since 5f41ba6d), since
 |      it's often useful to create GsmModem objects without writing to
 |      the modem. To compensate, this method returns 'self', so it can
 |      be easily chained onto the constructor, like so:
 |
 |        >>> gsm = GsmModem(port="whatever").boot()
 |
 |      This is exactly the same as:
 |
 |        >>> gsm = GsmModem(port="whatever")
 |        >>> gsm.boot()
 |
 |
 |  command(self, cmd, read_term=None, read_timeout=None, write_term='\r', raise_errors=True)
 |      Issue an AT command to the modem, and return the sanitized
 |      response. Sanitization removes status notifications, command
 |      echo, and incoming messages, (hopefully) leaving only the actual
 |      response to the command.
 |
 |      If Error 515 (init or command in progress) is returned, the
 |      command is automatically retried up to 'GsmModem.max_retries'
 |      times.
 |
 |
 |  connect(self, reconnect=False)
 |      Connect to the modem via pySerial, using the args and kwargs
 |      provided to the constructor. If 'reconnect' is True, and the
 |      modem is already connected, the entire serial.Serial object is
 |      destroyed and re-established.
 |
 |      Returns self.device, or raises GsmConnectError
 |
 |
 |  disconnect(self)
 |      Disconnect from the modem.
 |
 |
 |  hardware(self)
 |      Return a dict of containing information about the modem. The
 |      contents of each value are entirely manufacturer-dependant, and
 |      can vary wildly between devices.
 |
 |
 |  next_message(self, ping=True, fetch=True)
 |      Returns the next waiting IncomingMessage object, or None if the
 |      queue is empty. The optional 'ping' and 'fetch' args control
 |      whether the modem is pinged (to allow new messages to be
 |      delivered instantly, on those modems which support it) and
 |      queried for unread messages in storage, which can both be
 |      disabled in case you're already polling in a separate thread.
 |
 |
 |  ping(self)
 |      Send the "AT" command to the device, and return true if it is
 |      acknowledged. Since incoming notifications and messages are
 |      intercepted automatically, this is a good way to poll for new
 |      messages without using a worker thread like RubyGSM.
 |
 |
 |  query(self, cmd, prefix=None)
 |      Issue an AT command to the modem, and returns the relevant part
 |      of the response. This only works for commands that return a
 |      single line followed by "OK", but conveniently, this covers
 |      almost all AT commands that I've ever needed to use. Example:
 |
 |        >>> modem.query("AT+CSQ")
 |        "+CSQ: 20,99"
 |
 |      Optionally, the 'prefix' argument can specify a string to check
 |      for at the beginning of the output, and strip it from the return
 |      value. This is useful when you want to both verify that the
 |      output was as expected, but ignore the prefix. For example:
 |
 |        >>> modem.query("AT+CSQ", prefix="+CSQ:")
 |        "20,99"
 |
 |      For all unexpected responses (errors, no output, or too much
 |      output), returns None.
 |
 |
 |  query_list(self, cmd, prefix=None)
 |      Issue a single AT command to the modem, checks that the last
 |      line of the response is "OK", and returns a list containing the
 |      other lines. An empty list is returned if a command fails, so
 |      the output of this method can always be assumed to be iterable.
 |
 |      The 'prefix' argument can optionally specify a string to filter
 |      the output lines by. Matching lines are returned (sans prefix),
 |      and the rest are dropped.
 |
 |      Most AT commands return a single line, which is better handled
 |      by GsmModem.query, which returns a single value.
 |
 |
 |  reboot(self)
 |      Disconnect from the modem, reconnect, and reboot it (AT+CFUN=1,
 |      which clears all volatile state). This drops the connection to
 |      the network, so it's wise to call _GsmModem.wait_for_network_
 |      after rebooting.
 |
 |
 |  send_sms(self, recipient, text)
 |      Send an SMS to 'recipient' containing 'text'. Some networks will
 |      automatically split long messages into multiple parts, and join
 |      them upon delivery -- but some will silently drop them. pyGSM
 |      does nothing to avoid this (for now), so try to keep 'text'
 |      under 160 characters.
 |
 |
 |  signal_strength(self)
 |      Return an integer between 1 and 99, representing the current
 |      signal strength of the GSM network, False if we don't know, or
 |      None if the modem can't report it.
 |
 |
 |  wait_for_network(self)
 |      Block until the signal strength indicates that the device is
 |      active on the GSM network. It's a good idea to call this before
 |      trying to send or receive anything.
 |
 |
 |
 |
 |  Data descriptors defined here:
 |
 |
 |  network
 |      Return the name of the currently selected GSM network.
 |
 |
 |  service_center
 |      Get or set the service center address currently in use by the
 |      modem. Returns None if the modem does not support the AT+CSCA
 |      command.

More Repositories

1

terraform-inventory

Terraform State β†’ Ansible Dynamic Inventory
Go
1,817
star
2

ruby-icloud

Ruby library to access Apple's iCloud (Just reminders, for now)
Ruby
126
star
3

hexapod

Golang program for my junky robot
Go
63
star
4

rubygsm

Ruby interface to AT-compatible GSM modems
Ruby
48
star
5

minitest-stub-const

Stub constants for the duration of a block in MiniTest
Ruby
39
star
6

gh-news-feed-filters

Chrome extension to add per-repo alert filtering to GitHub's news feed
CoffeeScript
23
star
7

rubysms

Build SMS applications with Ruby
Ruby
20
star
8

pykannel

Kannel helper class (to send and receive SMS messages) in Python
Python
18
star
9

djtables

Declarative HTML table builder for Django
Python
16
star
10

forkreadme

Generate useful READMEs for GitHub forks
Ruby
16
star
11

djappsettings

Per-app default settings for Django
Python
15
star
12

icloud-reminders-cli

Command-line tool for managing iCloud reminders
Ruby
13
star
13

djtokeninput

jQuery Tokeninput for Django forms
Python
13
star
14

ranger

Generic range-based sharding prototype
Go
12
star
15

fuzz

Extract tokens from arbitrary strings in Ruby
Ruby
10
star
16

bam

Pow.cx for Django
Python
9
star
17

django-monkey-patching

Sandbox for extending Django models in a sane way
Python
8
star
18

pygnokii

Gnokii helper class (to send and receive SMS messages) in Python
Python
8
star
19

venv

Golang library to abstract and mock ENV access
Go
8
star
20

freshdirect

Golang interface to FreshDirect.com
Go
8
star
21

headless-raspbian

Create a Raspbian image with wifi and SSH
Shell
8
star
22

plumpynut

Delivery monitoring of Plumpynuts via SMS
JavaScript
7
star
23

spomskyd

RubySMS application to implement the OMC SMS Proxy Protocol
Ruby
6
star
24

socialsms

Anonymous SMS-based group messaging system
Python
6
star
25

dm-fuzz

Rich property types for DataMapper, with fancy string parsing
Ruby
6
star
26

reefer

Ruby interface to Etherpad
Ruby
6
star
27

columbawawi

Child growth monitoring over SMS
Ruby
6
star
28

restartomatic

Restart (Or re-run) a process every time the contents of a directory change
5
star
29

rapidsms-example-project

Python
5
star
30

sixaxis

Golang interface to the Sixaxis (PS3 controller)
Go
5
star
31

smsapp

Generic abstraction layer to implement SMS applications via PyKannel or PyGnokii
Python
5
star
32

crabgrass

My working copy of git://labs.riseup.net/crabgrass.git
Ruby
5
star
33

pull-status

Pull request status images (open, merged, or rejected)
Ruby
5
star
34

django-app-dependencies

Manage the dependencies between Django apps
Python
5
star
35

dynamixel

Go interface to Dynamixel servos
Go
5
star
36

minitest-pretty_diff

Pretty-print hashes and arrays before diffing them in MiniTest
Ruby
4
star
37

rapidsms-search-app

RapidSMS library for finding references to models in fuzzy strings
Python
4
star
38

gmaps-v3-mask

Inverse polygons for Google Maps v3
JavaScript
4
star
39

django-dbus-signals

Interface between Django signals and D-Bus
Python
4
star
40

rapidsms-questions-app

Python
4
star
41

gitfeeds

Git via RSS, because GitHub's News Feed is too noisy (for me)
Ruby
4
star
42

hexapod-parts

4
star
43

unicefinnovation

UNICEF Innovation dot org
PHP
3
star
44

rapidsms-community-apps

Python
3
star
45

djsms

Here be dragons
Python
3
star
46

mvln

Move a file, and create a symlink to its new location
3
star
47

dotfiles

These aren't the dotfiles you're looking for.
Shell
3
star
48

yjir

Youth Journalist Information Resource
JavaScript
3
star
49

smspoll

an Iraq Fit For Children: SMS Poll
Python
2
star
50

relreq

Require files using relative paths in Ruby
Ruby
2
star
51

git-grep-service

Sinatra JSON API to grep remote Git repos
Ruby
2
star
52

gmaps-v3-label-marker

Markers with HTML content for Google Maps v3
JavaScript
2
star
53

pants

Command-line application to transform an RSS feed into a chunk of HTML via ERB
Ruby
2
star
54

ik

Inverse Kinematics in Golang
Go
2
star
55

figleaf-pkgbuild

Arch Linux PKGBUILD for figleaf (a Python code coverage analysis tool)
1
star
56

sudoku

Rather crappy sudoku board generator in Python.
Python
1
star
57

retroport

Golang interface to USB RetroPort adapters
Go
1
star
58

rk-dont-break-the-chain

Don't Break the Chain calendar via the RunKeeper/Health Graph API
Ruby
1
star
59

hexapod-infra

Shell
1
star
60

gorubiks

Rubiks cube solver in Go. It doesn't work.
Go
1
star
61

iffc-wireframe

Python
1
star
62

krang

Etherpad plus Markdown minus like 90% of the features
JavaScript
1
star
63

handlebars

Handlebars in Go
Go
1
star
64

remotefile

Go library to read/write remote files via the local filesystem
Go
1
star
65

unicef-mapping-demo

Project Mapping and Regional Information UI
JavaScript
1
star