Intermediate
30 min
0

Break the shackles of conventional connectivity with EXS82-W and PIC32MX764F128L

Embrace the future with LTE IoT

LTE IoT 3 Click with UNI Clicker

Published Sep 02, 2023

Click board™

LTE IoT 3 Click

Development board

UNI Clicker

Compiler

NECTO Studio

MCU

PIC32MX764F128L

Our LTE IoT solution propels you into the era of tomorrow's connectivity. With our innovation, experience the seamless integration of devices, intelligence, and data that shapes the future of IoT.

A

A

Hardware Overview

How does it work?

LTE IoT 3 Click is based on the EXS82-W, a Low Power Wide Area (LPWA) Wireless IoT module that allows connections to the LTE CAT-M1, CAT NB1/2, and 2G networks from Thales. EXS82 IoT module supports all LTE bands and offers an efficient architecture with PSM and eDRX plus embedded processing. The EXS82 also includes a module services engine that supports Internet services and optimized operations. State-of-the-art security features protect the device and data and provide secure enrollment in cloud platforms, enabling trust in the IoT ecosystem. The module’s simplified power supply design and advanced management system extend the battery lifetime and improve the total cost of ownership. The integrated GNSS receiver supports the NMEA protocol via the ASC0 interface, representing combined electrical and data specifications for communication between various electronic devices, including GNSS receivers. By default, the GNSS receiver is switched off. It has to be switched on and configured using AT commands. This Click board™ is equipped with a USB type C connector. It allows the module to be powered and configured by a personal computer

(PC) using FT230X, a compact USB to a basic serial UART interface device which has been designed to operate efficiently with USB host controllers by using as little bandwidth as possible when compared to the total USB bandwidth available. The UART interface operates at 115200 bps and exchanges AT commands with the host, data transfer, and firmware updates. It also possesses the RX/TX LED Indicator, which indicates whether the bridge is in the RX or TX function. LTE IoT 3 Click can be battery-powered and used as a stand-alone device. It also has MC34671, a fully integrated Li-Ion or Li-Polymer battery charger that allows charging of the battery when Click board™ is inserted in a mikroBUS™ socket or plugged into a USB port, while the CHG LED indicator, which will indicate the charging in progress and will turn off once the battery charging is finished. The Nano SIM card holder on the back of the Click board™ is used to install a nano-SIM card. Two SMA antenna connectors with an impedance of 50Ω are used for connecting the appropriate antennas. There is one SMA connector for the LTE antenna and the second one for the GNSS antenna on which active

antennas can be used, either supplied with 3V or 5V, which can be selected by the appropriate jumper (J2 or J3). The yellow LED labeled STAT is used to indicate different operating modes of the module visually. Another indicator that this Click board™ has is the PWI LED indicator that reports the module’s power state and shows whether it is active or in Power-Down mode. The onboard pushbutton labeled ON is routed to the RST pin on the mikroBUS™, representing the ignition button. This Click Board™ uses the UART communication interface, but it also allows the user to use other interfaces, such as SPI and I2C if he wants to configure the module as SPI or I2C Master and write the library by himself. That can be achieved by populating the appropriate jumpers on the back of the board (J4 – J9), depending on the desired communication. This Click board™ can be interfaced with both 3.3V and 5V MCUs because appropriate voltage level shifters perform a proper logic voltage level conversion while the onboard LDOs ensure that recommended voltage levels power the module.

LTE IoT 3 Click hardware overview image

Features overview

Development board

UNI Clicker is a compact development board designed as a complete solution that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It supports a wide range of microcontrollers, such as different ARM, PIC32, dsPIC, PIC, and AVR from various vendors like Microchip, ST, NXP, and TI (regardless of their number of pins), four mikroBUS™ sockets for Click board™ connectivity, a USB connector, LED indicators, buttons, a debugger/programmer connector, and two 26-pin headers for interfacing with external electronics. Thanks to innovative manufacturing technology, it allows you to build

