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
388 stars 304 forks source link

SIMs that require PIN #4

Closed dauheeIRL closed 11 years ago

dauheeIRL commented 11 years ago

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.

faucamp commented 11 years ago

Thanks for the code! This is a feature that should have been implemented a while ago; I'll add it asap.

faucamp commented 11 years ago

Implemented in 5afd54cf245f58b397e85ac03a89df8411ff00c8

I've got a few more changes to commit and then I'll release a new stable version.