实现可靠的低延迟无线连接,支持全球 LTE 和 GNSS,非常适合物联网应用中的计量、资产追踪和远程监控
A
A
硬件概览
它是如何工作的?
LTE IoT 14 Click 基于 SIM7090G,这是来自 SIMCom 的多频段 LTE 模块,适用于全球连接。SIM7090G 支持 Cat-M 和 Cat-NB 无线通信模式,具有多个内置网络协议,最大下行速率为 0.589Mbps,最大上行速率为 1.119Mbps。此外,它支持多个 Cat-M 频段(B1/B2/B3/B4/B5/B8/B12/B13/B14/B18/B19/B20/B25/B26/B27/B28/B66/B85)和 Cat-NB 频段(B1/B2/B3/B4/B5/B8/B12/B13/B18/B19/B20/B25/B26/B28/B66/B71/B85),并且支持多星座 GNSS(GPS/GLONASS/Galileo/北斗)。基于其广泛的功能,这款 Click 板™ 非常适合需要低延迟、低吞吐量数据通信的 M2M 应用,例如计量、资产追踪、远程监控、电子健康等各种无线传播条件下的应用。SIM7090G 与主控 MCU 之间通过 UART 接口通信,使用标准的 UART RX 和 TX 引脚,以及硬件流控引脚(CTS/RTS/RI - 清除发送/准备发送/振铃指示)实现高效数据传输。模块默认通信速率为 115200bps,允许通过 AT 命令实现无缝数据交换。用户还可以选择切换到 I2C 接口,该接口支持高达 400kbps 的快速
模式,用于相同的目的。此 Click 板™ 还包括一个 USB Type-C 连接器,用于电源和数据传输,符合 USB 2.0 规范(仅外围设备)。此外,板载背面还有一个标有 USB BOOT 的 USB 固件升级开关,用于管理固件升级。此开关具有 0(正常操作)和 1(通过 USB 升级固件)两个位置,确保升级过程简单直观。LTE IoT 14 Click 提供了多种增强功能以提高其可用性和控制能力。PWR 按钮允许用户轻松开关模块电源,而 RESET 按钮可快速重置模块。这些功能还可以通过 mikroBUS™ 引脚 PWR 和 RST 进行数字控制,提供更大的灵活性。此外,该板还设有专用测试点(TP3/TP4 用于 DBG_UART,TP5/TP6 用于 GNSS 的 NMEA 数据输出),以便更轻松地进行调试和测试,并提供两个视觉指示灯以实时显示状态更新。第一个红色 NET LED 指示模块的当前网络状态。当 LED 缓慢闪烁(64ms 开,3000ms 关)时,表示设备已成功注册到网络,特别是在 PS 域。如果 LED 以正常速度闪烁(64ms 开,800ms 关),则表示设备尚未注册到网络。快速闪烁模式(64ms 开,300ms 关)表示正在进行数据传输,例如在 PPP 拨
号连接期间或使用内部 TCP、FTP 或 HTTP 等数据服务时。当 LED 完全熄灭时,表示设备已关闭或处于省电模式(PSM)。第二个黄色 STAT LED 指示模块的电源状态,当模块关闭时熄灭,模块上电或固件就绪时点亮。该板配备两个 SMA 连接器,用于 LTE 和 GNSS 天线,MIKROE 提供的 LTE 平板旋转天线和有源 GPS 天线可实现高效的连接选项。此外,用户可以通过板背面的 GNSS ANT 跳线在 3.3V 和 5V 之间轻松选择可选 GNSS 天线的电源。该板还配有一个微型 SIM 卡槽,仅支持 1.8V uSIM 卡,允许用户根据具体使用案例选择最合适的服务提供商。此 Click 板™ 可在 3.3V 和 5V 逻辑电压电平下运行,可通过 VCC SEL 跳线选择。由于 SIM7090G 模块在 3.8V 下运行,因此还使用了逻辑电平转换器 TXB0106 和 PCA9306,以确保正确操作和准确的信号电平转换。这样,3.3V 和 5V 的 MCU 都能正常使用通信线路。此外,该 Click 板™ 配备了包含易用功能的库和示例代码,可用作进一步开发的参考。
功能概述
开发板
Clicker 2 for Kinetis 是一款紧凑型入门开发板,它将 Click 板™的灵活性带给您喜爱的微控制器,使其成为实现您想法的完美入门套件。它配备了一款板载 32 位 ARM Cortex-M4F 微控制器,NXP 半导体公司的 MK64FN1M0VDC12,两个 mikroBUS™ 插槽用于 Click 板™连接,一个 USB 连接器,LED 指示灯,按钮,一个 JTAG 程序员连接器以及两个 26 针头用于与外部电子设备的接口。其紧凑的设计和清晰、易识别的丝网标记让您能够迅速构建具有独特功能和特性
的小工具。Clicker 2 for Kinetis 开发套件的每个部分 都包含了使同一板块运行最高效的必要组件。除了可以选择 Clicker 2 for Kinetis 的编程方式,使用 USB HID mikroBootloader 或外部 mikroProg 连接器进行 Kinetis 编程外,Clicker 2 板还包括一个干净且调节过的开发套件电源供应模块。它提供了两种供电方式;通过 USB Micro-B 电缆,其中板载电压调节器为板上每个组件提供适当的电压水平,或使用锂聚合物 电池通过板载电池连接器供电。所有 mikroBUS™ 本
身支持的通信方法都在这块板上,包括已经建立良好的 mikroBUS™ 插槽、重置按钮和几个用户可配置的按钮及 LED 指示灯。Clicker 2 for Kinetis 是 Mikroe 生态系统的一个组成部分,允许您在几分钟内创建新的应用程序。它由 Mikroe 软件工具原生支持,得益于大量不同的 Click 板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作的许多方面。
微控制器概述
MCU卡片 / MCU

