|
@@ -1,28 +1,33 @@
|
|
|
import logging
|
|
|
import serial
|
|
|
+import time
|
|
|
+logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
|
class Gsm:
|
|
|
def __init__(self, port, msisdn, imei=None, pin=None):
|
|
|
self.port = port
|
|
|
- logging.info('Initializing G clsm cass for port ' + port)
|
|
|
+ logging.info('Initializing Gsm cass for port ' + port)
|
|
|
try:
|
|
|
self.console = serial.Serial(self.port, 112500, timeout=3)
|
|
|
except:
|
|
|
logging.error('Error connecting to ' + self.port)
|
|
|
self.msisdn = msisdn
|
|
|
- self.cmd("AT+CMGF=1")
|
|
|
+ #self.cmd("AT+CMGF=1")
|
|
|
+ logging.info('Connection established')
|
|
|
self.status = self.check_status()
|
|
|
self.unlock_sim(pin)
|
|
|
- loggin.info("Current status: " + self.status)
|
|
|
+ logging.info("Current status: " + str(self.status))
|
|
|
if imei is not None:
|
|
|
r = self.set_imei(imei)
|
|
|
if r:
|
|
|
self.imei = imei
|
|
|
- loggin.info("IMEI Changed")
|
|
|
+ logging.info("IMEI Changed")
|
|
|
|
|
|
def cmd(self, cmd):
|
|
|
+ cmd += "\r\n"
|
|
|
self.console.write(cmd.encode("ascii"))
|
|
|
- return list(map(lambda elem: elem.decode("ascii", errors="replace"), port.readlines()))
|
|
|
+ time.sleep(0.5)
|
|
|
+ return list(map(lambda elem: elem.decode("ascii", errors="replace"), self.console.readlines()))
|
|
|
|
|
|
def check_status(self):
|
|
|
r = self.cmd("ATI")
|
|
@@ -39,7 +44,7 @@ class Gsm:
|
|
|
elif "+CPIN:SIM PIN" in status:
|
|
|
auth = self.cmd('AT+CPIN="' + pin + '"')
|
|
|
if "OK" in auth:
|
|
|
- loggin.info("Pin correct")
|
|
|
+ logging.info("Pin correct")
|
|
|
return True
|
|
|
else:
|
|
|
logging.error("Wrong PIN")
|