Coder Social home page Coder Social logo

faucamp / python-gsmmodem Goto Github PK

View Code? Open in Web Editor NEW
385.0 43.0 303.0 1.06 MB

Python module to control a GSM modem attached to the system: send/receive SMS messages, handle calls, etc

License: GNU Lesser General Public License v3.0

Python 98.11% Shell 1.89%

python-gsmmodem's Introduction

python-gsmmodem

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.

Requirements

  • Python 2.6 or later
  • pyserial

How to install this package

There are two ways to install python-gsmmodem:

Automatic installation

pip install python-gsmmodem

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 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.

Manual installation

Download and extract the python-gsmmodem archive from PyPI for the current release version, or clone from GitHub. Next, do this:

python setup.py install

Note that python-gsmmodem relies on pyserial for serial communications: http://pyserial.sourceforge.net

Testing the package

Build Status Coverage Status

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.

Building documentation

This package contains Sphinx-based documentation. To manually build or test the documentation locally, do the following:

git clone https://github.com/faucamp/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.

License information

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.

python-gsmmodem's People

Contributors

boomer74 avatar chakphanu avatar davidjb avatar faucamp avatar nioq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-gsmmodem's Issues

modem.dial write timeout

OK you are probably sick of all the issues my weird modem is throwing up at this stage!! I get the following timeout error when calling modem.dial - the receiving phone does get the call, however the self.write('ATD{0} . . . line hangs until the timeout:

Initializing modem...
INFO: Connecting to modem on port COM9 at 115200bps
DEBUG: write: ATZ
DEBUG: response: ['OK']
DEBUG: write: ATE0
DEBUG: response: ['ATE0\r', 'OK']
DEBUG: write: AT+CFUN?
DEBUG: response: ['+CFUN: 1', 'OK']
DEBUG: write: AT+CMEE=1
DEBUG: response: ['OK']
DEBUG: write: AT+CPIN?
DEBUG: response: ['+CPIN: READY', 'OK']
DEBUG: write: AT+CLAC
DEBUG: response: ['ERROR']
DEBUG: write: AT+WIND?
DEBUG: response: ['ERROR']
DEBUG: write: AT+CGMI
DEBUG: response: ['QUALCOMM INCORPORATED', 'OK']
INFO: Unknown modem type - will use polling for call state updates
DEBUG: write: AT+COPS=3,0
DEBUG: response: ['OK']
DEBUG: write: AT+CMGF=1
DEBUG: response: ['OK']
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CSCA: "+353857000000",145', 'OK']
DEBUG: write: AT+CSMP=49,167,0,0
DEBUG: response: ['OK']
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CSCA: "+15214361000000000000000000000000000000000",145', 'OK']
DEBUG: write: AT+CSCA="+353857000000"
DEBUG: response: ['OK']
DEBUG: write: AT+CPMS=?
DEBUG: response: ['+CPMS: ("ME","MT","SM","SR"),("ME","MT","SM","SR"),("ME","MT","SM","SR")', 'OK']
DEBUG: write: AT+CPMS="ME","ME","ME"
DEBUG: response: ['+CPMS: 1,100,1,100,1,100', 'OK']
DEBUG: write: AT+CNMI=2,1,0,2
DEBUG: response: ['OK']
DEBUG: write: AT+CLIP=1
DEBUG: response: ['OK']
DEBUG: write: AT+CRC=1
DEBUG: response: ['OK']
DEBUG: write: AT+CVHU=0
DEBUG: response: ['OK']
Waiting for network coverage...
DEBUG: write: AT+CSQ
DEBUG: response: ['+CSQ: 21,99', 'OK']
Waiting for SMS message...
DEBUG: write: ATD08711111;
Traceback (most recent call last):
File "C:\Per\Tools\raspberry pi\backup_Dev\scripts-dev\GSM2.py", line 74, in
main()
File "C:\Per\Tools\raspberry pi\backup_Dev\scripts-dev\GSM2.py", line 51, in main
call = modem.dial("08711111", 20)
File "c:\python27\lib\site-packages\gsmmodem\modem.py", line 470, in dial
self.write('ATD{0};'.format(number), waitForResponse=self._waitForAtdResponse, timeout=20)
File "c:\python27\lib\site-packages\gsmmodem\modem.py", line 239, in write
responseLines = SerialComms.write(self, data + writeTerm, waitForResponse=waitForResponse, timeout=timeout, expectedRespo
nseTermSeq=expectedResponseTermSeq)
File "c:\python27\lib\site-packages\gsmmodem\serial_comms.py", line 135, in write
raise TimeoutException()
gsmmodem.exceptions.TimeoutException

After modifying waitForResponse to be False instead of True, and then return out of the dial function:

self.write('ATD{0};'.format(number), waitForResponse=not self._waitForAtdResponse, timeout=40)
return

I then get the following instead of the error:

DEBUG: notification: ['CONNECT']
DEBUG: Unhandled unsolicited modem notification: ['CONNECT']
DEBUG: notification: ['HANGUP: 1']
DEBUG: Unhandled unsolicited modem notification: ['HANGUP: 1']

I'm guessing this modem is giving a different response than expected.

AttributeError: 'GsmModem' object has no attribute 'serial'

Hi,

Not sure if its something I am omitting or if an issue, but I get the error in the subject line when attempting to initalise GsmModem.

Basically I copied the GsmModem folder to C:\Python27\Lib and attempted the following call:
modem = GsmModem(PORT, BAUDRATE, incomingCallCallbackFunc=handleIncomingCall)

Just wondering what your thoughts are?

Thanks,

David.

Error in pdu reader, with alpha number

Sms to confirm

07919762020033F1400DD0CDF2396C7EBB010008415072411084618C0500035602010053004D005300200063006F00640065003A00200034003800350036002C00200063006F006E006600690072006D006100740069006F006E0020006F00660020006100730073006F00630069006100740069006F006E0020006200650074007700650065006E0020006100630063006F0075006E007400200061006E00640020004D00650067

Get error "ValueError: unconverted data remains: 01" since last alpha of number goes to time field

python-gsmmodem==0.9

Fix / Improve USSD error handling

According to the GSM spec, USSD responses can have the following status codes:

0 no further user action required (network initiated USSD-Notify, or no further information needed after mobile initiated operation)
1 further user action required (network initiated USSD-Request, or further information needed after mobile initiated operation)
2 USSD terminated by network
3 other local client has responded
4 operation not supported
5 network time out

I've never seen 0 or 3, but the 4s and 5s don't have any message text fields (e.g. +CUSD: 4).
This response isn't matched by the cusd regex, which leads to a nullpointer exception in parseCusdResponse.

Also, having access to the statuscodes would be nice, to be able to differentiate between a network timeout and unsopperted operation.

I've made a rough patch which changes the second regex group to optional (improvements welcome...), adds the statuscode as variable to USSD() and changes sessionActive to a property.

However, I am unsure how to adapt this if block. It looks to me like that is basically setting the message to the last CUSD indication with statuscode !=2. Is that really intended behaviour? Because in the "normal" case, statuscode 2 is what you get for succesfull "oneshot" USSD commands (e.g. checking credit).

UC2 SMS not encoded correctly

Hi,

First of all thanks for all the hardwork, it's very useful. I was able to connect and send sms no problem. Then I tried to send unicode message like chinese and arabic text, it sends out successfully but the content delivered at the destination wasn't the original message instead it's just a bunch of weird symbols.

I'm running the script "sendsms.py" under tools directory.
I'm using wavecom modem for your information.

Thanks in advance.

USSD Ordering issue (Initiating Release)

Hi

I've found another ordering/sequence issue, this time with Vodacom's response to a USSD balance enquiry. I know this is unique to Vodacom because it doesn't happen with MTN, Telkom or Cell-C.

AT Log

.OK
.AT+CSQ

.+CSQ: 11,0
.
.OK
.AT+CIMI

.655014247036844
.
.OK
.AT+CUSD=1,"*100#",15

.+CUSD: 2,"Initiating Release",15
.
.+CUSD: 0,"Your balance is R49.96. Out of Airtime? Dial *111# for Airtime Advance. T&Cs apply.",15
.
.OK
.AT+COPS?

.+COPS: 0,0,"VodaCom-SA",2
.
.OK
.

Result

What this means is that I get a Timeout on my USSD call, and a my COPS call (print modem.write("AT+COPS?")) responds with:

['+CUSD: 2,"Initiating Release",15', '+CUSD: 0,"Your balance is R49.96. Out of Airtime? Dial *111# for Airtime Advance. T&Cs apply.
",15', 'OK']

So I imagine you're just not expecting that "+CUSD: 2" line.

From the 3gpp:

For an USSD response from the network, or a network initiated operation, the format is: +CUSD: [,,].

: integer type (shows the USSD response from the network or the network initiated operation)
0 no further user action required (network initiated USSD Notify, or no further information needed after mobile initiated operation)
1 further user action required (network initiated USSD Request, or further information needed after mobile initiated operation)
2 USSD terminated by network
3 other local client has responded
4 operation not supported
5 network time out


And no, the oddity of Vodacom terminating the session and the giving you more info is not lost on me.

SIM card PIN required (SIM without PIN)

I have Huawei E173 modem and when running identify-modem.py i have the output:

root@abudhabi:/home/jtardin/Documents/python-gsmmodem/tools# ./identify-modem.py -b 115200 /dev/ttyUSB2
args: Namespace(baud='115200', debug=False, pin=None, port='/dev/ttyUSB2')
Connecting to GSM modem on /dev/ttyUSB2...
Error: SIM card PIN required. Please specify a PIN with the -p argument.

This SIM don't have PIN enabled.
I enable the PIN via smartphone and have the output now:

root@abudhabi:/home/jtardin/Documents/python-gsmmodem/tools# ./identify-modem.py -b 115200 /dev/ttyUSB2 -p 1010
args: Namespace(baud='115200', debug=False, pin='1010', port='/dev/ttyUSB2')
Connecting to GSM modem on /dev/ttyUSB2...
Traceback (most recent call last):
File "./identify-modem.py", line 88, in
main()
File "./identify-modem.py", line 49, in main
modem.connect(args.pin)
File "/usr/local/lib/python2.7/dist-packages/gsmmodem/modem.py", line 198, in connect
self._unlockSim(pin)
File "/usr/local/lib/python2.7/dist-packages/gsmmodem/modem.py", line 368, in _unlockSim
self.write('AT+CPIN="{0}"'.format(pin))
File "/usr/local/lib/python2.7/dist-packages/gsmmodem/modem.py", line 398, in write
responseLines = SerialComms.write(self, data + writeTerm, waitForResponse=waitForResponse, timeout=timeout, expectedResponseTermSeq=expectedResponseTermSeq)
File "/usr/local/lib/python2.7/dist-packages/gsmmodem/serial_comms.py", line 135, in write
raise TimeoutException()
gsmmodem.exceptions.TimeoutException

Any idea?

Thanks.

PDU is unaware of User Data Header

I've got an SMS in PDU mode.

0591721891F1400781721881F800003160526104848059050003C30101916536FB1DCABEEB2074D85E064941B19CAB060319A5C522289C96D3D3ED32286C0FA7D96131BBEC024941B19CAB0603DDD36C36A88C87A7E565D0DB0D82C55EB0DB4B068BCD5C20

When I decode it with gsmmodem's pdu the first few characters of the message are extended characters, which I suspect are actually the User Data Header.

If I use the decoder on http://smstools3.kekekasvi.com/topic.php?id=288 it extracts the correct SMS text, but also identifies the "User Data Header" as 05 00 03 C3 01 01

You can read more about the UDH at http://en.wikipedia.org/wiki/User_Data_Header

Output from http://smstools3.kekekasvi.com/topic.php?id=288:

SMS DELIVER (receive)
Receipt requested: no
SMSC: 2781191
Sender: 2781188
TOA: 81 unknown, Numbering Plan: unknown
TimeStamp: 25/06/13 16:40:48 GMT +02:00
TP-PID: 00
TP-DCS: 00
TP-DCS-desc: Uncompressed Text, No class
Alphabet: Default (7bit)
User Data Header: 05 00 03 C3 01 01

Hello!You have R 19.50 FREE airtime available. R 19.50 will expire on 01/07/2013.
Length: 89

SMSC not available for a number of seconds after starting

Apologies if I'm causing confusion I've opened up a fresh issue for what I've experienced. The code for stopping the SMSC from being wiped was perfect!

I was getting confused due to unplugging the modem sometimes, and also because self.smsc caching, changing versions of code, different timings because of me stepping through code in debug mode etc . . and most of all for me rushing!!

On first loading of this application, I still get a 330 no smsc error on the following line (175 of modem.py) of the latest code:
currentSmscNumber = self.smsc

however on the second execution (while modem still connected) the error is not there. I believe this issue is due to an inital slowness of connection to the network, causing the SMSC not to be available for a few seconds. And because the AT+CSMP command needs the smsc somehow (and wipes it on me), the error was generating at that point for me.

So based on a possible timing issue, I tried the following grotesque test code after freshly plugging in the modem:

    starttime = time.time()
    print("start time %i"%(starttime))
    while True:
        try:
            self.write('AT+CSCA?') #won't reach next line if there is an error
            currentSmscNumber = self.smsc
            print('got smsc')
            break
        except:
            if ((time.time() - starttime) > 30):
                #raise error as no smsc is available
                print('timeout get smsc')
                break
            else:
                time.sleep(1)
                print('retry get smsc')
                pass
    print("took seconds: %i"%(time.time() - starttime))

    self.write('AT+CSMP=49,167,0,0', parseError=False) # Enable delivery reports

and got the following output:
Initializing modem...
start time 1367503949
retry get smsc
retry get smsc
retry get smsc
retry get smsc
retry get smsc
retry get smsc
retry get smsc
retry get smsc
retry get smsc
got smsc
took seconds: 9
Waiting for SMS and/or calls...

So it appears for my modem + network combination it is taking about 9-10 seconds for the SMSC to become available. By leaving in the modem, the next time I start the application, it takes 0 seconds - this means there will only be a delay for slower modem/networks and shouldn't impact other users of this code. I used the following at different points in the connect:

print("step 1 %s"%(self.write('AT+CSCA?', True, 5, False)))

and it proved that the SMSC just takes time to become available after the first execution, and is available from the start on the second execution.

So getting the currentSmscNumber before AT+CSMP and setting it afterwards was perfect. This has now moved onto another issue for me. You were totally right about the shotgun :)

Apologies I will leave you alone now and stop interfering :)

