faucamp / python-gsmmodem

Python module to control a GSM modem attached to the system: send/receive SMS messages, handle calls, etc
GNU Lesser General Public License v3.0
384 stars 302 forks source link

Incorrect SIM card PIN entered for PIN-unlocked SIM #62

Open Jancs-E opened 8 years ago

Jancs-E commented 8 years ago

Hi! module gives mentioned error if used with GSM modem (ID 05c6:6000 Qualcomm, Inc. Siemens SG75) having PIN-unlocked SIM-card. I tried to enter the historical one the SIM had before unlocking as sendsms.py and identify-modem.py can not be used without giving PIN (without modification it seems). The modem works well with chat (from ppp package) and gammu (although the stability is poor). Also, using gsmterm.py and commands AT+CMGF=1//AT+CMGS="number"//msg^z// I can send the sms. I am using Slack14.1/Raspberry Pi, Python 2.7.5 Janis

P.S. Just wanted to add: the same problem I met with UMTSKeeper/Sakis3G so may be the problem lies very deep?

Jancs-E commented 8 years ago

if I give the following command: ./sendsms.py -i /dev/ttyUSB0 -p none -d NUMBER I get: Connecting to GSM modem on /dev/ttyUSB0... Traceback (most recent call last): File "./sendsms.py", line 88, in main() File "./sendsms.py", line 53, in main modem.connect(args.pin) File "/usr/lib/python2.7/site-packages/gsmmodem/modem.py", line 198, in connect self._unlockSim(pin) File "/usr/lib/python2.7/site-packages/gsmmodem/modem.py", line 368, in _unlockSim self.write('AT+CPIN="{0}"'.format(pin)) File "/usr/lib/python2.7/site-packages/gsmmodem/modem.py", line 428, in write raise CommandError(data) gsmmodem.exceptions.CommandError: AT+CPIN="none"

In the same time AT+CPIN? replies with +CPIN:READY//OK

Jancs-E commented 8 years ago

I found that removing the space on line 366 in modem.py so that the test looks so: if self.write('AT+CPIN?')[0] != '+CPIN:READY': solves half of the problem (I think the both versions '+CPIN:READY' and '+CPIN: READY' should be tested for compatibility or space to be stripped before test). The next is to solve issue with SMSC number which is either not retrieved or misinterpreted.

Jancs-E commented 8 years ago

Hi! I created the patch solving SMSC issue by adding the option to specify it and semi-solution for modem answer containing no space after ":".

smsc.patch.txt

mehdilauters commented 7 years ago

+1 with a 05c6:6000 Qualcomm, Inc. Siemens SG75

tomchy commented 7 years ago

What about:

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

It is not a clean solution, but should not break unit tests for other modems :slightly_smiling_face: You may also include this fix inside a new python-gsmmodem version.