Advanced
30 min

Achieve low-power LTE-M and NB-IoT connectivity with LEXI-R520 and STM32F446RE

Multi-band LTE-M/NB-IoT solution integrating cellular modem and A-GPS technology

LTE IoT 15 Click with Nucleo 64 with STM32F446RE MCU

Published Mar 27, 2025

Click board™

LTE IoT 15 Click

Dev. board

Nucleo 64 with STM32F446RE MCU

Compiler

NECTO Studio

MCU

STM32F446RE

Low-power LTE-M and NB-IoT connectivity for global IoT applications for asset tracking, smart metering, and remote monitoring

A

A

Hardware Overview

How does it work?

LTE IoT 15 Click is based on the LEXI-R520, a multi-band LTE-M/NB-IoT module from u-blox. Built on the UBX-R52 chipset, this module combines cellular connectivity with assisted GPS, offering data transmission and location tracking. Optimized for ultra-low power consumption, the LEXI-R520 supports deep-sleep modes like PSM and eDRX, making it ideal for battery-powered IoT applications. Its software-based multi-band configurability ensures global network compatibility, while 3GPP Release 14 features enable extended coverage, even in basements and underground areas when using NB2. A key advantage is its support for over-the-air firmware updates via u-blox’s uFOTA system, using the LwM2M protocol for efficient and lightweight updates. The module operates on multiple LTE bands (1/2/3/4/5/8/12/13/18/19/20/25/26/28/66/71/85), with a transmission power of +23dBm and data rates of up to 1200 kbit/s (uplink) and 588 kbit/s (downlink). Designed for compact IoT devices, this board is perfect for asset tracking, wearables, smart metering, remote monitoring, and connected healthcare. With an integrated IP stack and multiple interface options, it supports low-to-medium data throughput while ensuring long battery life. Communication between the LEXI-R520 and the host MCU is made through a UART interface, using

standard UART RX and TX pins and hardware flow control pins (CTS/RTS/RI - Clear to Send/Ready to Send/Ring Indicator) for efficient data transfer. The module defaults to a communication speed of 115200bps, allowing for seamless data exchange over AT commands. This Click board™ also includes a USB Type C connector for both power and data transfer, compliant with the USB 2.0 specification, available for diagnostic purpose only. The LTE IoT 15 Click includes several additional functionalities that enhance its usability and control. The PWR button allows users to easily power the module ON or OFF, while the RESET button provides a quick way to reset the module. These functions can also be controlled digitally via the mikroBUS™ pins PWR and RST, offering greater flexibility. Moreover, this board also has dedicated test points (TP2/TP3) for easier debugging and testing, one unsoldered header with three configurable GPIO pins from LEXI-R520, and two visual indicators to provide real-time status updates. The first red NET LED indicates the current network status of the module like when the device has successfully registered on the network, has not yet registered to a network, or signals when data transmission occurs. When the LED is completely OFF, it indicates that the device is either powered OFF or in Power Saving Mode. The

second yellow STAT LED indicates the module's status; power-off or deep-sleep mode versus idle, active or connected mode. The board features an SMA connector for an LTE antenna, such as the GSM/GPRS antenna offered by MIKROE, ensuring efficient connectivity options. However, please note that GNSS functionality is not currently supported on this Click board™, and as a result, GNSS-related components are not soldered. While the board includes a GNSS ANT jumper at the back, allowing the selection of either 3.3V or 5V for an optional GNSS antenna, this feature remains non-functional due to the absence of GNSS support. The board also has a micro SIM card holder that supports both 1.8V and 3.0V uSIM cards, allowing users to select the most appropriate service provider for their particular use case. This Click board™ can operate with both 3.3V and 5V logic voltage levels selected via the VCC SEL jumper. Since the LEXI-R520 module operates at 3.8V, a logic-level translator, the TXB0106, is also used for proper operation and an accurate signal-level translation. 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.

LTE IoT 15 Click hardware overview image

Features overview

Development board

Nucleo-64 with STM32F446RE MCU offers a cost-effective and adaptable platform for developers to explore new ideas and prototype their designs. This board harnesses the versatility of the STM32 microcontroller, enabling users to select the optimal balance of performance and power consumption for their projects. It accommodates the STM32 microcontroller in the LQFP64 package and includes essential components such as a user LED, which doubles as an ARDUINO® signal, alongside user and reset push-buttons, and a 32.768kHz crystal oscillator for precise timing operations. Designed with expansion and flexibility in mind, the Nucleo-64 board features an ARDUINO® Uno V3 expansion connector and ST morpho extension pin