sending SMS directly after connect()

There is an easy workaround for me here. Simply timer.sleep(7) after connect() and before sendSms. Just sending this on if is of interest - error output below:

Initializing modem...
INFO: Connecting to modem on port COM9 at 115200bps
DEBUG: write: ATZ
DEBUG: response: ['ATZ\r', 'ERROR']
DEBUG: write: AT+CMEE=1
DEBUG: response: ['AT+CMEE=1\r', 'OK']
DEBUG: write: AT+CPIN?
DEBUG: response: ['AT+CPIN?\r', '+CPIN: SIM PIN', 'OK']
DEBUG: write: AT+CPIN="xxxxx"
DEBUG: response: ['AT+CPIN="xxxxx"\r', 'OK']
DEBUG: write: ATZ
DEBUG: response: ['ATZ\r', 'OK']
DEBUG: write: ATE0
DEBUG: response: ['ATE0\r', 'OK']
DEBUG: write: AT+CFUN?
DEBUG: response: ['+CFUN: 0', 'OK']
DEBUG: write: AT+CFUN=1
DEBUG: response: ['OK']
DEBUG: write: AT+CMEE=1
DEBUG: response: ['OK']
DEBUG: write: AT+CLAC
DEBUG: response: ['ERROR']
DEBUG: write: AT+WIND?
DEBUG: response: ['ERROR']
DEBUG: write: AT+CGMI
DEBUG: response: ['QUALCOMM INCORPORATED', 'OK']
INFO: Unknown modem type - will use polling for call state updates
DEBUG: write: AT+COPS=3,0
DEBUG: response: ['OK']
DEBUG: write: AT+CMGF=1
DEBUG: response: ['OK']
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CME ERROR: 14']
DEBUG: 515 error detected; self._writeWait adjusted to 0s
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CME ERROR: 14']
DEBUG: 515 error detected; self._writeWait adjusted to 0s
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CME ERROR: 14']
DEBUG: 515 error detected; self._writeWait adjusted to 0s
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CME ERROR: 14']
DEBUG: 515 error detected; self._writeWait adjusted to 0s
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CME ERROR: 14']
DEBUG: 515 error detected; self._writeWait adjusted to 1s
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CME ERROR: 14']
DEBUG: notification: ['+ZDONR: "Not Found"', '+ZPASR: "No Service"']
DEBUG: Unhandled unsolicited modem notification: ['+ZDONR: "Not Found"', '+ZPASR: "No Service"']
DEBUG: 515 error detected; self._writeWait adjusted to 1s
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CME ERROR: 14']
DEBUG: 515 error detected; self._writeWait adjusted to 1s
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CSCA: "+353857000000",145', 'OK']
DEBUG: self_writeWait set to 0.1 because of recovering from 515 error
DEBUG: self_writeWait set to 0.1 because of recovering from 515 error
DEBUG: self_writeWait set to 0.1 because of recovering from 515 error
DEBUG: self_writeWait set to 0.1 because of recovering from 515 error
DEBUG: self_writeWait set to 0.1 because of recovering from 515 error
DEBUG: self_writeWait set to 0.1 because of recovering from 515 error
DEBUG: self_writeWait set to 0.1 because of recovering from 515 error
DEBUG: write: AT+CSMP=49,167,0,0
DEBUG: response: ['OK']
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CSCA: "+353857000000",145', 'OK']
DEBUG: write: AT+CPMS=?
DEBUG: response: ['+CPMS: ("ME","MT","SM","SR"),("ME","MT","SM","SR"),("ME","MT","SM","SR")', 'OK']
DEBUG: write: AT+CPMS="ME","ME","ME"
DEBUG: response: ['+CPMS: 1,100,1,100,1,100', 'OK']
DEBUG: write: AT+CNMI=2,1,0,2
DEBUG: response: ['OK']
DEBUG: write: AT+CLIP=1
DEBUG: response: ['OK']
DEBUG: write: AT+CRC=1
DEBUG: response: ['OK']
DEBUG: write: AT+CVHU=0
DEBUG: response: ['OK']
Waiting for SMS and/or calls...
DEBUG: write: AT+CMGS="087111111"
DEBUG: response: ['> ']
DEBUG: write: test message
DEBUG: response: ['+CMS ERROR: 500']
Traceback (most recent call last):
File "GSM2.py", line 65, in
main()
File "GSM2.py", line 50, in main
sms = modem.sendSms('087111111', 'test message', waitForDeliveryReport=False)
File "c:\python27\lib\site-packages\gsmmodem\modem.py", line 417, in sendSms
result = self.write(text, timeout=15, writeTerm=chr(26))[0]
File "c:\python27\lib\site-packages\gsmmodem\modem.py", line 266, in write
raise CmsError(data, int(errorCode))
gsmmodem.exceptions.CmsError: CMS 500

