Discover a smarter approach to IoT connectivity with LTE IoT, where the synergy of CAT M1 and NB1 technologies empowers your devices to communicate efficiently and effectively
A
A
Hardware Overview
How does it work?
LTE IoT 6 Click is based on the SARA-R412M, an ultra-compact LTE Cat M1/NB1, and an EGPRS module with multi-regional coverage with data communications up to 1200 kbit/s from u-Blox. It ensures data integrity between applications via secure communication protocols, including two-way authentication between the client and server, a strategy often utilized with cloud services. The u-Blox nested design principle makes SARA modules compatible with other u-Blox product families, enabling easy migration from 2G, 3G, and 4G. The SARA-R412M module targets long life, low maintenance, lower power consumption, and extended battery life applications. It is ideal for mission-critical IoT solutions, as they include a unique and immutable root of trust. This module requires a power supply of 3.8V. Therefore, the Click board™ incorporates a low-dropout (LDO) regulator labeled TPS7A7002 by Texas Instruments. This IC can output up to 3A of current, maintaining excellent regulation. Its task is to provide a stable 3.8V power supply capable of mitigating voltage drops at the input when a high current peak appears (typically at the StartUp of the device). The SARA-R412M communicates with MCU using the UART interface with commonly
used UART RX and TX pins with the hardware flow control pins UART CTS, RTS, RI (Clear to Send, Ready to Send, and Ring Indicator). It supports automatic baud rate detection, operates at 115200 bps by default configuration, and is used for data transmission and exchanging AT commands with the host MCU. This Click board™ is also USB 2.0 compliant, equipped with the USB type C connector with a maximum 480 Mbit/s data rate available for diagnostic purposes only. The module acts as a USB device and can be connected to any USB host with compatible drivers. The onboard push-button labeled as PWR routed to the AN pin on the mikroBUS™ socket represents the Ignition (Power-On) button, whose function can be visually displayed by the yellow LED labeled as STAT used to indicate the device's Operational Status. If the device is powered up, a LOW pulse with a duration of 1.5s on this pin will power the module down. It is also possible to power down the module by issuing the AT+CPWROFF command or with a Reset function routed to the RST pin on the mikroBUS™ socket that will cause an abrupt Power-Down (forced Power-Down) by sending an active low input on this pin with the duration of 10s. In addition to the STAT LED, this Click board™
has an additional LED indicator, a red LED labeled as TX used to indicate the Network Status. LTE IoT 6 Click has an SMA antenna connector with an impedance of 50Ω, and it can be used to connect the appropriate antenna that MIKROE offers. Besides the LTE SMA connector, this Click board™ has a nano-SIM card slot that provides multiple connections and interface options. The unpopulated header labeled as J1 allows you to access the configurable GPIO and EXT Interrupt pin of the SARA module, while test points marked from TP1 to TP6 allow you easy FW upgrades and testing of the module. Customers can future-proof their solutions through over-the-air firmware updates, thanks to the uFOTA client/server solution that utilizes LWM2M, a light and compact protocol ideal for IoT. We have also provided accessible test points directly connected to the TxD and RxD pins for FW upgrade purposes. This Click board™ can be interfaced with both 3.3V and 5V MCUs, which can be set via jumper labeled as VCC SEL because appropriate voltage level shifters perform a proper logic voltage level conversion while the onboard LDOs ensure that recommended voltage levels power the module.
Features overview
Development board
Nucleo-64 with STM32F091RC 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.
Microcontroller Overview
MCU Card / MCU

Architecture
ARM Cortex-M0
MCU Memory (KB)
256
Silicon Vendor
STMicroelectronics
Pin count
64
RAM (Bytes)
32768
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.
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.
Used MCU Pins
mikroBUS™ mapper
Take a closer look
Click board™ Schematic

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

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

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