gadgets with unique functionalities and features quickly. Each part of the UNI Clicker development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the UNI Clicker programming method, using a third-party programmer or CODEGRIP/mikroProg connected to onboard JTAG/SWD header, the UNI Clicker board also includes a clean and regulated power supply module for the development kit. It provides two ways of board-powering; through the USB Type-C (USB-C) connector, where onboard voltage regulators provide the appropriate voltage levels to each component on the board, or using a Li-Po/Li

Ion battery via an onboard battery connector. All communication methods that mikroBUS™ itself supports are on this board (plus USB HOST/DEVICE), including the well-established mikroBUS™ socket, a standardized socket for the MCU card (SiBRAIN standard), and several user-configurable buttons and LED indicators. UNI 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.

UNI clicker double image

Microcontroller Overview

MCU Card / MCU

default

Type

8th Generation

Architecture

PIC32

MCU Memory (KB)

128

Silicon Vendor

Microchip

Pin count

100

RAM (Bytes)

32768

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.

LTE IoT 3 Click accessories image

GNSS L-Band Active Antenna (LBAND01D-S6-00) is an active patch 50Ω antenna from Inpaq Technology that supports GNSS L-Band (frequency range from 1525 up to 1559MHz) applications. It offers excellent performance with its high gain and efficiency for tracking, fleet management, navigation, and many other tracking applications. The magnetic mounting type antenna, with dimensions of 37.5x34.5x12.5mm, connects to the device by a 3m long cable with an SMA PLUG male connector. It provides superior performance when coupled with Click boards™ that require highly accurate location abilities such as RTK.

LTE IoT 3 Click accessories 2 image

Used MCU Pins

mikroBUS™ mapper

SUSPEND Mode
PB8
AN
Ignition
PB0
RST
UART CTS
PD7
CS
SPI Clock
PD10
SCK
SPI Data OUT
PC4
MISO
SPI Data IN
PD0
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
SPI Chip Select
PD1
PWM
UART RTS
PE8
INT
UART TX
PF13
TX
UART RX
PF12
RX
I2C Clock
PA2
SCL
I2C Data
PA3
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

LTE IoT 3 Click Schematic schematic

Step by step

Project assembly

UNI Clicker front image hardware assembly

Start by selecting your development board and Click board™. Begin with the UNI Clicker as your development board.

UNI Clicker front image hardware assembly
GNSS2 Click front image hardware assembly
SiBRAIN for STM32F745VG front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
UNI Clicker Access MB 1 - upright/background 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
Necto image step 7 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

After loading the code example, pressing the "DEBUG" button builds and programs it on the selected setup.

Application Output Step 1

After programming is completed, a header with buttons for various actions available in the IDE appears. By clicking the green "PLAY "button, we start reading the results achieved with Click board™.

Application Output Step 3

Upon completion of programming, the Application Output tab is automatically opened, where the achieved result can be read. In case of an inability to perform the Debug function, check if a proper connection between the MCU used by the setup and the CODEGRIP programmer has been established. A detailed explanation of the CODEGRIP-board connection can be found in the CODEGRIP User Manual. Please find it in the RESOURCES section.

Application Output Step 4

Software Support

Library Description

This library contains API for LTE IoT 3 Click driver.