However when I put in the sleep, I works successfully as below:

Initializing modem...
INFO: Connecting to modem on port COM9 at 115200bps
DEBUG: write: ATZ
DEBUG: response: ['ATZ\r', 'ERROR']
DEBUG: write: AT+CMEE=1
DEBUG: response: ['AT+CMEE=1\r', 'OK']
DEBUG: write: AT+CPIN?
DEBUG: response: ['AT+CPIN?\r', '+CPIN: SIM PIN', 'OK']
DEBUG: write: AT+CPIN="xxx"
DEBUG: response: ['AT+CPIN="xxx"\r', 'OK']
DEBUG: write: ATZ
DEBUG: response: ['ATZ\r', 'OK']
DEBUG: write: ATE0
DEBUG: response: ['ATE0\r', 'OK']
DEBUG: write: AT+CFUN?
DEBUG: response: ['+CFUN: 0', 'OK']
DEBUG: write: AT+CFUN=1
DEBUG: response: ['OK']
DEBUG: write: AT+CMEE=1
DEBUG: response: ['OK']
DEBUG: write: AT+CLAC
DEBUG: response: ['ERROR']
DEBUG: write: AT+WIND?
DEBUG: response: ['ERROR']
DEBUG: write: AT+CGMI
DEBUG: response: ['QUALCOMM INCORPORATED', 'OK']
INFO: Unknown modem type - will use polling for call state updates
DEBUG: write: AT+COPS=3,0
DEBUG: response: ['OK']
DEBUG: write: AT+CMGF=1
DEBUG: response: ['OK']
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CME ERROR: 14']
DEBUG: 515 error detected; self._writeWait adjusted to 0s
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CME ERROR: 14']
DEBUG: 515 error detected; self._writeWait adjusted to 0s
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CME ERROR: 14']
DEBUG: 515 error detected; self._writeWait adjusted to 0s
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CME ERROR: 14']
DEBUG: 515 error detected; self._writeWait adjusted to 0s
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CME ERROR: 14']
DEBUG: 515 error detected; self._writeWait adjusted to 1s
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CME ERROR: 14']
DEBUG: notification: ['+ZDONR: "Not Found"', '+ZPASR: "No Service"']
DEBUG: Unhandled unsolicited modem notification: ['+ZDONR: "Not Found"', '+ZPASR: "No Service"']
DEBUG: 515 error detected; self._writeWait adjusted to 1s
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CME ERROR: 14']
DEBUG: 515 error detected; self._writeWait adjusted to 1s
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CSCA: "+353857000000",145', 'OK']
DEBUG: self_writeWait set to 0.1 because of recovering from 515 error
DEBUG: self_writeWait set to 0.1 because of recovering from 515 error
DEBUG: self_writeWait set to 0.1 because of recovering from 515 error
DEBUG: self_writeWait set to 0.1 because of recovering from 515 error
DEBUG: self_writeWait set to 0.1 because of recovering from 515 error
DEBUG: self_writeWait set to 0.1 because of recovering from 515 error
DEBUG: self_writeWait set to 0.1 because of recovering from 515 error
DEBUG: write: AT+CSMP=49,167,0,0
DEBUG: response: ['OK']
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CSCA: "+353857000000",145', 'OK']
DEBUG: write: AT+CPMS=?
DEBUG: response: ['+CPMS: ("ME","MT","SM","SR"),("ME","MT","SM","SR"),("ME","MT","SM","SR")', 'OK']
DEBUG: write: AT+CPMS="ME","ME","ME"
DEBUG: response: ['+CPMS: 1,100,1,100,1,100', 'OK']
DEBUG: write: AT+CNMI=2,1,0,2
DEBUG: response: ['OK']
DEBUG: write: AT+CLIP=1
DEBUG: response: ['OK']
DEBUG: write: AT+CRC=1
DEBUG: response: ['OK']
DEBUG: write: AT+CVHU=0
DEBUG: response: ['OK']
Waiting for SMS and/or calls...
DEBUG: notification: ['+ZDONR: "METEOR",272,3,"CS_ONLY","ROAM_OFF"', '+ZPASR: "UMTS"', '+ZDONR: "METEOR",272,3,"CS_ONLY","ROAM_OFF"', '+ZPASR: "UMTS"']
DEBUG: Unhandled unsolicited modem notification: ['+ZDONR: "METEOR",272,3,"CS_ONLY","ROAM_OFF"', '+ZPASR: "UMTS"', '+ZDONR: "METEOR",272,3,"CS_ONLY","ROAM_OFF"'
, '+ZPASR: "UMTS"']
DEBUG: notification: ['+ZDONR: "METEOR",272,3,"CS_PS","ROAM_OFF"', '+ZPASR: "UMTS"']
DEBUG: Unhandled unsolicited modem notification: ['+ZDONR: "METEOR",272,3,"CS_PS","ROAM_OFF"', '+ZPASR: "UMTS"']
DEBUG: write: AT+CMGS="0871111111"
DEBUG: response: ['> ']
DEBUG: write: test message
DEBUG: response: ['+CMGS: 61', 'OK']
Message sent.
DEBUG: notification: ['+CDSI: "SR",50']
DEBUG: SMS status report received
DEBUG: write: AT+CPMS="SR"
DEBUG: response: ['+CPMS: 1,100,2,100,2,100', 'OK']
DEBUG: write: AT+CMGR=50
DEBUG: response: ['+CMGR: ,6,61,"0871111111",129,"13/05/03,14:56:00+04","13/05/03,14:56:00+04",0', 'OK']
DEBUG: write: AT+CMGD=50
DEBUG: response: ['OK']

