I've got a gpy in a wakeup-lteattach-connect-upload-disconnect-detach-deeplseep cycle. There is an lte modem reset cmd in the attachment routine
if not lte.isattached(): print('lte attaching ', end=''); lte.attach() for i in range (10): if lte.isattached(): print ('attached'); break if i==5: print('modem reset'); lte.send_at_cmd('AT^RESET') print(i, ' ', end='')
it works OK with the reset in the middle of the 10 trys but if I remove the rest line then attachment failure can persist indefinitely. The reason the modem is sometimes not attaching & needs the modem reset is because it's already attached, which is possible if the previous deepsleep cycle ended without proper detachment. What I can't figure out is how an already attached modem gets past the if not lte.isattached() test?
I think you're correct, seeing a register rather than the actual modem state. What complicates this issue further is that reading the register also seems to clear it. So that
print('checking LTE') c='connected' if lte.isconnected() else 'not connected'; print('modem is', c) a='attached' if lte.isattached() else 'not attached'; print('modem is', a) a='attached' if lte.isattached() else 'not attached'; print('modem is', a)
checking LTE modem is connected modem is attached modem is not attached
@kjm haven’t checked the internals of those functions, but it’s quite possible the firmware maintains a state rather than checking what the modem says.
In that case, it would start considering (possibly incorrectly) that the modem is not attached.
One option could be to perform the reset in all cases to make sure the firmware and modem are in sync?