Key functions:

  • lteiot3_set_sim_apn - This function sets APN for sim card

  • lteiot3_send_sms_text - This function sends text message to a phone number

  • lteiot3_parse_gga - This function parses the GGA data from the read response buffer

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief LTE IoT 3 Click Example.
 *
 * # Description
 * This example reads and processes data from LTE IoT 3 clicks.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes driver and wake-up module and checks communication and device version.
 *
 * ## Application Task
 * Application taks is split in few stages:
 *  - CONFIGURATION_FOR_NETWORK : Sets configuration to device to 
 *                                be able to connect to newtork.
 * 
 *  - CHECK_NETWORK_CONNECTION  : Checks device connection status 
 *                                till device is connected to network.
 * 
 *  - SENDING_SMS               : Sends SMS message to desired number in text mode.
 * 
 *  - CONFIGURATION_FOR_GNSS    : Sets configuration to device to enable GNSS data.
 * 
 *  - GNSS_DATA                 : Reads and parses data from device to 
 *                                get latitude, longitude and altitude from device
 *
 * ## Additional Function
 * - lteiot3_clear_app_buf      : Function clears memory of app_buf.
 * 
 * - lteiot3_process            : Function collects data from module and 
 *                                concat that data to app_buf.
 * 
 * - lteiot3_error_check        : Function checks for different types of
 *                                errors and logs them on UART.
 *
 * - lteiot3_log_app_buf        : Function logs data from application buffer.
 * 
 * - lteiot3_rsp_check          : Function checks for response and returns 
 *                                the status of response.
 * 
 * - lteiot3_check_connection   : Function checks connection to the network and 
 *                                logs that status to UART.
 * 
 * - lteiot3_cmd_parser         : Function searches application buffer for command
 *                                and logs data of that command.
 * 
 * - lteiot3_element_parser     : Function searches application buffer for command and its 
 *                                element and copies data to element_data buffer.
 * 
 * - lteiot3_power_up_wait      : Function loops process function untill device respond with 
 *                                "^SYSSTART" that device sends on power up/restart.
 * 
 * - lteiot3_config_device_for_network  : Function sends commands for enableing network.
 * 
 * - lteiot3_check_connection_to_network : Function sends commands for checking connection to network.
 * 
 * - lteiot3_send_sms           : Function sends SMS via network in text mode.
 * 
 * - lteiot3_config_device_for_gnss : Function sends commands for enableing GNSS.
 * 
 * - lteiot3_gnss_data          : Function reads data from device and parses data 
 *                                to find latitude, longitude and altitude.
 * 
 * @note
 * In order for the example to work, 
 * user needs to set the phone number and sim apn to which he wants to send an SMS
 * Enter valid data for the following macros: SIM_APN and PHONE_NUMBER_TO_MESSAGE.
 * E.g. 
 *  SIM_APN "vipmobile"
 *  PHONE_NUMBER_TO_MESSAGE "+381659999999"
 *
 * @author Stefan Ilic
 *
 */

#include "board.h"
#include "log.h"
#include "lteiot3.h"


#define SIM_APN                             ""  // Set valid SIM APN
#define PHONE_NUMBER_TO_MESSAGE             ""  // Set Phone number to message
#define MESSAGE_CONTENT                     "LTE IoT 3 Click"   // Messege content 

#define PROCESS_BUFFER_SIZE                 550

#define CONFIGURATION_FOR_NETWORK           0
#define CHECK_NETWORK_CONNECTION            1
#define SENDING_SMS                         2
#define CONFIGURATION_FOR_GNSS              3
#define GNSS_DATA                           4

static lteiot3_t lteiot3;
static log_t logger;

static char app_buf[ PROCESS_BUFFER_SIZE ]  = { 0 };
static int32_t app_buf_len                  = 0;
static int32_t app_buf_cnt                  = 0;

static uint8_t app_connection_status        = CHECK_NETWORK_CONNECTION;

static char latitude_data[ 30 ]             = { 0 };
static char longitude_data[ 30 ]            = { 0 };
static char altitude_data[ 30 ]             = { 0 };

static err_t app_error_flag;
static err_t last_error_flag;

/**
 * @brief LTE IoT 3 clearing application buffer.
 * @details This function clears memory of application buffer and reset its length and counter.
 */
static void lteiot3_clear_app_buf ( void );

/**
 * @brief LTE IoT 3 data reading function.
 * @details This function reads data from device and concatenates data to application buffer.
 * 
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - Nothing is read.
 *         @li @c -2 - Application buffer overflow.
 *
 * See #err_t definition for detailed explanation.
 */
static err_t lteiot3_process ( void );

/**
 * @brief LTE IoT 3 check for errors.
 * @details This function checks for different types of errors and logs them on UART.
 */
static void lteiot3_error_check( err_t error_flag );

/**
 * @brief LTE IoT 3 logs application buffer.
 * @details This function logs data from application buffer.
 */
static void lteiot3_log_app_buf ( void );