forgot to say, that you so so much for all the excellent work on this. Its greatly appreciated!

Incoming SMS and Incoming Call in same Port

INFO: Connecting to modem on port /dev/ttyUSB1 at 115200bps
DEBUG: write: ATZ
DEBUG: response: ['OK']
DEBUG: write: ATE0
DEBUG: response: ['OK']
DEBUG: write: AT+CFUN?
DEBUG: response: ['+CFUN: 1', 'OK']
DEBUG: write: AT+CMEE=1
DEBUG: response: ['OK']
DEBUG: write: AT+CPIN?
DEBUG: response: ['+CPIN: READY', 'OK']
DEBUG: write: AT+CLAC
DEBUG: response: ['ERROR']
DEBUG: write: AT+WIND?
DEBUG: response: ['ERROR']
DEBUG: write: AT+CGMI
DEBUG: response: ['SIEMENS', 'OK']
DEBUG: write: AT+ZPAS?
DEBUG: response: ['ERROR']
INFO: Unknown/generic modem type - will use polling for call state updates
DEBUG: write: AT+COPS=3,0
DEBUG: response: ['OK']
DEBUG: write: AT+CMGF=0
DEBUG: response: ['OK']
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CSCA: "+919894051914",145', 'OK']
DEBUG: write: AT+CSMP=49,167,0,0
DEBUG: response: ['OK']
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CSCA: "+919894051914",145', 'OK']
DEBUG: write: AT+CPMS=?
DEBUG: response: ['+CPMS: ("MT","SM","ME"),("MT","SM","ME"),("MT","SM")', 'OK']
DEBUG: write: AT+CPMS="ME","ME","SM"
DEBUG: response: ['+CPMS: 9,25,9,25,0,20', 'OK']
DEBUG: write: AT+CNMI=2,1,0,2
DEBUG: response: ['OK']
DEBUG: write: AT+CLIP=1
DEBUG: response: ['OK']
DEBUG: write: AT+CRC=1
DEBUG: response: ['OK']
DEBUG: write: AT+CVHU=0
DEBUG: response: ['ERROR']
Checking for network coverage...
DEBUG: write: AT+CREG?
DEBUG: response: ['+CREG: 0,5', 'OK']
DEBUG: write: AT+CSQ
DEBUG: response: ['+CSQ: 23,99', 'OK']
Waiting ...
DEBUG: notification: ['+CIEV: call,0', '+CRING: VOICE', '+CLIP: "+91XXXXXXXX",145,,,,0']
DEBUG: Handling incoming call
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in *bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 504, in run
self.__target(_self.__args, _self.__kwargs)
File "build/bdist.linux-i686/egg/gsmmodem/modem.py", line 865, in __threadedHandleModemNotification
self._handleIncomingCall(lines)
File "build/bdist.linux-i686/egg/gsmmodem/modem.py", line 931, in _handleIncomingCall
call = IncomingCall(self, callerNumber, ton, callerName, callId, callType)
File "build/bdist.linux-i686/egg/gsmmodem/modem.py", line 1298, in __init

