My python script is working with a modem, and the first step of the process is to check if there is enough signal. Through AT commands,I can ask the modem for the signal intensity, so I made a loop that constantly asks for the strenght of the signal, and then proceeds if the signal is strong enough.
If there is signal available, it works just fine. The problem is when there is no signal. I've tried increasing the sleep time, but it seems not to work.
Signal = False
while Signal is not True:
x = ser.readline()
y = x.rstrip()
z = y.decode('utf-8')
ser.write(str.encode('AT+CSQ?\r'))
time.sleep(9)
if (z.startswith("+CSQ")):
a = int(z[5])
if a >= 3:
Signal = True
time.sleep(4)
enough_signal_write()
else:
checking_signal
With long loops, like 10 tries to catch signal, it seems to work strangely, like ignoring if the signal is strong enough sometimes, then finally catching up and running. (I can check this through the strange order of the modem outputs with 'print(z)' line)
I'm feeling like I need something to wait for the modem to respond, and then take actions with this, but I'm not sure how I should do it.
Thanks for you time