高级
30 分钟

使用SIM7070E和STM32F302VC为您的M2M项目提供LTE网络上的无线通信

适用于欧洲/澳大利亚地区的Cat-M、Cat-NB和GSM多频段LTE解决方案

LTE IoT 17 Click with CLICKER 4 for STM32F302VCT6

已发布 7月 22, 2025

点击板

LTE IoT 17 Click

开发板

CLICKER 4 for STM32F302VCT6

编译器

NECTO Studio

微控制器单元

STM32F302VC

低功耗、长距离蜂窝连接,支持多频段 LTE 和 GNSS,适用于资产追踪、计量和远程监控

A

A

硬件概览

它是如何工作的?

LTE IoT 17 Click基于SIMCom的多频段LTE模块SIM7070E,适用于欧洲和澳大利亚地区。SIM7070E支持Cat-M/Cat-NB/GPRS/EDGE无线通信模式,内置多个网络协议,最大下行速率为0.589Mbps,最大上行速率为1.119Mbps。此外,它还支持多个Cat-M频段(B1/B2/B3/B4/B5/B8/B12/B13/B14/B18/B19/B20/B
25/B26/B27/B28/B31/B66/B72/B85)、Cat-NB频段(B1/B2/B3/B4/B5/B8/B12/B13/B18/B19/B20/B25/
B26/B28/B31/B66/B85),以及850/900/1800/1900MHz的GSM频段,并提供可选的多星座GNSS支持。凭借其广泛的功能,此Click板™非常适合需要低延迟、低吞吐量数据通信的M2M应用,例如计量、资产追踪、远程监控、电子健康等。SIM7070E与主机MCU之间的通信通过UART接口实现,使用标准的UART RX和TX引脚以及硬件流控制引脚(CTS/RTS/RI - Clear to Send/Ready to Send/Ring Indicator),确保高效的数据传输。模块的默认通信速度为115200bps,支持通过AT命令进行无缝数据交换。该板还配备了模块家族支持的音频接口所需的所有组件和电路。然而,在当前版本中,板上的模块并不支持音频接口,因此这些组件未焊接至

板上。在音频接口的情况下,模块的音频接口通过I2C接口配置的NAU88C10单声道音频语音编解码器工作。这一配置与板背面的CTIA标准耳机插孔配合使用,CTIA耳机通常用于现代智能手机,集成了音频和麦克风连接器。这一标准确保了与广泛的耳机和耳麦兼容。此Click板™还包括一个USB Type C接口,既可用于电源供应也可用于数据传输,符合USB 2.0规范(仅限外围设备)。此外,板上还有一个USB固件升级开关,位于板背面,标为USB BOOT,用于管理固件升级。开关有两个位置:0表示正常操作,1表示通过USB进行固件升级,确保了简单的升级流程。LTE IoT 17 Click还包括几个增强其可用性和控制功能的附加功能。PWR按钮允许用户轻松打开或关闭模块电源。此功能还可通过PWR mikroBUS™引脚进行数字控制,提供更大的灵活性。此外,板上还设有专用测试点(TP1和TP2用于DBG_UART),便于调试和测试,并配备两个视觉指示灯,提供实时状态更新。第一个红色的NET LED指示模块的当前网络状态。当LED缓慢闪烁时(64ms亮,3000ms灭),表示设备已成功注册到网络的PS域。如果LED以正常速度闪烁(64ms亮,800ms灭),则表示设备尚未注册到网络。快速闪烁(64ms亮,300ms灭)表示数据传输正

在进行,例如PPP拨号连接或使用数据服务(如内部TCP、FTP或HTTP)时。当LED完全熄灭时,表示设备已关闭或处于省电模式(PSM)。第二个黄色STAT LED指示模块的电源状态,当模块关闭时,LED熄灭,当模块开启或固件准备就绪时,LED亮起。该板具有两个u.Fl连接器,用于主LTE和可选的GNSS天线,MIKROE提供了LTE扁平旋转天线和主动GPS天线,可与IPEX-SMA电缆结合,提供灵活且高效的连接选项。此外,用户还可以通过选择板背面的GNSS ANT跳线轻松选择可选GNSS天线的电源供应(3.3V或5V)。该板还具有一个micro SIM卡槽,仅支持1.8V的uSIM卡,允许用户选择最适合其特定使用场景的服务提供商。此Click板™可以在3.3V和5V逻辑电压水平下工作,通过VCC SEL跳线选择合适的电压。由于SIM7070E模块在3.8V下工作,因此还使用了逻辑电平转换器TXB0106和PCA9306,确保正常操作和准确的信号电平转换。这样,3.3V和5V的MCU都能正确使用通信线路。此外,此Click板™还附带了一个库,包含易于使用的功能和示例代码,可作为进一步开发的参考。