callType = self.CALL_TYPE_MAP[callType]
KeyError: 'call,0'

Timeout for CPIN command may be too short?

the timeout for CPIN command is 0.25
cpinResponse = lineStartingWith('+CPIN', self.write('AT+CPIN?', timeout=0.25))
it's very easy to raise TimeoutException.
and many other command use the default timeout (timeout=5),
so why this command use such a short timeout? dose it mean to?

Handling multi-line USSD responses

I've been playing around with USSD responses using the GsmModem class and I've found that multi-line USSD responses are handled as individual lines. For instance, an (unsolicited) +CUSD response can look something like this (a live example from Telstra in Australia):

AT+CUSD=1,"#100#",15
OK

+CUSD: 1,"Bal:$100.00 *
Exp 01 Jan 2013
1. Recharge
2. Balance
3. My Offer
4. PlusPacks
5. Tones&Extras
6. History
7. CredMe2U
8. Hlp
00. Home
*charges can take 48hrs",15

gets handled as a set of individual lines rather than as one response together. Each of the lines are seen (at least at the Python later) as being \r\n separated.

In addition, because none of the lines match the prescribed regex for USSD, no response gets returned from the call to sendUssd (despite a USSD session now existing).

Thoughts on being able to support responses like this? The v.250 standard seems to say that any characters may be included in a string and should be represented using a backslash and their character code.

So far, I've worked around the issue by just joining all the lines together in a custom _handleUssd method, and dividing up again based upon some modified regex to get each +CUSD response separately (eg re.findall('\+CUSD:\s*\d,".*?",\d+', joined_lines, re.DOTALL)). Hacky, but it works for now.

This is a fantastic library, by the way - greatly appreciate all the hard work. Works a treat with my ZTE K3571-Z modem.

Unhandled unsolicited modem notification: ['+CDS: 25',...

I am unable to see delivery status report. kindly advise. My logs are below:

DEBUG: 2015-01-09 17:45:55,829 write: AT+CVHU=0
DEBUG: 2015-01-09 17:45:55,914 response: ['OK']
DEBUG: 2015-01-09 17:46:16,187 notification: ['+CMTI: "SM",7']
DEBUG: 2015-01-09 17:46:16,188 SMS message received
DEBUG: 2015-01-09 17:46:16,190 write: AT+CPMS="SM"
DEBUG: 2015-01-09 17:46:16,289 response: ['+CPMS: 7,20,7,20,7,20', 'OK']
DEBUG: 2015-01-09 17:46:16,302 write: AT+CMGR=7
DEBUG: 2015-01-09 17:46:16,467 response: ['+CMGR: 0,,29', '0791198904100161240C911979099137640000511090718303220BC8B4421174CFD175D014', 'OK']
DEBUG: 2015-01-09 17:46:16,526 write: AT+CMGD=7,0
DEBUG: 2015-01-09 17:46:16,749 response: ['OK']
DEBUG: 2015-01-09 17:46:16,798 write: AT+CMGS=61
DEBUG: 2015-01-09 17:46:16,884 response: ['> ']
DEBUG: 2015-01-09 17:46:16,911 write: 0021000C91197909913764000036D3E614242F8FCB697B99AC038964B058AD058BB5603950ECA69BE17433D80A56D3CD603A1032AD5004DD73741D341501
DEBUG: 2015-01-09 17:46:31,352 response: ['+CMGS: 64', 'OK']
DEBUG: 2015-01-09 17:46:37,344 notification: ['+CDS: 25', '079119890400202306400C91197909913764511090718384225110907183252200']
DEBUG: 2015-01-09 17:46:37,345 Unhandled unsolicited modem notification: ['+CDS: 25', '079119890400202306400C91197909913764511090718384225110907183252200']

Unable to send unicode sms

Is there a way to tell the sendSms function that it should send unicode text?
I am trying to send arabic text which I am reading from a file but the sending process fails with error code 304. please help

Exposing API, examples and documentation

This is a great library and it works really well.

A suggestion I'd like to make is that having more information visible about what the library does (and indeed how useful it is) would help others both find, understand, and use this library.

There's heaps of useful documentation already within the code & the various examples, so exposing that's straight forward. My suggestion is to use Sphinx for the task -- it can autodocument from the Python code, integrates with http://readthedocs.org for hosting/autoupdating, and more. The only minor note to mention is that Sphinx is built around using reST, rather than Markdown, as I see the README is written in.

If you're interested, I've got some code together that I've been playing around with that I can put into a pull request. Essentially, it would add almost no overhead to the code - just adding an optional 'extras_require' dependency on Sphinx, and perhaps a few minor tidy-ups in the documentation. Happy to do the work, however, to help improve things & make it easier for all to work with.

Thoughts?

sendUssd encoding/decoding issues

Hi,

To send a Ussd to see the balance I do:

modem.sendUssd('AA514C361B01') # 'AA514C361B01' translates to '*#123#'

This will return s tring in the same format. How can I translate to human readable text?

Any ideas?

Best Regards,

Telnet-attache devices

Hello there!

It's rather a question than an issue, though...
Is there any convenient way to use that library with telnet-attached devices? There is a plenty of them and I'm interested to hear someone's experience with it.

Thank you!

SMSC getting wiped after connect

Its Mr. Trouble again :)

