发现一种更智能的物联网连接方式,使用LTE物联网技术,在CAT M1和NB1技术的协同作用下,让您的设备高效、有效地进行通信。
A
A
硬件概览
它是如何工作的?
LTE IoT 6 Click基于SARA-R412M,这是一个超紧凑的LTE Cat M1/NB1和EGPRS模块,具有多区域覆盖,数据通信速度高达1200 kbit/s,由u-Blox提供。它通过安全通信协议确保应用之间的数据完整性,包括客户端和服务器之间的双向认证,这种策略常用于云服务。u-Blox的嵌套设计原则使SARA模块与其他u-Blox产品系列兼容,便于从2G、3G和4G的轻松迁移。SARA-R412M模块旨在实现长寿命、低维护、低功耗和延长电池寿命的应用。它是关键任务物联网解决方案的理想选择,因为它们包含唯一且不可变的信任根。该模块需要3.8V的电源。因此,Click板™集成了由德州仪器(Texas Instruments)标记为TPS7A7002的低压差(LDO)稳压器。该IC可以输出高达3A的电流,保持卓越的调节性能。其任务是提供稳定的3.8V电源,能够在高电流峰值出现时(通常在设备启动时)减轻输入电压下降的影响。SARA-R412M使用常用的UART RX和TX
引脚以及硬件流控制引脚UART CTS、RTS、RI(Clear to Send、Ready to Send和Ring Indicator)通过UART接口与MCU通信。它支持自动波特率检测,默认配置为115200 bps,用于数据传输和与主机MCU交换AT命令。此Click板™还符合USB 2.0标准,配备了USB Type C连接器,最大480 Mbit/s的数据速率仅用于诊断目的。该模块作为USB设备,可以连接到任何带有兼容驱动程序的USB主机。板载标记为PWR的按钮连接到mikroBUS™插槽上的AN引脚,表示点火(电源开)按钮,其功能可以通过标记为STAT的黄色LED来显示,指示设备的操作状态。如果设备已通电,在此引脚上持续1.5秒的低脉冲将关闭模块。也可以通过发出AT+CPWROFF命令或通过mikroBUS™插槽上的RST引脚上的复位功能,通过在此引脚上发送持续10秒的有效低输入,导致强制断电(强制断电)来关闭模块。除了STAT LED外,此Click板™还有一个额外的LED指示灯,
一个标记为TX的红色LED用于指示网络状态。LTE IoT 6 Click有一个阻抗为50Ω的SMA天线连接器,可以用来连接MIKROE提供的适当天线。除了LTE SMA连接器外,此Click板™还有一个nano-SIM卡插槽,提供多种连接和接口选项。未焊接的标记为J1的插针允许您访问SARA模块的可配置GPIO和EXT中断引脚,而标记为TP1到TP6的测试点则允许您轻松进行FW升级和模块测试。客户可以通过空中固件更新来保障他们的解决方案,得益于uFOTA客户端/服务器解决方案,该解决方案利用LWM2M,这是一种轻便且紧凑的协议,非常适合物联网。我们还提供了直接连接到TxD和RxD引脚的可访问测试点,用于FW升级目的。此Click板™可以与3.3V和5V的MCU接口,可以通过标记为VCC SEL的跳线设置,因为适当的电压电平转换器会执行适当的逻辑电压电平转换,而板载LDO则确保模块由推荐的电压水平供电。
功能概述
开发板
Nucleo-64搭载STM32L073RZ MCU提供了一个经济实惠且灵活的平台,供开发人员探索新的想法并原型化其设计。该板利用了STM32微控制器的多功能性,使用户能够为其项目选择性能和功耗之间的最佳平衡。它采用LQFP64封装的STM32微控制器,并包括一些必要的组件,例如用户LED,可以同时作为ARDUINO®信号使用,以及用户和复位按钮,以及用于精准定时操作的32.768kHz晶体振荡器。设计时考虑了扩展性和灵活性,Nucleo-64板具有ARDUINO®
Uno V3扩展连接器和ST morpho扩展引脚标头,为全面项目集成提供了对STM32 I/O的完全访问权限。电源选项具有适应性,支持ST-LINK USB VBUS或外部电源,确保在各种开发环境中的适应性。该板还配备了一个内置的ST-LINK调试器/编程器,具有USB重新枚举功能,简化了编程和调试过程。此外,该板还设计了外部SMPS,以实现有效的Vcore逻辑供电,支持USB设备全速或USB SNK/UFP全速,以及内置的加密功能,增强了项目的功耗效率和安全性。通过专用
连接器提供了额外的连接性,用于外部SMPS实验、ST-LINK的USB连接器和MIPI®调试连接器,扩展了硬件接口和实验的可能性。开发人员将通过STM32Cube MCU软件包中全面的免费软件库和示例得到广泛的支持。这与与各种集成开发环境(IDE)的兼容性相结合,包括IAR Embedded Workbench®、MDK-ARM和STM32CubeIDE,确保了平稳高效的开发体验,使用户能够充分发挥Nucleo-64板在其项目中的功能。
微控制器概述
MCU卡片 / MCU

