connect modem one by one to receive sms
This commit is contained in:
@@ -28,12 +28,15 @@ class ModemPool:
|
|||||||
self._serial_list.append(ser)
|
self._serial_list.append(ser)
|
||||||
|
|
||||||
def reset_all_modems(self):
|
def reset_all_modems(self):
|
||||||
|
print("will reset modem pool")
|
||||||
for ser in self._serial_list:
|
for ser in self._serial_list:
|
||||||
# may encontre exception here, multi-access to serial port
|
# may encontre exception here, multi-access to serial port
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
self._send_command("AT+CFUN=1,1\r", ser)
|
self._send_command("AT+CFUN=1,1\r", ser)
|
||||||
# wait for 20 second, so that the modem can init all the sims
|
# wait for 20 second, so that the modem can init all the sims
|
||||||
time.sleep(20)
|
time.sleep(20)
|
||||||
|
for ser in self._serial_list:
|
||||||
|
ser.close()
|
||||||
|
|
||||||
def _generate_error_msg(self, slot_position, index, error: SIMError):
|
def _generate_error_msg(self, slot_position, index, error: SIMError):
|
||||||
msg = "slot({}) SIM({}), error:{}".format(slot_position, index + 1,
|
msg = "slot({}) SIM({}), error:{}".format(slot_position, index + 1,
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ from logs.AppLogging import init_logger
|
|||||||
from utils.message_receiver import MessageReceiver
|
from utils.message_receiver import MessageReceiver
|
||||||
|
|
||||||
BAUDRATE = 115200
|
BAUDRATE = 115200
|
||||||
OTP_TIMEOUT = 70
|
OTP_TIMEOUT = 90
|
||||||
is_finished = False
|
is_finished = False
|
||||||
commandor = Commandor()
|
commandor = Commandor()
|
||||||
contacts = []
|
contacts = []
|
||||||
|
current_gsm_modem = None
|
||||||
card_pool = CardPool(CARD_POOL_PORT)
|
card_pool = CardPool(CARD_POOL_PORT)
|
||||||
|
|
||||||
|
|
||||||
@@ -70,11 +70,6 @@ def create_modem_for_port(port: str) -> Union[SerialModem, None]:
|
|||||||
serial_modem = None
|
serial_modem = None
|
||||||
try:
|
try:
|
||||||
modem = GsmModem(port)
|
modem = GsmModem(port)
|
||||||
# time.sleep(1)
|
|
||||||
# modem.connect()
|
|
||||||
# number = modem.ownNumber
|
|
||||||
# logger.info("The SIM card phone number is:")
|
|
||||||
# logger.info(number)
|
|
||||||
return SerialModem(modem=modem)
|
return SerialModem(modem=modem)
|
||||||
except Exception as ext:
|
except Exception as ext:
|
||||||
print(ext)
|
print(ext)
|
||||||
@@ -87,6 +82,8 @@ def timeout_occurred(serial_modem: SerialModem):
|
|||||||
|
|
||||||
|
|
||||||
def start_to_handle_sms(serial_modem: SerialModem):
|
def start_to_handle_sms(serial_modem: SerialModem):
|
||||||
|
global current_gsm_modem
|
||||||
|
current_gsm_modem = serial_modem.modem
|
||||||
serial_modem.modem.smsReceivedCallback = handle_sms
|
serial_modem.modem.smsReceivedCallback = handle_sms
|
||||||
global is_finished
|
global is_finished
|
||||||
is_finished = False
|
is_finished = False
|
||||||
@@ -101,6 +98,7 @@ def start_to_handle_sms(serial_modem: SerialModem):
|
|||||||
logger.info("time out for {}, switch to next contact".format(serial_modem.phone_number))
|
logger.info("time out for {}, switch to next contact".format(serial_modem.phone_number))
|
||||||
# save the contact in timeout
|
# save the contact in timeout
|
||||||
timeout_occurred(serial_modem)
|
timeout_occurred(serial_modem)
|
||||||
|
current_gsm_modem.close()
|
||||||
return
|
return
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -110,7 +108,9 @@ def handle_sms(sms):
|
|||||||
u'== SMS message received ==\nFrom: {0}\nTime: {1}\nMessage:\n{2}\n'.format(sms.number, sms.time, sms.text))
|
u'== SMS message received ==\nFrom: {0}\nTime: {1}\nMessage:\n{2}\n'.format(sms.number, sms.time, sms.text))
|
||||||
# extract the otp number
|
# extract the otp number
|
||||||
logger.info("try to extract the otp")
|
logger.info("try to extract the otp")
|
||||||
match = re.search(r'\d{6,8}', sms.text)
|
pattern = r'\d{6,8}'
|
||||||
|
# if re.match(pattern, sms.text):
|
||||||
|
match = re.search(pattern, sms.text)
|
||||||
otp = match.group(0)
|
otp = match.group(0)
|
||||||
logger.info("otp is " + otp)
|
logger.info("otp is " + otp)
|
||||||
commandor.send_otp(otp)
|
commandor.send_otp(otp)
|
||||||
@@ -119,6 +119,9 @@ def handle_sms(sms):
|
|||||||
while not is_finished:
|
while not is_finished:
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
is_finished = True
|
is_finished = True
|
||||||
|
global current_gsm_modem
|
||||||
|
if current_gsm_modem:
|
||||||
|
current_gsm_modem.close()
|
||||||
|
|
||||||
|
|
||||||
def select_sim_storage(ser) -> bool:
|
def select_sim_storage(ser) -> bool:
|
||||||
@@ -173,8 +176,8 @@ def read_all_the_phone_number():
|
|||||||
|
|
||||||
|
|
||||||
def start_book():
|
def start_book():
|
||||||
slot_number = 12
|
slot_number = 7
|
||||||
slot_sum = 31
|
slot_sum = 29
|
||||||
for i in range(slot_number, slot_sum + 1):
|
for i in range(slot_number, slot_sum + 1):
|
||||||
card_pool.reset()
|
card_pool.reset()
|
||||||
print("will switch to " + str(i))
|
print("will switch to " + str(i))
|
||||||
@@ -187,16 +190,21 @@ def start_book():
|
|||||||
excel_reader = ExcelHelper()
|
excel_reader = ExcelHelper()
|
||||||
global contacts
|
global contacts
|
||||||
contacts = excel_reader.read_contacts()
|
contacts = excel_reader.read_contacts()
|
||||||
for index, modem in modem_list:
|
for modem in modem_list:
|
||||||
# get contact for current modem
|
try:
|
||||||
modem.get_ccid()
|
# get contact for current modem
|
||||||
contact = [contact for contact in contacts if contact.ccid == modem.ccid]
|
modem.get_ccid()
|
||||||
if len(contact) > 0:
|
# find the contact with ccid
|
||||||
modem.phone_number = contact[0].phone
|
contact = [contact for contact in contacts if contact.ccid == modem.ccid]
|
||||||
modem.contact = contact[0]
|
if len(contact) > 0:
|
||||||
if modem.contact:
|
modem.phone_number = contact[0].phone
|
||||||
commandor.start_page(modem.contact)
|
modem.contact = contact[0]
|
||||||
start_to_handle_sms(modem)
|
if modem.contact:
|
||||||
|
commandor.start_page(modem.contact)
|
||||||
|
start_to_handle_sms(modem)
|
||||||
|
except Exception as error:
|
||||||
|
print(error)
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user