Various fixes

This commit is contained in:
Giulio 2019-07-17 15:15:43 +02:00
parent 83213dbc46
commit dd08dfd93d
2 changed files with 14 additions and 7 deletions

View File

@ -28,7 +28,9 @@ messages_queue = list()
while True:
for gsm_object in gsm_modules:
messages = gsm_object.fetch_messages()
messages_queue.extend(messages)
if messages:
messages_queue.extend(messages)
messages = None
for message in messages_queue:
try:

View File

@ -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")