体验物联网通信的变革,LTE IoT通过集成CAT M1和NB1技术提供强大且面向未来的连接解决方案。
A
A
硬件概览
它是如何工作的?
LTE IoT 8 Click 基于SKY66430-11,这是一款为可穿戴设备、资产跟踪、工业监控和智能计量提供LTE-M和NB-IoT连接的紧凑低功耗5G就绪物联网SiP解决方案,由Skyworks Solutions和Sequans Communications提供。该SiP集成了RF前端、收发器、基带调制解调器、存储器和电源管理,提供从698到2200MHz的18个频段。它已经通过主要网络运营商、监管机构和标准组织的预认证,可快速进行全球部署。该设备支持高达300kbps的下载速度和375kbps的上传速度,支持LTE定位。它还具有同类最佳的“深度睡眠”功耗,仅为1uA,对于电池供电的物联网设备而言,这是一大优势。此外,它还具有100%基于软件的低功耗安全定位解决方案,可以在任何地方工作(在GPS无法工作的室内深处启用定位)。SKY66430-11通过
UART接口与MCU通信,使用常用的UART RX和TX引脚,以及硬件流控制引脚UART CTS、RTS、RI(发送就绪、接收就绪和振铃指示器)。默认配置下的工作速度为115200 bps,与主机MCU传输和交换数据。它还配备了一个USB Type C连接器,允许模块通过FT2232D(一个紧凑的USB转串行UART接口设备)由个人计算机(PC)供电和配置。此Click板™可以由电池供电并用作独立设备。它还包含MC34671,一款完全集成的锂离子或锂聚合物电池充电器,允许在Click板™插入mikroBUS™插座或插入USB端口时进行电池充电,充电进度通过CHG LED指示灯显示。当电池充满时,CHG LED将熄灭。此外,此Click板™还具有一个标记为STAT的额外黄色LED,用于指示模块的不同操作模式,而mikroBUS™插座上的PWM引脚
用作节能状态指示器。当调制解调器处于活动状态时,该指示器设置为高逻辑状态;当调制解调器处于低功耗模式时,设置为低逻辑状态。板载标记为ON的按钮连接到mikroBUS™的RST引脚,代表点火按钮。LTE IoT 8 Click具有50Ω阻抗的SMA天线连接器,用于连接MIKROE提供的适当天线。除了LTE SMA连接器外,此Click板™还具有一个Nano-SIM卡插槽,提供多种连接和接口选项。此Click板™可以与3.3V和5V的MCU一起工作。适当的电压电平转换由TXS0108E执行,确保适当的逻辑电压电平转换,而板载LDO确保电源模块的推荐电压水平。此外,该Click板™配备了包含易于使用的功能库和示例代码,可作为进一步开发的参考。
功能概述
开发板
Fusion for TIVA v8 是一款专为快速开发嵌入式应用的需求而特别设计的开发板。它支持广泛的微控制器,如不同的32位ARM® Cortex®-M基础MCUs,来自Texas Instruments,无论它们的引脚数量如何,并且具有一系列独特功能,例如首次通过WiFi网络实现的嵌入式调试器/程序员。开发板布局合理,设计周到,使得最终用户可以在一个地方找到所有必要的元素,如开关、按钮、指示灯、连接器等。得益于创新的制造技术,Fusion for TIVA v8 提供了流畅而沉浸式的工作体验,允许在任何情况下、任何地方、任何
时候都能访问。Fusion for TIVA v8开发板的每个部分都包含了使同一板块运行最高效的必要组件。一个先进的集成CODEGRIP程序/调试模块提供许多有价值的编程/调试选项,包括对JTAG、SWD和SWO Trace(单线输出)的支持,并与Mikroe软件环境无缝集成。此外,它还包括一个干净且调节过的开发板电源供应模块。它可以使用广泛的外部电源,包括电池、外部12V电源供应和通过USB Type-C(USB-C)连接器的电源。通信选项如USB-UART、USB HOST/DEVICE、CAN(如果MCU卡支持的话)和以
太网也包括在内。此外,它还拥有广受好评的 mikroBUS™标准,为MCU卡提供了标准化插座(SiBRAIN标准),以及两种显示选项,用于TFT板线产品和基于字符的LCD。Fusion for TIVA v8 是Mikroe快速开发生态系统的一个组成部分。它由Mikroe软件工具原生支持,得益于大量不同的Click板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作和开发的许多方面。
微控制器概述
MCU卡片 / MCU