/**
 * @brief LTE IoT 3 response check.
 * @details This function checks for response and returns the status of response.
 * 
 * @return application status.
 * See #err_t definition for detailed explanation.
 */
static err_t lteiot3_rsp_check ( void );

/**
 * @brief LTE IoT 3 chek connection.
 * @details This function checks connection to the network and 
 *          logs that status to UART.
 */
static void lteiot3_check_connection( void );

/**
 * @brief IRNSS command data parser.
 * @details This function searches @b app_buf for @b cmd and logs data of that command.
 *
 * @param[in] cmd : Command to parese.
 * 
 * @return @li @c  0 - Parsed data succes.
 *         @li @c -1 - No @b cmd in application buffer.
 *
 * See #err_t definition for detailed explanation.
 */
static err_t lteiot3_cmd_parser ( char *cmd );

/**
 * @brief IRNSS element of command data parser.
 * @details This function searches @b app_buf for @b cmd and it's 
 *          @b element and copies data to @b element_data buffer.
 *
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - No @b cmd in application buffer.
 *         @li @c -2 - No data for @b element in @b cmd.
 *         @li @c -3 - Data buffer overflow.
 *
 * See #err_t definition for detailed explanation.
 */
static err_t lteiot3_element_parser ( char *cmd, uint8_t element, char *element_data );

/**
 * @brief LTE IoT 3 waits device to respond with @b LTEIOT3_SYSSTART.
 * @details This function loops process function untill device respond with 
 *          @b LTEIOT3_SYSSTART that device sends on power up/restart.
 */
static void lteiot3_power_up_wait ( void );

/**
 * @brief LTE IoT 3 set up device for network.
 * @details This function sends commands for enableing network.
 */
static void lteiot3_config_device_for_network( void );

/**
 * @brief LTE IoT 3 check connection commands.
 * @details This function sends commands for checking connection to network.
 */
static void lteiot3_check_connection_to_network( void );

/**
 * @brief LTE IoT 3 sends SMS via network.
 * @details This function sends SMS via network in text mode.
 */
static void lteiot3_send_sms( void );

/**
 * @brief LTE IoT 3 set up device for GNSS.
 * @details This function sends commands for enableing GNSS.
 */
static void lteiot3_config_device_for_gnss( void );

/**
 * @brief LTE IoT 3 reads data from device and parses that data.
 * @details This function reads data from device and parses data 
 *          to find latitude, longitude and altitude.
 */
static void lteiot3_gnss_data( void );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    lteiot3_cfg_t lteiot3_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 " );
    Delay_ms( 1000 );

    // Click initialization.

    lteiot3_cfg_setup( &lteiot3_cfg );
    LTEIOT3_MAP_MIKROBUS( lteiot3_cfg, MIKROBUS_1 );
    err_t init_flag  = lteiot3_init( &lteiot3, &lteiot3_cfg );
    if ( UART_ERROR == init_flag ) {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }

    log_info( &logger, " Power on device... " );
    lteiot3_default_cfg ( &lteiot3 );
    lteiot3_process( );
    lteiot3_clear_app_buf( );
    
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_CFUN, "1,1" );
    lteiot3_power_up_wait();    
    app_buf_len = 0;
    app_buf_cnt = 0;
    
    //AT
    lteiot3_send_cmd( &lteiot3, LTEIOT3_CMD_AT );
    app_error_flag = lteiot3_rsp_check();
    lteiot3_error_check( app_error_flag );
    Delay_ms( 500 );
    //ATI
    lteiot3_send_cmd( &lteiot3, LTEIOT3_CMD_ATI );
    app_error_flag = lteiot3_rsp_check();
    lteiot3_error_check( app_error_flag );
    Delay_ms( 500 );

    app_connection_status = CONFIGURATION_FOR_NETWORK;
    log_info( &logger, " Application Task " );
    Delay_ms( 2000 );
}

