高级
30 分钟

使用 GM02S 和 STM32F031K6 实现全球覆盖的 LTE-M 和 NB-IoT 连接

适用于全球部署的双模 LTE-M/NB-IoT 解决方案

LTE IoT 10 Click with Nucleo 32 with STM32F031K6 MCU

已发布 3月 05, 2025

点击板

LTE IoT 10 Click

开发板

Nucleo 32 with STM32F031K6 MCU

编译器

NECTO Studio

微控制器单元

STM32F031K6

LTE-M 和 NB-IoT 连接,支持全球频段,完美适用于智能计量、资产追踪和工业物联网应用

A

A

硬件概览

它是如何工作的?

LTE IoT 10 Click 基于 Sequans 的 Monarch 2 GM02S 模块,专为提供可靠的 LTE-M 和 NB-IoT 连接而设计。GM02S 是一款高度优化的双模 LTE-M 和 NB-IoT 解决方案,支持全球频段,覆盖 617MHz 至 2.2GHz(频段 1、2、3、4、5、8、12、13、14、17、18、19、20、25、26、28、66、85),兼容全球公共和私有 LTE 网络。该板可用于连接 LTE 现网或测试设备(如 CMW500)。该模块基于 Sequans 的第二代 Monarch 2 芯片平台(Sequans SQN3430 芯片组),具备卓越的性能,极低的功耗(深度睡眠模式下仅 1μA,支持最佳 eDRX 和 PSM),并提供强大的安全性,是智能计量、工业传感器、资产追踪系统、智能家居与智慧城市应用、可穿戴设备及医疗监测解决方案等低功耗、高可靠性工业与商业物联网应用的理想选择。GM02S 模块利用 Sequans 15 年以上的 4G+ 连接经验,搭载成熟、获得运营商认证的 LTE 协议栈,确保无缝的网络集成。其 Single-SKU™ 射频前端可在全球 LTE 频段运行,无需进行区域化调整,从而简化部署。GM02S 具有 +23dBm 的发射功率,确保在各种复杂环境下提供强大且稳定

的连接。此外,该模块符合 3GPP LTE Release 14 标准,并具备未来升级至 Release 17 的潜力,确保长期兼容性。GM02S 模块的一大优势是能够在 LTE-M 和 NB-IoT 模式(Cat M1、NB1、NB2)之间自由切换,且仅需单一固件镜像,从而在不同物联网应用中提供卓越的灵活性。该模块还集成了嵌入式 IP 协议栈,支持 TCP(TLS 1.3)、UDP(DTLS 1.2)、CoAP/MQTT、HTTP/FTP 等协议,确保安全的数据通信。GM02S 与主控 MCU 之间通过 UART 接口进行通信,使用标准 UART RX 和 TX 引脚,并提供硬件流控制引脚(CTS/RTS/RI - 清除发送/准备发送/振铃指示),默认通信速率为 115200bps。该板背面设有 UBOOT 固件升级开关,提供 0(正常运行)和 1(固件升级)两种模式,确保固件升级过程简单高效。此外,该板还配备用于调试和模块升级的 DBG 测试点,并包含 JTAG 接口引脚,可用于电路板设计验证和测试。LTE IoT 10 Click 还具备多个增强功能,以提高可用性和控制能力。WAKE 按钮可唤醒模块退出睡眠模式,而 RESET 按钮可快速复位模块。此外,WKP 和 RST 引脚可通过 mikroBUS™ 进行数

