Modem information
The modem information library can be used by an LTE application to obtain specific data from a modem. It issues AT commands to retrieve the following data:
Signal strength indication (RSRP)
Current and supported LTE bands
Tracking area code, mobile country code, and mobile network code
Current mode and operator
The cell ID and IP address of the device
UICC state, SIM ICCID and SIM IMSI
The battery voltage and temperature level, measured by the modem
The modem firmware version
The modem serial number
The LTE-M, NB-IoT, and GNSS support mode
Mobile network time and date
The modem information library uses the AT command parser.
Call modem_info_init()
to initialize the library.
To obtain a data value, call modem_info_string_get()
(to retrieve the value as a string) or modem_info_short_get()
(to retrieve the value as a short).
You can also retrieve all available data.
To do so, call modem_info_params_init()
to initialize a structure that stores all retrieved information, then populate it by calling modem_info_params_get()
.
To retrieve the data as a single JSON string, call modem_info_json_string_encode()
.
Note, however, that signal strength data (RSRP) is only available by registering a subscription. To do so, call modem_info_rsrp_register()
.
API documentation
include/modem/modem_info.h
lib/modem_info/
- group modem_info
Defines
-
MODEM_INFO_MAX_RESPONSE_SIZE
Largest expected parameter response size.
-
MODEM_INFO_JSON_STRING_SIZE
Size of the JSON string.
-
RSRP_OFFSET_VAL
RSRP offset value.
-
RSRQ_OFFSET_VAL
RSRQ offset value.
-
RSRQ_SCALE_VAL
RSRQ scale value.
-
RSRP_IDX_TO_DBM(rsrp)
Modem returns RSRP and RSRQ as index values which require a conversion to dBm and dB respectively. See modem AT command reference guide for more information.
-
RSRQ_IDX_TO_DB(rsrq)
-
MODEM_INFO_NETWORK_MODE_MAX_SIZE
Maximum string size of the network mode string
Typedefs
-
typedef void (*rsrp_cb_t)(char rsrp_value)
RSRP event handler function protoype.
Enums
-
enum modem_info
LTE link information data.
Values:
-
enumerator MODEM_INFO_RSRP
Signal strength.
-
enumerator MODEM_INFO_CUR_BAND
Current LTE band.
-
enumerator MODEM_INFO_SUP_BAND
Supported LTE bands.
-
enumerator MODEM_INFO_AREA_CODE
Tracking area code.
-
enumerator MODEM_INFO_UE_MODE
Current mode.
-
enumerator MODEM_INFO_OPERATOR
Current operator name.
-
enumerator MODEM_INFO_MCC
Mobile country code.
-
enumerator MODEM_INFO_MNC
Mobile network code.
-
enumerator MODEM_INFO_CELLID
Cell ID of the device.
-
enumerator MODEM_INFO_IP_ADDRESS
IP address of the device.
-
enumerator MODEM_INFO_UICC
UICC state.
-
enumerator MODEM_INFO_BATTERY
Battery voltage.
-
enumerator MODEM_INFO_TEMP
Temperature level.
-
enumerator MODEM_INFO_FW_VERSION
Modem firmware version.
-
enumerator MODEM_INFO_ICCID
SIM ICCID.
-
enumerator MODEM_INFO_LTE_MODE
LTE-M support mode.
-
enumerator MODEM_INFO_NBIOT_MODE
NB-IoT support mode.
-
enumerator MODEM_INFO_GPS_MODE
GPS support mode.
-
enumerator MODEM_INFO_IMSI
Mobile subscriber identity.
-
enumerator MODEM_INFO_IMEI
Modem serial number.
-
enumerator MODEM_INFO_DATE_TIME
Mobile network time and date
-
enumerator MODEM_INFO_APN
Access point name.
-
enumerator MODEM_INFO_COUNT
Number of legal elements in the enum.
-
enumerator MODEM_INFO_RSRP
Functions
-
int modem_info_init(void)
Initialize the modem information module.
- Return values
0 – If the operation was successful. Otherwise, a (negative) error code is returned.
-
int modem_info_params_init(struct modem_param_info *modem_param)
Initialize the structure that stores modem information.
- Parameters
modem_param – Pointer to the modem parameter structure.
- Return values
0 – If the operation was successful. Otherwise, a (negative) error code is returned.
-
int modem_info_rsrp_register(rsrp_cb_t cb)
Initialize the subscription of RSRP values.
- Parameters
cb – Callback function.
- Return values
0 – If the operation was successful. Otherwise, a (negative) error code is returned.
-
int modem_info_string_get(enum modem_info info, char *buf, const size_t buf_size)
Request the current modem status of any predefined information value as a string.
If the data parameter returned by the modem is originally a short, it is still returned as a string.
- Parameters
info – The requested information type.
buf – The buffer to store the null-terminated string.
buf_size – The size of the buffer.
- Returns
Length of received data if the operation was successful. Otherwise, a (negative) error code is returned.
-
int modem_info_short_get(enum modem_info info, uint16_t *buf)
Request the current modem status of any predefined information value as a short.
If the data parameter returned by the modem is originally a string, this function fails.
- Parameters
info – The requested information type.
buf – The short where to store the information.
- Returns
Length of received data if the operation was successful. Otherwise, a (negative) error code is returned.
-
int modem_info_name_get(enum modem_info info, char *name)
Request the name of a modem information data type.
- Parameters
info – The requested information type.
name – The string where to store the name.
- Returns
Length of received data if the operation was successful. Otherwise, a (negative) error code is returned.
-
enum at_param_type modem_info_type_get(enum modem_info info)
Request the data type of the current modem information type.
- Parameters
info – The requested information type.
- Returns
The data type of the requested modem information data. Otherwise, a (negative) error code is returned.
-
int modem_info_params_get(struct modem_param_info *modem_param)
Obtain the modem parameters.
The data is stored in the provided info structure.
- Parameters
modem_param – Pointer to the storage parameters.
- Return values
0 – If the operation was successful. Otherwise, a (negative) error code is returned.
-
struct lte_param
- #include <modem_info.h>
LTE parameter data.
Public Members
-
uint16_t value
The retrieved value.
-
char value_string[100]
The retrieved value in string format.
-
char *data_name
The name of the information type.
-
enum modem_info type
The information type.
-
uint16_t value
-
struct network_param
- #include <modem_info.h>
Network parameters.
Public Members
-
double cellid_dec
Cell ID of the device (in decimal format).
-
double cellid_dec
-
struct sim_param
- #include <modem_info.h>
SIM card parameters.
-
struct device_param
- #include <modem_info.h>
Device parameters.
-
struct modem_param_info
- #include <modem_info.h>
Modem parameters.
Public Members
-
struct network_param network
Network parameters.
-
struct device_param device
Device parameters.
-
struct network_param network
-
MODEM_INFO_MAX_RESPONSE_SIZE