Intermediate
30 min

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

Dev 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

Click board™ 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

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.

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

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 3 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, tests the communication by sending "AT" command, and after that restarts the device.
 *
 * ## Application Task
 * Application task is split in few stages:
 *  - LTEIOT3_CONFIGURE_FOR_NETWORK:
 * Sets configuration to device to be able to connect to the network. (used only for SMS or TCP/UDP demo examples).
 *
 *  - LTEIOT3_WAIT_FOR_CONNECTION:
 * Waits for the network registration indicated via CREG URC event and then checks
 * the connection status (used only for SMS or TCP/UDP demo examples).
 *
 *  - LTEIOT3_CONFIGURE_FOR_EXAMPLE:
 * Sets the device configuration for sending SMS or TCP/UDP messages or for retrieving data from GNSS 
 * depending on the selected demo example.
 *
 *  - LTEIOT3_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 lteiot3_clear_app_buf ( void )
 * - static err_t lteiot3_process ( void )
 * - static void lteiot3_error_check( err_t error_flag )
 * - static void lteiot3_log_app_buf ( void )
 * - static err_t lteiot3_rsp_check ( uint8_t *rsp )
 * - static err_t lteiot3_configure_for_connection( void )
 * - static err_t lteiot3_check_connection( void )
 * - static err_t lteiot3_configure_for_messages( void )
 * - static err_t lteiot3_send_message( void )
 *
 * @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_TO_MESSAGE.
 * Example:
    SIM_APN "internet"
    SIM_SMSC "+381610401"
    PHONE_NUMBER_TO_MESSAGE "+381659999999"
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "lteiot3.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                             ""              // Set valid SIM APN

// SMS example parameters
#define SIM_SMSC                            ""              // Set valid SMS Service Center Address - only in SMS PDU mode
#define PHONE_NUMBER_TO_MESSAGE             ""              // 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 3 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
{
    LTEIOT3_CONFIGURE_FOR_NETWORK = 1,
    LTEIOT3_WAIT_FOR_CONNECTION,
    LTEIOT3_CONFIGURE_FOR_EXAMPLE,
    LTEIOT3_EXAMPLE

} lteiot3_example_state_t;

static lteiot3_t lteiot3;
static log_t logger;

/**
 * @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 err_t error_flag;
static lteiot3_example_state_t example_state;

/**
 * @brief 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 Data reading function.
 * @details This function reads data from device and
 * appends it to the application buffer.
 * @return @li @c  0 - Some data is read.
 *         @li @c -1 - Nothing is read.
 * See #err_t definition for detailed explanation.
 */
static err_t lteiot3_process ( void );

/**
 * @brief Check for errors.
 * @details This function checks for different types of
 * errors and logs them on UART or logs the response if no errors occured.
 * @param[in] error_flag  Error flag to check.
 */
static void lteiot3_error_check( err_t error_flag );

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

/**
 * @brief Response check.
 * @details This function checks for response and
 * returns the status of response.
 * @param[in] rsp  Expected response.
 * @return @li @c  0 - OK response.
 *         @li @c -2 - Timeout error.
 *         @li @c -3 - Command error.
 *         @li @c -4 - Unknown error.
 * See #err_t definition for detailed explanation.
 */
static err_t lteiot3_rsp_check ( uint8_t *rsp );

/**
 * @brief Configure device for connection to the network.
 * @details Sends commands to configure and enable
 * connection to the specified network.
 * @return @li @c  0 - OK response.
 *         @li @c -2 - Timeout error.
 *         @li @c -3 - Command error.
 *         @li @c -4 - Unknown error.
 * See #err_t definition for detailed explanation.
 */
static err_t lteiot3_configure_for_network( void );

/**
 * @brief Wait for connection signal.
 * @details Wait for connection signal from CREG URC.
 * @return @li @c  0 - OK response.
 *         @li @c -2 - Timeout error.
 *         @li @c -3 - Command error.
 *         @li @c -4 - Unknown error.
 * See #err_t definition for detailed explanation.
 */
static err_t lteiot3_check_connection( void );

/**
 * @brief Configure device for example.
 * @details Configure device for the specified example.
 * @return @li @c  0 - OK response.
 *         @li @c -2 - Timeout error.
 *         @li @c -3 - Command error.
 *         @li @c -4 - Unknown error.
 * See #err_t definition for detailed explanation.
 */
static err_t lteiot3_configure_for_example( void );

/**
 * @brief Execute example.
 * @details This function executes SMS, TCP/UDP or GNSS example depending on the DEMO_EXAMPLE macro.
 * @return @li @c  0 - OK response.
 *         @li @c -2 - Timeout error.
 *         @li @c -3 - Command error.
 *         @li @c -4 - Unknown error.
 * See #err_t definition for detailed explanation.
 */