字控制,提供更大的灵活性,同时这些控制信号还提供了专用测试点,方便调试和测试。该板还包括多个 LED 指示灯以提供实时状态更新。其中红色 PMS LED 用于指示省电状态,显示模块的低功耗运行模式;黄色 STAT LED 则指示模块的电源状态,确保实时监测其运行情况。LTE IoT 10 Click 采用一个 SMA 接口连接主要 LTE 天线,MIKROE 提供 LTE Flat Rotation Antenna 或 LTE Rubber Antenna 等选项,以实现灵活高效的网络连接。该板还配备一个微型 SIM 卡插槽,支持 1.8V uSIM 卡,确保兼容多种蜂窝网络,使用户能够根据具体应用选择最合适的服务提供商。该 Click board™ 可在 3.3V 和 5V 逻辑电压水平下工作,通过 VCC SEL 跳线进行选择。由于 GM02S 模块的通信电压为 1.8V,因此该板采用 TXB0106 和 PCA9306 逻辑电平转换器,确保信号转换的准确性,使 3.3V 和 5V 兼容的 MCU 均能正常使用通信线路。此外,该 Click board™ 配备了包含易于使用的函数库和示例代码,可作为进一步开发的参考。

LTE IoT 10 Click hardware overview image

功能概述

开发板

Nucleo 32开发板搭载STM32F031K6 MCU,提供了一种经济且灵活的平台,适用于使用32引脚封装的STM32微控制器进行实验。该开发板具有Arduino™ Nano连接性,便于通过专用扩展板进行功能扩展,并且支持mbed,使其能够无缝集成在线资源。板载集成

ST-LINK/V2-1调试器/编程器,支持通过USB重新枚举,提供三种接口:虚拟串口(Virtual Com port)、大容量存储和调试端口。该开发板的电源供应灵活,可通过USB VBUS或外部电源供电。此外,还配备了三个LED指示灯(LD1用于USB通信,LD2用于电源

指示,LD3为用户可控LED)和一个复位按钮。STM32 Nucleo-32开发板支持多种集成开发环境(IDEs),如IAR™、Keil®和基于GCC的IDE(如AC6 SW4STM32),使其成为开发人员的多功能工具。

Nucleo 32 with STM32F031K6 MCU double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

ARM Cortex-M0

MCU 内存 (KB)

32

硅供应商

STMicroelectronics

引脚数

32

RAM (字节)

4096

你完善了我!

配件

Click Shield for Nucleo-32是扩展您的开发板功能的理想选择,专为STM32 Nucleo-32引脚布局设计。Click Shield for Nucleo-32提供了两个mikroBUS™插座,可以添加来自我们不断增长的Click板™系列中的任何功能。从传感器和WiFi收发器到电机控制和音频放大器,我们应有尽有。Click Shield for Nucleo-32与STM32 Nucleo-32开发板兼容,为用户提供了一种经济且灵活的方式,使用任何STM32微控制器快速创建原型,并尝试各种性能、功耗和功能的组合。STM32 Nucleo-32开发板无需任何独立的探针,因为它集成了ST-LINK/V2-1调试器/编程器,并随附STM32全面的软件HAL库和各种打包的软件示例。这个开发平台为用户提供了一种简便且通用的方式,将STM32 Nucleo-32兼容开发板与他们喜欢的Click板™结合,应用于即将开展的项目中。

Click Shield for Nucleo-32 accessories 1 image

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

LTE IoT 10 Click accessories 1 image

这款多频段 LTE 橡胶天线具有可调角度,是所有基于 3G/4G LTE 的 Click boards™ 的理想选择,也适用于其他需要在全球主要蜂窝频段上获得卓越吞吐量的设备。天线配备 SMA 公头连接器,可以直接安装在 Click board™ 或 SMA 母头模块连接器上。天线位置可按 45° 增量调节(0°/45°/90°),提供灵活的安装选项,以实现最佳信号接收和设备性能。

LTE IoT 10 Click accessories 2 image

使用的MCU引脚

mikroBUS™映射器

Module Wake-Up
PA0
AN
Reset / ID SEL
PA11
RST
UART RTS / ID COMM
PA4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Ring Indicator
PA8
PWM
UART CTS
PA12
INT
UART TX
PA10
TX
UART RX
PA9
RX
I2C Clock
PB6
SCL
I2C Data
PB7
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

LTE IoT 10 Click Schematic schematic

一步一步来

项目组装

Click Shield for Nucleo-144 front image hardware assembly

