From 03d416096d2c7dd1e6cb73b77f045cc0589e9500 Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Fri, 9 Oct 2020 09:43:11 +0200 Subject: [PATCH 1/5] fixes --- content/tutorials/networks/lte/_index.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/content/tutorials/networks/lte/_index.md b/content/tutorials/networks/lte/_index.md index ed91f31..833b725 100644 --- a/content/tutorials/networks/lte/_index.md +++ b/content/tutorials/networks/lte/_index.md @@ -34,8 +34,8 @@ lte.init() #also, check the band settings with your carrier lte.attach(band=20, apn="your apn") print("attaching..",end='') -while not lte.isattached() - time.delay(0.25) +while not lte.isattached(): + time.sleep(0.25) print('.',end='') print(lte.send_at_cmd('AT!="fsm"')) # get the System FSM @@ -63,11 +63,12 @@ When the LTE disconnects in an unexpected situation, for example when the signal ```python from network import LTE import time -from sleep import sleep import machine def cb_handler(arg): print("CB: LTE Coverage lost") + s = 120 print("CB: sleep", s) + time.sleep(s) print("CB: deinit") lte.deinit() print("CB: reset") From 0f76b28ce075c6dc9893fde225161aa06aac8a66 Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Fri, 9 Oct 2020 15:04:53 +0200 Subject: [PATCH 2/5] changed headings --- content/tutorials/networks/lte/_index.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/content/tutorials/networks/lte/_index.md b/content/tutorials/networks/lte/_index.md index 833b725..e8420f8 100644 --- a/content/tutorials/networks/lte/_index.md +++ b/content/tutorials/networks/lte/_index.md @@ -17,6 +17,8 @@ When using the SigFox network, **Always** connect the appropriate LoRa antenna t GPy and FiPy support both LTE CAT-M1 and NB-IoT. These are newer, low power, long range, cellular protocols. They are not the same as the full version of 2G/3G/LTE supported by cell phones, and require your local carriers to support them. At the time of writing, CAT-M1 and NB-IoT connectivity is not widely available so be sure to check with local carriers if support is available where you are. Together with the SIM card, the provider will supply you with configuration details: Usually band and APN. Use these in the example code below. +## Example + ```python from network import LTE import time @@ -58,7 +60,7 @@ The last line of the script should return a tuple containing the IP address of t >Note: the first time, it can take a long while to attach to the network. -# LTE disconnecting +## LTE disconnecting 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: ```python from network import LTE @@ -77,7 +79,7 @@ def cb_handler(arg): lte.lte_callback(LTE.EVENT_COVERAGE_LOSS, cb_handler) ``` -# LTE Troubleshooting guide +## LTE Troubleshooting guide From 03e8ac1fca0ed15c4a954d229155739a8f2488f3 Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Fri, 27 Nov 2020 14:17:39 +0100 Subject: [PATCH 3/5] updated lte callback description --- content/tutorials/networks/lte/_index.md | 50 +++++++++++++++++------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/content/tutorials/networks/lte/_index.md b/content/tutorials/networks/lte/_index.md index e8420f8..5f3aa04 100644 --- a/content/tutorials/networks/lte/_index.md +++ b/content/tutorials/networks/lte/_index.md @@ -61,24 +61,46 @@ The last line of the script should return a tuple containing the IP address of t >Note: the first time, it can take a long while to attach to the network. ## LTE disconnecting -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: +> You will need firmware 1.20.2.r2 or later for this functionality + +It is possible that the LTE disconnects unexpectedly (some time after `lte.connect()`) due to a whole variety of reasons. + +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. + ```python -from network import LTE -import time -import machine -def cb_handler(arg): - print("CB: LTE Coverage lost") - s = 120 - print("CB: sleep", s) - time.sleep(s) - print("CB: deinit") - lte.deinit() - print("CB: reset") - machine.reset() +def lte_cb_handler(arg): + print("CB LTE Callback Handler") + ev = arg.events() # NB: reading the events clears them + t = time.ticks_ms() + print("CB", t, time.time(), ev, time.gmtime()) + pycom.rgbled(0x222200) + if ev & LTE.EVENT_COVERAGE_LOSS: + print("CB", t, "coverage loss") + if ev & LTE.EVENT_BREAK: + print("CB", t, "uart break signal") + # investiage the situation. Generally speaking, it will be one of the following: + # - the modem lost connection, but will automatically reestablish it by itself if we give it some time, e.g. new + # - the modem can't automatically reconnect, now we could + # - try to suspend/resume or detach/reattach, or lte.reset(), + # - but it could simply mean that we are out of lte coverage and all we can do is: + # log the event, and then either machine.deepsleep() and try again later or simply + # keep going and wait longer for the modem to reconnect. or, especially if we suspect a + # FW problem, we could machine.reset() and try again + print("CB", t, time.time(), "test connection") -lte.lte_callback(LTE.EVENT_COVERAGE_LOSS, cb_handler) + #write your own test_connection function + if test_connection(): + print("CB", t, time.time(), "connection ok") + else: + print("CB", t, time.time(), "connection not ok") + # suspendresume() + # lte.reset() + print("CB", t, time.time(), ev, " done") + +lte_callback(LTE.EVENT_BREAK, lte_cb_handler) ``` + ## LTE Troubleshooting guide From cfb8722d7077c7a73ed4bfe30aadfd016746896c Mon Sep 17 00:00:00 2001 From: Peter Putz Date: Mon, 30 Nov 2020 12:42:00 +0100 Subject: [PATCH 4/5] lte: fix lte not sigfox --- content/tutorials/networks/lte/_index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/tutorials/networks/lte/_index.md b/content/tutorials/networks/lte/_index.md index 5f3aa04..16d92ad 100644 --- a/content/tutorials/networks/lte/_index.md +++ b/content/tutorials/networks/lte/_index.md @@ -8,7 +8,7 @@ The following tutorial demonstrates the use of the LTE CAT-M1 and NB-IoT functio > Before you start, make sure that your Simcard is registered and activated with your carrier. -When using the SigFox network, **Always** connect the appropriate LoRa antenna to your device. See the figures below for the correct antenna placement +When using the LTE network, **Always** connect the appropriate antenna to your device. See the figures below for the correct antenna placement. | Gpy | Fipy | |---|---| From 5603e9997e1f23f8a4f822fe870bd09aada5c48d Mon Sep 17 00:00:00 2001 From: Peter Putz Date: Mon, 30 Nov 2020 12:43:17 +0100 Subject: [PATCH 5/5] lte: rewrite callback example and explanation - bit more background and move explanations out of the code comments - shorter callback example --- content/tutorials/networks/lte/_index.md | 43 +++++++++--------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/content/tutorials/networks/lte/_index.md b/content/tutorials/networks/lte/_index.md index 16d92ad..60fe481 100644 --- a/content/tutorials/networks/lte/_index.md +++ b/content/tutorials/networks/lte/_index.md @@ -60,43 +60,30 @@ The last line of the script should return a tuple containing the IP address of t >Note: the first time, it can take a long while to attach to the network. -## LTE disconnecting -> You will need firmware 1.20.2.r2 or later for this functionality +## LTE Connectivity loss +> You need firmware 1.20.2.r2 or later for this functionality -It is possible that the LTE disconnects unexpectedly (some time after `lte.connect()`) due to a whole variety of reasons. +It is possible that the LTE modem loses connectivity. It could be due to some radio interference, maybe the reception in the location of the module is not too good. Or if the module is being physically moved to another location with worse reception. -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. +If the connectivity is lost this will in general not be reflected when you check `lte.isconnected()`. However, the lte modem sends a `UART break` signal. You can receive these events by using the `lte_callback` functionality. When connectivity is lost, the modem will try it's best to re-establish connectivity and this also works well in general. When connectivity is re-established, the modem will send another break signal, ie, the `lte_callback` will fire again. + +This means the best practice is to capture the callback and inside the callback test whether the module is connected or not. If, with some timeout, there really is no connection, then one can try to react to this. Let's say the application is a sensor, that is most of the time in deepsleep, wakes up once in a while, measures something and then tries to send it's measurement before going back to deepsleep. In this case one could simply log the event, go back to sleep and hope that in the next interval the reception will be better. Or, if there is some alternative connectivity implemented, one could trigger it at this point. ```python def lte_cb_handler(arg): - print("CB LTE Callback Handler") - ev = arg.events() # NB: reading the events clears them - t = time.ticks_ms() - print("CB", t, time.time(), ev, time.gmtime()) + ev = arg.events() # NB: reading the events also clears them + print("LTE CB", time.time(), ev, time.gmtime()) pycom.rgbled(0x222200) - if ev & LTE.EVENT_COVERAGE_LOSS: - print("CB", t, "coverage loss") if ev & LTE.EVENT_BREAK: - print("CB", t, "uart break signal") - # investiage the situation. Generally speaking, it will be one of the following: - # - the modem lost connection, but will automatically reestablish it by itself if we give it some time, e.g. new - # - the modem can't automatically reconnect, now we could - # - try to suspend/resume or detach/reattach, or lte.reset(), - # - but it could simply mean that we are out of lte coverage and all we can do is: - # log the event, and then either machine.deepsleep() and try again later or simply - # keep going and wait longer for the modem to reconnect. or, especially if we suspect a - # FW problem, we could machine.reset() and try again - print("CB", t, time.time(), "test connection") - - #write your own test_connection function + print("LTE CB", "uart break signal") + print("LTE CB", time.time(), "test connection") + # TBD: write your own test_connection function if test_connection(): - print("CB", t, time.time(), "connection ok") + print("LTE CB", time.time(), "connection ok") else: - print("CB", t, time.time(), "connection not ok") - # suspendresume() - # lte.reset() - - print("CB", t, time.time(), ev, " done") + print("LTE CB", time.time(), "connection not ok") + # TBD: implement handling of lost connection + # machine.deepsleep(deepsleeptime) lte_callback(LTE.EVENT_BREAK, lte_cb_handler) ```