Skip to main content

SMS sending and receiving with enfora gsm modems

Project description

The sms package provides sms capabilities for Enfora gsm modems, and probably others. I developed this package for my location-specific nature haiku by sms project N8R TXT (http://n8rtxt.org/).

The sms package provides Modem and Message classes for sending and receiving sms message.

The sms.server module provides two servers that allow you to dispatch incoming sms messages. The sms.echo module is an example that works with the sms.server.subprocess_server.

Usage

Create a modem object passing it the serial device ID. On windows this would be something like ‘COM1’. The example below is for mac and linux:

>>> import sms
>>> m = sms.Modem('/dev/ttyS0')

You can have use several modem objects concurrently if you have more than one modem attached to different serial ports.

To send a sms message call the send method, passing a phone number string and a message string.

>>> m.send('14161234567', 'This is a message')

If an error occurs a ModemError will be raised with the error message.

>>> m.send('14161234567', 'This is a message')
Traceback (most recent call last):
...
ModemError: ['ERROR']

You can retrieve sms messages with the messages() method. It returns a sequence of message objects.

>>> m.messages()
[<sms.Message object at 0x...>]

Message objects have a couple attributes: number, date, and text.

>>> msgs = m.messages()
>>> msgs[0].number
'+16476186676'
>>> msgs[0].date
datetime.datetime(2008, 7, 11, 11, 2, 11)
>>> msgs[0].text
'Activation code 63966 Go 2 www.ipipi.com and signin with  your username and pwd, enter 63966 to activate your mobile/account\n\nWelcome 2 ipipi.com'

After you receive messages you’ll want to delete them from the SIM card. This is done by calling the delete method on the messages.

>>> msgs[0].delete()

Rather than polling the modem to find messages you can call the wait() method, which blocks until a message is received. The wait method takes an optional timeout argument.

>>> m.wait(1) # waiting with 1 timeout
>>> m.wait() # waiting with no timeout

The wait message doesn’t return anything. You should call the messages() method after it returns to receive the messages. Note that it’s possible that there may in fact be no messages available after the wait method returns.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sms-0.3.tar.gz (5.2 kB view details)

Uploaded Source

File details

Details for the file sms-0.3.tar.gz.

File metadata

  • Download URL: sms-0.3.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sms-0.3.tar.gz
Algorithm Hash digest
SHA256 7db0355884c0c187a489b3ca8ce121524d09bd526e333d880049cbf01a23afcb
MD5 fd23d99549101b3bf98c9f0b807bc95a
BLAKE2b-256 51a017b060982f88f007dc809ca36ff0d33b60cb75ed8cc57e12360b960ba8fc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page