Software Support
Library Description
This library contains API for LTE IoT 6 Click driver.
Key functions:
lteiot6_send_cmd
- Send command functionlteiot6_set_sim_apn
- Set SIM APNlteiot6_send_sms_pdu
- Send SMS message to number in pdu mode
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 6 Click Example.
*
* # Description
* Application example shows device capability to connect
* network and send SMS messages using standard "AT" commands.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes driver and wake-up module and test communication.
*
* ## Application Task
* Application taks is split in few stages:
* - LTEIOT6_CONFIGURE_FOR_CONNECTION:
* Sets configuration to device to be able to connect to newtork.
*
* - LTEIOT6_WAIT_FOR_CONNECTION:
* Checks device response untill device sends information
* that it is connected to network.
*
* - LTEIOT6_CHECK_CONNECTION:
* Checks device connection status parameters.
*
* - LTEIOT6_CONFIGURE_FOR_MESSAGES:
* Sets configuration to device to send SMS messages.
*
* - LTEIOT6_MESSAGES:
* Sends message in selected mode (PDU/TXT).
*
*
* ## Additional Function
* - static void lteiot6_clear_app_buf ( void )
* - static err_t lteiot6_process ( void )
* - static void lteiot6_error_check( err_t error_flag )
* - static void lteiot6_log_app_buf ( void )
* - static err_t lteiot6_rsp_check ( void )
* - static err_t lteiot6_configure_for_connection( void )
* - static err_t lteiot6_check_connection( void )
* - static err_t lteiot6_check_connection_parameters( void )
* - static err_t lteiot6_configure_for_meesages( void )
* - static err_t lteiot6_send_meesage( void )
* -
*
* @note
* In order for the example to work, user needs to set the phone number to which he wants
* to send an SMS, and also will need to set an APN and SMSC of entered SIM card.
* Enter valid data for the following macros: SIM_APN, SIM_SMSC and PHONE_NUMBER_TO_MESSAGE.
* E.g.
* SIM_APN "vip.iot"
* SMSC_ADDRESS_CSCA "\"+381999999\",145"
* SMSC_ADDRESS_PDU "+381999999\"
* PHONE_NUMBER_TO_MESSAGE "+381659999999"
*
* @author Luka Filipovic
*
*/
#include "board.h"
#include "log.h"
#include "lteiot6.h"
//Set valid SIM APN
#define SIM_APN ""
//Set Phone number to message
#define PHONE_NUMBER_TO_MESSAGE "+381659999999"
//Messege content
#define MESSAGE_CONTENT "LTE IoT 6 Click"
//Set valid SMSC fro SIM
#define SMSC_ADDRESS_CSCA "\"+381999999\",145"
#define SMSC_ADDRESS_PDU "+381999999"
#define PROCESS_BUFFER_SIZE 300
/**
* @brief Example states.
* @details Predefined enum values for application example state.
*/
typedef enum
{
LTEIOT6_CONFIGURE_FOR_CONNECTION = 1,
LTEIOT6_WAIT_FOR_CONNECTION,
LTEIOT6_CHECK_CONNECTION,
LTEIOT6_CONFIGURE_FOR_MESSAGES,
LTEIOT6_MESSAGES
} lteiot6_example_state_t;
static lteiot6_t lteiot6;
static log_t logger;
/**
* @brief Application example variables.
* @details Variables used in application example.
*/
static char app_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;
static int32_t app_buf_cnt = 0;
static err_t error_flag;
static lteiot6_example_state_t example_state;
/**
* @brief Clearing application buffer.
* @details This function clears memory of application
* buffer and reset it's length and counter.
*/
static void lteiot6_clear_app_buf ( void );
/**
* @brief Data reading function.
* @details This function reads data from device and
* appends 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 lteiot6_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.
*/
static void lteiot6_error_check( err_t error_flag );
/**
* @brief Logs application buffer.
* @details This function logs data from application buffer.
*/
static void lteiot6_log_app_buf ( void );
/**
* @brief 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 lteiot6_rsp_check ( void );
/**
* @brief Configure device for connection to the network.
* @details Sends commands to configure and enable
* connection to the secifide network.
*/
static err_t lteiot6_configure_for_connection( void );
/**
* @brief Whait for connection signal.
* @details Wait for connection signal from CREG command.
*/
static err_t lteiot6_check_connection( void );
/**
* @brief Check connection parameters.
* @details This function checks connection parameters.
*/
static err_t lteiot6_check_connection_parameters( void );
/**
* @brief Configure device for sending messages.
* @details Configure device to send txt mode
* messages and SMSC of the SIM card.
*/
static err_t lteiot6_configure_for_meesages( void );
/**
* @brief Sending text message.
* @details This function sends text messages to predefined number.
*/
static err_t lteiot6_send_meesage( void );
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
lteiot6_cfg_t lteiot6_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 );
Delay_ms ( 1000 );
log_info( &logger, " Application Init " );
Delay_ms ( 1000 );
// Click initialization.
lteiot6_cfg_setup( <eiot6_cfg );
LTEIOT6_MAP_MIKROBUS( lteiot6_cfg, MIKROBUS_1 );
err_t init_flag = lteiot6_init( <eiot6, <eiot6_cfg );
if ( init_flag == UART_ERROR )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
lteiot6_process();
lteiot6_clear_app_buf();
app_buf_len = 0;
app_buf_cnt = 0;
lteiot6_reset( <eiot6 );
lteiot6_power_on( <eiot6 );
//Check communication
lteiot6_send_cmd( <eiot6, LTEIOT6_CMD_AT );
error_flag = lteiot6_rsp_check();
lteiot6_error_check( error_flag );
//Check fw version
lteiot6_send_cmd( <eiot6, LTEIOT6_CMD_ATI );
error_flag = lteiot6_rsp_check();
lteiot6_error_check( error_flag );
log_info( &logger, " Application Task " );
example_state = LTEIOT6_CONFIGURE_FOR_CONNECTION;
}
void application_task ( void )
{
switch ( example_state )
{
case LTEIOT6_CONFIGURE_FOR_CONNECTION:
{
if ( LTEIOT6_OK == lteiot6_configure_for_connection( ) )
{
example_state = LTEIOT6_WAIT_FOR_CONNECTION;
}
break;
}
case LTEIOT6_WAIT_FOR_CONNECTION:
{
if ( LTEIOT6_OK == lteiot6_check_connection( ) )
{
example_state = LTEIOT6_CHECK_CONNECTION;
}
break;
}
case LTEIOT6_CHECK_CONNECTION:
{
Delay_ms ( 1000 );
if ( LTEIOT6_OK == lteiot6_check_connection_parameters( ) )
{
example_state = LTEIOT6_CONFIGURE_FOR_MESSAGES;
}
Delay_ms ( 1000 );
break;
}
case LTEIOT6_CONFIGURE_FOR_MESSAGES:
{
if ( LTEIOT6_OK == lteiot6_configure_for_meesages( ) )
{
example_state = LTEIOT6_MESSAGES;
}
Delay_ms ( 1000 );
break;
}
case LTEIOT6_MESSAGES:
{
lteiot6_send_meesage();
Delay_ms ( 1000 );
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 lteiot6_clear_app_buf ( void )
{
memset( app_buf, 0, app_buf_len );
app_buf_len = 0;
app_buf_cnt = 0;
}
static err_t lteiot6_process ( void )
{
int32_t rx_size;
char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };
rx_size = lteiot6_generic_read( <eiot6, rx_buff, PROCESS_BUFFER_SIZE );
if ( rx_size > 0 )
{
int32_t buf_cnt = 0;
if ( app_buf_len + rx_size >= PROCESS_BUFFER_SIZE )
{
lteiot6_clear_app_buf( );
return LTEIOT6_ERROR;
}
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--;
buf_cnt--;
}
}
return LTEIOT6_OK;
}
return LTEIOT6_ERROR;
}
static err_t lteiot6_rsp_check ( void )
{
uint16_t timeout_cnt = 0;
uint16_t timeout = 50000;
err_t error_flag = lteiot6_process( );
if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
{
return error_flag;
}
while ( ( 0 == strstr( app_buf, LTEIOT6_RSP_OK ) ) &&
( 0 == strstr( app_buf, LTEIOT6_RSP_ERROR ) ) )
{
error_flag = lteiot6_process( );
if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
{
return error_flag;
}
timeout_cnt++;
if ( timeout_cnt > timeout )
{
lteiot6_clear_app_buf( );
return LTEIOT6_ERROR_TIMEOUT;
}
Delay_ms ( 1 );
}
if ( 0 != strstr( app_buf, LTEIOT6_RSP_OK ) )
{
return LTEIOT6_OK;
}
else if ( 0 == strstr( app_buf, LTEIOT6_RSP_ERROR ) )
{
return LTEIOT6_ERROR_CMD;
}
else
{
return LTEIOT6_ERROR_UNKNOWN;
}
}
static void lteiot6_error_check( err_t error_flag )
{
switch ( error_flag )
{
case LTEIOT6_OK:
{
lteiot6_log_app_buf( );
break;
}
case LTEIOT6_ERROR:
{
log_error( &logger, " Overflow!" );
break;
}
case LTEIOT6_ERROR_TIMEOUT:
{
log_error( &logger, " Timeout!" );
break;
}
case LTEIOT6_ERROR_CMD:
{
log_error( &logger, " CMD!" );
break;
}
case LTEIOT6_ERROR_UNKNOWN:
default:
{
log_error( &logger, " Unknown!" );
break;
}
}
lteiot6_clear_app_buf( );
Delay_ms ( 500 );
}
static void lteiot6_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 lteiot6_configure_for_connection( void )
{
err_t func_error = LTEIOT6_OK;
//Disconnect
#define DISCONNECT "2"
lteiot6_send_cmd_with_parameter( <eiot6, LTEIOT6_CMD_COPS, DISCONNECT );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
//Airplane mode
#define AIRPLANE_MODE "4"
lteiot6_send_cmd_with_parameter( <eiot6, LTEIOT6_CMD_CFUN, AIRPLANE_MODE );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
//Set SIM APN
lteiot6_set_sim_apn( <eiot6, SIM_APN );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
//Enable full functionality
#define FULL_FUNCTIONALITY "1"
lteiot6_send_cmd_with_parameter( <eiot6, LTEIOT6_CMD_CFUN, FULL_FUNCTIONALITY );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
//Automatic configure cops
#define AUTOMATIC "0"
lteiot6_send_cmd_with_parameter( <eiot6, LTEIOT6_CMD_COPS, AUTOMATIC );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
//Enable network registartion
#define ENABLE_REG "2"
lteiot6_send_cmd_with_parameter( <eiot6, LTEIOT6_CMD_CREG, ENABLE_REG );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
return func_error;
}
static err_t lteiot6_check_connection( void )
{
#define CONNECTED "+CREG: 1"
lteiot6_process();
if ( 0 != strstr(app_buf, CONNECTED ) )
{
Delay_ms ( 100 );
lteiot6_process();
lteiot6_log_app_buf( );
lteiot6_clear_app_buf( );
return LTEIOT6_OK;
}
return LTEIOT6_ERROR;
}
static err_t lteiot6_check_connection_parameters( void )
{
err_t func_error = LTEIOT6_OK;
//Check if connected
lteiot6_send_cmd_check( <eiot6, LTEIOT6_CMD_CGATT );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
//Check registration
lteiot6_send_cmd_check( <eiot6, LTEIOT6_CMD_CREG );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
//Check signal quality
lteiot6_send_cmd( <eiot6, LTEIOT6_CMD_CSQ );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
return func_error;
}
static err_t lteiot6_configure_for_meesages( void )
{
err_t func_error = LTEIOT6_OK;
//Set message mode
#define PDU_MESSAGE_MODE "0"
#define TXT_MESSAGE_MODE "1"
lteiot6_send_cmd_with_parameter( <eiot6, LTEIOT6_CMD_CMGF, PDU_MESSAGE_MODE );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
//Set SMSC for SIM card
lteiot6_send_cmd_with_parameter( <eiot6, LTEIOT6_CMD_CSCA, SMSC_ADDRESS_CSCA );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
return func_error;
}
static err_t lteiot6_send_meesage( void )
{
#define CMGF_PDU "+CMGF: 0"
#define CMGF_TXT "+CMGF: 1"
//Sendind message
lteiot6_send_cmd_check( <eiot6, LTEIOT6_CMD_CMGF );
error_flag = lteiot6_rsp_check();
if ( 0 != strstr( app_buf, CMGF_PDU ) )
{
lteiot6_clear_app_buf( );
lteiot6_send_sms_pdu( <eiot6, SMSC_ADDRESS_PDU, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
error_flag = lteiot6_rsp_check();
lteiot6_error_check( error_flag );
}
else if ( 0 != strstr( app_buf, CMGF_TXT ) )
{
lteiot6_clear_app_buf( );
lteiot6_send_text_message( <eiot6, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
error_flag = lteiot6_rsp_check();
lteiot6_error_check( error_flag );
}
return error_flag;
}
// ------------------------------------------------------------------------ END
/*!
* @file main.c
* @brief LTE IoT 6 Click Example.
*
* # Description
* Application example shows device capability to connect
* network and send SMS messages using standard "AT" commands.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes driver and wake-up module and test communication.
*
* ## Application Task
* Application taks is split in few stages:
* - LTEIOT6_CONFIGURE_FOR_CONNECTION:
* Sets configuration to device to be able to connect to newtork.
*
* - LTEIOT6_WAIT_FOR_CONNECTION:
* Checks device response untill device sends information
* that it is connected to network.
*
* - LTEIOT6_CHECK_CONNECTION:
* Checks device connection status parameters.
*
* - LTEIOT6_CONFIGURE_FOR_MESSAGES:
* Sets configuration to device to send SMS messages.
*
* - LTEIOT6_MESSAGES:
* Sends message in selected mode (PDU/TXT).
*
*
* ## Additional Function
* - static void lteiot6_clear_app_buf ( void )
* - static err_t lteiot6_process ( void )
* - static void lteiot6_error_check( err_t error_flag )
* - static void lteiot6_log_app_buf ( void )
* - static err_t lteiot6_rsp_check ( void )
* - static err_t lteiot6_configure_for_connection( void )
* - static err_t lteiot6_check_connection( void )
* - static err_t lteiot6_check_connection_parameters( void )
* - static err_t lteiot6_configure_for_meesages( void )
* - static err_t lteiot6_send_meesage( void )
* -
*
* @note
* In order for the example to work, user needs to set the phone number to which he wants
* to send an SMS, and also will need to set an APN and SMSC of entered SIM card.
* Enter valid data for the following macros: SIM_APN, SIM_SMSC and PHONE_NUMBER_TO_MESSAGE.
* E.g.
* SIM_APN "vip.iot"
* SMSC_ADDRESS_CSCA "\"+381999999\",145"
* SMSC_ADDRESS_PDU "+381999999\"
* PHONE_NUMBER_TO_MESSAGE "+381659999999"
*
* @author Luka Filipovic
*
*/
#include "board.h"
#include "log.h"
#include "lteiot6.h"
//Set valid SIM APN
#define SIM_APN ""
//Set Phone number to message
#define PHONE_NUMBER_TO_MESSAGE "+381659999999"
//Messege content
#define MESSAGE_CONTENT "LTE IoT 6 Click"
//Set valid SMSC fro SIM
#define SMSC_ADDRESS_CSCA "\"+381999999\",145"
#define SMSC_ADDRESS_PDU "+381999999"
#define PROCESS_BUFFER_SIZE 300
/**
* @brief Example states.
* @details Predefined enum values for application example state.
*/
typedef enum
{
LTEIOT6_CONFIGURE_FOR_CONNECTION = 1,
LTEIOT6_WAIT_FOR_CONNECTION,
LTEIOT6_CHECK_CONNECTION,
LTEIOT6_CONFIGURE_FOR_MESSAGES,
LTEIOT6_MESSAGES
} lteiot6_example_state_t;
static lteiot6_t lteiot6;
static log_t logger;
/**
* @brief Application example variables.
* @details Variables used in application example.
*/
static char app_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;
static int32_t app_buf_cnt = 0;
static err_t error_flag;
static lteiot6_example_state_t example_state;
/**
* @brief Clearing application buffer.
* @details This function clears memory of application
* buffer and reset it's length and counter.
*/
static void lteiot6_clear_app_buf ( void );
/**
* @brief Data reading function.
* @details This function reads data from device and
* appends 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 lteiot6_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.
*/
static void lteiot6_error_check( err_t error_flag );
/**
* @brief Logs application buffer.
* @details This function logs data from application buffer.
*/
static void lteiot6_log_app_buf ( void );
/**
* @brief 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 lteiot6_rsp_check ( void );
/**
* @brief Configure device for connection to the network.
* @details Sends commands to configure and enable
* connection to the secifide network.
*/
static err_t lteiot6_configure_for_connection( void );
/**
* @brief Whait for connection signal.
* @details Wait for connection signal from CREG command.
*/
static err_t lteiot6_check_connection( void );
/**
* @brief Check connection parameters.
* @details This function checks connection parameters.
*/
static err_t lteiot6_check_connection_parameters( void );
/**
* @brief Configure device for sending messages.
* @details Configure device to send txt mode
* messages and SMSC of the SIM card.
*/
static err_t lteiot6_configure_for_meesages( void );
/**
* @brief Sending text message.
* @details This function sends text messages to predefined number.
*/
static err_t lteiot6_send_meesage( void );
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
lteiot6_cfg_t lteiot6_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 );
Delay_ms ( 1000 );
log_info( &logger, " Application Init " );
Delay_ms ( 1000 );
// Click initialization.
lteiot6_cfg_setup( <eiot6_cfg );
LTEIOT6_MAP_MIKROBUS( lteiot6_cfg, MIKROBUS_1 );
err_t init_flag = lteiot6_init( <eiot6, <eiot6_cfg );
if ( init_flag == UART_ERROR )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
lteiot6_process();
lteiot6_clear_app_buf();
app_buf_len = 0;
app_buf_cnt = 0;
lteiot6_reset( <eiot6 );
lteiot6_power_on( <eiot6 );
//Check communication
lteiot6_send_cmd( <eiot6, LTEIOT6_CMD_AT );
error_flag = lteiot6_rsp_check();
lteiot6_error_check( error_flag );
//Check fw version
lteiot6_send_cmd( <eiot6, LTEIOT6_CMD_ATI );
error_flag = lteiot6_rsp_check();
lteiot6_error_check( error_flag );
log_info( &logger, " Application Task " );
example_state = LTEIOT6_CONFIGURE_FOR_CONNECTION;
}
void application_task ( void )
{
switch ( example_state )
{
case LTEIOT6_CONFIGURE_FOR_CONNECTION:
{
if ( LTEIOT6_OK == lteiot6_configure_for_connection( ) )
{
example_state = LTEIOT6_WAIT_FOR_CONNECTION;
}
break;
}
case LTEIOT6_WAIT_FOR_CONNECTION:
{
if ( LTEIOT6_OK == lteiot6_check_connection( ) )
{
example_state = LTEIOT6_CHECK_CONNECTION;
}
break;
}
case LTEIOT6_CHECK_CONNECTION:
{
Delay_ms ( 1000 );
if ( LTEIOT6_OK == lteiot6_check_connection_parameters( ) )
{
example_state = LTEIOT6_CONFIGURE_FOR_MESSAGES;
}
Delay_ms ( 1000 );
break;
}
case LTEIOT6_CONFIGURE_FOR_MESSAGES:
{
if ( LTEIOT6_OK == lteiot6_configure_for_meesages( ) )
{
example_state = LTEIOT6_MESSAGES;
}
Delay_ms ( 1000 );
break;
}
case LTEIOT6_MESSAGES:
{
lteiot6_send_meesage();
Delay_ms ( 1000 );
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 lteiot6_clear_app_buf ( void )
{
memset( app_buf, 0, app_buf_len );
app_buf_len = 0;
app_buf_cnt = 0;
}
static err_t lteiot6_process ( void )
{
int32_t rx_size;
char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };
rx_size = lteiot6_generic_read( <eiot6, rx_buff, PROCESS_BUFFER_SIZE );
if ( rx_size > 0 )
{
int32_t buf_cnt = 0;
if ( app_buf_len + rx_size >= PROCESS_BUFFER_SIZE )
{
lteiot6_clear_app_buf( );
return LTEIOT6_ERROR;
}
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--;
buf_cnt--;
}
}
return LTEIOT6_OK;
}
return LTEIOT6_ERROR;
}
static err_t lteiot6_rsp_check ( void )
{
uint16_t timeout_cnt = 0;
uint16_t timeout = 50000;
err_t error_flag = lteiot6_process( );
if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
{
return error_flag;
}
while ( ( 0 == strstr( app_buf, LTEIOT6_RSP_OK ) ) &&
( 0 == strstr( app_buf, LTEIOT6_RSP_ERROR ) ) )
{
error_flag = lteiot6_process( );
if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
{
return error_flag;
}
timeout_cnt++;
if ( timeout_cnt > timeout )
{
lteiot6_clear_app_buf( );
return LTEIOT6_ERROR_TIMEOUT;
}
Delay_ms ( 1 );
}
if ( 0 != strstr( app_buf, LTEIOT6_RSP_OK ) )
{
return LTEIOT6_OK;
}
else if ( 0 == strstr( app_buf, LTEIOT6_RSP_ERROR ) )
{
return LTEIOT6_ERROR_CMD;
}
else
{
return LTEIOT6_ERROR_UNKNOWN;
}
}
static void lteiot6_error_check( err_t error_flag )
{
switch ( error_flag )
{
case LTEIOT6_OK:
{
lteiot6_log_app_buf( );
break;
}
case LTEIOT6_ERROR:
{
log_error( &logger, " Overflow!" );
break;
}
case LTEIOT6_ERROR_TIMEOUT:
{
log_error( &logger, " Timeout!" );
break;
}
case LTEIOT6_ERROR_CMD:
{
log_error( &logger, " CMD!" );
break;
}
case LTEIOT6_ERROR_UNKNOWN:
default:
{
log_error( &logger, " Unknown!" );
break;
}
}
lteiot6_clear_app_buf( );
Delay_ms ( 500 );
}
static void lteiot6_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 lteiot6_configure_for_connection( void )
{
err_t func_error = LTEIOT6_OK;
//Disconnect
#define DISCONNECT "2"
lteiot6_send_cmd_with_parameter( <eiot6, LTEIOT6_CMD_COPS, DISCONNECT );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
//Airplane mode
#define AIRPLANE_MODE "4"
lteiot6_send_cmd_with_parameter( <eiot6, LTEIOT6_CMD_CFUN, AIRPLANE_MODE );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
//Set SIM APN
lteiot6_set_sim_apn( <eiot6, SIM_APN );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
//Enable full functionality
#define FULL_FUNCTIONALITY "1"
lteiot6_send_cmd_with_parameter( <eiot6, LTEIOT6_CMD_CFUN, FULL_FUNCTIONALITY );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
//Automatic configure cops
#define AUTOMATIC "0"
lteiot6_send_cmd_with_parameter( <eiot6, LTEIOT6_CMD_COPS, AUTOMATIC );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
//Enable network registartion
#define ENABLE_REG "2"
lteiot6_send_cmd_with_parameter( <eiot6, LTEIOT6_CMD_CREG, ENABLE_REG );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
return func_error;
}
static err_t lteiot6_check_connection( void )
{
#define CONNECTED "+CREG: 1"
lteiot6_process();
if ( 0 != strstr(app_buf, CONNECTED ) )
{
Delay_ms ( 100 );
lteiot6_process();
lteiot6_log_app_buf( );
lteiot6_clear_app_buf( );
return LTEIOT6_OK;
}
return LTEIOT6_ERROR;
}
static err_t lteiot6_check_connection_parameters( void )
{
err_t func_error = LTEIOT6_OK;
//Check if connected
lteiot6_send_cmd_check( <eiot6, LTEIOT6_CMD_CGATT );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
//Check registration
lteiot6_send_cmd_check( <eiot6, LTEIOT6_CMD_CREG );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
//Check signal quality
lteiot6_send_cmd( <eiot6, LTEIOT6_CMD_CSQ );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
return func_error;
}
static err_t lteiot6_configure_for_meesages( void )
{
err_t func_error = LTEIOT6_OK;
//Set message mode
#define PDU_MESSAGE_MODE "0"
#define TXT_MESSAGE_MODE "1"
lteiot6_send_cmd_with_parameter( <eiot6, LTEIOT6_CMD_CMGF, PDU_MESSAGE_MODE );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
//Set SMSC for SIM card
lteiot6_send_cmd_with_parameter( <eiot6, LTEIOT6_CMD_CSCA, SMSC_ADDRESS_CSCA );
error_flag = lteiot6_rsp_check();
func_error |= error_flag;
lteiot6_error_check( error_flag );
return func_error;
}
static err_t lteiot6_send_meesage( void )
{
#define CMGF_PDU "+CMGF: 0"
#define CMGF_TXT "+CMGF: 1"
//Sendind message
lteiot6_send_cmd_check( <eiot6, LTEIOT6_CMD_CMGF );
error_flag = lteiot6_rsp_check();
if ( 0 != strstr( app_buf, CMGF_PDU ) )
{
lteiot6_clear_app_buf( );
lteiot6_send_sms_pdu( <eiot6, SMSC_ADDRESS_PDU, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
error_flag = lteiot6_rsp_check();
lteiot6_error_check( error_flag );
}
else if ( 0 != strstr( app_buf, CMGF_TXT ) )
{
lteiot6_clear_app_buf( );
lteiot6_send_text_message( <eiot6, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
error_flag = lteiot6_rsp_check();
lteiot6_error_check( error_flag );
}
return error_flag;
}
// ------------------------------------------------------------------------ END