static err_t lteiot3_example( 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 " );

    // Click initialization.
    lteiot3_cfg_setup( &lteiot3_cfg );
    LTEIOT3_MAP_MIKROBUS( lteiot3_cfg, MIKROBUS_1 );
    if ( UART_ERROR == lteiot3_init( &lteiot3, &lteiot3_cfg ) )
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );
        for ( ; ; );
    }
    
    lteiot3_process( );
    lteiot3_clear_app_buf( );

    // Check communication
    lteiot3_send_cmd( &lteiot3, LTEIOT3_CMD_AT );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    lteiot3_error_check( error_flag );
    
    // Restart device
    #define RESTART_DEVICE "1,1"
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_CFUN, RESTART_DEVICE );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_SYSSTART );
    lteiot3_error_check( error_flag );

    log_info( &logger, " Application Task " );
    example_state = LTEIOT3_CONFIGURE_FOR_NETWORK;
}

void application_task ( void )
{
    switch ( example_state )
    {
        case LTEIOT3_CONFIGURE_FOR_NETWORK:
        {
            if ( LTEIOT3_OK == lteiot3_configure_for_network( ) )
            {
                example_state = LTEIOT3_WAIT_FOR_CONNECTION;
            }
            break;
        }
        case LTEIOT3_WAIT_FOR_CONNECTION:
        {
            if ( LTEIOT3_OK == lteiot3_check_connection( ) )
            {
                example_state = LTEIOT3_CONFIGURE_FOR_EXAMPLE;
            }
            break;
        }
        case LTEIOT3_CONFIGURE_FOR_EXAMPLE:
        {
            if ( LTEIOT3_OK == lteiot3_configure_for_example( ) )
            {
                example_state = LTEIOT3_EXAMPLE;
            }
            break;
        }
        case LTEIOT3_EXAMPLE:
        {
            lteiot3_example( );
            break;
        }
        default:
        {
            log_error( &logger, " Example 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 lteiot3_clear_app_buf ( void )
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static err_t lteiot3_process ( void )
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t rx_size = 0;
    rx_size = lteiot3_generic_read( &lteiot3, rx_buf, PROCESS_BUFFER_SIZE );
    if ( rx_size > 0 ) 
    {
        int32_t buf_cnt = app_buf_len;
        if ( ( ( app_buf_len + rx_size ) > APP_BUFFER_SIZE ) && ( app_buf_len > 0 ) ) 
        {
            buf_cnt = APP_BUFFER_SIZE - ( ( app_buf_len + rx_size ) - APP_BUFFER_SIZE );
            memmove ( app_buf, &app_buf[ APP_BUFFER_SIZE - buf_cnt ], buf_cnt );
        }
        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) 
        {
            if ( rx_buf[ rx_cnt ] ) 
            {
                app_buf[ buf_cnt++ ] = rx_buf[ rx_cnt ];
                if ( app_buf_len < APP_BUFFER_SIZE )
                {
                    app_buf_len++;
                }
            }
        }
        return LTEIOT3_OK;
    }
    return LTEIOT3_ERROR;
}

static err_t lteiot3_rsp_check ( uint8_t *rsp )
{
    uint32_t timeout_cnt = 0;
    uint32_t timeout = 120000;
    err_t error_flag = lteiot3_process( );
    if ( ( LTEIOT3_OK != error_flag ) && ( LTEIOT3_ERROR != error_flag ) )
    {
        return error_flag;
    }
    while ( ( 0 == strstr( app_buf, rsp ) ) &&
            ( 0 == strstr( app_buf, LTEIOT3_RSP_ERROR ) ) )
    {
        error_flag = lteiot3_process( );
        if ( ( LTEIOT3_OK != error_flag ) && ( LTEIOT3_ERROR != error_flag ) )
        {
            return error_flag;
        }
        if ( timeout_cnt++ > timeout )
        {
            lteiot3_clear_app_buf( );
            return LTEIOT3_ERROR_TIMEOUT;
        }
        Delay_ms ( 1 );
    }
    if ( strstr( app_buf, rsp ) )
    {
        return LTEIOT3_OK;
    }
    else if ( strstr( app_buf, LTEIOT3_RSP_ERROR ) )
    {
        return LTEIOT3_ERROR_CMD;
    }
    else
    {
        return LTEIOT3_ERROR_UNKNOWN;
    }
}

static void lteiot3_error_check( err_t error_flag )
{
    switch ( error_flag )
    {
        case LTEIOT3_OK:
        {
            lteiot3_log_app_buf( );
            break;
        }
        case LTEIOT3_ERROR:
        {
            log_error( &logger, " Overflow!" );
            break;
        }
        case LTEIOT3_ERROR_TIMEOUT:
        {
            log_error( &logger, " Timeout!" );
            break;
        }
        case LTEIOT3_ERROR_CMD:
        {
            log_error( &logger, " CMD!" );
            break;
        }
        case LTEIOT3_ERROR_UNKNOWN:
        default:
        {
            log_error( &logger, " Unknown!" );
            break;
        }
    }
    lteiot3_clear_app_buf(  );
    Delay_ms ( 500 );
}

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 ] );
    }
}

