Discover the power of limitless connection through our advanced LTE IoT solution. Transforming the way devices communicate, our technology redefines what's possible, enabling IoT experiences that go beyond convention.
A
A
Hardware Overview
How does it work?
LTE IoT 5 Click is based on the SARA-R510M8S, a cellular module that supports LTE Cat M1/Cat NB2 bands with an integrated high-performance standard precision M8 GNSS receiver from u-blox. It comes in a miniature SARA LGA form factor module, a drop-in migration from other u-blox cellular module families. The SARA-R510 series modules provide software-based multi-band configurability, enabling international multi-regional coverage in LTE Cat M1/NB2 radio access technologies, supporting a comprehensive set of 3GPP Rel. 14 features that are relevant for IoT applications with data communications up to 1200 kbit/s. The GNSS RF input of the SARA-R510M8S, designed with 50Ω characteristic impedance and with an internal DC block, is suitable for both active and passive GNSS antennas due to the built-in SAW filter followed by an LNA in front of the integrated high-performing u-Blox M8 concurrent positioning engine. This module requires a power supply of 3.8V. Therefore, the Click board™ incorporates an integrated buck (step-down DC-DC) converter labeled TPS7A7002 by Texas Instruments. This IC can output up to 3A of current, maintaining excellent regulation. Its task is to provide a stable 3.8V power supply capable of mitigating voltage drops at the input
when a high current peak appears (typically at the StartUp of the device). The SARA-R510M8S communicates with MCU using the UART interface with automatic baud rate detection used for module control from the external application host processor that can be conveniently configured through AT commands that u-blox provides. This Click board™ is also USB 2.0 compliant, equipped with the USB type C connector with a maximum 480 Mbit/s data rate available for diagnostic purposes only. The module acts as a USB device and can be connected to any USB host with compatible drivers. Besides two female SMA connectors (for LTE and active GNSS antennas), the LTE IoT 5 Click also has a nano-SIM card slot that provides multiple connections and interface options. The J1 header allows you to access the configurable GPIO and EXT Interrupt pin of the SARA module, while test points labeled from TP1 to TP6 enable easy FW upgrades and testing of the module. The onboard active-low push-button labeled as PWR routed to the AN pin on the mikroBUS™ socket represents the Ignition (Power-On) button, which successful action will be indicated by the STAT LED. If the device is powered up, a LOW pulse with a duration of 1.5s on this pin will power the module down. It is also possible
to power down the module by issuing the AT+CPWROFF command or with a Reset function routed to the RST pin on the mikroBUS™ socket that will cause an abrupt Power-Down (forced Power-Down) by sending an active low input on this pin with the duration of 10s. In addition to the Power LED indicator, this Click board™ has two additional LED indicators: the yellow LED labeled as STAT is used to visually indicate the device's Operational Status and a red LED labeled as TX is used to indicate the Network Status. Customers can future-proof their solutions through over-the-air firmware updates, thanks to the uFOTA client/server solution that utilizes LwM2M, a light and compact protocol ideal for IoT. We have also provided accessible test points directly connected to the TxD and RxD pins for FW upgrade purposes. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. Also, this Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used as a reference for further development.
Features overview
Development board
PIC32MZ Clicker is a compact starter development board that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit PIC32MZ microcontroller with FPU from Microchip, a USB connector, LED indicators, buttons, a mikroProg connector, and a header for interfacing with external electronics. Thanks to its compact design with clear and easy-recognizable silkscreen markings, it provides a fluid and immersive working experience, allowing access anywhere and under
any circumstances. Each part of the PIC32MZ Clicker development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the PIC32MZ Clicker programming method, using USB HID mikroBootloader, or through an external mikroProg connector for PIC, dsPIC, or PIC32 programmer, the Clicker board also includes a clean and regulated power supply module for the development kit. The USB Micro-B connection can provide up to 500mA of current, which is more than enough to operate all onboard
and additional modules. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several buttons and LED indicators. PIC32MZ Clicker is an integral part of the Mikroe ecosystem, allowing you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.
Microcontroller Overview
MCU Card / MCU