从选择您的开发板和Click板™开始。以Nucleo 32 with STM32F031K6 MCU作为您的开发板开始。

Click Shield for Nucleo-144 front image hardware assembly
Nucleo 144 with STM32L4A6ZG MCU front image hardware assembly
Stepper 22 Click front image hardware assembly
Prog-cut hardware assembly
Stepper 22 Click complete accessories setup image hardware assembly
Nucleo-32 with STM32 MCU Access MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
STM32 M4 Clicker HA MCU/Select Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

实时跟踪您的结果

应用程序输出

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 10 Click 演示应用程序使用 NECTO Studio开发,确保与 mikroSDK 的开源库和工具兼容。该演示设计为即插即用,可与所有具有 mikroBUS™ 插座的 开发板、入门板和 mikromedia 板完全兼容,用于快速实现和测试。

示例描述
该应用示例展示了设备通过标准 "AT" 指令连接网络并发送 SMS 或 TCP/UDP 消息的能力。

关键功能:

  • lteiot10_cfg_setup - 初始化 Click 配置结构为默认值。

  • lteiot10_init - 初始化该 Click 板所需的所有引脚和外设。

  • lteiot10_set_sim_apn - 为 SIM 卡设置 APN。

  • lteiot10_send_sms_text - 发送文本消息到指定手机号码。

  • lteiot10_cmd_set - 设置 Click 模块的特定 AT 指令参数值。

应用初始化
初始化驱动程序和日志记录模块。

应用任务
该任务分为多个阶段执行:

  • LTEIOT10_POWER_UP: 启动设备,执行工厂复位并读取系统信息。

  • LTEIOT10_CONFIG_CONNECTION: 配置设备以连接到网络。

  • LTEIOT10_CHECK_CONNECTION: 等待 CEREG 指令指示的网络注册完成,然后检查信号质量报告。

  • LTEIOT10_CONFIG_EXAMPLE: 根据选择的示例配置设备。

  • LTEIOT10_EXAMPLE: 根据选定的演示示例,发送 SMS(PDU 或 TXT 模式)或 TCP/UDP 消息。默认选择 TCP/UDP 示例。

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * @file main.c
 * @brief LTE IoT 10 Click Example.
 *
 * # Description
 * Application example shows device capability of connecting to the network and
 * sending SMS or TCP/UDP messages 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:
 *  - LTEIOT10_POWER_UP:
 * Powers up the device, performs a device factory reset and reads system information.
 *
 *  - LTEIOT10_CONFIG_CONNECTION:
 * Sets configuration to device to be able to connect to the network.
 *
 *  - LTEIOT10_CHECK_CONNECTION:
 * Waits for the network registration indicated via CEREG command and then checks the signal quality report.
 *
 *  - LTEIOT10_CONFIG_EXAMPLE:
 * Configures device for the selected example.
 *
 *  - LTEIOT10_EXAMPLE:
 * Depending on the selected demo example, it sends an SMS message (in PDU or TXT mode) or TCP/UDP message.
 *
 * By default, the TCP/UDP example is selected.
 *
 * ## Additional Function
 * - static void lteiot10_clear_app_buf ( void )
 * - static void lteiot10_log_app_buf ( void )
 * - static err_t lteiot10_process ( lteiot10_t *ctx )
 * - static err_t lteiot10_read_response ( lteiot10_t *ctx, uint8_t *rsp )
 * - static err_t lteiot10_power_up ( lteiot10_t *ctx )
 * - static err_t lteiot10_config_connection ( lteiot10_t *ctx )
 * - static err_t lteiot10_check_connection ( lteiot10_t *ctx )
 * - static err_t lteiot10_config_example ( lteiot10_t *ctx )
 * - static err_t lteiot10_example ( lteiot10_t *ctx )
 *
 * @note
 * In order for the examples to work, 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.
 * Example:
    SIM_APN "internet"
    SIM_SMSC "+381610401"
    PHONE_NUMBER "+381659999999"
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "lteiot10.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 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                        ""              // 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 10 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
{
    LTEIOT10_POWER_UP = 1,
    LTEIOT10_CONFIG_CONNECTION,
    LTEIOT10_CHECK_CONNECTION,
    LTEIOT10_CONFIG_EXAMPLE,
    LTEIOT10_EXAMPLE

} lteiot10_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 lteiot10_app_state_t app_state = LTEIOT10_POWER_UP;