The SMSC number appears to get wiped on each connect - the return value of modem.smsc() goes to:
+10787132000000000000000000000000000000000
But another time it goes to modem.smsc():
+47204226000000000000000000000000000000000

Not sure what the string is but from debugging it looks like AT+CSCA? value is:
+
I didn't see this behaviour before, not sure if its something new. to get around this I put the following 2 lines after the setting echo off line in the connect function:
self.write('ATE0') # echo off
tempsmsc = self.smsc

and this at the end of connect:
if tempsmsc != "+":
self.smsc = tempsmsc

Again, this could be non standard behaviour by my modem, but I have seen lots of posts about SMSC needing to be set manually which could be related.

sending SMS - delivery report error

OK I'm beginning to look like a stalker :) I get an error after sending a SMS (Text mode) using:
sms = modem.sendSms('0870000000', 'test4', waitForDeliveryReport=False)

And the error is below - message sends OK but it seems to get a delivery report a few seconds after:

Initializing modem...
INFO: Connecting to modem on port COM9 at 115200bps
DEBUG: write: ATZ
DEBUG: response: ['OK']
DEBUG: write: ATE0
DEBUG: response: ['ATE0\r', 'OK']
DEBUG: write: AT+CSCA?
DEBUG: response: ['+CSCA: "+353857000000",145', 'OK']
DEBUG: write: AT+CFUN?
DEBUG: response: ['+CFUN: 1', 'OK']
DEBUG: write: AT+CMEE=1
DEBUG: response: ['OK']
DEBUG: write: AT+CPIN?
DEBUG: response: ['+CPIN: READY', 'OK']
DEBUG: write: AT+CLAC
DEBUG: response: ['ERROR']
DEBUG: write: AT+WIND?
DEBUG: response: ['ERROR']
INFO: Loading Huawei call update table
DEBUG: write: AT+COPS=3,0
DEBUG: response: ['OK']
DEBUG: write: AT+CMGF=1
DEBUG: response: ['OK']
DEBUG: write: AT+CSCA="+353857000000"
DEBUG: response: ['OK']
DEBUG: write: AT+CSMP=49,167,0,0
DEBUG: response: ['OK']
DEBUG: write: AT+CPMS=?
DEBUG: response: ['+CPMS: ("ME","MT","SM","SR"),("ME","MT","SM","SR"),("ME","MT","SM","SR")', 'OK']
DEBUG: write: AT+CPMS="ME","ME","ME"
DEBUG: response: ['+CPMS: 7,100,7,100,7,100', 'OK']
DEBUG: write: AT+CNMI=2,1,0,2
DEBUG: response: ['OK']
DEBUG: write: AT+CLIP=1
DEBUG: response: ['OK']
DEBUG: write: AT+CRC=1
DEBUG: response: ['OK']
DEBUG: write: AT+CVHU=0
DEBUG: response: ['OK']
DEBUG: write: AT+CSQ
DEBUG: response: ['+CSQ: 22,99', 'OK']
DEBUG: write: AT+CUSD?
DEBUG: response: ['+CUSD: 0', 'OK']
['+CUSD: 0', 'OK']
Waiting for SMS and/or calls...
DEBUG: write: AT+CMGS="0870000000"
DEBUG: response: ['> ']
DEBUG: write: test4
DEBUG: response: ['+CMGS: 20', 'OK']
Message sent.
DEBUG: notification: ['+CDSI: "SR",57']
DEBUG: SMS status report received
DEBUG: write: AT+CPMS="SR"
DEBUG: response: ['+CPMS: 8,100,8,100,8,100', 'OK']
DEBUG: write: AT+CMGR=57
DEBUG: response: ['+CMGR: ,6,20,"0870000000",129,"13/04/29,19:58:00+04","13/04/29,19:59:00+04",0', 'OK']
Exception in thread Thread-3:
Traceback (most recent call last):
File "c:\python27\lib\threading.py", line 551, in __bootstrap_inner
self.run()
File "c:\python27\lib\threading.py", line 504, in run
self.__target(_self.__args, *_self.__kwargs)
File "c:\python27\lib\site-packages\gsmmodem\modem.py", line 513, in __threadedHandleModemNotification
self._handleSmsStatusReport(line)
File "c:\python27\lib\site-packages\gsmmodem\modem.py", line 607, in _handleSmsStatusReport
report = self._readStoredSmsMessage(msgIndex, msgMemory)
File "c:\python27\lib\site-packages\gsmmodem\modem.py", line 660, in _readStoredSmsMessage
raise CommandError('Failed to parse the SMS message +CMGR response: {0}'.format(msgData))
CommandError: Failed to parse the SMS message +CMGR response: ['+CMGR: ,6,20,"0870000000",129,"13/04/29,19:58:00+04","13/04/29,19:59:00+04",0', 'OK']

in PDU mode the following is returned:
CommandError: Failed to parse the SMS message +CMGR response: ['+CMGR: ,,24', '059475000085061D0AA18027123654314092129300403140921293004000', 'OK']

unread sms on startup

Hi,

Just in case you weren't busy enough, I had an idea for a feature request on connect() - call something like:
AT+CMGL="REC UNREAD"
and read all SMS that has been sent while the application was not running. When finished this, can then delete all read SMS like following (or just do each singularly):
AT+CMGD=1,1
That way the modem memory will not fill up with unread messages if using the application over time, and users can get messages that were sent prior to the app running, which could be handy.

Just an idea anyhow, not sure how easy/hard it would be to implement.

Best regards,

David.

Odd ordering of AT response breaks USSD