建筑
ARM Cortex-M4
MCU 内存 (KB)
1024
硅供应商
NXP
引脚数
121
RAM (字节)
262144
你完善了我!
配件
LTE Flat Rotation Antenna 是增强 3G/4G LTE 设备性能的多功能选择。凭借 700-2700MHz 的宽频率范围,它确保在全球主要蜂窝频段上的最佳连接。该平板天线采用 SMA 公头连接器,便于直接连接到设备或 SMA 模块连接器。其亮点之一是可调角度,可按 45⁰ 增量(0⁰/45⁰/90⁰)设置,允许您微调天线的方向以获得最佳信号接收。具有 50Ω 阻抗和 <2.0:1 的电压驻波比 (VSWR),此天线确保可靠高效的连接。其 5dB 增益、垂直极化和全向辐射图形增强了信号强度,适用于各种应用。天线长度为 196mm,宽度为 38mm,提供紧凑但有效的解决方案来改善您的连接。最大输入功率为 50W,能够满足各种设备的需求。

主动 GPS 天线旨在增强您的 GPS 和 GNSS Click 板™ 的性能。这款外置天线结构坚固,适用于各种天气条件。凭借 1575.42MHz 的频率范围和 50Ohm 的阻抗,它确保了可靠的信号接收。天线在较宽的角度范围内提供大于 -4dBic 的增益,确保超过 75% 的覆盖率。± 5MHz 的带宽进一步保证了精确的数据采集。天线采用右旋圆极化 (RHCP),提供稳定的信号接收。其紧凑的尺寸为 48.5×39×15mm,配有 2 米长的电缆,安装方便。磁性天线类型与 SMA 公连接器确保了安全便捷的连接。如果您需要为定位设备提供可靠的外置天线,我们的主动 GPS 天线是完美的解决方案。