void application_task ( void ) 
{    
    switch( app_connection_status )
    {
        case CONFIGURATION_FOR_NETWORK:
        {
            lteiot3_config_device_for_network( );
            break;
        }
        case CHECK_NETWORK_CONNECTION:
        {
            lteiot3_check_connection_to_network( );
            break;
        }
        case SENDING_SMS:
        {
            lteiot3_send_sms( );
            break;
        }
        case CONFIGURATION_FOR_GNSS:
        {
            lteiot3_config_device_for_gnss( );
            break;
        }
        case GNSS_DATA:
        {
            lteiot3_gnss_data();

            break;
        }
        default:
        {
            log_error( &logger, "Application status error!" );
            app_connection_status = CHECK_NETWORK_CONNECTION;
            Delay_ms( 1000 );
            break;
        }
    }
}

void main ( void ) 
{
    application_init( );

    for ( ; ; ) 
    {
        application_task( );
    }
}

static void lteiot3_clear_app_buf ( void )
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
    app_buf_cnt = 0;
}

static err_t lteiot3_process ( void )
{
    err_t return_flag = LTEIOT3_ERROR;
    int32_t rx_size;
    char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };
    
    rx_size = lteiot3_generic_read( &lteiot3, rx_buff, PROCESS_BUFFER_SIZE );

    if ( rx_size > 0 )
    { 
        int32_t buf_cnt = 0;
        return_flag = LTEIOT3_OK;

        if ( app_buf_len + rx_size >= PROCESS_BUFFER_SIZE )
        {
            lteiot3_clear_app_buf(  );
            return_flag = LTEIOT3_ERROR_OVERFLOW;
        }
        else
        {
            buf_cnt = app_buf_len;
            app_buf_len += rx_size;
        }

        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ )
        {
            if ( rx_buff[ rx_cnt ] != 0 ) 
            {
                app_buf[ ( buf_cnt + rx_cnt ) ] = rx_buff[ rx_cnt ];
            }
            else
            {
                app_buf_len--;
            }
        }
    } 

    return return_flag;
}

static err_t lteiot3_rsp_check ( void )
{
    uint32_t timeout_cnt = 0;
    uint32_t timeout = 1000000;
    
    volatile err_t error_flag = lteiot3_process(  );
    if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
    {
        return error_flag;
    }
    
    while ( ( strstr( app_buf, LTEIOT3_RSP_OK ) == 0 ) && 
            ( strstr( app_buf, LTEIOT3_RSP_ERROR ) == 0 ) )
    {
        error_flag = lteiot3_process(  );
        if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
        {
            return error_flag;
        }
        
        timeout_cnt++;
        if ( timeout_cnt > timeout )
        {
            while ( ( strstr( app_buf, LTEIOT3_RSP_OK ) == 0 ) && 
                    ( strstr( app_buf, LTEIOT3_RSP_ERROR ) == 0 ) )
            {
                lteiot3_send_cmd( &lteiot3, LTEIOT3_CMD_AT );
                Delay_ms( 100 );
                lteiot3_process(  );
                Delay_ms( 100 );
            }
            lteiot3_clear_app_buf(  );
            return LTEIOT3_ERROR_TIMEOUT;
        }
        
        Delay_ms( 1 );
    }
    
    lteiot3_check_connection();
    
    error_flag = LTEIOT3_OK;
    
    if ( strstr( app_buf, LTEIOT3_RSP_ERROR ) != 0 )
    {
        error_flag = LTEIOT3_ERROR;
    }
    
    lteiot3_log_app_buf();
    
    log_printf( &logger, "-----------------------------------\r\n" );
    
    return error_flag;
}

static void lteiot3_error_check( err_t error_flag )
{
    if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
    {
        switch ( error_flag )
        {
            case -2:
            {
                log_error( &logger, " Overflow!" );
                break;
            }
            case -3:
            {
                log_error( &logger, " Timeout!" );
                break;
            }
            default:
            {
                break;
            }
        }
    }
}

static void lteiot3_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 ] );
    }
    log_printf( &logger, "\r\n" );
    lteiot3_clear_app_buf(  );
}

