質問

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']
役に立ちましたか?

解決

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.

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top