类型
8th Generation
建筑
ARM Cortex-M4
MCU 内存 (KB)
1024
硅供应商
Texas Instruments
引脚数
128
RAM (字节)
262144
你完善了我!
配件
LTE Flat Rotation Antenna 是提升3G/4G LTE设备性能的多功能选择。其宽频率范围为700-2700MHz,确保在全球主要蜂窝频段上的最佳连接。该平板天线配有SMA公连接器,便于直接连接到您的设备或SMA模块连接器。其突出特点之一是可调节角度,可按45⁰增量(0⁰/45⁰/90⁰)设置,允许您微调天线的方向以获得最佳信号接收。该天线具有50Ω的阻抗和小于2.0:1的电压驻波比,确保连接可靠且高效。其5dB增益、垂直极化和全向辐射模式增强了信号强度,适用于各种应用。天线长度为196mm,宽度为38mm,提供了紧凑而有效的连接解决方案。其最大输入功率为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 8 Click 驱动程序的 API。
关键功能:
lteiot8_send_cmd
- 发送命令功能lteiot8_set_sim_apn
- 设置SIM APNlteiot8_send_text_message
- 以文本模式发送短信到指定号码
开源
代码示例
完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio。 应用程序代码也可以在MIKROE的GitHub账户中找到。
/*!
* @file main.c
* @brief LTE IoT 8 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:
* - LTEIOT8_CONFIGURE_FOR_CONNECTION:
* Sets configuration to device to be able to connect to newtork.
*
* - LTEIOT8_WAIT_FOR_CONNECTION:
* Checks device response untill device sends information
* that it is connected to network.
*
* - LTEIOT8_CHECK_CONNECTION:
* Checks device connection status parameters.
*
* - LTEIOT8_CONFIGURE_FOR_MESSAGES:
* Sets configuration to device to send SMS messages.
*
* - LTEIOT8_MESSAGES:
* Sends message in selected mode (PDU/TXT).
*
*
* ## Additional Function
* - static void lteiot8_clear_app_buf ( void )
* - static err_t lteiot8_process ( void )
* - static void lteiot8_error_check( err_t error_flag )
* - static void lteiot8_log_app_buf ( void )
* - static err_t lteiot8_rsp_check ( void )
* - static err_t lteiot8_configure_for_connection( void )
* - static err_t lteiot8_check_connection( void )
* - static err_t lteiot8_check_connection_parameters( void )
* - static err_t lteiot8_configure_for_meesages( void )
* - static err_t lteiot8_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 "lteiot8.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 8 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
{
LTEIOT8_CONFIGURE_FOR_CONNECTION = 1,
LTEIOT8_WAIT_FOR_CONNECTION,
LTEIOT8_CHECK_CONNECTION,
LTEIOT8_CONFIGURE_FOR_MESSAGES,
LTEIOT8_MESSAGES
} lteiot8_example_state_t;
static lteiot8_t lteiot8;
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 lteiot8_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 lteiot8_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 lteiot8_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 lteiot8_error_check( err_t error_flag );
/**
* @brief Logs application buffer.
* @details This function logs data from application buffer.
*/
static void lteiot8_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 lteiot8_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 lteiot8_configure_for_connection( void );
/**
* @brief Whait for connection signal.
* @details Wait for connection signal from CREG command.
*/
static err_t lteiot8_check_connection( void );
/**
* @brief Check connection parameters.
* @details This function checks connection parameters.
*/
static err_t lteiot8_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 lteiot8_configure_for_meesages( void );
/**
* @brief Sending text message.
* @details This function sends text messages to predefined number.
*/
static err_t lteiot8_send_meesage( void );
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
lteiot8_cfg_t lteiot8_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.
lteiot8_cfg_setup( <eiot8_cfg );
LTEIOT8_MAP_MIKROBUS( lteiot8_cfg, MIKROBUS_1 );
err_t init_flag = lteiot8_init( <eiot8, <eiot8_cfg );
if ( init_flag == UART_ERROR )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
lteiot8_process();
lteiot8_clear_app_buf();
app_buf_len = 0;
app_buf_cnt = 0;
lteiot8_default_cfg ( <eiot8 );
while ( 0 == strstr( app_buf, LTEIOT8_RSP_SYSTART ) )
{
lteiot8_process();
}
//Check communication
lteiot8_send_cmd( <eiot8, "AT" );
error_flag = lteiot8_rsp_check();
lteiot8_error_check( error_flag );
log_info( &logger, " Application Task " );
example_state = LTEIOT8_CONFIGURE_FOR_CONNECTION;
}
void application_task ( void )
{
switch ( example_state )
{
case LTEIOT8_CONFIGURE_FOR_CONNECTION:
{
if ( LTEIOT8_OK == lteiot8_configure_for_connection( ) )
{
example_state = LTEIOT8_WAIT_FOR_CONNECTION;
}
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
break;
}
case LTEIOT8_WAIT_FOR_CONNECTION:
{
if ( LTEIOT8_OK == lteiot8_check_connection( ) )
{
example_state = LTEIOT8_CHECK_CONNECTION;
}
break;
}
case LTEIOT8_CHECK_CONNECTION:
{
if ( LTEIOT8_OK == lteiot8_check_connection_parameters( ) )
{
example_state = LTEIOT8_CONFIGURE_FOR_MESSAGES;
}
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
break;
}
case LTEIOT8_CONFIGURE_FOR_MESSAGES:
{
if ( LTEIOT8_OK == lteiot8_configure_for_meesages( ) )
{
example_state = LTEIOT8_MESSAGES;
}
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
break;
}
case LTEIOT8_MESSAGES:
{
lteiot8_send_meesage();
// 10 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 );
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 lteiot8_clear_app_buf ( void )
{
memset( app_buf, 0, app_buf_len );
app_buf_len = 0;
app_buf_cnt = 0;
}
static err_t lteiot8_process ( void )
{
int32_t rx_size;
char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };
rx_size = lteiot8_generic_read( <eiot8, rx_buff, PROCESS_BUFFER_SIZE );
if ( rx_size > 0 )
{
int32_t buf_cnt = 0;
if ( app_buf_len + rx_size >= PROCESS_BUFFER_SIZE )
{
lteiot8_clear_app_buf( );
return LTEIOT8_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 LTEIOT8_OK;
}
return LTEIOT8_ERROR;
}
static err_t lteiot8_rsp_check ( void )
{
uint16_t timeout_cnt = 0;
uint16_t timeout = 10000;
err_t error_flag = lteiot8_process( );
if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
{
return error_flag;
}
while ( ( 0 == strstr( app_buf, LTEIOT8_RSP_OK ) ) &&
( 0 == strstr( app_buf, LTEIOT8_RSP_ERROR ) ) )
{
error_flag = lteiot8_process( );
if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
{
return error_flag;
}
timeout_cnt++;
if ( timeout_cnt > timeout )
{
lteiot8_clear_app_buf( );
return LTEIOT8_ERROR_TIMEOUT;
}
Delay_ms ( 1 );
}
if ( 0 != strstr( app_buf, LTEIOT8_RSP_OK ) )
{
return LTEIOT8_OK;
}
else if ( 0 == strstr( app_buf, LTEIOT8_RSP_ERROR ) )
{
return LTEIOT8_ERROR_CMD;
}
else
{
return LTEIOT8_ERROR_UNKNOWN;
}
}
static void lteiot8_error_check( err_t error_flag )
{
switch ( error_flag )
{
case LTEIOT8_OK:
{
lteiot8_log_app_buf( );
break;
}
case LTEIOT8_ERROR:
{
log_error( &logger, " Overflow!" );
break;
}
case LTEIOT8_ERROR_TIMEOUT:
{
log_error( &logger, " Timeout!" );
break;
}
case LTEIOT8_ERROR_CMD:
{
log_error( &logger, " CMD!" );
break;
}
case LTEIOT8_ERROR_UNKNOWN:
default:
{
log_error( &logger, " Unknown!" );
break;
}
}
lteiot8_clear_app_buf( );
Delay_ms ( 500 );
}
static void lteiot8_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 lteiot8_configure_for_connection( void )
{
err_t func_error = LTEIOT8_OK;
//Enable full functionality
#define FULL_FUNCTIONALITY "1"
lteiot8_send_cmd_with_parameter( <eiot8, LTEIOT8_CMD_CFUN, FULL_FUNCTIONALITY );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
//Enable device LED
#define GNSS_LEN "1"
lteiot8_send_cmd_with_parameter( <eiot8, LTEIOT8_CMD_SQNLED, GNSS_LEN );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
//Set SIM APN
lteiot8_set_sim_apn( <eiot8, SIM_APN );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
//Automatic configure cops
#define AUTOMATIC "0"
lteiot8_send_cmd_with_parameter( <eiot8, LTEIOT8_CMD_COPS, AUTOMATIC );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
//Enable network registartion
#define ENABLE_REG "2"
lteiot8_send_cmd_with_parameter( <eiot8, LTEIOT8_CMD_CEREG, ENABLE_REG );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
return func_error;
}
static err_t lteiot8_check_connection( void )
{
#define CONNECTED "+CEREG: 1"
lteiot8_process();
if ( 0 != strstr(app_buf, CONNECTED ) )
{
Delay_ms ( 100 );
lteiot8_process();
lteiot8_log_app_buf( );
lteiot8_clear_app_buf( );
return LTEIOT8_OK;
}
return LTEIOT8_ERROR;
}
static err_t lteiot8_check_connection_parameters( void )
{
err_t func_error = LTEIOT8_OK;
//Check if connected
lteiot8_send_cmd_check( <eiot8, LTEIOT8_CMD_CGATT );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
//Check registration
lteiot8_send_cmd_check( <eiot8, LTEIOT8_CMD_CEREG );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
//Check signal quality
lteiot8_send_cmd( <eiot8, LTEIOT8_CMD_CSQ );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
return func_error;
}
static err_t lteiot8_configure_for_meesages( void )
{
err_t func_error = LTEIOT8_OK;
//Set message mode
#define PDU_MESSAGE_MODE "0"
#define TXT_MESSAGE_MODE "1"
lteiot8_send_cmd_with_parameter( <eiot8, LTEIOT8_CMD_CMGF, TXT_MESSAGE_MODE );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
//Set SMSC for SIM card
lteiot8_send_cmd_with_parameter( <eiot8, LTEIOT8_CMD_CSCA, SMSC_ADDRESS_CSCA );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
return func_error;
}
static err_t lteiot8_send_meesage( void )
{
#define CMGF_PDU "+CMGF: 0"
#define CMGF_TXT "+CMGF: 1"
//Sendind message
lteiot8_send_cmd_check( <eiot8, LTEIOT8_CMD_CMGF );
error_flag = lteiot8_rsp_check();
if ( 0 != strstr( app_buf, CMGF_PDU ) )
{
lteiot8_clear_app_buf( );
lteiot8_send_sms_pdu( <eiot8, SMSC_ADDRESS_PDU, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
error_flag = lteiot8_rsp_check();
lteiot8_error_check( error_flag );
}
else if ( 0 != strstr( app_buf, CMGF_TXT ) )
{
lteiot8_clear_app_buf( );
lteiot8_send_text_message( <eiot8, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
error_flag = lteiot8_rsp_check();
lteiot8_error_check( error_flag );
}
return error_flag;
}
// ------------------------------------------------------------------------ END
/*!
* @file main.c
* @brief LTE IoT 8 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:
* - LTEIOT8_CONFIGURE_FOR_CONNECTION:
* Sets configuration to device to be able to connect to newtork.
*
* - LTEIOT8_WAIT_FOR_CONNECTION:
* Checks device response untill device sends information
* that it is connected to network.
*
* - LTEIOT8_CHECK_CONNECTION:
* Checks device connection status parameters.
*
* - LTEIOT8_CONFIGURE_FOR_MESSAGES:
* Sets configuration to device to send SMS messages.
*
* - LTEIOT8_MESSAGES:
* Sends message in selected mode (PDU/TXT).
*
*
* ## Additional Function
* - static void lteiot8_clear_app_buf ( void )
* - static err_t lteiot8_process ( void )
* - static void lteiot8_error_check( err_t error_flag )
* - static void lteiot8_log_app_buf ( void )
* - static err_t lteiot8_rsp_check ( void )
* - static err_t lteiot8_configure_for_connection( void )
* - static err_t lteiot8_check_connection( void )
* - static err_t lteiot8_check_connection_parameters( void )
* - static err_t lteiot8_configure_for_meesages( void )
* - static err_t lteiot8_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 "lteiot8.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 8 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
{
LTEIOT8_CONFIGURE_FOR_CONNECTION = 1,
LTEIOT8_WAIT_FOR_CONNECTION,
LTEIOT8_CHECK_CONNECTION,
LTEIOT8_CONFIGURE_FOR_MESSAGES,
LTEIOT8_MESSAGES
} lteiot8_example_state_t;
static lteiot8_t lteiot8;
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 lteiot8_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 lteiot8_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 lteiot8_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 lteiot8_error_check( err_t error_flag );
/**
* @brief Logs application buffer.
* @details This function logs data from application buffer.
*/
static void lteiot8_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 lteiot8_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 lteiot8_configure_for_connection( void );
/**
* @brief Whait for connection signal.
* @details Wait for connection signal from CREG command.
*/
static err_t lteiot8_check_connection( void );
/**
* @brief Check connection parameters.
* @details This function checks connection parameters.
*/
static err_t lteiot8_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 lteiot8_configure_for_meesages( void );
/**
* @brief Sending text message.
* @details This function sends text messages to predefined number.
*/
static err_t lteiot8_send_meesage( void );
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
lteiot8_cfg_t lteiot8_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.
lteiot8_cfg_setup( <eiot8_cfg );
LTEIOT8_MAP_MIKROBUS( lteiot8_cfg, MIKROBUS_1 );
err_t init_flag = lteiot8_init( <eiot8, <eiot8_cfg );
if ( init_flag == UART_ERROR )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
lteiot8_process();
lteiot8_clear_app_buf();
app_buf_len = 0;
app_buf_cnt = 0;
lteiot8_default_cfg ( <eiot8 );
while ( 0 == strstr( app_buf, LTEIOT8_RSP_SYSTART ) )
{
lteiot8_process();
}
//Check communication
lteiot8_send_cmd( <eiot8, "AT" );
error_flag = lteiot8_rsp_check();
lteiot8_error_check( error_flag );
log_info( &logger, " Application Task " );
example_state = LTEIOT8_CONFIGURE_FOR_CONNECTION;
}
void application_task ( void )
{
switch ( example_state )
{
case LTEIOT8_CONFIGURE_FOR_CONNECTION:
{
if ( LTEIOT8_OK == lteiot8_configure_for_connection( ) )
{
example_state = LTEIOT8_WAIT_FOR_CONNECTION;
}
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
break;
}
case LTEIOT8_WAIT_FOR_CONNECTION:
{
if ( LTEIOT8_OK == lteiot8_check_connection( ) )
{
example_state = LTEIOT8_CHECK_CONNECTION;
}
break;
}
case LTEIOT8_CHECK_CONNECTION:
{
if ( LTEIOT8_OK == lteiot8_check_connection_parameters( ) )
{
example_state = LTEIOT8_CONFIGURE_FOR_MESSAGES;
}
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
break;
}
case LTEIOT8_CONFIGURE_FOR_MESSAGES:
{
if ( LTEIOT8_OK == lteiot8_configure_for_meesages( ) )
{
example_state = LTEIOT8_MESSAGES;
}
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
break;
}
case LTEIOT8_MESSAGES:
{
lteiot8_send_meesage();
// 10 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 );
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 lteiot8_clear_app_buf ( void )
{
memset( app_buf, 0, app_buf_len );
app_buf_len = 0;
app_buf_cnt = 0;
}
static err_t lteiot8_process ( void )
{
int32_t rx_size;
char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };
rx_size = lteiot8_generic_read( <eiot8, rx_buff, PROCESS_BUFFER_SIZE );
if ( rx_size > 0 )
{
int32_t buf_cnt = 0;
if ( app_buf_len + rx_size >= PROCESS_BUFFER_SIZE )
{
lteiot8_clear_app_buf( );
return LTEIOT8_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 LTEIOT8_OK;
}
return LTEIOT8_ERROR;
}
static err_t lteiot8_rsp_check ( void )
{
uint16_t timeout_cnt = 0;
uint16_t timeout = 10000;
err_t error_flag = lteiot8_process( );
if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
{
return error_flag;
}
while ( ( 0 == strstr( app_buf, LTEIOT8_RSP_OK ) ) &&
( 0 == strstr( app_buf, LTEIOT8_RSP_ERROR ) ) )
{
error_flag = lteiot8_process( );
if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
{
return error_flag;
}
timeout_cnt++;
if ( timeout_cnt > timeout )
{
lteiot8_clear_app_buf( );
return LTEIOT8_ERROR_TIMEOUT;
}
Delay_ms ( 1 );
}
if ( 0 != strstr( app_buf, LTEIOT8_RSP_OK ) )
{
return LTEIOT8_OK;
}
else if ( 0 == strstr( app_buf, LTEIOT8_RSP_ERROR ) )
{
return LTEIOT8_ERROR_CMD;
}
else
{
return LTEIOT8_ERROR_UNKNOWN;
}
}
static void lteiot8_error_check( err_t error_flag )
{
switch ( error_flag )
{
case LTEIOT8_OK:
{
lteiot8_log_app_buf( );
break;
}
case LTEIOT8_ERROR:
{
log_error( &logger, " Overflow!" );
break;
}
case LTEIOT8_ERROR_TIMEOUT:
{
log_error( &logger, " Timeout!" );
break;
}
case LTEIOT8_ERROR_CMD:
{
log_error( &logger, " CMD!" );
break;
}
case LTEIOT8_ERROR_UNKNOWN:
default:
{
log_error( &logger, " Unknown!" );
break;
}
}
lteiot8_clear_app_buf( );
Delay_ms ( 500 );
}
static void lteiot8_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 lteiot8_configure_for_connection( void )
{
err_t func_error = LTEIOT8_OK;
//Enable full functionality
#define FULL_FUNCTIONALITY "1"
lteiot8_send_cmd_with_parameter( <eiot8, LTEIOT8_CMD_CFUN, FULL_FUNCTIONALITY );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
//Enable device LED
#define GNSS_LEN "1"
lteiot8_send_cmd_with_parameter( <eiot8, LTEIOT8_CMD_SQNLED, GNSS_LEN );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
//Set SIM APN
lteiot8_set_sim_apn( <eiot8, SIM_APN );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
//Automatic configure cops
#define AUTOMATIC "0"
lteiot8_send_cmd_with_parameter( <eiot8, LTEIOT8_CMD_COPS, AUTOMATIC );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
//Enable network registartion
#define ENABLE_REG "2"
lteiot8_send_cmd_with_parameter( <eiot8, LTEIOT8_CMD_CEREG, ENABLE_REG );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
return func_error;
}
static err_t lteiot8_check_connection( void )
{
#define CONNECTED "+CEREG: 1"
lteiot8_process();
if ( 0 != strstr(app_buf, CONNECTED ) )
{
Delay_ms ( 100 );
lteiot8_process();
lteiot8_log_app_buf( );
lteiot8_clear_app_buf( );
return LTEIOT8_OK;
}
return LTEIOT8_ERROR;
}
static err_t lteiot8_check_connection_parameters( void )
{
err_t func_error = LTEIOT8_OK;
//Check if connected
lteiot8_send_cmd_check( <eiot8, LTEIOT8_CMD_CGATT );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
//Check registration
lteiot8_send_cmd_check( <eiot8, LTEIOT8_CMD_CEREG );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
//Check signal quality
lteiot8_send_cmd( <eiot8, LTEIOT8_CMD_CSQ );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
return func_error;
}
static err_t lteiot8_configure_for_meesages( void )
{
err_t func_error = LTEIOT8_OK;
//Set message mode
#define PDU_MESSAGE_MODE "0"
#define TXT_MESSAGE_MODE "1"
lteiot8_send_cmd_with_parameter( <eiot8, LTEIOT8_CMD_CMGF, TXT_MESSAGE_MODE );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
//Set SMSC for SIM card
lteiot8_send_cmd_with_parameter( <eiot8, LTEIOT8_CMD_CSCA, SMSC_ADDRESS_CSCA );
error_flag = lteiot8_rsp_check();
func_error |= error_flag;
lteiot8_error_check( error_flag );
return func_error;
}
static err_t lteiot8_send_meesage( void )
{
#define CMGF_PDU "+CMGF: 0"
#define CMGF_TXT "+CMGF: 1"
//Sendind message
lteiot8_send_cmd_check( <eiot8, LTEIOT8_CMD_CMGF );
error_flag = lteiot8_rsp_check();
if ( 0 != strstr( app_buf, CMGF_PDU ) )
{
lteiot8_clear_app_buf( );
lteiot8_send_sms_pdu( <eiot8, SMSC_ADDRESS_PDU, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
error_flag = lteiot8_rsp_check();
lteiot8_error_check( error_flag );
}
else if ( 0 != strstr( app_buf, CMGF_TXT ) )
{
lteiot8_clear_app_buf( );
lteiot8_send_text_message( <eiot8, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
error_flag = lteiot8_rsp_check();
lteiot8_error_check( error_flag );
}
return error_flag;
}
// ------------------------------------------------------------------------ END