|
| 1 | +.. _asset_tracker_v2_modem_module: |
| 2 | + |
| 3 | +Modem module |
| 4 | +############ |
| 5 | + |
| 6 | +.. contents:: |
| 7 | + :local: |
| 8 | + :depth: 2 |
| 9 | + |
| 10 | +The modem module communicates with the modem to control the LTE connection and retrieve information from the modem about the device and LTE network. |
| 11 | + |
| 12 | +Features |
| 13 | +******** |
| 14 | + |
| 15 | +This section documents the features implemented by the module. |
| 16 | + |
| 17 | +LTE connection handling |
| 18 | +======================= |
| 19 | + |
| 20 | +The module uses the :ref:`lte_lc_readme` library to control and monitor the LTE connection. |
| 21 | +The module registers an event handler with :ref:`lte_lc_readme` to receive updates from the modem about the state of the LTE connection and network information. |
| 22 | +If you use the :ref:`liblwm2m_carrier_readme` library, refer to :ref:`modem_module_carrier_lib` for additional information on LTE connection handling. |
| 23 | + |
| 24 | +In its default configuration, the modem module makes an attempt to establish an LTE connection immediately when it is initialized. |
| 25 | +There is no timeout on the connection attempt, so the modem searches for a suitable LTE network until it finds one. |
| 26 | + |
| 27 | +When the device is registered to an LTE network, the LTE connection is considered to be established, and a :c:enum:`MODEM_EVT_LTE_CONNECTED` event is sent. |
| 28 | +If the network registration is lost at some point, a :c:enum:`MODEM_EVT_LTE_DISCONNECTED` event is sent. |
| 29 | + |
| 30 | +If the device connects to a new LTE cell, an :c:enum:`LTE_LC_EVT_CELL_UPDATE` is sent. |
| 31 | +The event contains cell ID and tracking area code as payload, which can be used to determine the device's coarse position. |
| 32 | + |
| 33 | +If the modem module receives an ``APP_EVT_LTE_DISCONNECT`` event, it instructs the modem to detach from the network, and a subsequent :c:enum:`MODEM_EVT_LTE_DISCONNECTED` event can be expected after the disconnect. |
| 34 | + |
| 35 | +To configure the LTE connection parameters, refer to the :ref:`lte_lc_readme` Kconfig options. |
| 36 | +These options can be used to select the access technology to use (LTE-M or NB-IoT), default values for :term:`Power Saving Mode (PSM)` timers and more. |
| 37 | + |
| 38 | +Note that some network parameters, such as PSM timer values, are requests to the network and might not be granted as requested, and the network might grant a different value than the requested values or deny the request altogether. |
| 39 | +The actual values that are received from the network are distributed in :c:enum:`MODEM_EVT_LTE_PSM_UPDATE` events. |
| 40 | + |
| 41 | +.. _modem_module_carrier_lib: |
| 42 | + |
| 43 | +Carrier library support |
| 44 | +======================= |
| 45 | + |
| 46 | +The modem module has support for the :ref:`liblwm2m_carrier_readme` library. |
| 47 | +When the library is enabled, the modem module leaves the LTE connection handling to the library in order to adhere to the specific carrier's requirements. |
| 48 | + |
| 49 | +If the :ref:`liblwm2m_carrier_readme` library starts a modem firmware update, the modem module sends a :c:enum:`MODEM_EVT_CARRIER_FOTA_PENDING` event. |
| 50 | +This event signals that a modem firmware FOTA download is about to start, and all the other TLS connections in the system must be closed, including any cloud connection. |
| 51 | +After a successful FOTA, :c:enum:`MODEM_EVT_CARRIER_REBOOT_REQUEST` is sent, indicating that the application must perform a graceful shutdown and reboot the device to apply the new modem firmware. |
| 52 | +If a FOTA download fails, a :c:enum:`MODEM_EVT_CARRIER_FOTA_STOPPED` event is sent, and the application might again establish TLS connections and continue normal operation. |
| 53 | + |
| 54 | +For more details and configuration options, you can refer to :ref:`liblwm2m_carrier_readme`. |
| 55 | + |
| 56 | +Modem information |
| 57 | +================= |
| 58 | + |
| 59 | +When the application module sends out an ``APP_EVT_DATA_GET`` event, the modem module checks the requested data list for relevant requests: |
| 60 | + |
| 61 | +* ``APP_DATA_MODEM_STATIC`` - Static modem data, such as configured system mode (any combination of LTE-M, NB-IoT and GNSS), ICCID, modem firmware version, application version and board version. |
| 62 | +* ``APP_DATA_MODEM_DYNAMIC`` - Dynamic modem data, such as Cell ID, tracking area code, RSRP, IP address and PLMN (MCCMNC). |
| 63 | +* ``APP_DATA_BATTERY`` - Voltage of the modem's power supply. |
| 64 | + |
| 65 | +The module uses :ref:`modem_info_readme` to acquire information about the modem, LTE network and the modem's power supply. |
| 66 | +The response for the three different data types is sent as separate events: |
| 67 | + |
| 68 | +* Static data as :c:enum:`MODEM_EVT_MODEM_STATIC_DATA_READY` |
| 69 | +* Dynamic data as :c:enum:`MODEM_EVT_MODEM_DYNAMIC_DATA_READY` |
| 70 | +* Battery voltage as :c:enum:`MODEM_EVT_BATTERY_DATA_READY` |
| 71 | + |
| 72 | +If the sampling of data fails, a corresponding error message is sent through one of the following events: |
| 73 | + |
| 74 | +* :c:enum:`MODEM_EVT_MODEM_STATIC_DATA_NOT_READY` |
| 75 | +* :c:enum:`MODEM_EVT_MODEM_DYNAMIC_DATA_NOT_READY` |
| 76 | +* :c:enum:`MODEM_EVT_BATTERY_DATA_NOT_READY` |
| 77 | + |
| 78 | +Neighbor cell measurements |
| 79 | +========================== |
| 80 | + |
| 81 | +Neighbor cell measurements can be requested by the application by sending an ``APP_EVT_DATA_GET`` event where ``APP_DATA_NEIGHBOR_CELLS`` is part of the requested data list. |
| 82 | +Upon reception of that event, the modem module uses the LTE link controller to start a neighbor cell search of type :c:enum:`LTE_LC_NEIGHBOR_SEARCH_TYPE_DEFAULT`. |
| 83 | +See :ref:`lte_lc_readme` for more details on the available search types. |
| 84 | +When the search completes, the module sends a :c:enum:`MODEM_EVT_NEIGHBOR_CELLS_DATA_READY` event containing the cell information received from the modem. |
| 85 | +If the search fails, a :c:enum:`MODEM_EVT_NEIGHBOR_CELLS_DATA_NOT_READY` event is sent. |
| 86 | + |
| 87 | +Module internals |
| 88 | +**************** |
| 89 | + |
| 90 | +The modem module has an internal thread with a message queue for processing. |
| 91 | +When an event is received in the :ref:`event_manager` handler, the event is converted to a message and put into the module's queue for processing in thread context. |
| 92 | +This gives the module the flexibility to call functions that might take some time to complete. |
| 93 | + |
| 94 | +Module states |
| 95 | +============= |
| 96 | + |
| 97 | +The modem module has an internal state machine with the following states: |
| 98 | + |
| 99 | + * ``STATE_INIT`` - The initial state of the module in which it awaits the modem to be initialized. |
| 100 | + The module enters this state only if the :ref:`liblwm2m_carrier_readme` library is enabled because the modem is automatically initialized otherwise. |
| 101 | + * ``STATE_DISCONNECTED`` - The module has performed all required initializations and is ready to establish an LTE connection. |
| 102 | + This is the initial state for applications that do not use the :ref:`liblwm2m_carrier_readme` library. |
| 103 | + * ``STATE_CONNECTING`` - The modem is currently searching for a suitable LTE network and attempting to establish a connection. |
| 104 | + * ``STATE_CONNECTED`` - The device is connected to an LTE network. |
| 105 | + * ``STATE_SHUTDOWN`` - The module has been shut down after receiving a request from the utility module. |
| 106 | + |
| 107 | +State transitions take place based on input from other modules through the event manager handler and the LTE link controller handler. |
| 108 | + |
| 109 | +Configuration options |
| 110 | +********************* |
| 111 | + |
| 112 | +You can set the following options to configure the modem module: |
| 113 | + |
| 114 | +.. _CONFIG_MODEM_MODULE: |
| 115 | + |
| 116 | +CONFIG_MODEM_MODULE - Configuration for modem module |
| 117 | + This option enables the modem module. |
| 118 | + |
| 119 | +.. _CONFIG_MODEM_THREAD_STACK_SIZE: |
| 120 | + |
| 121 | +CONFIG_MODEM_THREAD_STACK_SIZE - Configuration for thread stack size |
| 122 | + This option configures the modem module thread stack size. |
| 123 | + |
| 124 | +.. _CONFIG_MODEM_SEND_ALL_SAMPLED_DATA: |
| 125 | + |
| 126 | +CONFIG_MODEM_SEND_ALL_SAMPLED_DATA - Configuration for sending all sampled data |
| 127 | + By default, the modem module sends only events with sampled data that has changed since the last sampling. |
| 128 | + To send unchanged data also, enable this option. |
| 129 | + |
| 130 | +.. _CONFIG_MODEM_AUTO_REQUEST_POWER_SAVING_FEATURES: |
| 131 | + |
| 132 | +CONFIG_MODEM_AUTO_REQUEST_POWER_SAVING_FEATURES - Configuration for automatic requests of PSM |
| 133 | + The module automatically requests PSM from the LTE network. |
| 134 | + If PSM is granted by the network, it results in reduction of the modem's power consumption. |
| 135 | + Note that the device is not reachable from the cloud when it is in PSM. |
| 136 | + The device exits PSM whenever the application sends data, or the configured PSM TAU (Tracking Area Update) interval has passed. |
| 137 | + To not request PSM from the network, disable this option. |
| 138 | + |
| 139 | +For more information on LTE configuration options, see :ref:`lte_lc_readme`. |
| 140 | + |
| 141 | +Module events |
| 142 | +************* |
| 143 | + |
| 144 | +The :file:`asset_tracker_v2/src/events/modem_module_event.h` header file contains a list of the events sent by the modem module. |
| 145 | + |
| 146 | +Dependencies |
| 147 | +************ |
| 148 | + |
| 149 | +The module uses the following |NCS| libraries: |
| 150 | + |
| 151 | +* :ref:`event_manager` |
| 152 | +* :ref:`lte_lc_readme` |
| 153 | +* :ref:`modem_info_readme` |
| 154 | + |
| 155 | +API documentation |
| 156 | +***************** |
| 157 | + |
| 158 | +| Header file: :file:`asset_tracker_v2/src/events/modem_module_event.h` |
| 159 | +| Source files: :file:`asset_tracker_v2/src/events/modem_module_event.c`, :file:`asset_tracker_v2/src/modules/modem_module.c` |
| 160 | +
|
| 161 | +.. doxygengroup:: modem_module_event |
| 162 | + :project: nrf |
| 163 | + :members: |
0 commit comments