static void lteiot3_check_connection( void )
{
    #define CONNECTED "+CGATT: 1"
    
    if ( strstr( app_buf, CONNECTED ) != 0 )
    {
        app_connection_status = SENDING_SMS;
    }
}

static err_t lteiot3_cmd_parser ( char *cmd )
{
    err_t ret_flag = 0;
    
    if ( strstr( app_buf, cmd ) != 0 )
    {
        char * __generic gngga_ptr;
        
        gngga_ptr = strstr( app_buf, cmd );
        
        while (strchr( gngga_ptr, LTEIOT3_GNSS_START ) == 0)
        {
            lteiot3_process();
        }
        
        for ( ; ; )
        {
            log_printf( &logger, "%c", *gngga_ptr );
            gngga_ptr++;
            
            if ( ( *gngga_ptr == LTEIOT3_GNSS_START ) )
            {
                break;
            }
        }
    }
    else
    {
        ret_flag = -1;
    }
    
    return ret_flag;
}

static err_t lteiot3_element_parser ( char *cmd, uint8_t element, char *element_data )
{
    err_t ret_flag = 0;
    
    
    if ( strstr( app_buf, cmd ) != 0 )
    {
        uint8_t element_cnt = 0;
        char data_buf[ 30 ] = { 0 };
        uint8_t data_cnt = 0;
        char * __generic gngga_ptr;
        
        gngga_ptr = strstr( app_buf, cmd );
        
        while (strchr( gngga_ptr, LTEIOT3_GNSS_START ) == 0)
        {
            lteiot3_process();
        }
        
        for ( ; ; )
        {
            if ( ( *gngga_ptr == LTEIOT3_GNSS_START ) )
            {
                ret_flag = -2;
                break;
            }
            
            if ( *gngga_ptr == LTEIOT3_GNSS_SEPARATOR )
            {
                if (element_cnt == element)
                {
                    if ( data_cnt == 0 )
                    {
                        ret_flag = -2;
                    }
                    strcpy( element_data, data_buf );
                    break;
                }
                
                element_cnt++;
            }
            
            if ( ( element == element_cnt ) && ( *gngga_ptr != LTEIOT3_GNSS_SEPARATOR ) )
            {
                data_buf[ data_cnt ] = *gngga_ptr;
                data_cnt++;
                
                if ( data_cnt >= 30 )
                {
                    ret_flag = -3;
                    break;
                }
            }
            
            gngga_ptr++;
        }
    }
    else
    {
        ret_flag = -1;
    }
    
    return ret_flag;
}

static void lteiot3_power_up_wait ( void )
{
    do
    {
        lteiot3_process();
        Delay_ms( 10 );
    } while( 0 == strstr( app_buf, LTEIOT3_SYSSTART ) );
    
    lteiot3_log_app_buf();
}

static void lteiot3_config_device_for_network( void )
{   
    //CIMI
    lteiot3_send_cmd( &lteiot3, LTEIOT3_CMD_CIMI );
    app_error_flag = lteiot3_rsp_check();
    lteiot3_error_check( app_error_flag );
    Delay_ms( 2000 );
    
    //CGDCONT
    lteiot3_set_sim_apn( &lteiot3, SIM_APN );
    app_error_flag = lteiot3_rsp_check();
    lteiot3_error_check( app_error_flag );
    Delay_ms( 500 );

    //CEREG
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_CREG, "2" );
    app_error_flag = lteiot3_rsp_check();
    lteiot3_error_check( app_error_flag );
    Delay_ms( 500 );
    
    app_connection_status = CHECK_NETWORK_CONNECTION;
}

static void lteiot3_check_connection_to_network( void )
{
    lteiot3_send_cmd_check( &lteiot3, LTEIOT3_CMD_CGATT );
    app_error_flag = lteiot3_rsp_check();
    lteiot3_error_check( app_error_flag );
    Delay_ms( 500 );
    
    lteiot3_send_cmd_check( &lteiot3, LTEIOT3_CMD_CEREG );
    app_error_flag = lteiot3_rsp_check();
    lteiot3_error_check( app_error_flag );
    Delay_ms( 500 );
    
    lteiot3_send_cmd( &lteiot3, LTEIOT3_CMD_CSQ );
    app_error_flag = lteiot3_rsp_check();
    lteiot3_error_check( app_error_flag );
    Delay_ms( 2000 );
        
    if ( CHECK_NETWORK_CONNECTION != app_connection_status )
    {
        log_info( &logger, "CONNECTED TO NETWORK" );
    }
}