Architecture
PIC32
MCU Memory (KB)
1024
Silicon Vendor
Microchip
Pin count
64
RAM (Bytes)
524288
You complete me!
Accessories
LTE Flat Rotation Antenna is a versatile choice for boosting the performance of 3G/4G LTE devices. With a wide frequency range of 700-2700MHz, it ensures optimal connectivity on major cellular bands worldwide. This flat antenna features an SMA male connector, making it easy to attach directly to your device or SMA module connector. One of its standout features is its adjustable angle, which can be set in 45⁰ increments (0⁰/45⁰/90⁰), allowing you to fine-tune the antenna's orientation for maximum signal reception. With an impedance of 50Ω and a VSW Ratio of <2.0:1, this antenna ensures a reliable and efficient connection. Its 5dB gain, vertical polarization, and omnidirectional radiation pattern enhance signal strength, making it suitable for various applications. Measuring 196mm in length and 38mm in width, this antenna offers a compact yet effective solution for improving your connectivity. With a maximum input power of 50W, it can handle the demands of various devices.
GNSS Active External Antenna is a unique multi-band type of antenna coming from u-blox that is the perfect selection for high precision GNSS applications, which require highly accurate location abilities such as RTK. The ANN-MB-00 is a multi-band (L1, L2/E5b/B2I) active GNSS antenna with a 5m cable and SMA connector. The antenna supports GPS, GLONASS, Galileo, and BeiDou and includes a high-performance multi-band RHCP dual-feed patch antenna element, a built-in high-gain LNA with SAW pre-filtering, and a 5 m antenna cable with SMA connector, and is waterproof.
Used MCU Pins
mikroBUS™ mapper
Take a closer look
Click board™ Schematic