建筑
ARM Cortex-M0
MCU 内存 (KB)
192
硅供应商
STMicroelectronics
引脚数
64
RAM (字节)
20480
你完善了我!
配件
Click Shield for Nucleo-64 配备了两个专有的 mikroBUS™ 插座,使得所有的 Click board™ 设备都可以轻松地与 STM32 Nucleo-64 开发板连接。这样,Mikroe 允许其用户从不断增长的 Click boards™ 范围中添加任何功能,如 WiFi、GSM、GPS、蓝牙、ZigBee、环境传感器、LED、语音识别、电机控制、运动传感器等。您可以使用超过 1537 个 Click boards™,这些 Click boards™ 可以堆叠和集成。STM32 Nucleo-64 开发板基于 64 引脚封装的微控制器,采用 32 位 MCU,配备 ARM Cortex M4 处理器,运行速度为 84MHz,具有 512Kb Flash 和 96KB SRAM,分为两个区域,顶部区域代表 ST-Link/V2 调试器和编程器,而底部区域是一个实际的开发板。通过 USB 连接方便地控制和供电这些板子,以便直接对 Nucleo-64 开发板进行编程和高效调试,其中还需要额外的 USB 线连接到板子上的 USB 迷你接口。大多数 STM32 微控制器引脚都连接到了板子左右边缘的 IO 引脚上,然后连接到两个现有的 mikroBUS™ 插座上。该 Click Shield 还有几个开关,用于选择 mikroBUS™ 插座上模拟信号的逻辑电平和 mikroBUS™ 插座本身的逻辑电压电平。此外,用户还可以通过现有的双向电平转换器,使用任何 Click board™,无论 Click board™ 是否在 3.3V 或 5V 逻辑电压电平下运行。一旦将 STM32 Nucleo-64 开发板与我们的 Click Shield for Nucleo-64 连接,您就可以访问数百个工作于 3.3V 或 5V 逻辑电压电平的 Click boards™。
LTE平板旋转天线是一种多功能选择,可以提升3G/4G LTE设备的性能。其宽频率范围为700-2700MHz,确保在全球主要蜂窝频段上实现最佳连接。这款平板天线配备SMA公头连接器,可以轻松直接连接到您的设备或SMA模块连接器。其突出特点之一是可调角度,可以以45度增量(0度/45度/90度)进行设置,让您微调天线的方向以获得最大信号接收。该天线的阻抗为50Ω,电压驻波比(VSW比)小于2.0:1,确保可靠高效的连接。5dB增益、垂直极化和全向辐射模式增强了信号强度,使其适用于各种应用。天线长度为196毫米,宽度为38毫米,提供紧凑但有效的解决方案来改善您的连接。其最大输入功率为50W,能够应对各种设备的需求。
使用的MCU引脚
mikroBUS™映射器
“仔细看看!”
Click board™ 原理图

一步一步来
项目组装
实时跟踪您的结果
应用程序输出
1. 应用程序输出 - 在调试模式下,“应用程序输出”窗口支持实时数据监控,直接提供执行结果的可视化。请按照提供的教程正确配置环境,以确保数据正确显示。

2. UART 终端 - 使用UART Terminal通过USB to UART converter监视数据传输,实现Click board™与开发系统之间的直接通信。请根据项目需求配置波特率和其他串行设置,以确保正常运行。有关分步设置说明,请参考提供的教程。

3. Plot 输出 - Plot功能提供了一种强大的方式来可视化实时传感器数据,使趋势分析、调试和多个数据点的对比变得更加直观。要正确设置,请按照提供的教程,其中包含使用Plot功能显示Click board™读数的分步示例。在代码中使用Plot功能时,请使用以下函数:plot(insert_graph_name, variable_name);。这是一个通用格式,用户需要将“insert_graph_name”替换为实际图表名称,并将“variable_name”替换为要显示的参数。

软件支持
库描述
该库包含 LTE IoT 6 Click 驱动程序的 API。
关键功能:
lteiot6_send_cmd
- 发送命令功能lteiot6_set_sim_apn
- 设置SIM卡的APNlteiot6_send_sms_pdu
- 以PDU模式发送短信到指定号码
开源
代码示例
完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio。 应用程序代码也可以在MIKROE的GitHub账户中找到。
/*!
* @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