Skip to content

Commit 03e8ac1

Browse files
committed
updated lte callback description
1 parent 0f76b28 commit 03e8ac1

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

content/tutorials/networks/lte/_index.md

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,46 @@ The last line of the script should return a tuple containing the IP address of t
6161
>Note: the first time, it can take a long while to attach to the network.
6262
6363
## LTE disconnecting
64-
When the LTE disconnects in an unexpected situation, for example when the signal is lost, `lte.isconnected()` will still return `True`. Currently, there is a solution using the callback and handler function listed below:
64+
> You will need firmware 1.20.2.r2 or later for this functionality
65+
66+
It is possible that the LTE disconnects unexpectedly (some time after `lte.connect()`) due to a whole variety of reasons.
67+
68+
When such event happens, the modem will report a `UART break`, which triggers the callback functionality we discuss later. By default the model will automatically reconnect and no user intervention is needed, or, the modem can not automatically reconnect and we can take action. Note that taking action might not resolve the issue and will keep us disconnected.
69+
6570
```python
66-
from network import LTE
67-
import time
68-
import machine
69-
def cb_handler(arg):
70-
print("CB: LTE Coverage lost")
71-
s = 120
72-
print("CB: sleep", s)
73-
time.sleep(s)
74-
print("CB: deinit")
75-
lte.deinit()
76-
print("CB: reset")
77-
machine.reset()
78-
79-
lte.lte_callback(LTE.EVENT_COVERAGE_LOSS, cb_handler)
71+
def lte_cb_handler(arg):
72+
print("CB LTE Callback Handler")
73+
ev = arg.events() # NB: reading the events clears them
74+
t = time.ticks_ms()
75+
print("CB", t, time.time(), ev, time.gmtime())
76+
pycom.rgbled(0x222200)
77+
if ev & LTE.EVENT_COVERAGE_LOSS:
78+
print("CB", t, "coverage loss")
79+
if ev & LTE.EVENT_BREAK:
80+
print("CB", t, "uart break signal")
81+
# investiage the situation. Generally speaking, it will be one of the following:
82+
# - the modem lost connection, but will automatically reestablish it by itself if we give it some time, e.g. new
83+
# - the modem can't automatically reconnect, now we could
84+
# - try to suspend/resume or detach/reattach, or lte.reset(),
85+
# - but it could simply mean that we are out of lte coverage and all we can do is:
86+
# log the event, and then either machine.deepsleep() and try again later or simply
87+
# keep going and wait longer for the modem to reconnect. or, especially if we suspect a
88+
# FW problem, we could machine.reset() and try again
89+
print("CB", t, time.time(), "test connection")
90+
91+
#write your own test_connection function
92+
if test_connection():
93+
print("CB", t, time.time(), "connection ok")
94+
else:
95+
print("CB", t, time.time(), "connection not ok")
96+
# suspendresume()
97+
# lte.reset()
8098

99+
print("CB", t, time.time(), ev, " done")
100+
101+
lte_callback(LTE.EVENT_BREAK, lte_cb_handler)
81102
```
103+
82104
## LTE Troubleshooting guide
83105

84106

0 commit comments

Comments
 (0)