Step by step
Project assembly
Track your results in real time
Application Output
1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support
Library Description
This library contains API for LTE IoT 5 Click driver.
Key functions:
lteiot5_generic_read
- LTE IoT 5 data reading functionlteiot5_send_cmd
- Send command functionlteiot5_power_on
- LTE IoT 5 power on.
Open Source
Code example
The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.
/*!
* @file main.c
* @brief LTE IoT 5 Click Example.
*
* # Description
* Application example shows device capability of connecting to the network and
* sending SMS or TCP/UDP messages, or retrieving data from GNSS using standard "AT" commands.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes the driver and logger.
*
* ## Application Task
* Application task is split in few stages:
* - LTEIOT5_POWER_UP:
* Powers up the device, performs a device factory reset and reads system information.
*
* - LTEIOT5_CONFIG_CONNECTION:
* Sets configuration to device to be able to connect to the network (used only for SMS or TCP/UDP demo examples).
*
* - LTEIOT5_CHECK_CONNECTION:
* Waits for the network registration indicated via CEREG command and then checks the signal quality report
* (used only for SMS or TCP/UDP demo examples).
*
* - LTEIOT5_CONFIG_EXAMPLE:
* Configures device for the selected example.
*
* - LTEIOT5_EXAMPLE:
* Depending on the selected demo example, it sends an SMS message (in PDU or TXT mode) or TCP/UDP message or
* waits for the GPS fix to retrieve location info from GNSS.
*
* By default, the TCP/UDP example is selected.
*
* ## Additional Function
* - static void lteiot5_clear_app_buf ( void )
* - static void lteiot5_log_app_buf ( void )
* - static err_t lteiot5_process ( lteiot5_t *ctx )
* - static err_t lteiot5_read_response ( lteiot5_t *ctx, uint8_t *rsp )
* - static err_t lteiot5_power_up ( lteiot5_t *ctx )
* - static err_t lteiot5_config_connection ( lteiot5_t *ctx )
* - static err_t lteiot5_check_connection ( lteiot5_t *ctx )
* - static err_t lteiot5_config_example ( lteiot5_t *ctx )
* - static err_t lteiot5_example ( lteiot5_t *ctx )
*
* @note
* In order for the examples to work (except GNSS example), user needs to set the APN and SMSC (SMS PDU mode only)
* of entered SIM card as well as the phone number (SMS mode only) to which he wants to send an SMS.
* Enter valid values for the following macros: SIM_APN, SIM_SMSC and PHONE_NUMBER.
* Example:
SIM_APN "internet"
SIM_SMSC "+381610401"
PHONE_NUMBER "+381659999999"
*
* @author Stefan Filipovic
*
*/
#include "board.h"
#include "log.h"
#include "lteiot5.h"
#include "generic_pointer.h"
#include "conversions.h"
// Example selection macros
#define EXAMPLE_TCP_UDP 0 // Example of sending messages to a TCP/UDP echo server
#define EXAMPLE_SMS 1 // Example of sending SMS to a phone number
#define EXAMPLE_GNSS 2 // Example of retrieving location info from GNSS
#define DEMO_EXAMPLE EXAMPLE_TCP_UDP // Example selection macro
// SIM APN config
#define SIM_APN "internet" // Set valid SIM APN
// SMS example parameters
#define SIM_SMSC "" // Set valid SMS Service Center Address - only in SMS PDU mode
#define PHONE_NUMBER "" // Set Phone number to message
#define SMS_MODE "1" // SMS mode: "0" - PDU, "1" - TXT
// TCP/UDP example parameters
#define REMOTE_IP "77.46.162.162" // TCP/UDP echo server IP address
#define REMOTE_PORT "51111" // TCP/UDP echo server port
// Message content
#define MESSAGE_CONTENT "LTE IoT 5 Click board - demo example."
// Application buffer size
#define APP_BUFFER_SIZE 256
#define PROCESS_BUFFER_SIZE 256
/**
* @brief Example states.
* @details Predefined enum values for application example state.
*/
typedef enum
{
LTEIOT5_POWER_UP = 1,
LTEIOT5_CONFIG_CONNECTION,
LTEIOT5_CHECK_CONNECTION,
LTEIOT5_CONFIG_EXAMPLE,
LTEIOT5_EXAMPLE
} lteiot5_app_state_t;
/**
* @brief Application example variables.
* @details Variables used in application example.
*/
static uint8_t app_buf[ APP_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;
static lteiot5_app_state_t app_state = LTEIOT5_POWER_UP;
static lteiot5_t lteiot5;
static log_t logger;
/**
* @brief LTE IoT 5 clearing application buffer.
* @details This function clears memory of application buffer and reset its length.
* @note None.
*/
static void lteiot5_clear_app_buf ( void );
/**
* @brief LTE IoT 5 log application buffer.
* @details This function logs data from application buffer to USB UART.
* @note None.
*/
static void lteiot5_log_app_buf ( void );
/**
* @brief LTE IoT 5 data reading function.
* @details This function reads data from device and concatenates data to application buffer.
* @param[in] ctx : Click context object.
* See #lteiot5_t object definition for detailed explanation.
* @return @li @c 0 - Read some data.
* @li @c -1 - Nothing is read.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t lteiot5_process ( lteiot5_t *ctx );
/**
* @brief LTE IoT 5 read response function.
* @details This function waits for a response message, reads and displays it on the USB UART.
* @param[in] ctx : Click context object.
* See #lteiot5_t object definition for detailed explanation.
* @param[in] rsp Expected response.
* @return @li @c 0 - OK response.
* @li @c -2 - Timeout error.
* @li @c -3 - Command error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t lteiot5_read_response ( lteiot5_t *ctx, uint8_t *rsp );
/**
* @brief LTE IoT 5 power up function.
* @details This function powers up the device, performs a factory reset and reads system information.
* @param[in] ctx : Click context object.
* See #lteiot5_t object definition for detailed explanation.
* @return @li @c 0 - OK.
* @li @c != 0 - Read response error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t lteiot5_power_up ( lteiot5_t *ctx );
/**
* @brief LTE IoT 5 config connection function.
* @details This function configures and enables connection to the specified network.
* @param[in] ctx : Click context object.
* See #lteiot5_t object definition for detailed explanation.
* @return @li @c 0 - OK.
* @li @c != 0 - Read response error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t lteiot5_config_connection ( lteiot5_t *ctx );
/**
* @brief LTE IoT 5 check connection function.
* @details This function checks the connection to network.
* @param[in] ctx : Click context object.
* See #lteiot5_t object definition for detailed explanation.
* @return @li @c 0 - OK.
* @li @c != 0 - Read response error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t lteiot5_check_connection ( lteiot5_t *ctx );
/**
* @brief LTE IoT 5 config example function.
* @details This function configures device for the selected example.
* @param[in] ctx : Click context object.
* See #lteiot5_t object definition for detailed explanation.
* @return @li @c 0 - OK.
* @li @c != 0 - Read response error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t lteiot5_config_example ( lteiot5_t *ctx );
/**
* @brief LTE IoT 5 example function.
* @details This function executes SMS or TCP/UDP depending on the DEMO_EXAMPLE macro.
* @param[in] ctx : Click context object.
* See #lteiot5_t object definition for detailed explanation.
* @return @li @c 0 - OK.
* @li @c != 0 - Read response error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t lteiot5_example ( lteiot5_t *ctx );
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
lteiot5_cfg_t lteiot5_cfg; /**< Click config object. */
/**
* Logger initialization.
* Default baud rate: 115200
* Default log level: LOG_LEVEL_DEBUG
* @note If USB_UART_RX and USB_UART_TX
* are defined as HAL_PIN_NC, you will
* need to define them manually for log to work.
* See @b LOG_MAP_USB_UART macro definition for detailed explanation.
*/
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
lteiot5_cfg_setup( <eiot5_cfg );
LTEIOT5_MAP_MIKROBUS( lteiot5_cfg, MIKROBUS_1 );
if ( UART_ERROR == lteiot5_init( <eiot5, <eiot5_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
app_state = LTEIOT5_POWER_UP;
log_printf( &logger, ">>> APP STATE - POWER UP <<<\r\n\n" );
}
void application_task ( void )
{
switch ( app_state )
{
case LTEIOT5_POWER_UP:
{
if ( LTEIOT5_OK == lteiot5_power_up( <eiot5 ) )
{
app_state = LTEIOT5_CONFIG_CONNECTION;
log_printf( &logger, ">>> APP STATE - CONFIG CONNECTION <<<\r\n\n" );
}
break;
}
case LTEIOT5_CONFIG_CONNECTION:
{
if ( LTEIOT5_OK == lteiot5_config_connection( <eiot5 ) )
{
app_state = LTEIOT5_CHECK_CONNECTION;
log_printf( &logger, ">>> APP STATE - CHECK CONNECTION <<<\r\n\n" );
}
break;
}
case LTEIOT5_CHECK_CONNECTION:
{
if ( LTEIOT5_OK == lteiot5_check_connection( <eiot5 ) )
{
app_state = LTEIOT5_CONFIG_EXAMPLE;
log_printf( &logger, ">>> APP STATE - CONFIG EXAMPLE <<<\r\n\n" );
}
break;
}
case LTEIOT5_CONFIG_EXAMPLE:
{
if ( LTEIOT5_OK == lteiot5_config_example( <eiot5 ) )
{
app_state = LTEIOT5_EXAMPLE;
log_printf( &logger, ">>> APP STATE - EXAMPLE <<<\r\n\n" );
}
break;
}
case LTEIOT5_EXAMPLE:
{
lteiot5_example( <eiot5 );
break;
}
default:
{
log_error( &logger, " APP STATE." );
break;
}
}
}
int main ( void )
{
/* Do not remove this line or clock might not be set correctly. */
#ifdef PREINIT_SUPPORTED
preinit();
#endif
application_init( );
for ( ; ; )
{
application_task( );
}
return 0;
}
static void lteiot5_clear_app_buf ( void )
{
memset( app_buf, 0, app_buf_len );
app_buf_len = 0;
}
static void lteiot5_log_app_buf ( void )
{
for ( int32_t buf_cnt = 0; buf_cnt < app_buf_len; buf_cnt++ )
{
log_printf( &logger, "%c", app_buf[ buf_cnt ] );
}
}
static err_t lteiot5_process ( lteiot5_t *ctx )
{
uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
int32_t overflow_bytes = 0;
int32_t rx_cnt = 0;
int32_t rx_size = lteiot5_generic_read( ctx, rx_buf, PROCESS_BUFFER_SIZE );
if ( ( rx_size > 0 ) && ( rx_size <= APP_BUFFER_SIZE ) )
{
if ( ( app_buf_len + rx_size ) > APP_BUFFER_SIZE )
{
overflow_bytes = ( app_buf_len + rx_size ) - APP_BUFFER_SIZE;
app_buf_len = APP_BUFFER_SIZE - rx_size;
memmove ( app_buf, &app_buf[ overflow_bytes ], app_buf_len );
memset ( &app_buf[ app_buf_len ], 0, overflow_bytes );
}
for ( rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ )
{
if ( rx_buf[ rx_cnt ] )
{
app_buf[ app_buf_len++ ] = rx_buf[ rx_cnt ];
}
}
return LTEIOT5_OK;
}
return LTEIOT5_ERROR;
}
static err_t lteiot5_read_response ( lteiot5_t *ctx, uint8_t *rsp )
{
#define READ_RESPONSE_TIMEOUT_MS 120000
uint32_t timeout_cnt = 0;
lteiot5_clear_app_buf ( );
lteiot5_process( ctx );
while ( ( 0 == strstr( app_buf, rsp ) ) &&
( 0 == strstr( app_buf, LTEIOT5_RSP_ERROR ) ) )
{
lteiot5_process( ctx );
if ( timeout_cnt++ > READ_RESPONSE_TIMEOUT_MS )
{
lteiot5_log_app_buf( );
lteiot5_clear_app_buf( );
log_error( &logger, " Timeout!" );
return LTEIOT5_ERROR_TIMEOUT;
}
Delay_ms( 1 );
}
Delay_ms ( 200 );
lteiot5_process( ctx );
lteiot5_log_app_buf( );
if ( strstr( app_buf, rsp ) )
{
log_printf( &logger, "--------------------------------\r\n" );
return LTEIOT5_OK;
}
return LTEIOT5_ERROR_CMD;
}
static err_t lteiot5_power_up ( lteiot5_t *ctx )
{
err_t error_flag = LTEIOT5_OK;
uint8_t power_state = LTEIOT5_POWER_STATE_OFF;
for ( ; ; )
{
lteiot5_process( ctx );
lteiot5_log_app_buf ( );
lteiot5_clear_app_buf ( );
// Wake up UART interface
lteiot5_cmd_run( ctx, LTEIOT5_CMD_AT );
log_printf( &logger, ">>> Check communication.\r\n" );
lteiot5_cmd_run( ctx, LTEIOT5_CMD_AT );
if ( ( ( LTEIOT5_OK == lteiot5_process( ctx ) ) && strstr( app_buf, LTEIOT5_RSP_OK ) ) )
{
power_state = LTEIOT5_POWER_STATE_ON;
break;
}
else if ( LTEIOT5_POWER_STATE_OFF == power_state )
{
power_state = LTEIOT5_POWER_STATE_ON;
log_printf( &logger, ">>> Power up device.\r\n" );
lteiot5_set_power_state ( ctx, LTEIOT5_POWER_STATE_ON );
}
else if ( LTEIOT5_POWER_STATE_ON == power_state )
{
power_state = LTEIOT5_POWER_STATE_OFF;
log_printf( &logger, ">>> Power down device.\r\n" );
lteiot5_set_power_state ( ctx, LTEIOT5_POWER_STATE_OFF );
}
}
lteiot5_cmd_run( ctx, LTEIOT5_CMD_AT );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
log_printf( &logger, ">>> Factory reset.\r\n" );
lteiot5_cmd_run( ctx, LTEIOT5_CMD_FACTORY_RESET );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
log_printf( &logger, ">>> Get device software version ID.\r\n" );
lteiot5_cmd_run( ctx, LTEIOT5_CMD_GET_SW_VERSION );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
log_printf( &logger, ">>> Get device serial number.\r\n" );
lteiot5_cmd_run( ctx, LTEIOT5_CMD_GET_SERIAL_NUM );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
return error_flag;
}
static err_t lteiot5_config_connection ( lteiot5_t *ctx )
{
err_t error_flag = LTEIOT5_OK;
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
log_printf( &logger, ">>> Deregister from network.\r\n" );
#define DEREGISTER_FROM_NETWORK "2"
lteiot5_cmd_set( ctx, LTEIOT5_CMD_OPERATOR_SELECTION, DEREGISTER_FROM_NETWORK );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
log_printf( &logger, ">>> Set SIM APN.\r\n" );
lteiot5_set_sim_apn( <eiot5, SIM_APN );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
log_printf( &logger, ">>> Enable full functionality.\r\n" );
#define FULL_FUNCTIONALITY "1"
lteiot5_cmd_set( ctx, LTEIOT5_CMD_SET_MODULE_FUNCTIONALITY, FULL_FUNCTIONALITY );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
log_printf( &logger, ">>> Enable network registration.\r\n" );
#define ENABLE_REG "2"
lteiot5_cmd_set( ctx, LTEIOT5_CMD_EPS_NETWORK_REGISTRATION, ENABLE_REG );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
log_printf( &logger, ">>> Set automatic registration.\r\n" );
#define AUTOMATIC_REGISTRATION "0"
lteiot5_cmd_set( ctx, LTEIOT5_CMD_OPERATOR_SELECTION, AUTOMATIC_REGISTRATION );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
#endif
return error_flag;
}
static err_t lteiot5_check_connection ( lteiot5_t *ctx )
{
err_t error_flag = LTEIOT5_OK;
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
log_printf( &logger, ">>> Check network registration.\r\n" );
#define CONNECTED "+CEREG: 2,1"
lteiot5_cmd_get ( <eiot5, LTEIOT5_CMD_EPS_NETWORK_REGISTRATION );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
if ( strstr( app_buf, CONNECTED ) )
{
Delay_ms ( 1000 );
log_printf( &logger, ">>> Check signal quality.\r\n" );
lteiot5_cmd_run ( <eiot5, LTEIOT5_CMD_SIGNAL_QUALITY_REPORT );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
}
else
{
error_flag = LTEIOT5_ERROR;
Delay_ms ( 1000 );
Delay_ms ( 1000 );
}
#endif
return error_flag;
}
static err_t lteiot5_config_example ( lteiot5_t *ctx )
{
err_t error_flag = LTEIOT5_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
log_printf( &logger, ">>> Activate PDP context.\r\n" );
#define ACTIVATE_PDP_CONTEXT "1,1"
lteiot5_cmd_set( <eiot5, LTEIOT5_CMD_ACTIVATE_PDP_CONTEXT, ACTIVATE_PDP_CONTEXT );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
log_printf( &logger, ">>> Set PDP type to IPv4.\r\n" );
#define SET_PDP_TYPE_IPV4 "0,0,0"
lteiot5_cmd_set( <eiot5, LTEIOT5_CMD_PSD_CONFIG, SET_PDP_TYPE_IPV4 );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
log_printf( &logger, ">>> Map PSD profile to CID.\r\n" );
#define MAP_PSD_PROFILE "0,100,1"
lteiot5_cmd_set( <eiot5, LTEIOT5_CMD_PSD_CONFIG, MAP_PSD_PROFILE );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
log_printf( &logger, ">>> Activate PSD profile.\r\n" );
#define ACTIVATE_PSD_PROFILE "0,3"
lteiot5_cmd_set( <eiot5, LTEIOT5_CMD_PSD_ACTION, ACTIVATE_PSD_PROFILE );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
log_printf( &logger, ">>> Show PDP address.\r\n" );
#define PDP_CID "1"
lteiot5_cmd_set( <eiot5, LTEIOT5_CMD_SHOW_PDP_ADDRESS, PDP_CID );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
log_printf( &logger, ">>> Select SMS format.\r\n" );
lteiot5_cmd_set( <eiot5, LTEIOT5_CMD_SELECT_SMS_FORMAT, SMS_MODE );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
#elif ( DEMO_EXAMPLE == EXAMPLE_GNSS )
log_printf( &logger, ">>> Check GNSS enable.\r\n" );
lteiot5_cmd_get( <eiot5, LTEIOT5_CMD_GNSS_POWER_MANAGEMENT );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
#define GNSS_POWERED_OFF "+UGPS: 0"
if ( strstr( app_buf, GNSS_POWERED_OFF ) )
{
log_printf( &logger, ">>> Enable GNSS.\r\n" );
#define ENABLE_GNSS "1,0,1"
lteiot5_cmd_set( <eiot5, LTEIOT5_CMD_GNSS_POWER_MANAGEMENT, ENABLE_GNSS );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
Delay_ms ( 1000 );
}
log_printf( &logger, ">>> Enable NMEA $GGA messages.\r\n" );
#define ENABLE_NMEA_GGA "1"
lteiot5_cmd_set( <eiot5, LTEIOT5_CMD_GET_GNSS_FIX_DATA, ENABLE_NMEA_GGA );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
#endif
return error_flag;
}
static err_t lteiot5_example ( lteiot5_t *ctx )
{
err_t error_flag = LTEIOT5_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
uint8_t cmd_buf[ 100 ] = { 0 };
uint8_t * __generic_ptr socket_num_buf = 0;
uint8_t tcp_socket_num[ 2 ] = { 0 };
uint8_t udp_socket_num[ 2 ] = { 0 };
log_printf( &logger, ">>> Create TCP socket.\r\n" );
#define TCP_PROTOCOL "6"
lteiot5_cmd_set ( <eiot5, LTEIOT5_CMD_CREATE_SOCKET, TCP_PROTOCOL );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
socket_num_buf = strstr( app_buf, LTEIOT5_URC_CREATE_SOCKET ) + strlen ( LTEIOT5_URC_CREATE_SOCKET );
if ( NULL != socket_num_buf )
{
tcp_socket_num[ 0 ] = *socket_num_buf;
}
log_printf( &logger, ">>> Create UDP socket.\r\n" );
#define UDP_PROTOCOL "17"
lteiot5_cmd_set ( <eiot5, LTEIOT5_CMD_CREATE_SOCKET, UDP_PROTOCOL );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
socket_num_buf = strstr( app_buf, LTEIOT5_URC_CREATE_SOCKET ) + strlen ( LTEIOT5_URC_CREATE_SOCKET );
if ( NULL != socket_num_buf )
{
udp_socket_num[ 0 ] = *socket_num_buf;
}
log_printf( &logger, ">>> Open TCP connection.\r\n" );
strcpy( cmd_buf, tcp_socket_num );
strcat( cmd_buf, ",\"" );
strcat( cmd_buf, REMOTE_IP );
strcat( cmd_buf, "\"," );
strcat( cmd_buf, REMOTE_PORT );
lteiot5_cmd_set ( <eiot5, LTEIOT5_CMD_CONNECT_SOCKET, cmd_buf );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
log_printf( &logger, ">>> Open UDP connection.\r\n" );
strcpy( cmd_buf, udp_socket_num );
strcat( cmd_buf, ",\"" );
strcat( cmd_buf, REMOTE_IP );
strcat( cmd_buf, "\"," );
strcat( cmd_buf, REMOTE_PORT );
lteiot5_cmd_set ( <eiot5, LTEIOT5_CMD_CONNECT_SOCKET, cmd_buf );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
// Get message length
uint8_t message_len_buf[ 10 ] = { 0 };
uint16_t message_len = strlen( MESSAGE_CONTENT );
uint16_to_str( message_len, message_len_buf );
l_trim( message_len_buf );
r_trim( message_len_buf );
log_printf( &logger, ">>> Write message to TCP connection.\r\n" );
strcpy( cmd_buf, tcp_socket_num );
strcat( cmd_buf, "," );
strcat( cmd_buf, message_len_buf );
strcat( cmd_buf, ",\"" );
strcat( cmd_buf, MESSAGE_CONTENT );
strcat( cmd_buf, "\"" );
lteiot5_cmd_set ( <eiot5, LTEIOT5_CMD_WRITE_SOCKET_DATA, cmd_buf );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_URC_RECEIVED_DATA );
log_printf( &logger, ">>> Read response from TCP connection.\r\n" );
strcpy( cmd_buf, tcp_socket_num );
strcat( cmd_buf, "," );
strcat( cmd_buf, message_len_buf );
lteiot5_cmd_set( <eiot5, LTEIOT5_CMD_READ_SOCKET_DATA, cmd_buf );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
log_printf( &logger, ">>> Write message to UDP connection.\r\n" );
strcpy( cmd_buf, udp_socket_num );
strcat( cmd_buf, "," );
strcat( cmd_buf, message_len_buf );
strcat( cmd_buf, ",\"" );
strcat( cmd_buf, MESSAGE_CONTENT );
strcat( cmd_buf, "\"" );
lteiot5_cmd_set ( <eiot5, LTEIOT5_CMD_WRITE_SOCKET_DATA, cmd_buf );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_URC_RECEIVED_DATA );
log_printf( &logger, ">>> Read response from UDP connection.\r\n" );
strcpy( cmd_buf, udp_socket_num );
strcat( cmd_buf, "," );
strcat( cmd_buf, message_len_buf );
lteiot5_cmd_set( <eiot5, LTEIOT5_CMD_READ_SOCKET_DATA, cmd_buf );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
log_printf( &logger, ">>> Close TCP connection.\r\n" );
lteiot5_cmd_set ( <eiot5, LTEIOT5_CMD_CLOSE_SOCKET, tcp_socket_num );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
log_printf( &logger, ">>> Close UDP connection.\r\n" );
lteiot5_cmd_set ( <eiot5, LTEIOT5_CMD_CLOSE_SOCKET, udp_socket_num );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
#define CMGF_PDU "+CMGF: 0"
#define CMGF_TXT "+CMGF: 1"
log_printf( &logger, ">>> Check SMS format.\r\n" );
lteiot5_cmd_get( <eiot5, LTEIOT5_CMD_SELECT_SMS_FORMAT );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
if ( strstr( app_buf, CMGF_PDU ) )
{
log_printf( &logger, ">>> Send SMS in PDU mode.\r\n" );
lteiot5_send_sms_pdu( <eiot5, SIM_SMSC, PHONE_NUMBER, MESSAGE_CONTENT );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
}
else if ( strstr( app_buf, CMGF_TXT ) )
{
log_printf( &logger, ">>> Send SMS in TXT mode.\r\n" );
lteiot5_send_sms_text ( <eiot5, PHONE_NUMBER, MESSAGE_CONTENT );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
}
// 30 seconds delay
for ( uint8_t delay_cnt = 0; delay_cnt < 30; delay_cnt++ )
{
Delay_ms ( 1000 );
}
#elif ( DEMO_EXAMPLE == EXAMPLE_GNSS )
log_printf( &logger, ">>> Get GNSS fix data.\r\n" );
lteiot5_cmd_get( <eiot5, LTEIOT5_CMD_GET_GNSS_FIX_DATA );
error_flag |= lteiot5_read_response( ctx, LTEIOT5_RSP_OK );
if ( app_buf_len > ( sizeof ( LTEIOT5_RSP_GGA ) + LTEIOT5_GGA_ELEMENT_SIZE ) )
{
uint8_t element_buf[ 100 ] = { 0 };
if ( LTEIOT5_OK == lteiot5_parse_gga( app_buf, LTEIOT5_GGA_LATITUDE, element_buf ) )
{
if ( strlen( element_buf ) > 0 )
{
log_printf( &logger, "Latitude: %.2s degrees, %s minutes\r\n", element_buf, &element_buf[ 2 ] );
lteiot5_parse_gga( app_buf, LTEIOT5_GGA_LONGITUDE, element_buf );
log_printf( &logger, "Longitude: %.3s degrees, %s minutes\r\n", element_buf, &element_buf[ 3 ] );
memset( element_buf, 0, sizeof( element_buf ) );
lteiot5_parse_gga( app_buf, LTEIOT5_GGA_ALTITUDE, element_buf );
log_printf( &logger, "Altitude: %s m\r\n", element_buf );
}
else
{
log_printf( &logger, "Waiting for the position fix...\r\n" );
}
Delay_ms ( 5 );
log_printf( &logger, "--------------------------------\r\n" );
lteiot5_clear_app_buf( );
}
}
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
#else
#error "No demo example selected"
#endif
return error_flag;
}
// ------------------------------------------------------------------------ END