使用的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 14 Click 驱动程序的 API。
关键功能:
lteiot14_set_sim_apn
- 设置 SIM 卡的接入点名称(APN)的函数lteiot14_send_sms_text
- 发送短信到指定电话号码的函数lteiot14_send_cmd
- 发送指定命令到点击模块的函数
开源
代码示例
完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio。 应用程序代码也可以在MIKROE的GitHub账户中找到。
/*!
* @file main.c
* @brief LTE IoT 14 Click Example.
*
* # Description
* Application example shows device capability of connecting to the network and
* sending SMS or TCP/UDP messages, or retrieving data from GNSS using standard "AT" commands.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes the driver and logger.
*
* ## Application Task
* Application task is split in few stages:
* - LTEIOT14_POWER_UP:
* Powers up the device, performs a device reset and reads system information.
*
* - LTEIOT14_CONFIG_CONNECTION:
* Sets configuration to device to be able to connect to the network (used only for SMS or TCP/UDP demo examples).
*
* - LTEIOT14_CHECK_CONNECTION:
* Waits for the network registration indicated via CREG command and then checks the signal quality report
* (used only for SMS or TCP/UDP demo examples).
*
* - LTEIOT14_CONFIG_EXAMPLE:
* Configures device for the selected example.
*
* - LTEIOT14_EXAMPLE:
* Depending on the selected demo example, it sends an SMS message (in PDU or TXT mode) or TCP/UDP message or
* waits for the GPS fix to retrieve location info from GNSS.
*
* By default, the TCP/UDP example is selected.
*
* ## Additional Function
* - static void lteiot14_clear_app_buf ( void )
* - static void lteiot14_log_app_buf ( void )
* - static err_t lteiot14_process ( lteiot14_t *ctx )
* - static err_t lteiot14_read_response ( lteiot14_t *ctx, uint8_t *rsp )
* - static err_t lteiot14_power_up ( lteiot14_t *ctx )
* - static err_t lteiot14_config_connection ( lteiot14_t *ctx )
* - static err_t lteiot14_check_connection ( lteiot14_t *ctx )
* - static err_t lteiot14_config_example ( lteiot14_t *ctx )
* - static err_t lteiot14_example ( lteiot14_t *ctx )
*
* @note
* In order for the examples to work (except GNSS example), user needs to set the APN and SMSC (SMS PDU mode only)
* of entered SIM card as well as the phone number (SMS mode only) to which he wants to send an SMS.
* Enter valid values for the following macros: SIM_APN, SIM_SMSC and PHONE_NUMBER_TO_MESSAGE.
* Example:
SIM_APN "internet"
SIM_SMSC "+381610401"
PHONE_NUMBER_TO_MESSAGE "+381659999999"
*
* @author Stefan Filipovic
*
*/
#include "board.h"
#include "log.h"
#include "lteiot14.h"
#include "conversions.h"
// Example selection macros
#define EXAMPLE_TCP_UDP 0 // Example of sending messages to a TCP/UDP echo server
#define EXAMPLE_SMS 1 // Example of sending SMS to a phone number
#define EXAMPLE_GNSS 2 // Example of retrieving location info from GNSS
#define DEMO_EXAMPLE EXAMPLE_TCP_UDP // Example selection macro
// SIM APN config
#define SIM_APN "internet" // Set valid SIM APN
// SMS example parameters
#define SIM_SMSC "" // Set valid SMS Service Center Address - only in SMS PDU mode
#define PHONE_NUMBER_TO_MESSAGE "" // Set Phone number to message
#define SMS_MODE "1" // SMS mode: "0" - PDU, "1" - TXT
// TCP/UDP example parameters
#define REMOTE_IP "77.46.162.162" // TCP/UDP echo server IP address
#define REMOTE_PORT "51111" // TCP/UDP echo server port
// Message content
#define MESSAGE_CONTENT "LTE IoT 14 click board - demo example."
// Application buffer size
#define APP_BUFFER_SIZE 256
#define PROCESS_BUFFER_SIZE 256
/**
* @brief Example states.
* @details Predefined enum values for application example state.
*/
typedef enum
{
LTEIOT14_POWER_UP = 1,
LTEIOT14_CONFIG_CONNECTION,
LTEIOT14_CHECK_CONNECTION,
LTEIOT14_CONFIG_EXAMPLE,
LTEIOT14_EXAMPLE
} lteiot14_app_state_t;
/**
* @brief Application example variables.
* @details Variables used in application example.
*/
static uint8_t app_buf[ APP_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;
static lteiot14_app_state_t app_state = LTEIOT14_POWER_UP;
static lteiot14_t lteiot14;
static log_t logger;
/**
* @brief LTE IoT 14 clearing application buffer.
* @details This function clears memory of application buffer and reset its length.
* @note None.
*/
static void lteiot14_clear_app_buf ( void );
/**
* @brief LTE IoT 14 log application buffer.
* @details This function logs data from application buffer to USB UART.
* @note None.
*/
static void lteiot14_log_app_buf ( void );
/**
* @brief LTE IoT 14 data reading function.
* @details This function reads data from device and concatenates data to application buffer.
* @param[in] ctx : Click context object.
* See #lteiot14_t object definition for detailed explanation.
* @return @li @c 0 - Read some data.
* @li @c -1 - Nothing is read.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t lteiot14_process ( lteiot14_t *ctx );
/**
* @brief LTE IoT 14 read response function.
* @details This function waits for a response message, reads and displays it on the USB UART.
* @param[in] ctx : Click context object.
* See #lteiot14_t object definition for detailed explanation.
* @param[in] rsp Expected response.
* @return @li @c 0 - OK response.
* @li @c -2 - Timeout error.
* @li @c -3 - Command error.
* @li @c -4 - Unknown error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t lteiot14_read_response ( lteiot14_t *ctx, uint8_t *rsp );
/**
* @brief LTE IoT 14 power up function.
* @details This function powers up the device, performs device hardware reset and reads system information.
* @param[in] ctx : Click context object.
* See #lteiot14_t object definition for detailed explanation.
* @return @li @c 0 - OK.
* @li @c != 0 - Read response error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t lteiot14_power_up ( lteiot14_t *ctx );
/**
* @brief LTE IoT 14 config connection function.
* @details This function configures and enables connection to the specified network.
* @param[in] ctx : Click context object.
* See #lteiot14_t object definition for detailed explanation.
* @return @li @c 0 - OK.
* @li @c != 0 - Read response error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t lteiot14_config_connection ( lteiot14_t *ctx );
/**
* @brief LTE IoT 14 check connection function.
* @details This function checks the connection to network.
* @param[in] ctx : Click context object.
* See #lteiot14_t object definition for detailed explanation.
* @return @li @c 0 - OK.
* @li @c != 0 - Read response error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t lteiot14_check_connection ( lteiot14_t *ctx );
/**
* @brief LTE IoT 14 config example function.
* @details This function configures device for the selected example.
* @param[in] ctx : Click context object.
* See #lteiot14_t object definition for detailed explanation.
* @return @li @c 0 - OK.
* @li @c != 0 - Read response error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t lteiot14_config_example ( lteiot14_t *ctx );
/**
* @brief LTE IoT 14 example function.
* @details This function executes SMS, TCP/UDP or GNSS example depending on the DEMO_EXAMPLE macro.
* @param[in] ctx : Click context object.
* See #lteiot14_t object definition for detailed explanation.
* @return @li @c 0 - OK.
* @li @c != 0 - Read response error.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t lteiot14_example ( lteiot14_t *ctx );
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
lteiot14_cfg_t lteiot14_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.
lteiot14_cfg_setup( <eiot14_cfg );
LTEIOT14_MAP_MIKROBUS( lteiot14_cfg, MIKROBUS_1 );
if ( UART_ERROR == lteiot14_init( <eiot14, <eiot14_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
app_state = LTEIOT14_POWER_UP;
log_printf( &logger, ">>> APP STATE - POWER UP <<<\r\n\n" );
}
void application_task ( void )
{
switch ( app_state )
{
case LTEIOT14_POWER_UP:
{
if ( LTEIOT14_OK == lteiot14_power_up( <eiot14 ) )
{
app_state = LTEIOT14_CONFIG_CONNECTION;
log_printf( &logger, ">>> APP STATE - CONFIG CONNECTION <<<\r\n\n" );
}
break;
}
case LTEIOT14_CONFIG_CONNECTION:
{
if ( LTEIOT14_OK == lteiot14_config_connection( <eiot14 ) )
{
app_state = LTEIOT14_CHECK_CONNECTION;
log_printf( &logger, ">>> APP STATE - CHECK CONNECTION <<<\r\n\n" );
}
break;
}
case LTEIOT14_CHECK_CONNECTION:
{
if ( LTEIOT14_OK == lteiot14_check_connection( <eiot14 ) )
{
app_state = LTEIOT14_CONFIG_EXAMPLE;
log_printf( &logger, ">>> APP STATE - CONFIG EXAMPLE <<<\r\n\n" );
}
break;
}
case LTEIOT14_CONFIG_EXAMPLE:
{
if ( LTEIOT14_OK == lteiot14_config_example( <eiot14 ) )
{
app_state = LTEIOT14_EXAMPLE;
log_printf( &logger, ">>> APP STATE - EXAMPLE <<<\r\n\n" );
}
break;
}
case LTEIOT14_EXAMPLE:
{
lteiot14_example( <eiot14 );
break;
}
default:
{
log_error( &logger, " APP 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 lteiot14_clear_app_buf ( void )
{
memset( app_buf, 0, app_buf_len );
app_buf_len = 0;
}
static void lteiot14_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 lteiot14_process ( lteiot14_t *ctx )
{
uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
int32_t overflow_bytes = 0;
int32_t rx_cnt = 0;
int32_t rx_size = lteiot14_generic_read( ctx, rx_buf, PROCESS_BUFFER_SIZE );
if ( ( rx_size > 0 ) && ( rx_size <= APP_BUFFER_SIZE ) )
{
if ( ( app_buf_len + rx_size ) > APP_BUFFER_SIZE )
{
overflow_bytes = ( app_buf_len + rx_size ) - APP_BUFFER_SIZE;
app_buf_len = APP_BUFFER_SIZE - rx_size;
memmove ( app_buf, &app_buf[ overflow_bytes ], app_buf_len );
memset ( &app_buf[ app_buf_len ], 0, overflow_bytes );
}
for ( rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ )
{
if ( rx_buf[ rx_cnt ] )
{
app_buf[ app_buf_len++ ] = rx_buf[ rx_cnt ];
}
}
return LTEIOT14_OK;
}
return LTEIOT14_ERROR;
}
static err_t lteiot14_read_response ( lteiot14_t *ctx, uint8_t *rsp )
{
#define READ_RESPONSE_TIMEOUT_MS 120000
uint32_t timeout_cnt = 0;
lteiot14_clear_app_buf ( );
lteiot14_process( ctx );
while ( ( 0 == strstr( app_buf, rsp ) ) &&
( 0 == strstr( app_buf, LTEIOT14_RSP_ERROR ) ) )
{
lteiot14_process( ctx );
if ( timeout_cnt++ > READ_RESPONSE_TIMEOUT_MS )
{
lteiot14_clear_app_buf( );
log_error( &logger, " Timeout!" );
return LTEIOT14_ERROR_TIMEOUT;
}
Delay_ms( 1 );
}
Delay_ms ( 200 );
lteiot14_process( ctx );
if ( strstr( app_buf, rsp ) )
{
lteiot14_log_app_buf( );
log_printf( &logger, "--------------------------------\r\n" );
return LTEIOT14_OK;
}
else if ( strstr( app_buf, LTEIOT14_RSP_ERROR ) )
{
log_error( &logger, " CMD!" );
return LTEIOT14_ERROR_CMD;
}
log_error( &logger, " Unknown!" );
return LTEIOT14_ERROR_UNKNOWN;
}
static err_t lteiot14_power_up ( lteiot14_t *ctx )
{
err_t error_flag = LTEIOT14_OK;
log_printf( &logger, ">>> Power up device.\r\n" );
lteiot14_set_power_state ( ctx, LTEIOT14_POWER_STATE_ON );
log_printf( &logger, ">>> Perform device hardware reset.\r\n" );
lteiot14_set_power_state ( ctx, LTEIOT14_POWER_STATE_RESET );
log_printf( &logger, ">>> Check communication.\r\n" );
lteiot14_process( ctx );
lteiot14_clear_app_buf ( );
for ( uint8_t num_tries = 0; ; num_tries++ )
{
// Wake up AT interface
lteiot14_send_cmd( ctx, LTEIOT14_CMD_AT );
Delay_ms ( 1000 );
if ( LTEIOT14_OK == lteiot14_process( ctx ) )
{
break;
}
if ( num_tries > 10 )
{
lteiot14_set_power_state ( ctx, LTEIOT14_POWER_STATE_ON );
lteiot14_process( ctx );
lteiot14_clear_app_buf ( );
num_tries = 0;
}
}
lteiot14_send_cmd( ctx, LTEIOT14_CMD_AT );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
log_printf( &logger, ">>> Get device model ID.\r\n" );
lteiot14_send_cmd( ctx, LTEIOT14_CMD_GET_MODEL_ID );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
log_printf( &logger, ">>> Get device software version ID.\r\n" );
lteiot14_send_cmd( ctx, LTEIOT14_CMD_GET_SW_VERSION );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
log_printf( &logger, ">>> Get device serial number.\r\n" );
lteiot14_send_cmd( ctx, LTEIOT14_CMD_GET_SERIAL_NUM );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
return error_flag;
}
static err_t lteiot14_config_connection ( lteiot14_t *ctx )
{
err_t error_flag = LTEIOT14_OK;
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
log_printf( &logger, ">>> Deregister from network.\r\n" );
#define DEREGISTER_FROM_NETWORK "2"
lteiot14_send_cmd_par( ctx, LTEIOT14_CMD_OPERATOR_SELECTION, DEREGISTER_FROM_NETWORK );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
log_printf( &logger, ">>> Set SIM APN.\r\n" );
lteiot14_set_sim_apn( <eiot14, SIM_APN );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
log_printf( &logger, ">>> Enable full functionality.\r\n" );
#define FULL_FUNCTIONALITY "1"
lteiot14_send_cmd_par( ctx, LTEIOT14_CMD_SET_PHONE_FUNCTIONALITY, FULL_FUNCTIONALITY );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
log_printf( &logger, ">>> Enable network registration.\r\n" );
#define ENABLE_REG "2"
lteiot14_send_cmd_par( ctx, LTEIOT14_CMD_NETWORK_REGISTRATION, ENABLE_REG );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
log_printf( &logger, ">>> Set automatic registration.\r\n" );
#define AUTOMATIC_REGISTRATION "0"
lteiot14_send_cmd_par( ctx, LTEIOT14_CMD_OPERATOR_SELECTION, AUTOMATIC_REGISTRATION );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
#endif
return error_flag;
}
static err_t lteiot14_check_connection ( lteiot14_t *ctx )
{
err_t error_flag = LTEIOT14_OK;
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
log_printf( &logger, ">>> Check network registration.\r\n" );
#define CONNECTED "+CREG: 2,1"
lteiot14_send_cmd_check ( <eiot14, LTEIOT14_CMD_NETWORK_REGISTRATION );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
if ( strstr( app_buf, CONNECTED ) )
{
Delay_ms ( 1000 );
log_printf( &logger, ">>> Check signal quality.\r\n" );
lteiot14_send_cmd( <eiot14, LTEIOT14_CMD_SIGNAL_QUALITY_REPORT );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
}
else
{
error_flag = LTEIOT14_ERROR;
Delay_ms ( 1000 );
Delay_ms ( 1000 );
}
#endif
return error_flag;
}
static err_t lteiot14_config_example ( lteiot14_t *ctx )
{
err_t error_flag = LTEIOT14_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
log_printf( &logger, ">>> Activate PDP context.\r\n" );
#define ACTIVATE_PDP_CONTEXT "1,1"
lteiot14_send_cmd_par( <eiot14, LTEIOT14_CMD_ACTIVATE_PDP_CONTEXT, ACTIVATE_PDP_CONTEXT );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
log_printf( &logger, ">>> Show PDP address.\r\n" );
#define PDP_CID "1"
lteiot14_send_cmd_par( <eiot14, LTEIOT14_CMD_SHOW_PDP_ADDRESS, PDP_CID );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
log_printf( &logger, ">>> Activate APP network.\r\n" );
#define ACTIVATE_APP_NETWORK "1,1"
lteiot14_send_cmd_par( <eiot14, LTEIOT14_CMD_APP_NETWORK_ACTIVE, ACTIVATE_APP_NETWORK );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
log_printf( &logger, ">>> Select SMS format.\r\n" );
lteiot14_send_cmd_par( <eiot14, LTEIOT14_CMD_SELECT_SMS_FORMAT, SMS_MODE );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
#elif ( DEMO_EXAMPLE == EXAMPLE_GNSS )
log_printf( &logger, ">>> Turn on GNSS power supply.\r\n" );
#define GNNS_TURN_ON "1"
lteiot14_send_cmd_par( <eiot14, LTEIOT14_CMD_GNSS_POWER_CONTROL, GNNS_TURN_ON );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
#endif
return error_flag;
}
static err_t lteiot14_example ( lteiot14_t *ctx )
{
err_t error_flag = LTEIOT14_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
uint8_t cmd_buf[ 100 ] = { 0 };
log_printf( &logger, ">>> Set TCP ID.\r\n" );
#define TCP_CID "1"
lteiot14_send_cmd_par ( <eiot14, LTEIOT14_CMD_SET_TCP_UDP_ID, TCP_CID );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
log_printf( &logger, ">>> Open TCP connection.\r\n" );
#define PDP_CID "1"
#define TCP_CONN_TYPE "TCP"
strcpy( cmd_buf, TCP_CID );
strcat( cmd_buf, "," );
strcat( cmd_buf, PDP_CID );
strcat( cmd_buf, ",\"" );
strcat( cmd_buf, TCP_CONN_TYPE );
strcat( cmd_buf, "\",\"" );
strcat( cmd_buf, REMOTE_IP );
strcat( cmd_buf, "\"," );
strcat( cmd_buf, REMOTE_PORT );
lteiot14_send_cmd_par ( <eiot14, LTEIOT14_CMD_OPEN_TCP_UDP_CONNECTION, cmd_buf );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
log_printf( &logger, ">>> Set UDP ID.\r\n" );
#define UDP_CID "2"
lteiot14_send_cmd_par ( <eiot14, LTEIOT14_CMD_SET_TCP_UDP_ID, UDP_CID );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
log_printf( &logger, ">>> Open UDP connection.\r\n" );
#define UDP_CONN_TYPE "UDP"
strcpy( cmd_buf, UDP_CID );
strcat( cmd_buf, "," );
strcat( cmd_buf, PDP_CID );
strcat( cmd_buf, ",\"" );
strcat( cmd_buf, UDP_CONN_TYPE );
strcat( cmd_buf, "\",\"" );
strcat( cmd_buf, REMOTE_IP );
strcat( cmd_buf, "\"," );
strcat( cmd_buf, REMOTE_PORT );
lteiot14_send_cmd_par ( <eiot14, LTEIOT14_CMD_OPEN_TCP_UDP_CONNECTION, cmd_buf );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
// Get message length
uint8_t message_len_buf[ 5 ] = { 0 };
uint16_t message_len = strlen( MESSAGE_CONTENT );
uint16_to_str( message_len, message_len_buf );
l_trim( message_len_buf );
r_trim( message_len_buf );
log_printf( &logger, ">>> Write message to TCP connection.\r\n" );
strcpy( cmd_buf, TCP_CID );
strcat( cmd_buf, "," );
strcat( cmd_buf, message_len_buf );
lteiot14_send_cmd_par ( <eiot14, LTEIOT14_CMD_SEND_DATA_VIA_CONNECTION, cmd_buf );
Delay_ms ( 100 );
lteiot14_generic_write ( <eiot14, MESSAGE_CONTENT, message_len );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_URC_RECEIVED_DATA );
log_printf( &logger, ">>> Read response from TCP connection.\r\n" );
lteiot14_send_cmd_par( <eiot14, LTEIOT14_CMD_RECEIVE_DATA_VIA_CONNECTION, cmd_buf );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
log_printf( &logger, ">>> Write message to UDP connection.\r\n" );
strcpy( cmd_buf, UDP_CID );
strcat( cmd_buf, "," );
strcat( cmd_buf, message_len_buf );
lteiot14_send_cmd_par ( <eiot14, LTEIOT14_CMD_SEND_DATA_VIA_CONNECTION, cmd_buf );
Delay_ms ( 100 );
lteiot14_generic_write ( <eiot14, MESSAGE_CONTENT, message_len );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_URC_RECEIVED_DATA );
log_printf( &logger, ">>> Read response from UDP connection.\r\n" );
lteiot14_send_cmd_par( <eiot14, LTEIOT14_CMD_RECEIVE_DATA_VIA_CONNECTION, cmd_buf );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
log_printf( &logger, ">>> Close TCP connection.\r\n" );
lteiot14_send_cmd_par ( <eiot14, LTEIOT14_CMD_CLOSE_TCP_UDP_CONNECTION, TCP_CID );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
log_printf( &logger, ">>> Close UDP connection.\r\n" );
lteiot14_send_cmd_par ( <eiot14, LTEIOT14_CMD_CLOSE_TCP_UDP_CONNECTION, UDP_CID );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
// Check SMS mode
#define CMGF_PDU "+CMGF: 0"
#define CMGF_TXT "+CMGF: 1"
lteiot14_send_cmd_check( <eiot14, LTEIOT14_CMD_SELECT_SMS_FORMAT );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
if ( strstr( app_buf, CMGF_PDU ) )
{
// Send SMS in PDU mode
lteiot14_send_sms_pdu( <eiot14, SIM_SMSC, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
}
else if ( strstr( app_buf, CMGF_TXT ) )
{
// Send SMS in TXT mode
lteiot14_send_sms_text ( <eiot14, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
}
// 30 seconds delay
for ( uint8_t delay_cnt = 0; delay_cnt < 30; delay_cnt++ )
{
Delay_ms ( 1000 );
}
#elif ( DEMO_EXAMPLE == EXAMPLE_GNSS )
log_printf( &logger, ">>> Get GNSS info.\r\n" );
lteiot14_send_cmd ( <eiot14, LTEIOT14_CMD_GET_GNSS_INFO );
error_flag |= lteiot14_read_response( ctx, LTEIOT14_RSP_OK );
Delay_ms ( 1000 );
#else
#error "No demo example selected"
#endif
return error_flag;
}
// ------------------------------------------------------------------------ END