I received the following report via email from Jonathan Endersby:
(edited to remove service identifiers since I'm not sure how sensitive the info is)

I'm working on something that simulates USSD traffic and have picked up a "bug" in gsmmodem that is probably quite easy to fix. I say "bug" because really it's probably the modem doing something non-3gpp compliant (What a surprise right?)

Basically I have a USSD conversation and everything goes well except sometimes I receive my "+CUSD" before my "OK", which confuses gsmmodem and it gets a timeout.

I suspect it is ignoring the +CUSD thinking it is an "OK" and then waiting for an "+CUSD" when all it ever receives is an "OK".

.AT+CUSD=1,"_111_11111#",15

.OK
.
.+CUSD: 1,"What would you like to search for?",0
.AT+CUSD=1,"Test Answer",15

.OK
.
.+CUSD: 1,"1. Option 1.2. Another option",0
.AT+CUSD=1,"1",15

.OK
.
.+CUSD: 1,"1. Heading.2. First section.3. Second section.",0
.AT+CUSD=1,"2",15

.+CUSD: 0,"Lorem ipsum blah blah ....",15
.
.OK

Notice how that the last +CUSD arrived before it's "OK".

"TypeError: an integer is required" when used with Python 3.2 on rpi

When I try sendsms.py using Python 3.2.3 I get this:

Traceback (most recent call last):
File "/usr/local/bin/sendsms.py", line 88, in
main()
File "/usr/local/bin/sendsms.py", line 53, in main
modem.connect(args.pin)
File "/usr/local/lib/python3.2/dist-packages/gsmmodem/modem.py", line 177, in connect
self.write('ATZ') # reset configuration
File "/usr/local/lib/python3.2/dist-packages/gsmmodem/modem.py", line 398, in write
responseLines = SerialComms.write(self, data + writeTerm, waitForResponse=waitForResponse, timeout=timeout, expectedResponseTermSeq=expectedResponseTermSeq)
File "/usr/local/lib/python3.2/dist-packages/gsmmodem/serial_comms.py", line 127, in write
self.serial.write(data)
File "/usr/local/lib/python3.2/dist-packages/serial/serialposix.py", line 491, in write
d = to_bytes(data)
File "/usr/local/lib/python3.2/dist-packages/serial/serialutil.py", line 76, in to_bytes
b.append(item) # this one handles int and str for our emulation and ints for Python 3.x
TypeError: an integer is required

Error comes from pyserial, but I found this as solution
http://stackoverflow.com/questions/22275079/pyserial-write-wont-take-my-string
so maybe gsmmodem should handle string to bytes conversion.

I have latest pySerial (2.7). Maybe you have used older version of that or something since I assume that this has not happened to you when you have tested this with python 3.

Also using 0.9 python-gsmmodem and Python 3.2.3 on Raspberry Pi.

It also happens with my own code and it happens if I use pyserial and it's write with string directly. Still I don't know I should blame pyserial (as it might be meant to be take bytes).

Do you think this is bug in gsmmodem or should this be talked with pyserial devs?

PDU not decoded correctly

Hi,

When I try to decode the following PDU 07912160130320F5440B917130263521F600005160101235458AA005C01BF40201E8E5393D2C1E93CBE633BD3CA787C56372D97CA697E7F4B0784C2E9BCFF4F29C1E168FC965F3995E9ED3C3E231B96C3ED3CB737A583C2697CD677A794E0F8BC7E4B2F94C2FCFE961F1985C369FE9E5393D2C1E93CBE633BD3CA787C56372D97CA697E7F4B0784C2E9BCFF4F29C1E168FC965F3995E9ED3C3E231B96C3ED3CB737A583C2697CD

I got the content as following as the sms text
<LÖlöLÜ<Nß,<LÖlöLÜ<Nß,<LÖlöLÜ<Nß,<LÖlöLÜ<Nß,<LÖlöLÜ<Nß,<LÖlöLÜ<Nß,<LÖlöLÜ<Nß,<LÖlöLÜ<Nß,<LÖlöLÜ<Nß,<LÖlöLÜ<Nß,<LÖlöLÜ<Nß,<LÖl

I'm using the decodeSmsPdu from pdu.py by passing the du as string. Am I doing anything wrong?

Long messages are incorrectly split into parts

Many thanks for your effort in making and maintaining this project.

I use only part of the application to encode into the PDU format.
I noticed that messages longer than 160 characters translated into GSM7 alphabet is incorrectly split into parts. One character in between of the two parts is skipped.

Can it work when the 3G connection is active?

So all works well when there's no 3G connection. But when there is I have an issue running the incoming_call_demo.py script. When I dial the number it is ringing and with every ring an error message logs to the screen:

Exception in thread Thread-58:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 505, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/dist-packages/python_gsmmodem-0.8-py2.7.egg/gsmmodem/modem.py", line 643, in __threadedHandleModemNotification
    self._handleIncomingCall(lines)
  File "/usr/local/lib/python2.7/dist-packages/python_gsmmodem-0.8-py2.7.egg/gsmmodem/modem.py", line 672, in _handleIncomingCall
    callType = ringLine.split(' ', 1)[1]
IndexError: list index out of range

Manufacturer: huawei
Model: K3715
Revision: 11.104.05.00.00

Furthermore, I'm using the sakis3G script to connect.

getting attribute error.

Getting error . AttributeError: 'GsmModem' object has no attribute 'rxThread'.Can anyone explain this error?

SIMs that require PIN

Hi,

I have a SIM that requires PIN before any activities can be conducted. How I have gotten around this is:
modem.connect('6572')

and made the following amendment in modem.py to pass in PIN:

def connect(self, PIN = '', runInit=True):
    """ Opens the port and initializes the modem """
    self.log.info('Connecting to modem on port %s at %dbps', self.port, self.baudrate)
    super(GsmModem, self).connect()

    if (self.write('AT+CPIN?')[0] !='+CPIN: READY') and (PIN !=''):
        self.write('AT+CPIN="'+PIN+'"')

    # Send some initialization commands to the modem
    self.write('ATZ') # reset configuration
    self.write('ATE0') # echo off

More of a feature request than issue. But think it might be helpful

Best regards,

David.

Failed to parse PDU-mode (comeback of issue #9?)

An intermittent error, some SMS are processed correctly, while handling others ends up with the following error. What other information should I provide?

Exception in thread Thread-7:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 505, in run
    self.__target(*self.__args, **self.__kwargs)
  File "build/bdist.linux-x86_64/egg/gsmmodem/modem.py", line 869, in __threadedHandleModemNotification
    self._handleSmsReceived(line)
  File "build/bdist.linux-x86_64/egg/gsmmodem/modem.py", line 998, in _handleSmsReceived
    sms = self.readStoredSms(msgIndex, msgMemory)
  File "build/bdist.linux-x86_64/egg/gsmmodem/modem.py", line 1059, in readStoredSms
    raise CommandError('Failed to parse PDU-mode SMS message +CMGR response: {0}'.format(msgData))
CommandError: Failed to parse PDU-mode SMS message +CMGR response: ['^RSSI: 20', '+CMGR: 0,,20', '07919762020033F1240B919792956102F30000418011026315610133', 'OK']

USSD responseTimeout not being passed to self.write in sendUssd (modem.py)

Hi

Not sure if this was "by design" or simply an omission, but, the default timeout is 5 seconds for most things and 15 seconds for USSD. 15 seconds is indeed needed, again for Vodacom. (I timed a few balance check queries and the average on Vodacom was just over 5 seconds).

So, what's happening (as I understand it) - because responseTimeout isn't being passed to the self.write, we're defaulting to the pyserial timeout (which is 5) and even though your thread is waiting around, pyserial isn't, and we get a timeout.

The fix is as simple as changing: (modem.py Line:538)

cusdResponse = self.write('AT+CUSD=1,"{0}",15'.format(ussdString))

to

cusdResponse = self.write('AT+CUSD=1,"{0}",15'.format(ussdString), timeout=responseTimeout)

Cheers,
J.

gsmmodem.exceptions.TimeoutException

Hi, i installed python-gsmmodem module for python3.2
and after connecting to modem show this error:
File "C:\Python32\lib\site-packages\gsmmodem\serial_comms.py", line 135, in write
raise TimeoutException()
gsmmodem.exceptions.TimeoutException

why show such a error?
where is problem?

my python code :

from future import print_function

import logging

PORT = 'COM30'
BAUDRATE = 115200
PIN = None # SIM card PIN (if any)
from gsmmodem.modem import GsmModem
def main():
print('Initializing modem...')
modem = GsmModem(PORT, BAUDRATE)
modem.connect(PIN)
modem.close()

if name == 'main':
main()

model of the modem : WAVECOM MODEM MULTIBAND 900E 1800

nokia gsm - no sms reading

Hey guys,

I'm not sure if you want to support all kinds of gsm modems or only certain ones, but just in case:

from what i could gather there is a problem with newer nokia phones (and their modems), s60 i believe, as they do not support receiving sms.

Because of that fails the connect() at two points:

at+cpms=?

+CPMS: (),(),()

OK

and

at+cnmi=2,1,0,2

ERROR

or in code (line 227 in modem.py):

self.write('AT+CPMS={0}'.format(','.join(cpmsItems))) # Set message storage
del cpmsSupport
del cpmsLine

self.write('AT+CNMI=2,1,0,2') # Set message notifications

i have bypassed that issue for now by catching the exception and checking if it the (),(),() response:

try:
self.write('AT+CPMS={0}'.format(','.join(cpmsItems))) # Set message storage
except CommandError as e:
if cpmsItems == [ '' , '' , '' ]:
pass # my error -> ignore
else:
raise e
del cpmsSupport
del cpmsLine

try:
self.write('AT+CNMI=2,1,0,2') # Set message notifications
except CommandError as e:
if cpmsItems == [ '' , '' , '' ]:
pass # my error -> ignore
else:
raise e

it's a quick and dirty fix, but for now it works..

cheers

error on SMS received

last one I promise!

I get an error using the SMS demo example. When a SMS is received I get the following error:

Initializing modem...
Waiting for SMS message...
Exception in thread Thread-2:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 551, in __bootstrap_inner
self.run()
File "C:\Python27\lib\threading.py", line 504, in run
self.__target(_self.__args, *_self.__kwargs)
File "C:\Python27\lib\site-packages\gsmmodem\modem.py", line 444, in __threadedHandleModemNotification
self._handleSmsReceived(line)
File "C:\Python27\lib\site-packages\gsmmodem\modem.py", line 534, in _handleSmsReceived
sms = self._readStoredSmsMessage(msgIndex)
File "C:\Python27\lib\site-packages\gsmmodem\modem.py", line 583, in _readStoredSmsMessage
raise CommandError('Failed to parse the SMS message +CMGR response: {0}'.format(msgData))
CommandError

Again this could be particular to my GSM dongle and/or my telecoms carrier and nothing to do with the gsmmodem project.

Thanks.

Wavecom M1306 does not issue 'OK' at end of AT+CPIN? response

This report was submitted via email; quoting original text below:

I bought a wavecom M1306 model for monitoring temperature of computer room.
But gsmmodem.GsmModem.connect() always throw a timeout exception. Since I'm
a newbie on Python, I use print 'some string' to locate that the problem is
in method _handleLineRead. Then I realize that for normal AT command like
'AT+CFUN?', the modem respond an 'OK' after displaying CFUN's value, But
when asking 'AT+CPIN?' my M1306 modem simply reply 'AT+CPIN: READY' without
'OK' appended. So the _handleLineRead won't call self._responseEvent.set(),
The read thread is then waiting until timeout.

order of commands

Hi Its me again :)

in the demos such as the following:
modem = GsmModem(PORT, BAUDRATE, smsReceivedCallbackFunc=handleSms)
modem.smsTextMode = True
modem.connect(PIN)

I need to reorder the the check for pin to be the first thing called in def connect because ATZ is rejected until PIN is entered. This may be something specific to my particular GSM dongle so may not be of relevance.

smsReceived Callback not working?

Hi. First of all thanks for great Python module. I've planned to use it just for sending and receiving SMS. So first thing I did was testing sms_handler_demo.py.
Example gets to "Waiting for SMS message..." part but it never reads any SMS and it never runs handleSms function.

I've tryed another code and I see that sending and reading of messages works (for example: modem.listStoredSms(0) reads all unread messages), but in my case
modem.rxThread.join(2**31) never triggers smsReceivedCallbackFunc.

I've tried that on Raspberry Pi and Mac OS X and it's all the same. I'm using Huawei E3131 USB modem and modem.smsTextMode = True (it didn't work when set to False also).
I guess I could write my own code using listStoredSms to check for new SMS from time to time, but callback seems to be more appropriate.
Any idea why this doesn't work?

Cannot parse PDU

Hi
I've got pdu line which pdu library from python-gsmmodem cannot parse:
07918340247399484007D035DA6C06000051401091731321A0050003720201846176D83D07C56A2E180C2D77B340E2B7BB3E07C15C30185AEE7629542A954258D6B3D3ED341DE40E83D86973599702C5603010DA0E82BF41B11A68FD86BB4034980B066A0A414937BD2C7797E920F81B440FCBF3E6BA0B34A381A6CD2908FE0655D7F270DA9D7681A0E175990E82BFE7ECFA193487B3C36374D9FD0691DFA0D8CD05A3B962

but here it can be decoded
http://www.diafaan.com/sms-tutorials/gsm-modem-tutorial/online-sms-pdu-decoder/

new release to PIP??

the master repo has quite a lot of changes but the PIP is using using a old mid 2013 release

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.