LTE IoT 17 Click hardware overview image

功能概述

开发板

Clicker 4 for STM32F3 是一款紧凑型开发板,作为完整的解决方案而设计,可帮助用户快速构建具备独特功能的定制设备。该板搭载 STMicroelectronics 的 STM32F302VCT6 微控制器,配备四个 mikroBUS™ 插槽用于连接 Click boards™、完善的电源管理功能以及其他实用资源,是快速开发各类应用的理想平台。其核心 MCU STM32F302VCT6 基于高性能 

Arm® Cortex®-M4 32 位处理器,运行频率高达 168MHz,处理能力强大,能够满足各种高复杂度任务的需求,使 Clicker 4 能灵活适应多种应用场景。除了两个 1x20 引脚排针外,板载最显著的连接特性是四个增强型 mikroBUS™ 插槽,支持接入数量庞大的 Click boards™ 生态系统,该生态每日持续扩展。Clicker 4 各功能区域标识清晰,界面直观简洁,极大

提升使用便捷性和开发效率。Clicker 4 的价值不仅在于加速原型开发与应用构建阶段,更在于其作为独立完整方案可直接集成至实际项目中,无需额外硬件修改。四角各设有直径 4.2mm(0.165")的安装孔,便于通过螺丝轻松固定。对于多数应用,只需配套一个外壳,即可将 Clicker 4 开发板转化为完整、实用且外观精美的定制系统。

CLICKER 4 for STM32F302VCT6 double image

微控制器概述 

MCU卡片 / MCU

STM32F302VC Image

建筑

ARM Cortex-M4

MCU 内存 (KB)

256

硅供应商

STMicroelectronics

引脚数

100

RAM (字节)

40960

你完善了我!

配件

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 17 Click accessories 1 image

使用的MCU引脚

mikroBUS™映射器

Module Power-ON
PC4
AN
ID SEL
PC15
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
PE9
PWM
UART CTS
PD0
INT
UART TX
PA2
TX
UART RX
PA3
RX
I2C Clock
PB10
SCL
I2C Data
PB11
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

LTE IoT 17 Click Schematic schematic

一步一步来

项目组装

PIC32MZ MXS Data Capture Board front image hardware assembly

从选择您的开发板和Click板™开始。以CLICKER 4 for STM32F302VCT6作为您的开发板开始。

PIC32MZ MXS Data Capture Board front image hardware assembly
Thermo 21 Click front image hardware assembly
Thermo 21 Click complete accessories setup image hardware assembly
Board mapper by product6 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
PIC32MZ MXS Data Capture Board NECTO MCU Selection Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto image step 11 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 Click 驱动程序的 API。

关键功能:

  • lteiot17_set_sim_apn - 此函数设置 SIM 卡的接入点名称(APN)。

  • lteiot17_send_sms_text - 此函数向指定电话号码发送短信。

  • lteiot17_send_cmd - 此函数向 Click 模块发送指定命令。

开源

代码示例

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

/*!
 * @file main.c
 * @brief LTE IoT 17 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:
 *  - LTEIOT17_POWER_UP:
 * Powers up the device, performs a device factory reset and reads system information.
 *
 *  - LTEIOT17_CONFIG_CONNECTION:
 * Sets configuration to device to be able to connect to the network.
 *
 *  - LTEIOT17_CHECK_CONNECTION:
 * Waits for the network registration indicated via CREG command and then checks the signal quality report.
 *
 *  - LTEIOT17_CONFIG_EXAMPLE:
 * Configures device for the selected example.
 *
 *  - LTEIOT17_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 lteiot17_clear_app_buf ( void )
 * - static void lteiot17_log_app_buf ( void )
 * - static err_t lteiot17_process ( lteiot17_t *ctx )
 * - static err_t lteiot17_read_response ( lteiot17_t *ctx, uint8_t *rsp )
 * - static err_t lteiot17_power_up ( lteiot17_t *ctx )
 * - static err_t lteiot17_config_connection ( lteiot17_t *ctx )
 * - static err_t lteiot17_check_connection ( lteiot17_t *ctx )
 * - static err_t lteiot17_config_example ( lteiot17_t *ctx )
 * - static err_t lteiot17_example ( lteiot17_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_TO_MESSAGE.
 * Example:
    SIM_APN "internet"
    SIM_SMSC "+381610401"
    PHONE_NUMBER_TO_MESSAGE "+381659999999"
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "lteiot17.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_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 17 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
{
    LTEIOT17_POWER_UP = 1,
    LTEIOT17_CONFIG_CONNECTION,
    LTEIOT17_CHECK_CONNECTION,
    LTEIOT17_CONFIG_EXAMPLE,
    LTEIOT17_EXAMPLE

} lteiot17_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 lteiot17_app_state_t app_state = LTEIOT17_POWER_UP;

static lteiot17_t lteiot17;
static log_t logger;

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

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

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

/**
 * @brief LTE IoT 17 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 #lteiot17_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 lteiot17_read_response ( lteiot17_t *ctx, uint8_t *rsp );

/**
 * @brief LTE IoT 17 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 #lteiot17_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 lteiot17_power_up ( lteiot17_t *ctx );

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

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

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

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

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    lteiot17_cfg_t lteiot17_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.
    lteiot17_cfg_setup( &lteiot17_cfg );
    LTEIOT17_MAP_MIKROBUS( lteiot17_cfg, MIKROBUS_1 );
    if ( UART_ERROR == lteiot17_init( &lteiot17, &lteiot17_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );

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

void application_task ( void ) 
{
    switch ( app_state )
    {
        case LTEIOT17_POWER_UP:
        {
            if ( LTEIOT17_OK == lteiot17_power_up( &lteiot17 ) )
            {
                app_state = LTEIOT17_CONFIG_CONNECTION;
                log_printf( &logger, ">>> APP STATE - CONFIG CONNECTION <<<\r\n\n" );
            }
            break;
        }
        case LTEIOT17_CONFIG_CONNECTION:
        {
            if ( LTEIOT17_OK == lteiot17_config_connection( &lteiot17 ) )
            {
                app_state = LTEIOT17_CHECK_CONNECTION;
                log_printf( &logger, ">>> APP STATE - CHECK CONNECTION <<<\r\n\n" );
            }
            break;
        }
        case LTEIOT17_CHECK_CONNECTION:
        {
            if ( LTEIOT17_OK == lteiot17_check_connection( &lteiot17 ) )
            {
                app_state = LTEIOT17_CONFIG_EXAMPLE;
                log_printf( &logger, ">>> APP STATE - CONFIG EXAMPLE <<<\r\n\n" );
            }
            break;
        }
        case LTEIOT17_CONFIG_EXAMPLE:
        {
            if ( LTEIOT17_OK == lteiot17_config_example( &lteiot17 ) )
            {
                app_state = LTEIOT17_EXAMPLE;
                log_printf( &logger, ">>> APP STATE - EXAMPLE <<<\r\n\n" );
            }
            break;
        }
        case LTEIOT17_EXAMPLE:
        {
            lteiot17_example( &lteiot17 );
            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 lteiot17_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static void lteiot17_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 lteiot17_process ( lteiot17_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t overflow_bytes = 0;
    int32_t rx_cnt = 0;
    int32_t rx_size = lteiot17_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 LTEIOT17_OK;
    }
    return LTEIOT17_ERROR;
}

static err_t lteiot17_read_response ( lteiot17_t *ctx, uint8_t *rsp ) 
{
    #define READ_RESPONSE_TIMEOUT_MS    120000
    uint32_t timeout_cnt = 0;
    lteiot17_clear_app_buf ( );
    lteiot17_process( ctx );
    while ( ( 0 == strstr( app_buf, rsp ) ) &&
            ( 0 == strstr( app_buf, LTEIOT17_RSP_ERROR ) ) )
    {
        lteiot17_process( ctx );
        if ( timeout_cnt++ > READ_RESPONSE_TIMEOUT_MS )
        {
            lteiot17_clear_app_buf( );
            log_error( &logger, " Timeout!" );
            return LTEIOT17_ERROR_TIMEOUT;
        }
        Delay_ms( 1 );
    }
    Delay_ms ( 200 );
    lteiot17_process( ctx );
    if ( strstr( app_buf, rsp ) )
    {
        lteiot17_log_app_buf( );
        log_printf( &logger, "--------------------------------\r\n" );
        return LTEIOT17_OK;
    }
    else if ( strstr( app_buf, LTEIOT17_RSP_ERROR ) )
    {
        log_error( &logger, " CMD!" );
        return LTEIOT17_ERROR_CMD;
    }
    log_error( &logger, " Unknown!" );
    return LTEIOT17_ERROR_UNKNOWN;
}

static err_t lteiot17_power_up ( lteiot17_t *ctx )
{
    err_t error_flag = LTEIOT17_OK;
    
    uint8_t power_state = LTEIOT17_POWER_STATE_OFF;
    for ( ; ; )
    {
        lteiot17_process( ctx );
        lteiot17_clear_app_buf ( );
        // Wake up UART interface
        lteiot17_send_cmd( ctx, LTEIOT17_CMD_AT );
        Delay_ms ( 500 );

        log_printf( &logger, ">>> Check communication.\r\n" );
        lteiot17_send_cmd( ctx, LTEIOT17_CMD_AT );
        if ( ( ( LTEIOT17_OK == lteiot17_process( ctx ) ) && strstr( app_buf, LTEIOT17_RSP_OK ) ) )
        {
            power_state = LTEIOT17_POWER_STATE_ON;
            break;
        }
        else if ( LTEIOT17_POWER_STATE_OFF == power_state )
        {
            power_state = LTEIOT17_POWER_STATE_ON;
            log_printf( &logger, ">>> Power up device.\r\n" );
            lteiot17_set_power_state ( ctx, LTEIOT17_POWER_STATE_ON );
        }
        else if ( LTEIOT17_POWER_STATE_ON == power_state )
        {
            power_state = LTEIOT17_POWER_STATE_OFF;
            log_printf( &logger, ">>> Power down device.\r\n" );
            lteiot17_set_power_state ( ctx, LTEIOT17_POWER_STATE_OFF );
        }
    }
    lteiot17_send_cmd( ctx, LTEIOT17_CMD_AT );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );
    
    log_printf( &logger, ">>> Get device model ID.\r\n" );
    lteiot17_send_cmd( ctx, LTEIOT17_CMD_GET_MODEL_ID );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );

    log_printf( &logger, ">>> Get device software version ID.\r\n" );
    lteiot17_send_cmd( ctx, LTEIOT17_CMD_GET_SW_VERSION );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );

    log_printf( &logger, ">>> Get device serial number.\r\n" );
    lteiot17_send_cmd( ctx, LTEIOT17_CMD_GET_SERIAL_NUM );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );

    return error_flag;
}

static err_t lteiot17_config_connection ( lteiot17_t *ctx )
{
    err_t error_flag = LTEIOT17_OK;
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
    log_printf( &logger, ">>> Deregister from network.\r\n" );
    #define DEREGISTER_FROM_NETWORK "2"
    lteiot17_send_cmd_par( ctx, LTEIOT17_CMD_OPERATOR_SELECTION, DEREGISTER_FROM_NETWORK );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );

    log_printf( &logger, ">>> Set SIM APN.\r\n" );
    lteiot17_set_sim_apn( &lteiot17, SIM_APN );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );
    
    log_printf( &logger, ">>> Enable full functionality.\r\n" );
    #define FULL_FUNCTIONALITY "1"
    lteiot17_send_cmd_par( ctx, LTEIOT17_CMD_SET_PHONE_FUNCTIONALITY, FULL_FUNCTIONALITY );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );

    log_printf( &logger, ">>> Enable network registration.\r\n" );
    #define ENABLE_REG "2"
    lteiot17_send_cmd_par( ctx, LTEIOT17_CMD_NETWORK_REGISTRATION, ENABLE_REG );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );

    log_printf( &logger, ">>> Set automatic registration.\r\n" );
    #define AUTOMATIC_REGISTRATION "0"
    lteiot17_send_cmd_par( ctx, LTEIOT17_CMD_OPERATOR_SELECTION, AUTOMATIC_REGISTRATION );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );
#endif
    return error_flag;
}

static err_t lteiot17_check_connection ( lteiot17_t *ctx )
{
    err_t error_flag = LTEIOT17_OK;
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
    log_printf( &logger, ">>> Check network registration.\r\n" );
    #define CONNECTED "+CREG: 2,1"
    lteiot17_send_cmd_check ( &lteiot17, LTEIOT17_CMD_NETWORK_REGISTRATION );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );
    if ( strstr( app_buf, CONNECTED ) )
    {
        Delay_ms ( 1000 );
        log_printf( &logger, ">>> Check signal quality.\r\n" );
        lteiot17_send_cmd( &lteiot17, LTEIOT17_CMD_SIGNAL_QUALITY_REPORT );
        error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );
    }
    else
    {
        error_flag = LTEIOT17_ERROR;
        Delay_ms ( 1000 );
        Delay_ms ( 1000 );
    }
#endif
    return error_flag;
}

static err_t lteiot17_config_example ( lteiot17_t *ctx )
{
    err_t error_flag = LTEIOT17_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
    log_printf( &logger, ">>> Config APP network.\r\n" );
    #define CONFIG_APP_NETWORK "1,1"
    lteiot17_send_cmd_par( &lteiot17, LTEIOT17_CMD_APP_NETWORK_CONFIG, CONFIG_APP_NETWORK );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );
    
    log_printf( &logger, ">>> Activate APP network.\r\n" );
    #define ACTIVATE_APP_NETWORK "1,1"
    lteiot17_send_cmd_par( &lteiot17, LTEIOT17_CMD_APP_NETWORK_ACTIVE, ACTIVATE_APP_NETWORK );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );
    if ( strstr ( app_buf, "DEACTIVE" ) )
    {
        error_flag |= LTEIOT17_ERROR;
    }
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
    log_printf( &logger, ">>> Select SMS format.\r\n" );
    lteiot17_send_cmd_par( &lteiot17, LTEIOT17_CMD_SELECT_SMS_FORMAT, SMS_MODE );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );
#endif
    return error_flag;
}

static err_t lteiot17_example ( lteiot17_t *ctx )
{
    err_t error_flag = LTEIOT17_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"
    lteiot17_send_cmd_par ( &lteiot17, LTEIOT17_CMD_SET_TCP_UDP_ID, TCP_CID );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_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 );
    lteiot17_send_cmd_par ( &lteiot17, LTEIOT17_CMD_OPEN_TCP_UDP_CONNECTION, cmd_buf );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_URC_CONNECTION_OPEN );

    log_printf( &logger, ">>> Set UDP ID.\r\n" );
    #define UDP_CID "2"
    lteiot17_send_cmd_par ( &lteiot17, LTEIOT17_CMD_SET_TCP_UDP_ID, UDP_CID );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_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 );
    lteiot17_send_cmd_par ( &lteiot17, LTEIOT17_CMD_OPEN_TCP_UDP_CONNECTION, cmd_buf );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_URC_CONNECTION_OPEN );

    // 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_CID );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, message_len_buf );
    lteiot17_send_cmd_par ( &lteiot17, LTEIOT17_CMD_SEND_DATA_VIA_CONNECTION, cmd_buf );
    Delay_ms ( 200 );
    lteiot17_generic_write ( &lteiot17, MESSAGE_CONTENT, message_len );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_URC_RECEIVED_DATA );
    log_printf( &logger, ">>> Read response from TCP connection.\r\n" );
    lteiot17_send_cmd_par( &lteiot17, LTEIOT17_CMD_RECEIVE_DATA_VIA_CONNECTION, cmd_buf );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_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 );
    lteiot17_send_cmd_par ( &lteiot17, LTEIOT17_CMD_SEND_DATA_VIA_CONNECTION, cmd_buf );
    Delay_ms ( 200 );
    lteiot17_generic_write ( &lteiot17, MESSAGE_CONTENT, message_len );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_URC_RECEIVED_DATA );
    log_printf( &logger, ">>> Read response from UDP connection.\r\n" );
    lteiot17_send_cmd_par( &lteiot17, LTEIOT17_CMD_RECEIVE_DATA_VIA_CONNECTION, cmd_buf );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );
    
    log_printf( &logger, ">>> Close TCP connection.\r\n" );
    lteiot17_send_cmd_par ( &lteiot17, LTEIOT17_CMD_CLOSE_TCP_UDP_CONNECTION, TCP_CID );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );
    
    log_printf( &logger, ">>> Close UDP connection.\r\n" );
    lteiot17_send_cmd_par ( &lteiot17, LTEIOT17_CMD_CLOSE_TCP_UDP_CONNECTION, UDP_CID );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_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" );
    lteiot17_send_cmd_check( &lteiot17, LTEIOT17_CMD_SELECT_SMS_FORMAT );
    error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );
    if ( strstr( app_buf, CMGF_PDU ) )
    {
        // Send SMS in PDU mode
        log_printf( &logger, ">>> Send SMS in PDU mode.\r\n" );
        lteiot17_send_sms_pdu( &lteiot17, SIM_SMSC, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
        error_flag |= lteiot17_read_response( ctx, LTEIOT17_RSP_OK );
    }
    else if ( strstr( app_buf, CMGF_TXT ) )
    {
        // Send SMS in TXT mode
        log_printf( &logger, ">>> Send SMS in TXT mode.\r\n" );
        lteiot17_send_sms_text ( &lteiot17, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
        error_flag |= lteiot17_read_response( ctx, LTEIOT17_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

额外支持

资源

喜欢这个项目吗?

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