Modem communication working
This commit is contained in:
parent
dd08dfd93d
commit
3b88286b6b
@ -6,9 +6,11 @@ logging.basicConfig(level=logging.DEBUG)
|
||||
class Gsm:
|
||||
def __init__(self, port, msisdn, imei=None, pin=None):
|
||||
self.port = port
|
||||
logging.info('Initializing Gsm cass for port ' + port)
|
||||
logging.info('Initializing Gsm class for port ' + port)
|
||||
try:
|
||||
self.console = serial.Serial(self.port, 112500, timeout=3)
|
||||
self.console = serial.Serial(self.port, 115200, timeout=3)
|
||||
if not self.console.isOpen():
|
||||
self.console.open()
|
||||
except:
|
||||
logging.error('Error connecting to ' + self.port)
|
||||
self.msisdn = msisdn
|
||||
@ -26,8 +28,9 @@ class Gsm:
|
||||
def cmd(self, cmd):
|
||||
cmd += "\r\n"
|
||||
self.console.write(cmd.encode("ascii"))
|
||||
time.sleep(0.5)
|
||||
return list(map(lambda elem: elem.decode("ascii", errors="replace"), self.console.readlines()))
|
||||
time.sleep(1)
|
||||
output = self.console.readlines()
|
||||
return ''.join(l.decode('ascii') for l in output)
|
||||
|
||||
def check_status(self):
|
||||
r = self.cmd("ATI")
|
||||
@ -38,9 +41,13 @@ class Gsm:
|
||||
|
||||
def unlock_sim(self, pin):
|
||||
status = self.cmd("AT+CPIN?")
|
||||
logging.info(status)
|
||||
|
||||
if status == "+CPIN:READY":
|
||||
if "+CPIN:READY" in status:
|
||||
return True
|
||||
elif "+CME ERROR:10" in status:
|
||||
logging.error("Sim not inserted")
|
||||
return False
|
||||
elif "+CPIN:SIM PIN" in status:
|
||||
auth = self.cmd('AT+CPIN="' + pin + '"')
|
||||
if "OK" in auth:
|
||||
|
Loading…
Reference in New Issue
Block a user