static err_t lteiot3_configure_for_network( void )
{
    err_t func_error = LTEIOT3_OK;
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
    // Deregister from network
    #define DEREGISTER_FROM_NETWORK "2"
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_COPS, DEREGISTER_FROM_NETWORK );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
    
    // Set SIM APN
    lteiot3_set_sim_apn( &lteiot3, SIM_APN );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );

    // Enable full functionality
    #define FULL_FUNCTIONALITY "1"
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_CFUN, FULL_FUNCTIONALITY );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );

    // Enable network registartion
    #define ENABLE_REG "2"
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_CREG, ENABLE_REG );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
    
    // Automatic registration
    #define AUTOMATIC_REGISTRATION "0"
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_COPS, AUTOMATIC_REGISTRATION );
#endif
    return func_error;
}

static err_t lteiot3_check_connection( void )
{
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
    #define CONNECTED "+CREG: 1"
    lteiot3_process( );
    if ( strstr( app_buf, CONNECTED ) )
    {
        Delay_ms ( 100 );
        lteiot3_process( );
        lteiot3_log_app_buf( );
        log_printf( &logger, "\r\n" );
        lteiot3_clear_app_buf( );
        // Check signal quality
        lteiot3_send_cmd( &lteiot3, LTEIOT3_CMD_CESQ );
        error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
        lteiot3_error_check( error_flag );
        return error_flag;
    }
    return LTEIOT3_ERROR;
#endif
    return LTEIOT3_OK;
}

static err_t lteiot3_configure_for_example( void )
{
    err_t func_error = LTEIOT3_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
    #define ACTIVATE_PDP_CONTEXT "1,1"
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SICA, ACTIVATE_PDP_CONTEXT );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
    #define REQ_DYNAMIC_IP "1"
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_CGPADDR, REQ_DYNAMIC_IP );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_CMGF, SMS_MODE );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
#elif ( DEMO_EXAMPLE == EXAMPLE_GNSS )
    #define GNNS_START_MODE_EN "\"Engine/StartMode\",0"
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SGPSC, GNNS_START_MODE_EN );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
    #define GNNS_START_GPS "\"Nmea/GPS\",\"on\""
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SGPSC, GNNS_START_GPS );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
    #define GNSS_POWER_UP "\"Engine\",3"
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SGPSC, GNSS_POWER_UP );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
#else
    #error "No demo example selected"
#endif
    return func_error;
}