headers, granting complete access to the STM32's I/Os for comprehensive project integration. Power supply options are adaptable, supporting ST-LINK USB VBUS or external power sources, ensuring adaptability in various development environments. The board also has an on-board ST-LINK debugger/programmer with USB re-enumeration capability, simplifying the programming and debugging process. Moreover, the board is designed to simplify advanced development with its external SMPS for efficient Vcore logic supply, support for USB Device full speed or USB SNK/UFP full speed, and built-in cryptographic features, enhancing both the power efficiency and security of projects. Additional connectivity is

provided through dedicated connectors for external SMPS experimentation, a USB connector for the ST-LINK, and a MIPI® debug connector, expanding the possibilities for hardware interfacing and experimentation. Developers will find extensive support through comprehensive free software libraries and examples, courtesy of the STM32Cube MCU Package. This, combined with compatibility with a wide array of Integrated Development Environments (IDEs), including IAR Embedded Workbench®, MDK-ARM, and STM32CubeIDE, ensures a smooth and efficient development experience, allowing users to fully leverage the capabilities of the Nucleo-64 board in their projects.

Nucleo 64 with STM32F446RE MCU double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M4

MCU Memory (KB)

512

Silicon Vendor

STMicroelectronics

Pin count

64

RAM (Bytes)

131072

You complete me!

Accessories

Click Shield for Nucleo-64 comes equipped with two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the STM32 Nucleo-64 board with no effort. This way, Mikroe allows its users to add any functionality from our ever-growing range of Click boards™, such as WiFi, GSM, GPS, Bluetooth, ZigBee, environmental sensors, LEDs, speech recognition, motor control, movement sensors, and many more. More than 1537 Click boards™, which can be stacked and integrated, are at your disposal. The STM32 Nucleo-64 boards are based on the microcontrollers in 64-pin packages, a 32-bit MCU with an ARM Cortex M4 processor operating at 84MHz, 512Kb Flash, and 96KB SRAM, divided into two regions where the top section represents the ST-Link/V2 debugger and programmer while the bottom section of the board is an actual development board. These boards are controlled and powered conveniently through a USB connection to program and efficiently debug the Nucleo-64 board out of the box, with an additional USB cable connected to the USB mini port on the board. Most of the STM32 microcontroller pins are brought to the IO pins on the left and right edge of the board, which are then connected to two existing mikroBUS™ sockets. This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the STM32 Nucleo-64 board with our Click Shield for Nucleo-64, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Nucleo-64 accessories 1 image

This multiband LTE Rubber Antenna with adjustable angle is an excellent choice for all 3G/4G LTE-based click boards from our offer, as well as other devices that require excellent throughput on all major cellular bands worldwide. The antenna has an SMA male connector, which allows it to be mounted directly on the Click board™ or the female SMA module connector. The antenna position can be adjusted in 45⁰ increments (0⁰/45⁰/90⁰).

LTE IoT 15 Click accessories 1 image

Used MCU Pins

mikroBUS™ mapper

Module Power-ON
PC0
AN
Reset / ID SEL
PC12
RST
UART RTS / ID COMM
PB12
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Ring Indicator
PC8
PWM
UART CTS
PC14
INT
UART TX
PA2
TX
UART RX
PA3
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

LTE IoT 15 Click Schematic schematic

Step by step

Project assembly

Click Shield for Nucleo-64 accessories 1 image hardware assembly

Start by selecting your development board and Click board™. Begin with the Nucleo 64 with STM32F446RE MCU as your development board.

Click Shield for Nucleo-64 accessories 1 image hardware assembly
Nucleo 64 with STM32F401RE MCU front image hardware assembly
LTE IoT 5 Click front image hardware assembly
Prog-cut hardware assembly
LTE IoT 5 Click complete accessories setup image hardware assembly
Board mapper by product8 hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Clicker 4 for STM32F4 HA MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware 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

LTE IoT 15 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.

Example Description
Application example shows device capability of connecting to the network and sending SMS or TCP/UDP messages using standard "AT" commands.

Key functions:

  • lteiot15_cfg_setup - This function initializes Click configuration structure to initial values.

  • lteiot15_init - This function initializes all necessary pins and peripherals used for this Click board.

  • lteiot15_set_sim_apn - This function sets APN for sim card.

  • lteiot15_send_sms_text - This function sends text message to a phone number.

  • lteiot15_cmd_set - This function sets a value to a specified command of the Click module.