static lteiot10_t lteiot10;
static log_t logger;

/**
 * @brief LTE IoT 10 clearing application buffer.
 * @details This function clears memory of application buffer and reset its length.
 * @note None.
 */
static void lteiot10_clear_app_buf ( void );

/**
 * @brief LTE IoT 10 log application buffer.
 * @details This function logs data from application buffer to USB UART.
 * @note None.
 */
static void lteiot10_log_app_buf ( void );

/**
 * @brief LTE IoT 10 data reading function.
 * @details This function reads data from device and concatenates data to application buffer. 
 * @param[in] ctx : Click context object.
 * See #lteiot10_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 lteiot10_process ( lteiot10_t *ctx );

/**
 * @brief LTE IoT 10 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 #lteiot10_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.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t lteiot10_read_response ( lteiot10_t *ctx, uint8_t *rsp );

/**
 * @brief LTE IoT 10 power up function.
 * @details This function powers up the device, performs device factory reset and reads system information.
 * @param[in] ctx : Click context object.
 * See #lteiot10_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 lteiot10_power_up ( lteiot10_t *ctx );

/**
 * @brief LTE IoT 10 config connection function.
 * @details This function configures and enables connection to the specified network.
 * @param[in] ctx : Click context object.
 * See #lteiot10_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 lteiot10_config_connection ( lteiot10_t *ctx );

/**
 * @brief LTE IoT 10 check connection function.
 * @details This function checks the connection to network.
 * @param[in] ctx : Click context object.
 * See #lteiot10_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 lteiot10_check_connection ( lteiot10_t *ctx );

/**
 * @brief LTE IoT 10 config example function.
 * @details This function configures device for the selected example.
 * @param[in] ctx : Click context object.
 * See #lteiot10_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 lteiot10_config_example ( lteiot10_t *ctx );

/**
 * @brief LTE IoT 10 example function.
 * @details This function executes SMS or TCP/UDP example depending on the DEMO_EXAMPLE macro.
 * @param[in] ctx : Click context object.
 * See #lteiot10_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 lteiot10_example ( lteiot10_t *ctx );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    lteiot10_cfg_t lteiot10_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.
    lteiot10_cfg_setup( &lteiot10_cfg );
    LTEIOT10_MAP_MIKROBUS( lteiot10_cfg, MIKROBUS_1 );
    if ( UART_ERROR == lteiot10_init( &lteiot10, &lteiot10_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );

    app_state = LTEIOT10_POWER_UP;
    log_printf( &logger, ">>> APP STATE - POWER UP <<<\r\n\n" );
}

void application_task ( void ) 
{
    switch ( app_state )
    {
        case LTEIOT10_POWER_UP:
        {
            if ( LTEIOT10_OK == lteiot10_power_up( &lteiot10 ) )
            {
                app_state = LTEIOT10_CONFIG_CONNECTION;
                log_printf( &logger, ">>> APP STATE - CONFIG CONNECTION <<<\r\n\n" );
            }
            break;
        }
        case LTEIOT10_CONFIG_CONNECTION:
        {
            if ( LTEIOT10_OK == lteiot10_config_connection( &lteiot10 ) )
            {
                app_state = LTEIOT10_CHECK_CONNECTION;
                log_printf( &logger, ">>> APP STATE - CHECK CONNECTION <<<\r\n\n" );
            }
            break;
        }
        case LTEIOT10_CHECK_CONNECTION:
        {
            if ( LTEIOT10_OK == lteiot10_check_connection( &lteiot10 ) )
            {
                app_state = LTEIOT10_CONFIG_EXAMPLE;
                log_printf( &logger, ">>> APP STATE - CONFIG EXAMPLE <<<\r\n\n" );
            }
            break;
        }
        case LTEIOT10_CONFIG_EXAMPLE:
        {
            if ( LTEIOT10_OK == lteiot10_config_example( &lteiot10 ) )
            {
                app_state = LTEIOT10_EXAMPLE;
                log_printf( &logger, ">>> APP STATE - EXAMPLE <<<\r\n\n" );
            }
            break;
        }
        case LTEIOT10_EXAMPLE:
        {
            lteiot10_example( &lteiot10 );
            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 lteiot10_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static void lteiot10_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 lteiot10_process ( lteiot10_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t overflow_bytes = 0;
    int32_t rx_cnt = 0;
    int32_t rx_size = lteiot10_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 LTEIOT10_OK;
    }
    return LTEIOT10_ERROR;
}

static err_t lteiot10_read_response ( lteiot10_t *ctx, uint8_t *rsp ) 
{
    #define READ_RESPONSE_TIMEOUT_MS    120000
    uint32_t timeout_cnt = 0;
    lteiot10_clear_app_buf( );
    lteiot10_process( ctx );
    while ( ( 0 == strstr( app_buf, rsp ) ) &&
            ( 0 == strstr( app_buf, LTEIOT10_RSP_ERROR ) ) )
    {
        lteiot10_process( ctx );
        if ( timeout_cnt++ > READ_RESPONSE_TIMEOUT_MS )
        {
            lteiot10_log_app_buf( );
            lteiot10_clear_app_buf( );
            log_error( &logger, " Timeout!" );
            return LTEIOT10_ERROR_TIMEOUT;
        }
        Delay_ms( 1 );
    }
    Delay_ms ( 200 );
    lteiot10_process( ctx );
    lteiot10_log_app_buf( );
    if ( strstr( app_buf, rsp ) )
    {
        log_printf( &logger, "--------------------------------\r\n" );
        return LTEIOT10_OK;
    }
    return LTEIOT10_ERROR_CMD;
}

static err_t lteiot10_power_up ( lteiot10_t *ctx )
{
    err_t error_flag = LTEIOT10_OK;
    
    log_printf( &logger, ">>> HW reset device.\r\n" );
    lteiot10_reset_device( ctx );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_URC_READY );

    log_printf( &logger, ">>> Check communication.\r\n" );
    lteiot10_cmd_run( ctx, LTEIOT10_CMD_AT );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );

    log_printf( &logger, ">>> Factory reset.\r\n" );
    lteiot10_cmd_run( ctx, LTEIOT10_CMD_FACTORY_RESET );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );

    log_printf( &logger, ">>> SW reset device.\r\n" );
    lteiot10_cmd_run( ctx, LTEIOT10_CMD_HARD_RESET );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_URC_READY );

    log_printf( &logger, ">>> Enable command echo.\r\n" );
    lteiot10_cmd_run( ctx, LTEIOT10_CMD_ENABLE_ECHO );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );

    log_printf( &logger, ">>> Get device model ID.\r\n" );
    lteiot10_cmd_run( ctx, LTEIOT10_CMD_GET_MODEL_ID );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );

    log_printf( &logger, ">>> Get device software version ID.\r\n" );
    lteiot10_cmd_run( ctx, LTEIOT10_CMD_GET_SW_VERSION );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );

    log_printf( &logger, ">>> Get device serial number.\r\n" );
    lteiot10_cmd_run( ctx, LTEIOT10_CMD_GET_SERIAL_NUM );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );

    return error_flag;
}

static err_t lteiot10_config_connection ( lteiot10_t *ctx )
{
    err_t error_flag = LTEIOT10_OK;
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
    log_printf( &logger, ">>> Set SIM APN.\r\n" );
    lteiot10_set_sim_apn( &lteiot10, SIM_APN );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );
    
    log_printf( &logger, ">>> Enable full functionality.\r\n" );
    #define FULL_FUNCTIONALITY "1"
    lteiot10_cmd_set( ctx, LTEIOT10_CMD_SET_PHONE_FUNCTIONALITY, FULL_FUNCTIONALITY );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );

    log_printf( &logger, ">>> Enable network registration.\r\n" );
    #define ENABLE_REG "2"
    lteiot10_cmd_set( ctx, LTEIOT10_CMD_NETWORK_REGISTRATION, ENABLE_REG );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );

    log_printf( &logger, ">>> Set automatic registration.\r\n" );
    #define AUTOMATIC_REGISTRATION "0"
    lteiot10_cmd_set( ctx, LTEIOT10_CMD_OPERATOR_SELECTION, AUTOMATIC_REGISTRATION );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );
#endif
    return error_flag;
}

static err_t lteiot10_check_connection ( lteiot10_t *ctx )
{
    err_t error_flag = LTEIOT10_OK;
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
    log_printf( &logger, ">>> Check network registration.\r\n" );
    #define CONNECTED "+CEREG: 2,1"
    lteiot10_cmd_get( &lteiot10, LTEIOT10_CMD_NETWORK_REGISTRATION );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );
    if ( strstr( app_buf, CONNECTED ) )
    {
        Delay_ms ( 1000 );
        log_printf( &logger, ">>> Check signal quality.\r\n" );
        lteiot10_cmd_run( &lteiot10, LTEIOT10_CMD_SIGNAL_QUALITY_REPORT );
        error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );
    }
    else
    {
        error_flag = LTEIOT10_ERROR;
        Delay_ms ( 1000 );
        Delay_ms ( 1000 );
    }
#endif
    return error_flag;
}

static err_t lteiot10_config_example ( lteiot10_t *ctx )
{
    err_t error_flag = LTEIOT10_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
    log_printf( &logger, ">>> Activate PDP context.\r\n" );
    #define ACTIVATE_PDP_CONTEXT "1,1"
    lteiot10_cmd_set( &lteiot10, LTEIOT10_CMD_ACTIVATE_PDP_CONTEXT, ACTIVATE_PDP_CONTEXT );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );

    log_printf( &logger, ">>> Show PDP address.\r\n" );
    #define PDP_CID "1"
    lteiot10_cmd_set( &lteiot10, LTEIOT10_CMD_SHOW_PDP_ADDRESS, PDP_CID );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
    log_printf( &logger, ">>> Select SMS format.\r\n" );
    lteiot10_cmd_set( &lteiot10, LTEIOT10_CMD_SELECT_SMS_FORMAT, SMS_MODE );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );
#endif
    return error_flag;
}

static err_t lteiot10_example ( lteiot10_t *ctx )
{
    err_t error_flag = LTEIOT10_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
    uint8_t cmd_buf[ 100 ] = { 0 };
    uint8_t ctrl_z = 0x1A;
    
    log_printf( &logger, ">>> Open TCP connection.\r\n" );
    #define TCP_LINK_NUM "1"
    #define TCP_CONN_TYPE "0"
    strcpy( cmd_buf, TCP_LINK_NUM );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, TCP_CONN_TYPE );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, REMOTE_PORT );
    strcat( cmd_buf, ",\"" );
    strcat( cmd_buf, REMOTE_IP );
    strcat( cmd_buf, "\",0,0,1" ); // Closure type, local port, and connection mode CMD.
    lteiot10_cmd_set( &lteiot10, LTEIOT10_CMD_OPEN_TCP_UDP_CONNECTION, cmd_buf );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );

    log_printf( &logger, ">>> Open UDP connection.\r\n" );
    #define UDP_LINK_NUM "2"
    #define UDP_CONN_TYPE "1"
    strcpy( cmd_buf, UDP_LINK_NUM );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, UDP_CONN_TYPE );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, REMOTE_PORT );
    strcat( cmd_buf, ",\"" );
    strcat( cmd_buf, REMOTE_IP );
    strcat( cmd_buf, "\",0,5000,1" ); // Closure type, local port, and connection mode CMD.
    lteiot10_cmd_set( &lteiot10, LTEIOT10_CMD_OPEN_TCP_UDP_CONNECTION, cmd_buf );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );

    // Get message length
    uint8_t message_len_buf[ 10 ] = { 0 };
    uint16_t message_len = strlen( MESSAGE_CONTENT );
    uint16_to_str( message_len, message_len_buf );
    l_trim( message_len_buf );
    r_trim( message_len_buf );

    log_printf( &logger, ">>> Write message to TCP connection.\r\n" );
    strcpy( cmd_buf, TCP_LINK_NUM );
    lteiot10_cmd_set( &lteiot10, LTEIOT10_CMD_SEND_DATA_VIA_CONNECTION, cmd_buf );
    Delay_ms ( 100 );
    lteiot10_generic_write ( &lteiot10, MESSAGE_CONTENT, message_len );
    lteiot10_generic_write ( &lteiot10, &ctrl_z, 1 );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_URC_RECEIVED_DATA );
    log_printf( &logger, ">>> Read response from TCP connection.\r\n" );
    strcpy( cmd_buf, TCP_LINK_NUM );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, message_len_buf );
    lteiot10_cmd_set( &lteiot10, LTEIOT10_CMD_RECEIVE_DATA_VIA_CONNECTION, cmd_buf );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );

    log_printf( &logger, ">>> Write message to UDP connection.\r\n" );
    strcpy( cmd_buf, UDP_LINK_NUM );
    lteiot10_cmd_set( &lteiot10, LTEIOT10_CMD_SEND_DATA_VIA_CONNECTION, cmd_buf );
    Delay_ms ( 100 );
    lteiot10_generic_write ( &lteiot10, MESSAGE_CONTENT, message_len );
    lteiot10_generic_write ( &lteiot10, &ctrl_z, 1 );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_URC_RECEIVED_DATA );
    log_printf( &logger, ">>> Read response from UDP connection.\r\n" );
    strcpy( cmd_buf, UDP_LINK_NUM );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, message_len_buf );
    lteiot10_cmd_set( &lteiot10, LTEIOT10_CMD_RECEIVE_DATA_VIA_CONNECTION, cmd_buf );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );
    
    log_printf( &logger, ">>> Close TCP connection.\r\n" );
    lteiot10_cmd_set( &lteiot10, LTEIOT10_CMD_CLOSE_TCP_UDP_CONNECTION, TCP_LINK_NUM );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );
    
    log_printf( &logger, ">>> Close UDP connection.\r\n" );
    lteiot10_cmd_set( &lteiot10, LTEIOT10_CMD_CLOSE_TCP_UDP_CONNECTION, UDP_LINK_NUM );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_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"
    log_printf( &logger, ">>> Check SMS format.\r\n" );
    lteiot10_cmd_get( &lteiot10, LTEIOT10_CMD_SELECT_SMS_FORMAT );
    error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );
    if ( strstr( app_buf, CMGF_PDU ) )
    {
        // Send SMS in PDU mode
        log_printf( &logger, ">>> Send SMS in PDU mode.\r\n" );
        lteiot10_send_sms_pdu( &lteiot10, SIM_SMSC, PHONE_NUMBER, MESSAGE_CONTENT );
        error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );
    }
    else if ( strstr( app_buf, CMGF_TXT ) )
    {
        // Send SMS in TXT mode
        log_printf( &logger, ">>> Send SMS in TXT mode.\r\n" );
        lteiot10_send_sms_text ( &lteiot10, PHONE_NUMBER, MESSAGE_CONTENT );
        error_flag |= lteiot10_read_response( ctx, LTEIOT10_RSP_OK );
    }
    // 30 seconds delay
    for ( uint8_t delay_cnt = 0; delay_cnt < 30; delay_cnt++ )
    {
        Delay_ms ( 1000 );
    }
#else
    #error "No demo example selected"
#endif
    return error_flag;
}

// ------------------------------------------------------------------------ END

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。