static err_t lteiot3_example( void )
{
    err_t func_error = LTEIOT3_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
    uint8_t cmd_buf[ 100 ] = { 0 };
    uint8_t tcp_socket_num[ 2 ] = { '0', 0 };
    uint8_t udp_socket_num[ 2 ] = { '1', 0 };

    // Select service type Socket.
    #define SRVTYPE_SOCKET ",srvtype,\"socket\""
    strcpy( cmd_buf, tcp_socket_num );
    strcat( cmd_buf, SRVTYPE_SOCKET );
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SISS, cmd_buf );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );

    strcpy( cmd_buf, udp_socket_num );
    strcat( cmd_buf, SRVTYPE_SOCKET );
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SISS, cmd_buf );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );

    // Select connection profile.
    #define CONN_PROFILE ",conid,\"1\""
    strcpy( cmd_buf, tcp_socket_num );
    strcat( cmd_buf, CONN_PROFILE );
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SISS, cmd_buf );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
    
    strcpy( cmd_buf, udp_socket_num );
    strcat( cmd_buf, CONN_PROFILE );
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SISS, cmd_buf );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
    
    // Choose ASCII alphabet.
    #define ASCII_ALPHABET ",alphabet,1"
    strcpy( cmd_buf, tcp_socket_num );
    strcat( cmd_buf, ASCII_ALPHABET );
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SISS, cmd_buf );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
    
    strcpy( cmd_buf, udp_socket_num );
    strcat( cmd_buf, ASCII_ALPHABET );
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SISS, cmd_buf );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );

    // Specify the TCP remote IP and port
    #define ADDRESS_TCP ",address,\"socktcp://"
    strcpy( cmd_buf, tcp_socket_num );
    strcat( cmd_buf, ADDRESS_TCP );
    strcat( cmd_buf, REMOTE_IP );
    strcat( cmd_buf, ":" );
    strcat( cmd_buf, REMOTE_PORT );
    strcat( cmd_buf, "\"" );
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SISS, cmd_buf );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
    
    // Specify the UDP remote IP and port
    #define ADDRESS_UDP ",address,\"sockudp://"
    strcpy( cmd_buf, udp_socket_num );
    strcat( cmd_buf, ADDRESS_UDP );
    strcat( cmd_buf, REMOTE_IP );
    strcat( cmd_buf, ":" );
    strcat( cmd_buf, REMOTE_PORT );
    strcat( cmd_buf, "\"" );
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SISS, cmd_buf );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
    
    // Open TCP socket
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SISO, tcp_socket_num );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
    
    // Open UDP socket
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SISO, udp_socket_num );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );

    // 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 );

    // Write message to TCP socket and read response
    strcpy( cmd_buf, tcp_socket_num );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, message_len_buf );
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SISW, cmd_buf );
    Delay_ms ( 100 );
    lteiot3_generic_write ( &lteiot3, MESSAGE_CONTENT, message_len );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
    Delay_ms ( 1000 );
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SISR, cmd_buf );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );

    // Write message to UDP socket and read response
    strcpy( cmd_buf, udp_socket_num );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, message_len_buf );
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SISW, cmd_buf );
    Delay_ms ( 100 );
    lteiot3_generic_write ( &lteiot3, MESSAGE_CONTENT, message_len );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
    Delay_ms ( 1000 );
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SISR, cmd_buf );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
    
    // Close TCP socket
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SISC, tcp_socket_num );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
    
    // Close UDP socket
    lteiot3_send_cmd_with_parameter( &lteiot3, LTEIOT3_CMD_SISC, udp_socket_num );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    lteiot3_error_check( error_flag );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
    // Check SMS mode
    #define CMGF_PDU "+CMGF: 0"
    #define CMGF_TXT "+CMGF: 1"
    lteiot3_send_cmd_check( &lteiot3, LTEIOT3_CMD_CMGF );
    error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
    func_error |= error_flag;
    if ( strstr( app_buf, CMGF_PDU ) )
    {
        lteiot3_error_check( error_flag );
        // Send SMS in PDU mode
        lteiot3_send_sms_pdu( &lteiot3, SIM_SMSC, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
        error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
        func_error |= error_flag;
    }
    else if ( strstr( app_buf, CMGF_TXT ) )
    {
        lteiot3_error_check( error_flag );
        // Send SMS in TXT mode
        lteiot3_send_sms_text ( &lteiot3, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
        error_flag = lteiot3_rsp_check( LTEIOT3_RSP_OK );
        func_error |= error_flag;
    }
    lteiot3_error_check( error_flag );
    // 30 seconds delay
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
#elif ( DEMO_EXAMPLE == EXAMPLE_GNSS )
    lteiot3_process ( );
    if ( app_buf_len > ( sizeof ( LTEIOT3_RSP_GGA ) + LTEIOT3_GGA_ELEMENT_SIZE ) ) 
    {
        uint8_t element_buf[ 100 ] = { 0 };
        if ( LTEIOT3_OK == lteiot3_parse_gga( app_buf, LTEIOT3_GGA_LATITUDE, element_buf ) )
        {
            static uint8_t wait_for_fix_cnt = 0;
            if ( strlen( element_buf ) > 0 )
            {
                log_printf( &logger, "\r\n Latitude: %.2s degrees, %s minutes \r\n", element_buf, &element_buf[ 2 ] );
                lteiot3_parse_gga( app_buf, LTEIOT3_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 ) );
                lteiot3_parse_gga( app_buf, LTEIOT3_GGA_ALTITUDE, element_buf );
                log_printf( &logger, " Altitude: %s m \r\n", element_buf );
                wait_for_fix_cnt = 0;
            }
            else
            {
                if ( wait_for_fix_cnt % 5 == 0 )
                {
                    log_printf( &logger, " Waiting for the position fix...\r\n\n" );
                    wait_for_fix_cnt = 0;
                }
                wait_for_fix_cnt++;
            }
            lteiot3_clear_app_buf(  );
        }
    }
#else
    #error "No demo example selected"
#endif
    return func_error;
}

// ------------------------------------------------------------------------ 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.