Application Init
Initializes the driver and logger.

Application Task
Application task is split in few stages:

  • LTEIOT15_POWER_UP: Powers up the device, performs a device factory reset and reads system information.

  • LTEIOT15_CONFIG_CONNECTION: Sets configuration to device to be able to connect to the network.

  • LTEIOT15_CHECK_CONNECTION: Waits for the network registration indicated via CEREG command and then checks the signal quality report.

  • LTEIOT15_CONFIG_EXAMPLE: Configures device for the selected example.

  • LTEIOT15_EXAMPLE: Depending on the selected demo example, it sends an SMS message (in PDU or TXT mode) or TCP/UDP message. By default, the TCP/UDP example is selected.

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 15 Click Example.
 *
 * # Description
 * Application example shows device capability of connecting to the network and
 * sending SMS or TCP/UDP messages 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:
 *  - LTEIOT15_POWER_UP:
 * Powers up the device, performs a device factory reset and reads system information.
 *
 *  - LTEIOT15_CONFIG_CONNECTION:
 * Sets configuration to device to be able to connect to the network.
 *
 *  - LTEIOT15_CHECK_CONNECTION:
 * Waits for the network registration indicated via CEREG command and then checks the signal quality report.
 *
 *  - LTEIOT15_CONFIG_EXAMPLE:
 * Configures device for the selected example.
 *
 *  - LTEIOT15_EXAMPLE:
 * Depending on the selected demo example, it sends an SMS message (in PDU or TXT mode) or TCP/UDP message.
 *
 * By default, the TCP/UDP example is selected.
 *
 * ## Additional Function
 * - static void lteiot15_clear_app_buf ( void )
 * - static void lteiot15_log_app_buf ( void )
 * - static err_t lteiot15_process ( lteiot15_t *ctx )
 * - static err_t lteiot15_read_response ( lteiot15_t *ctx, uint8_t *rsp )
 * - static err_t lteiot15_power_up ( lteiot15_t *ctx )
 * - static err_t lteiot15_config_connection ( lteiot15_t *ctx )
 * - static err_t lteiot15_check_connection ( lteiot15_t *ctx )
 * - static err_t lteiot15_config_example ( lteiot15_t *ctx )
 * - static err_t lteiot15_example ( lteiot15_t *ctx )
 *
 * @note
 * In order for the examples to work, 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 "lteiot15.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 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 15 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
{
    LTEIOT15_POWER_UP = 1,
    LTEIOT15_CONFIG_CONNECTION,
    LTEIOT15_CHECK_CONNECTION,
    LTEIOT15_CONFIG_EXAMPLE,
    LTEIOT15_EXAMPLE

} lteiot15_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 lteiot15_app_state_t app_state = LTEIOT15_POWER_UP;

static lteiot15_t lteiot15;
static log_t logger;

/**
 * @brief LTE IoT 15 clearing application buffer.
 * @details This function clears memory of application buffer and reset its length.
 * @note None.
 */
static void lteiot15_clear_app_buf ( void );

/**
 * @brief LTE IoT 15 log application buffer.
 * @details This function logs data from application buffer to USB UART.
 * @note None.
 */
static void lteiot15_log_app_buf ( void );

