From 333eb0578c97e17c2ccd23f7855ee75fec01d0cd Mon Sep 17 00:00:00 2001 From: Pavel Valach Date: Tue, 28 Jul 2020 11:37:25 +0000 Subject: [PATCH] sms_functions.unlock_sim: read PIN from modem_pin.txt --- sms_functions.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/sms_functions.py b/sms_functions.py index bdd6fed..f6fe687 100644 --- a/sms_functions.py +++ b/sms_functions.py @@ -55,15 +55,18 @@ def unlock_sim(modem): props = modem.GetStatus() print(props) if props and props['state'] == 2: - logger.info("Trying to unlock %s", sim_path) - with SystemBus() as bus: - sim = bus.get('.ModemManager1', sim_path) - sim.SendPin("1234", timeout=10000) - props = modem.GetStatus() - if props and props['state'] == 2: - remaining_attempts = modem.UnlockRetries - print(remaining_attempts) - raise SIMError('Wrong PIN!') + # check if the modem_pin.txt file exists + with open('modem_pin.txt', 'r') as mp: + mypin = mp.readline().rstrip('\n') + + logger.info("Trying to unlock %s", sim_path) + with SystemBus() as bus: + sim = bus.get('.ModemManager1', sim_path) + sim.SendPin(mypin, timeout=10000) + props = modem.GetStatus() + if props and props['state'] == 2: + remaining_attempts = modem.UnlockRetries + raise SIMError('Wrong PIN! Remaining attempts: {}'.format(remaining_attempts)) def send_sms(recipients, smsstring): @@ -95,7 +98,7 @@ def send_sms(recipients, smsstring): modem_msg = modem['org.freedesktop.ModemManager1.Modem.Messaging'] smses = modem_msg.List() - while not modem.GetStatus()['signal-quality'][1]: + while not modem.GetStatus().get('signal-quality', None) or not modem.GetStatus()['signal-quality'][1]: modem = get_modem() print(modem.GetStatus()['signal-quality']) time.sleep(2)