static void lteiot3_send_sms( void )
{
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_CMGF, "1" );
    app_error_flag = lteiot3_rsp_check();
    lteiot3_error_check( app_error_flag );
    Delay_ms( 2000 );
    
    log_printf( &logger, "> Sending message to phone number...\r\n" );
    lteiot3_send_text_message( &lteiot3, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
    app_error_flag = lteiot3_rsp_check();
    lteiot3_error_check( app_error_flag );
    if ( LTEIOT3_OK == app_error_flag )
    {
        log_printf( &logger, "> Message sent...\r\n" );
        app_connection_status = CONFIGURATION_FOR_GNSS;
    }
    Delay_ms( 2000 );
}

static void lteiot3_config_device_for_gnss( void )
{
    #define GNNS_START_MODE_EN  "AT^SGPSC=\"Engine/StartMode\",0"
    #define GNNS_START_GPS      "AT^SGPSC=\"Nmea/GPS\",\"on\""
    #define GNSS_POWER_UP       "AT^SGPSC=\"Engine\",3"
    
    lteiot3_send_cmd( &lteiot3, GNNS_START_GPS );
    app_error_flag = lteiot3_rsp_check();
    lteiot3_error_check( app_error_flag );
    Delay_ms( 500 );
    
    lteiot3_send_cmd( &lteiot3, GNNS_START_MODE_EN );
    app_error_flag = lteiot3_rsp_check();
    lteiot3_error_check( app_error_flag );
    Delay_ms( 500 );
        
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_CFUN, "1,1" );
    lteiot3_power_up_wait();
    Delay_ms( 3000 );
    
    do {
        lteiot3_send_cmd( &lteiot3, GNSS_POWER_UP );
        app_error_flag = lteiot3_rsp_check();
        lteiot3_error_check( app_error_flag );
        
    } while ( app_error_flag < 0 );
    
    app_connection_status = GNSS_DATA;
    last_error_flag = 0;
    log_info( &logger, "GNSS APP" );
}

static void lteiot3_gnss_data( void )
{
    lteiot3_process();
    
    err_t error_flag = lteiot3_element_parser( LTEIOT3_GNSS_GPGGA, LTEIOT3_GPGGA_LATITUDE, 
                                            latitude_data );
    
    error_flag |= lteiot3_element_parser(  LTEIOT3_GNSS_GPGGA, LTEIOT3_GPGGA_LONGITUDE, 
                                        longitude_data );
    
    error_flag |= lteiot3_element_parser(  LTEIOT3_GNSS_GPGGA, LTEIOT3_GPGGA_ALTITUDE, 
                                        altitude_data );
    
    if ( error_flag == 0 )
    {
        if ( last_error_flag != 0)
        {
            log_printf( &logger, "\r\n" );
        }
        log_printf( &logger, ">Latitude:\r\n - deg: %.2s \r\n - min: %s\r\n", 
                    latitude_data, &latitude_data[ 2 ] );
        
        log_printf( &logger, ">Longitude:\r\n - deg: %.3s \r\n - min: %s\r\n", 
                    longitude_data, &longitude_data[ 3 ] );
        
        log_printf( &logger, ">Altitude:\r\n - %sm\r\n", 
                    altitude_data );
        
        log_printf( &logger, "----------------------------------------\r\n" );
    }
    else if ( error_flag < -1 )
    {
        if ( last_error_flag == 0 )
        {
            log_printf( &logger, "Waiting for data" );
        }
        log_printf( &logger, "." );
    }
    
    if ( error_flag != -1 )
    {
        last_error_flag = error_flag;
        lteiot3_clear_app_buf(  );
    }
}

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

Additional Support

Resources