/**
 * @brief LTE IoT 15 data reading function.
 * @details This function reads data from device and concatenates data to application buffer. 
 * @param[in] ctx : Click context object.
 * See #lteiot15_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 lteiot15_process ( lteiot15_t *ctx );

/**
 * @brief LTE IoT 15 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 #lteiot15_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 lteiot15_read_response ( lteiot15_t *ctx, uint8_t *rsp );

/**
 * @brief LTE IoT 15 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 #lteiot15_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 lteiot15_power_up ( lteiot15_t *ctx );

/**
 * @brief LTE IoT 15 config connection function.
 * @details This function configures and enables connection to the specified network.
 * @param[in] ctx : Click context object.
 * See #lteiot15_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 lteiot15_config_connection ( lteiot15_t *ctx );

/**
 * @brief LTE IoT 15 check connection function.
 * @details This function checks the connection to network.
 * @param[in] ctx : Click context object.
 * See #lteiot15_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 lteiot15_check_connection ( lteiot15_t *ctx );

/**
 * @brief LTE IoT 15 config example function.
 * @details This function configures device for the selected example.
 * @param[in] ctx : Click context object.
 * See #lteiot15_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 lteiot15_config_example ( lteiot15_t *ctx );

/**
 * @brief LTE IoT 15 example function.
 * @details This function executes SMS or TCP/UDP depending on the DEMO_EXAMPLE macro.
 * @param[in] ctx : Click context object.
 * See #lteiot15_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 lteiot15_example ( lteiot15_t *ctx );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    lteiot15_cfg_t lteiot15_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.
    lteiot15_cfg_setup( &lteiot15_cfg );
    LTEIOT15_MAP_MIKROBUS( lteiot15_cfg, MIKROBUS_1 );
    if ( UART_ERROR == lteiot15_init( &lteiot15, &lteiot15_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );

    app_state = LTEIOT15_POWER_UP;
    log_printf( &logger, ">>> APP STATE - POWER UP <<<\r\n\n" );
}

void application_task ( void ) 
{
    switch ( app_state )
    {
        case LTEIOT15_POWER_UP:
        {
            if ( LTEIOT15_OK == lteiot15_power_up( &lteiot15 ) )
            {
                app_state = LTEIOT15_CONFIG_CONNECTION;
                log_printf( &logger, ">>> APP STATE - CONFIG CONNECTION <<<\r\n\n" );
            }
            break;
        }
        case LTEIOT15_CONFIG_CONNECTION:
        {
            if ( LTEIOT15_OK == lteiot15_config_connection( &lteiot15 ) )
            {
                app_state = LTEIOT15_CHECK_CONNECTION;
                log_printf( &logger, ">>> APP STATE - CHECK CONNECTION <<<\r\n\n" );
            }
            break;
        }
        case LTEIOT15_CHECK_CONNECTION:
        {
            if ( LTEIOT15_OK == lteiot15_check_connection( &lteiot15 ) )
            {
                app_state = LTEIOT15_CONFIG_EXAMPLE;
                log_printf( &logger, ">>> APP STATE - CONFIG EXAMPLE <<<\r\n\n" );
            }
            break;
        }
        case LTEIOT15_CONFIG_EXAMPLE:
        {
            if ( LTEIOT15_OK == lteiot15_config_example( &lteiot15 ) )
            {
                app_state = LTEIOT15_EXAMPLE;
                log_printf( &logger, ">>> APP STATE - EXAMPLE <<<\r\n\n" );
            }
            break;
        }
        case LTEIOT15_EXAMPLE:
        {
            lteiot15_example( &lteiot15 );
            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 lteiot15_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static void lteiot15_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 lteiot15_process ( lteiot15_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t overflow_bytes = 0;
    int32_t rx_cnt = 0;
    int32_t rx_size = lteiot15_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 LTEIOT15_OK;
    }
    return LTEIOT15_ERROR;
}

static err_t lteiot15_read_response ( lteiot15_t *ctx, uint8_t *rsp ) 
{
    #define READ_RESPONSE_TIMEOUT_MS    120000
    uint32_t timeout_cnt = 0;
    lteiot15_clear_app_buf ( );
    lteiot15_process( ctx );
    while ( ( 0 == strstr( app_buf, rsp ) ) &&
            ( 0 == strstr( app_buf, LTEIOT15_RSP_ERROR ) ) )
    {
        lteiot15_process( ctx );
        if ( timeout_cnt++ > READ_RESPONSE_TIMEOUT_MS )
        {
            lteiot15_log_app_buf( );
            lteiot15_clear_app_buf( );
            log_error( &logger, " Timeout!" );
            return LTEIOT15_ERROR_TIMEOUT;
        }
        Delay_ms( 1 );
    }
    Delay_ms ( 200 );
    lteiot15_process( ctx );
    lteiot15_log_app_buf( );
    if ( strstr( app_buf, rsp ) )
    {
        log_printf( &logger, "--------------------------------\r\n" );
        return LTEIOT15_OK;
    }
    return LTEIOT15_ERROR_CMD;
}

static err_t lteiot15_power_up ( lteiot15_t *ctx )
{
    err_t error_flag = LTEIOT15_OK;

    uint8_t power_state = LTEIOT15_POWER_STATE_OFF;
    for ( ; ; )
    {
        lteiot15_process( ctx );
        lteiot15_log_app_buf ( );
        lteiot15_clear_app_buf ( );
        // Wake up UART interface
        lteiot15_cmd_run( ctx, LTEIOT15_CMD_AT );

        log_printf( &logger, ">>> Check communication.\r\n" );
        lteiot15_cmd_run( ctx, LTEIOT15_CMD_AT );
        if ( ( ( LTEIOT15_OK == lteiot15_process( ctx ) ) && strstr( app_buf, LTEIOT15_RSP_OK ) ) )
        {
            power_state = LTEIOT15_POWER_STATE_ON;
            break;
        }
        else if ( LTEIOT15_POWER_STATE_OFF == power_state )
        {
            power_state = LTEIOT15_POWER_STATE_ON;
            log_printf( &logger, ">>> Power up device.\r\n" );
            lteiot15_set_power_state ( ctx, LTEIOT15_POWER_STATE_ON );
        }
        else if ( LTEIOT15_POWER_STATE_ON == power_state )
        {
            power_state = LTEIOT15_POWER_STATE_OFF;
            log_printf( &logger, ">>> Power down device.\r\n" );
            lteiot15_set_power_state ( ctx, LTEIOT15_POWER_STATE_OFF );
        }
    }
    lteiot15_cmd_run( ctx, LTEIOT15_CMD_AT );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );
    
    log_printf( &logger, ">>> Factory reset.\r\n" );
    lteiot15_cmd_run( ctx, LTEIOT15_CMD_FACTORY_RESET );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );

    log_printf( &logger, ">>> Get device software version ID.\r\n" );
    lteiot15_cmd_run( ctx, LTEIOT15_CMD_GET_SW_VERSION );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );

    log_printf( &logger, ">>> Get device serial number.\r\n" );
    lteiot15_cmd_run( ctx, LTEIOT15_CMD_GET_SERIAL_NUM );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );

    return error_flag;
}

static err_t lteiot15_config_connection ( lteiot15_t *ctx )
{
    err_t error_flag = LTEIOT15_OK;
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
    log_printf( &logger, ">>> Configure network status LED.\r\n" );
    #define NETWORK_STATUS_LED "14,2"
    lteiot15_cmd_set( ctx, LTEIOT15_CMD_GPIO_CONFIG, NETWORK_STATUS_LED );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );

    log_printf( &logger, ">>> Configure module status LED.\r\n" );
    #define MODULE_STATUS_LED "15,10"
    lteiot15_cmd_set( ctx, LTEIOT15_CMD_GPIO_CONFIG, MODULE_STATUS_LED );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );

    log_printf( &logger, ">>> Deregister from network.\r\n" );
    #define DEREGISTER_FROM_NETWORK "2"
    lteiot15_cmd_set( ctx, LTEIOT15_CMD_OPERATOR_SELECTION, DEREGISTER_FROM_NETWORK );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );

    log_printf( &logger, ">>> Set SIM APN.\r\n" );
    lteiot15_set_sim_apn( &lteiot15, SIM_APN );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );
    
    log_printf( &logger, ">>> Enable full functionality.\r\n" );
    #define FULL_FUNCTIONALITY "1"
    lteiot15_cmd_set( ctx, LTEIOT15_CMD_SET_MODULE_FUNCTIONALITY, FULL_FUNCTIONALITY );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );

    log_printf( &logger, ">>> Enable network registration.\r\n" );
    #define ENABLE_REG "2"
    lteiot15_cmd_set( ctx, LTEIOT15_CMD_EPS_NETWORK_REGISTRATION, ENABLE_REG );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );

    log_printf( &logger, ">>> Set automatic registration.\r\n" );
    #define AUTOMATIC_REGISTRATION "0"
    lteiot15_cmd_set( ctx, LTEIOT15_CMD_OPERATOR_SELECTION, AUTOMATIC_REGISTRATION );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );
#endif
    return error_flag;
}

static err_t lteiot15_check_connection ( lteiot15_t *ctx )
{
    err_t error_flag = LTEIOT15_OK;
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
    log_printf( &logger, ">>> Check network registration.\r\n" );
    #define CONNECTED "+CEREG: 2,1"
    lteiot15_cmd_get ( &lteiot15, LTEIOT15_CMD_EPS_NETWORK_REGISTRATION );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );
    if ( strstr( app_buf, CONNECTED ) )
    {
        Delay_ms ( 1000 );
        log_printf( &logger, ">>> Check signal quality.\r\n" );
        lteiot15_cmd_run ( &lteiot15, LTEIOT15_CMD_SIGNAL_QUALITY_REPORT );
        error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );
    }
    else
    {
        error_flag = LTEIOT15_ERROR;
        Delay_ms ( 1000 );
        Delay_ms ( 1000 );
    }
#endif
    return error_flag;
}

static err_t lteiot15_config_example ( lteiot15_t *ctx )
{
    err_t error_flag = LTEIOT15_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
    log_printf( &logger, ">>> Activate PDP context.\r\n" );
    #define ACTIVATE_PDP_CONTEXT "1,1"
    lteiot15_cmd_set( &lteiot15, LTEIOT15_CMD_ACTIVATE_PDP_CONTEXT, ACTIVATE_PDP_CONTEXT );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );
    log_printf( &logger, ">>> Show PDP address.\r\n" );
    #define PDP_CID "1"
    lteiot15_cmd_set( &lteiot15, LTEIOT15_CMD_SHOW_PDP_ADDRESS, PDP_CID );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
    log_printf( &logger, ">>> Select SMS format.\r\n" );
    lteiot15_cmd_set( &lteiot15, LTEIOT15_CMD_SELECT_SMS_FORMAT, SMS_MODE );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );
#endif
    return error_flag;
}

static err_t lteiot15_example ( lteiot15_t *ctx )
{
    err_t error_flag = LTEIOT15_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"
    lteiot15_cmd_set ( &lteiot15, LTEIOT15_CMD_CREATE_SOCKET, TCP_PROTOCOL );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );
    socket_num_buf = strstr( app_buf, LTEIOT15_URC_CREATE_SOCKET ) + strlen ( LTEIOT15_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"
    lteiot15_cmd_set ( &lteiot15, LTEIOT15_CMD_CREATE_SOCKET, UDP_PROTOCOL );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );
    socket_num_buf = strstr( app_buf, LTEIOT15_URC_CREATE_SOCKET ) + strlen ( LTEIOT15_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 );
    lteiot15_cmd_set ( &lteiot15, LTEIOT15_CMD_CONNECT_SOCKET, cmd_buf );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_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 );
    lteiot15_cmd_set ( &lteiot15, LTEIOT15_CMD_CONNECT_SOCKET, cmd_buf );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_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, "\"" );
    lteiot15_cmd_set ( &lteiot15, LTEIOT15_CMD_WRITE_SOCKET_DATA, cmd_buf );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_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 );
    lteiot15_cmd_set( &lteiot15, LTEIOT15_CMD_READ_SOCKET_DATA, cmd_buf );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_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, "\"" );
    lteiot15_cmd_set ( &lteiot15, LTEIOT15_CMD_WRITE_SOCKET_DATA, cmd_buf );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_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 );
    lteiot15_cmd_set( &lteiot15, LTEIOT15_CMD_READ_SOCKET_DATA, cmd_buf );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );
    
    log_printf( &logger, ">>> Close TCP connection.\r\n" );
    lteiot15_cmd_set ( &lteiot15, LTEIOT15_CMD_CLOSE_SOCKET, tcp_socket_num );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );
    
    log_printf( &logger, ">>> Close UDP connection.\r\n" );
    lteiot15_cmd_set ( &lteiot15, LTEIOT15_CMD_CLOSE_SOCKET, udp_socket_num );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_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" );
    lteiot15_cmd_get( &lteiot15, LTEIOT15_CMD_SELECT_SMS_FORMAT );
    error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );
    if ( strstr( app_buf, CMGF_PDU ) )
    {
        log_printf( &logger, ">>> Send SMS in PDU mode.\r\n" );
        lteiot15_send_sms_pdu( &lteiot15, SIM_SMSC, PHONE_NUMBER, MESSAGE_CONTENT );
        error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );
    }
    else if ( strstr( app_buf, CMGF_TXT ) )
    {
        log_printf( &logger, ">>> Send SMS in TXT mode.\r\n" );
        lteiot15_send_sms_text ( &lteiot15, PHONE_NUMBER, MESSAGE_CONTENT );
        error_flag |= lteiot15_read_response( ctx, LTEIOT15_RSP_OK );
    }
    // 30 seconds delay
    for ( uint8_t delay_cnt = 0; delay_cnt < 30; delay_cnt++ )
    {
        Delay_ms ( 1000 );
    }
#else
    #error "No demo example selected"
#endif
    return error_flag;
}

// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.