0

I am trying to programmatically send and recieve txt messages in python, using a huawei e220 modem on vodafone.

editedit: I got it to work, need to set smsc to *****. what i need to know is, what is the command to set it to this?? EG AT+????

How do I do this with serial.Serial module??? I'm having a difficult time.

is PyGSM the best module to do this? How do I use it? I can't find any documentation anywhere, but also I can't find a better module.

Daisy13_on_D1="/dev/ttyUSB0"

gsm = GsmModem(port=Daisy13_on_D1,baudrate=115200,logger=GsmModem.debug_logger).boot()

s = gsm.wait_for_network()

gsm.send_sms(642723243,"Hey, what's up")

gives me this output

debug Booting
   debug Connecting
   write 'ATE0\r'
    read '\r\n'
    read 'OK\r\n'
   write 'AT+CMEE=1\r'
    read '\r\n'
    read 'OK\r\n'
   write 'AT+WIND=0\r'
    read '\r\n'
    read 'COMMAND NOT SUPPORT\r\n'
   write 'AT+CMGF=1\r'
    read '\r\n'
    read 'OK\r\n'
   write 'AT+CSQ\r'
    read '\r\n'
    read '+CSQ: 19,99\r\n'
    read '\r\n'
    read 'OK\r\n'
   write 'AT+CMGS="642723243"\r'
    read '\r\n'
    read '+CMS ERROR: 330\r\n'
   write '\x1b

I am also trying to use the sms0.4 module now too with no luck.

import sms

m = sms.Modem("/dev/ttyUSB0")

m.send('64272923243','This works YO')
print m.conn.sent()

results:

Traceback (most recent call last):   File "testSMSMODULE.py", line 5, in <module>
    m.send('0272923243','This works YO')   File "/usr/local/lib/python2.7/dist-packages/sms-0.4-py2.7.egg/sms/__init__.py", line 61, in send
    self._command('AT+CMGS="%s"' % number)   File "/usr/local/lib/python2.7/dist-packages/sms-0.4-py2.7.egg/sms/__init__.py", line 109, in _command
    raise ModemError(results) sms.ModemError: ['\r\n', '+CMS ERROR: 330\r\n']
straykiwi
  • 538
  • 6
  • 23

2 Answers2

1

AFAIK the best free library that does what you want is called SMSLib, and it's written in Java. Be prepared to fix numerous issues specific to your hardware, but in general it works OK.

There's a commercial solution called "ActiveXperts Mobile Messaging Toolkit" which you can use from Python through COM bindings. Didn't tried that myself (when I needed to, I've implemented my own solution instead), however people on the Internets say it works OK.

AFAIK the rest of them is crap.

Soonts
  • 20,079
  • 9
  • 57
  • 130
  • Unfortunatley I have looked at that library but I need it to be in python so I can maintain it. Do you know anything about the AT+CMGS codes needed to send it? Another option is for me to just code an android app, and buy an android phone, would that be easier than finding a python library? – straykiwi Nov 27 '12 at 00:23
  • 1. Here: http://depositfiles.com/files/qif38zuo8 The problem is, few devices support text mode for messages. Also, text mode has its limitations. Its very likely you'll have to send them in PDU mode, which is harder, esp. if you have to deal with multipart and/or Unicode messages. 2. Don't know, have little experience with Android. – Soonts Nov 27 '12 at 00:39
  • If you're going to implement your own solution in Python, here's the complete set of the documentation I used while creating the same in C#: http://depositfiles.com/files/sznrcdm73 The most useful one is ubinetics-at-command-set.pdf - it's for some random device, but that particular device complies to the standards, and the documentation is good. – Soonts Nov 27 '12 at 00:45
  • Ok thanks I will have a look at those docs. just waiting for them to download. hmmm so you're saying I should either write my own solution in python, or use Smslib? – straykiwi Nov 27 '12 at 00:51
  • Depends on your goal, and also on your experience with both Python and Java languages. If it's sending "Happy Christmas" to your friends - custom python solution might work. If however you're creating a reliable, robust and generic solution, IMO using SMSLib will save you a lot of time. – Soonts Nov 27 '12 at 00:54
  • Initializing a modem could be tricky: SIM card can be PIN or even PUK locked. Sometimes you'll need to select operator manually. Reading messages is hard: there're several storage folders on the device, there're several versions of SMS formats (e.g. some crazy people invented selectively colored messages), there're multipart messages, there're several encodings you'll have to support, there're several ways how devices notify you about new messages, and so on.. – Soonts Nov 27 '12 at 00:57
  • this is for work, we no longer support java which is frustrating in this case. we had an existing java app running on windows which sucked. so the modem is fine.. hmm – straykiwi Nov 27 '12 at 01:13
1

The sms module seems a lot easier to use: http://pypi.python.org/pypi/sms

In brief, to send a text via serial interface of a GSM modem in Python:

#!env python
import serial
m = serial.Serial('/dev/ttyUSB0', 115200, timeout=1)
m.write('ATZ\r')
m.write('AT+CMGF=1\r\n')
m.write('AT+CMGS="%s"\r\n' % '+phone_number_here')
m.write('this is the text message here')
m.write(chr(26))
m.close()

The AT command to set SMSC is: AT+CSCA="+smsc_number_here",145. See http://www.developershome.com/sms/cscaCommand.asp

koniu
  • 578
  • 5
  • 15