初学者
10 分钟

使用TX62-W和PIC32MZ2048EFM100体验物联网连接的未来

您的一体化解决方案,实现全球范围内无缝LTE-M和NB-IoT连接!

LTE IoT 11 Click with Curiosity PIC32 MZ EF

已发布 6月 27, 2024

点击板

LTE IoT 11 Click

开发板

Curiosity PIC32 MZ EF

编译器

NECTO Studio

微控制器单元

PIC32MZ2048EFM100

您的通往连接未来的通行证就在这里——一个紧凑的奇迹,将全球物联网连接轻松带入您的项目。

A

A

硬件概览

它是如何工作的?

LTE IoT 11 Click 基于 Thales 的 TX62-W,这是一款全球 MTC 模块。该模块高度高效,利用成熟的 Rel. 14 第二代 Cat. M1/NB1/NB2 提供全球 LPWAN LTE 连接,速度高达 1.1Mbps。TX61-W 支持优化的 3GPP 功率模式 PSM 和 eDRx,彻底改变了电池供电的蜂窝设备的可能性。所有这些,加上集成的 GNSS 支持(GPS/GALILEO/GLONASS/BeiDou),为全球范围内的精确定位数据提供稳定的限制和位置信息流。这个超集成的物联网模块具有独特的架构,允许灵活地在主 MCU 或模块内部运行应用程序。此外,该模块支持作为可选平台管理连接的 Cinterion IoT Suite Services。TX62-W 模块支持嵌入式 Ipv4 和 Ipv6 TCP/IP 堆栈访问以及透明的 TCP/UDP 服务。还支持互联网服务 TCP 服务器/客户端、UDP 客户端、DNS、Ping、HTTP 客户端、FTP 客户端和 MQTT 客户端。在安全方面,该模块支持 TLS/DTLS 和安全启动的安全连接。LTE IoT 11 Click 配备了两个 SMA 连接器,用于

连接 MIKROE 提供的合适天线,并且在没有它们的情况下不应使用此 Click board™。有两个 LED,RX/TX 和 STAT,用于状态指示。microSIM 卡插槽位于板的底部。TX62-W 还支持 MFF-XS 格式的 eUICC 接口。该接口可用作 8 针垫头。底部的 VPP SEL 跳线用于单线协议,是 eUICC 接口的一部分。如果您计划使用外部 SWP 主机,应将此跳线连接到 VCC。LTE IoT 11 Click 可以使用几种接口与主 MCU 通信。默认接口通过 COMM SEL 跳线选择为常用 UART RX 和 TX 线的 UART 串行接口。您还可以通过 UART 接口使用硬件控制流 UART RTS 和 CTS 引脚。MIKROE 提供了此 Click board™ 的适当库,但您也可以使用 AT 命令集来控制模块。如果更适合,您可以将其更改为 SPI 串行接口,传输速率高达 6.5Mbps。此外,您还可以使用 I2C 接口,支持高达 400kbps 的快速模式。LTE IoT 11 Click 使用 SMI 引脚作为挂起模式指示器,当模块进入挂起模式时指示主 MCU。此功能可以通过软件打开/关闭。ON 引脚或 ON 板

载按钮可以快速关闭。TX62-W 还支持直接 USB 2.0 连接,速度为 480Mbps,可通过 3 针插头使用。USB 接口仅用于跟踪接口。但是,您可以通过 USB C 连接器和 FTDI 的 USB 基本 UART IC FT230x 访问 TX62-W 调制解调器的 UART 接口。由于 TX62-W 在较低电压下工作,LTE IoT 11 Click 具有德州仪器的 6 位双向电平转换和电压转换器 TXB0106。此外,它还使用 NXP 的双向电压电平转换器 NVT2010。还有德州仪器的两个 LDO,TPS7A7002 和 LP2985,用于额外的电压调节。有一个 VCORE 作为推荐的测试垫,您可以在正常运行、睡眠模式运行和挂起模式运行期间检查核心电压。此 Click board™ 可以通过 VCC SEL 跳线选择使用 3.3V 或 5V 逻辑电压水平。这样,3.3V 和 5V 的 MCU 都可以正确使用通信线路。此外,这款 Click board™ 配备了包含易于使用的功能和示例代码的库,可用于进一步开发。

LTE IoT 11 Click hardware overview image

功能概述

开发板

Curiosity PIC32 MZ EF 开发板是一个完全集成的 32 位开发平台,特点是高性能的 PIC32MZ EF 系列(PIC32MZ2048EFM),该系列具有 2MB Flash、512KB RAM、集成的浮点单元(FPU)、加密加速器和出色的连接选项。它包括一个集成的程序员和调试器,无需额外硬件。用户可以通过 MIKROE 

mikroBUS™ Click™ 适配器板扩展功能,通过 Microchip PHY 女儿板添加以太网连接功能,使用 Microchip 扩展板添加 WiFi 连接能力,并通过 Microchip 音频女儿板添加音频输入和输出功能。这些板完全集成到 PIC32 强大的软件框架 MPLAB Harmony 中,该框架提供了一个灵活且模块化的接口

来应用开发、一套丰富的互操作软件堆栈(TCP-IP、USB)和易于使用的功能。Curiosity PIC32 MZ EF 开发板提供了扩展能力,使其成为连接性、物联网和通用应用中快速原型设计的绝佳选择。

Curiosity PIC32MZ EF double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC32

MCU 内存 (KB)

2048

硅供应商

Microchip

引脚数

100

RAM (字节)

524288

你完善了我!

配件

GNSS L1/L5 有源外部天线 (YB0017AA) 是 Quectel 的一款有源贴片天线,支持 GNSS L1/L5 BD B1/B2 GLONASS L1,具有高增益和高效率,为车队管理、导航、RTK 以及许多其他跟踪应用提供卓越性能。该天线采用磁性安装,尺寸为 61.5×56.5×23mm,设计适用于各种接地平面尺寸或自由空间,并通过一根 3 米长的电缆与 SMA 公头连接器连接到设备。

LTE IoT 11 Click accessories 1 image

LTE 平板旋转天线是提升 3G/4G LTE 设备性能的多功能选择。其宽频率范围为 700-2700MHz,确保在全球主要蜂窝频段上的最佳连接。这款平板天线配有 SMA 公头连接器,便于直接连接到设备或 SMA 模块连接器。其一大特色是可调节角度,可以以 45⁰ 增量(0⁰/45⁰/90⁰)设置,使您能够微调天线的方向以获得最大信号接收。该天线具有 50Ω 的阻抗和 <2.0:1 的 VSW 比率,确保可靠和高效的连接。其 5dB 增益、垂直极化和全向辐射模式增强了信号强度,使其适用于各种应用。天线长度为 196mm,宽度为 38mm,提供了紧凑而有效的连接解决方案。最大输入功率为 50W,能够满足各种设备的需求。

LTE IoT 11 Click accessories 2 image

使用的MCU引脚

mikroBUS™映射器

Suspend Mode Indicator
RPB4
AN
Module ON
RA9
RST
SPI Chip Select
RPD4
CS
SPI Clock
RPD1
SCK
SPI Data OUT
RPD14
MISO
SPI Data IN
RPD3
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
UART CTS
RPE8
PWM
UART RTS
RF13
INT
UART TX
RPD10
TX
UART RX
RPD15
RX
I2C Clock
RPA14
SCL
I2C Data
RPA15
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

LTE IoT 11 Click Schematic schematic

一步一步来

项目组装

Curiosity PIC32MZ EF front image hardware assembly

从选择您的开发板和Click板™开始。以Curiosity PIC32 MZ EF作为您的开发板开始。

Curiosity PIC32MZ EF front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Curiosity PIC32 MZ EF MB 1 Access - 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
Curiosity PIC32 MZ EF MCU 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 11 Click 驱动程序的 API。

关键功能:

  • lteiot11_set_sim_apn - 此功能设置 SIM 卡的 APN。

  • lteiot11_send_sms_text - 此功能发送短信到电话号码。

  • lteiot11_parse_gga - 此功能从读取的响应缓冲区解析 GGA 数据。

开源

代码示例

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

/*!
 * @file main.c
 * @brief LTE IoT 11 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, tests the communication by sending "AT" command, and after that restarts the device.
 *
 * ## Application Task
 * Application task is split in few stages:
 *  - LTEIOT11_CONFIGURE_FOR_NETWORK:
 * Sets configuration to device to be able to connect to the network. (used only for SMS or TCP/UDP demo examples).
 *
 *  - LTEIOT11_WAIT_FOR_CONNECTION:
 * Waits for the network registration indicated via CREG URC event and then checks
 * the connection status (used only for SMS or TCP/UDP demo examples).
 *
 *  - LTEIOT11_CONFIGURE_FOR_EXAMPLE:
 * Sets the device configuration for sending SMS or TCP/UDP messages or for retrieving data from GNSS 
 * depending on the selected demo example.
 *
 *  - LTEIOT11_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 lteiot11_clear_app_buf ( void )
 * - static err_t lteiot11_process ( void )
 * - static void lteiot11_error_check( err_t error_flag )
 * - static void lteiot11_log_app_buf ( void )
 * - static err_t lteiot11_rsp_check ( uint8_t *rsp )
 * - static err_t lteiot11_configure_for_connection( void )
 * - static err_t lteiot11_check_connection( void )
 * - static err_t lteiot11_configure_for_messages( void )
 * - static err_t lteiot11_send_message( void )
 *
 * @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"
 * In order to establish communication with the module, some of the supported MCUs may require the UART RX line
 * to be pulled up additionally either with the external or internal weak pull-up resistor.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "lteiot11.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                             ""              // 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 11 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
{
    LTEIOT11_CONFIGURE_FOR_NETWORK = 1,
    LTEIOT11_WAIT_FOR_CONNECTION,
    LTEIOT11_CONFIGURE_FOR_EXAMPLE,
    LTEIOT11_EXAMPLE

} lteiot11_example_state_t;

static lteiot11_t lteiot11;
static log_t logger;

/**
 * @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 err_t error_flag;
static lteiot11_example_state_t example_state;

/**
 * @brief Clearing application buffer.
 * @details This function clears memory of application
 * buffer and reset its length and counter.
 */
static void lteiot11_clear_app_buf ( void );

/**
 * @brief Data reading function.
 * @details This function reads data from device and
 * appends it to the application buffer.
 * @return @li @c  0 - Some data is read.
 *         @li @c -1 - Nothing is read.
 * See #err_t definition for detailed explanation.
 */
static err_t lteiot11_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.
 * @param[in] error_flag  Error flag to check.
 */
static void lteiot11_error_check ( err_t error_flag );

/**
 * @brief Logs application buffer.
 * @details This function logs data from application buffer.
 */
static void lteiot11_log_app_buf ( void );

/**
 * @brief Response check.
 * @details This function checks for response and
 * returns the status of response.
 * @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.
 */
static err_t lteiot11_rsp_check ( uint8_t *rsp );

/**
 * @brief Configure device for connection to the network.
 * @details Sends commands to configure and enable
 * connection to the specified network.
 * @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.
 */
static err_t lteiot11_configure_for_network ( void );

/**
 * @brief Wait for connection signal.
 * @details Wait for connection signal from CREG URC.
 * @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.
 */
static err_t lteiot11_check_connection ( void );

/**
 * @brief Configure device for example.
 * @details Configure device for the specified example.
 * @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.
 */
static err_t lteiot11_configure_for_example ( void );

/**
 * @brief Execute example.
 * @details This function executes SMS, TCP/UDP or GNSS example depending on the DEMO_EXAMPLE macro.
 * @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.
 */
static err_t lteiot11_example ( void );

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    lteiot11_cfg_t lteiot11_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.
    lteiot11_cfg_setup( &lteiot11_cfg );
    LTEIOT11_MAP_MIKROBUS( lteiot11_cfg, MIKROBUS_1 );
    if ( UART_ERROR == lteiot11_init( &lteiot11, &lteiot11_cfg ) )
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );
        for ( ; ; );
    }
    
    lteiot11_process( );
    lteiot11_clear_app_buf( );

    // Check communication
    lteiot11_send_cmd( &lteiot11, LTEIOT11_CMD_AT );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    lteiot11_error_check( error_flag );
    
    // Restart device
    #define RESTART_DEVICE "1,1"
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_CFUN, RESTART_DEVICE );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_SYSSTART );
    lteiot11_error_check( error_flag );

    log_info( &logger, " Application Task " );
    example_state = LTEIOT11_CONFIGURE_FOR_NETWORK;
}

void application_task ( void )
{
    switch ( example_state )
    {
        case LTEIOT11_CONFIGURE_FOR_NETWORK:
        {
            if ( LTEIOT11_OK == lteiot11_configure_for_network( ) )
            {
                example_state = LTEIOT11_WAIT_FOR_CONNECTION;
            }
            break;
        }
        case LTEIOT11_WAIT_FOR_CONNECTION:
        {
            if ( LTEIOT11_OK == lteiot11_check_connection( ) )
            {
                example_state = LTEIOT11_CONFIGURE_FOR_EXAMPLE;
            }
            break;
        }
        case LTEIOT11_CONFIGURE_FOR_EXAMPLE:
        {
            if ( LTEIOT11_OK == lteiot11_configure_for_example( ) )
            {
                example_state = LTEIOT11_EXAMPLE;
            }
            break;
        }
        case LTEIOT11_EXAMPLE:
        {
            lteiot11_example( );
            break;
        }
        default:
        {
            log_error( &logger, " Example state." );
            break;
        }
    }
}

void main ( void )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}

static void lteiot11_clear_app_buf ( void )
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static err_t lteiot11_process ( void )
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t rx_size = 0;
    rx_size = lteiot11_generic_read( &lteiot11, rx_buf, PROCESS_BUFFER_SIZE );
    if ( rx_size > 0 ) 
    {
        int32_t buf_cnt = app_buf_len;
        if ( ( ( app_buf_len + rx_size ) > APP_BUFFER_SIZE ) && ( app_buf_len > 0 ) ) 
        {
            buf_cnt = APP_BUFFER_SIZE - ( ( app_buf_len + rx_size ) - APP_BUFFER_SIZE );
            memmove ( app_buf, &app_buf[ APP_BUFFER_SIZE - buf_cnt ], buf_cnt );
        }
        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) 
        {
            if ( rx_buf[ rx_cnt ] ) 
            {
                app_buf[ buf_cnt++ ] = rx_buf[ rx_cnt ];
                if ( app_buf_len < APP_BUFFER_SIZE )
                {
                    app_buf_len++;
                }
            }
        }
        return LTEIOT11_OK;
    }
    return LTEIOT11_ERROR;
}

static err_t lteiot11_rsp_check ( uint8_t *rsp )
{
    uint32_t timeout_cnt = 0;
    uint32_t timeout = 120000;
    lteiot11_clear_app_buf( );
    lteiot11_process( );
    while ( ( 0 == strstr( app_buf, rsp ) ) &&
            ( 0 == strstr( app_buf, LTEIOT11_RSP_ERROR ) ) )
    {
        lteiot11_process( );
        if ( timeout_cnt++ > timeout )
        {
            lteiot11_clear_app_buf( );
            return LTEIOT11_ERROR_TIMEOUT;
        }
        Delay_ms( 1 );
    }
    Delay_ms( 100 );
    lteiot11_process( );
    if ( strstr( app_buf, rsp ) )
    {
        return LTEIOT11_OK;
    }
    else if ( strstr( app_buf, LTEIOT11_RSP_ERROR ) )
    {
        return LTEIOT11_ERROR_CMD;
    }
    else
    {
        return LTEIOT11_ERROR_UNKNOWN;
    }
}

static void lteiot11_error_check ( err_t error_flag )
{
    switch ( error_flag )
    {
        case LTEIOT11_OK:
        {
            lteiot11_log_app_buf( );
            break;
        }
        case LTEIOT11_ERROR:
        {
            log_error( &logger, " Overflow!" );
            break;
        }
        case LTEIOT11_ERROR_TIMEOUT:
        {
            log_error( &logger, " Timeout!" );
            break;
        }
        case LTEIOT11_ERROR_CMD:
        {
            log_error( &logger, " CMD!" );
            break;
        }
        case LTEIOT11_ERROR_UNKNOWN:
        default:
        {
            log_error( &logger, " Unknown!" );
            break;
        }
    }
    Delay_ms( 500 );
}

static void lteiot11_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 lteiot11_configure_for_network ( void )
{
    err_t func_error = LTEIOT11_OK;
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
    // Deregister from network
    #define DEREGISTER_FROM_NETWORK "2"
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_COPS, DEREGISTER_FROM_NETWORK );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    
    // Set SIM APN
    lteiot11_set_sim_apn( &lteiot11, SIM_APN );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );

    // Enable full functionality
    #define FULL_FUNCTIONALITY "1"
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_CFUN, FULL_FUNCTIONALITY );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );

    // Enable network registartion
    #define ENABLE_REG "2"
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_CREG, ENABLE_REG );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    
    // Automatic registration
    #define AUTOMATIC_REGISTRATION "0"
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_COPS, AUTOMATIC_REGISTRATION );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
#endif
    return func_error;
}

static err_t lteiot11_check_connection ( void )
{
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
    #define CONNECTED "+CREG: 1"
    lteiot11_process( );
    if ( strstr( app_buf, CONNECTED ) )
    {
        Delay_ms( 100 );
        lteiot11_process( );
        lteiot11_log_app_buf( );
        log_printf( &logger, "\r\n" );
        lteiot11_clear_app_buf( );
        // Check signal quality
        lteiot11_send_cmd( &lteiot11, LTEIOT11_CMD_CESQ );
        error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
        lteiot11_error_check( error_flag );
        return error_flag;
    }
    return LTEIOT11_ERROR;
#endif
    return LTEIOT11_OK;
}

static err_t lteiot11_configure_for_example ( void )
{
    err_t func_error = LTEIOT11_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
    #define ACTIVATE_PDP_CONTEXT "1,1"
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SICA, ACTIVATE_PDP_CONTEXT );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    #define REQ_DYNAMIC_IP "1"
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_CGPADDR, REQ_DYNAMIC_IP );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_CMGF, SMS_MODE );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
#elif ( DEMO_EXAMPLE == EXAMPLE_GNSS )
    #define GNNS_START_MODE_EN "\"Engine/StartMode\",0"
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SGPSC, GNNS_START_MODE_EN );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    #define GNNS_START_GPS "\"Nmea/GPS\",\"on\""
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SGPSC, GNNS_START_GPS );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    #define GNSS_POWER_UP "\"Engine\",3"
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SGPSC, GNSS_POWER_UP );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
#else
    #error "No demo example selected"
#endif
    return func_error;
}

static err_t lteiot11_example ( void )
{
    err_t func_error = LTEIOT11_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
    uint8_t cmd_buf[ 100 ] = { 0 };
    uint8_t tcp_socket_num[ 2 ] = { '0', 0 };
    uint8_t udp_socket_num[ 2 ] = { '1', 0 };

    // Select service type Socket.
    #define SRVTYPE_SOCKET ",srvtype,\"socket\""
    strcpy( cmd_buf, tcp_socket_num );
    strcat( cmd_buf, SRVTYPE_SOCKET );
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SISS, cmd_buf );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );

    strcpy( cmd_buf, udp_socket_num );
    strcat( cmd_buf, SRVTYPE_SOCKET );
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SISS, cmd_buf );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );

    // Select connection profile.
    #define CONN_PROFILE ",conid,\"1\""
    strcpy( cmd_buf, tcp_socket_num );
    strcat( cmd_buf, CONN_PROFILE );
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SISS, cmd_buf );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    
    strcpy( cmd_buf, udp_socket_num );
    strcat( cmd_buf, CONN_PROFILE );
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SISS, cmd_buf );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    
    // Choose ASCII alphabet.
    #define ASCII_ALPHABET ",alphabet,1"
    strcpy( cmd_buf, tcp_socket_num );
    strcat( cmd_buf, ASCII_ALPHABET );
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SISS, cmd_buf );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    
    strcpy( cmd_buf, udp_socket_num );
    strcat( cmd_buf, ASCII_ALPHABET );
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SISS, cmd_buf );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );

    // Specify the TCP remote IP and port
    #define ADDRESS_TCP ",address,\"socktcp://"
    strcpy( cmd_buf, tcp_socket_num );
    strcat( cmd_buf, ADDRESS_TCP );
    strcat( cmd_buf, REMOTE_IP );
    strcat( cmd_buf, ":" );
    strcat( cmd_buf, REMOTE_PORT );
    strcat( cmd_buf, "\"" );
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SISS, cmd_buf );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    
    // Specify the UDP remote IP and port
    #define ADDRESS_UDP ",address,\"sockudp://"
    strcpy( cmd_buf, udp_socket_num );
    strcat( cmd_buf, ADDRESS_UDP );
    strcat( cmd_buf, REMOTE_IP );
    strcat( cmd_buf, ":" );
    strcat( cmd_buf, REMOTE_PORT );
    strcat( cmd_buf, "\"" );
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SISS, cmd_buf );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    
    // Open TCP socket
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SISO, tcp_socket_num );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    
    // Open UDP socket
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SISO, udp_socket_num );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );

    // 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 );

    // Write message to TCP socket and read response
    strcpy( cmd_buf, tcp_socket_num );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, message_len_buf );
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SISW, cmd_buf );
    Delay_ms ( 100 );
    lteiot11_generic_write ( &lteiot11, MESSAGE_CONTENT, message_len );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    Delay_ms ( 1000 );
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SISR, cmd_buf );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );

    // Write message to UDP socket and read response
    strcpy( cmd_buf, udp_socket_num );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, message_len_buf );
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SISW, cmd_buf );
    Delay_ms ( 100 );
    lteiot11_generic_write ( &lteiot11, MESSAGE_CONTENT, message_len );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    Delay_ms ( 1000 );
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SISR, cmd_buf );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    
    // Close TCP socket
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SISC, tcp_socket_num );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    
    // Close UDP socket
    lteiot11_send_cmd_with_par( &lteiot11, LTEIOT11_CMD_SISC, udp_socket_num );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    Delay_ms( 5000 );
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
    // Check SMS mode
    #define CMGF_PDU "+CMGF: 0"
    #define CMGF_TXT "+CMGF: 1"
    lteiot11_send_cmd_check( &lteiot11, LTEIOT11_CMD_CMGF );
    error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
    func_error |= error_flag;
    lteiot11_error_check( error_flag );
    if ( strstr( app_buf, CMGF_PDU ) )
    {
        // Send SMS in PDU mode
        lteiot11_send_sms_pdu( &lteiot11, SIM_SMSC, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
        error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
        func_error |= error_flag;
        lteiot11_error_check( error_flag );
    }
    else if ( strstr( app_buf, CMGF_TXT ) )
    {
        // Send SMS in TXT mode
        lteiot11_send_sms_text ( &lteiot11, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
        error_flag = lteiot11_rsp_check( LTEIOT11_RSP_OK );
        func_error |= error_flag;
        lteiot11_error_check( error_flag );
    }
    Delay_ms( 10000 );
    Delay_ms( 10000 );
    Delay_ms( 10000 );
#elif ( DEMO_EXAMPLE == EXAMPLE_GNSS )
    lteiot11_process ( );
    if ( app_buf_len > ( sizeof ( LTEIOT11_RSP_GGA ) + LTEIOT11_GGA_ELEMENT_SIZE ) ) 
    {
        uint8_t element_buf[ 100 ] = { 0 };
        if ( LTEIOT11_OK == lteiot11_parse_gga( app_buf, LTEIOT11_GGA_LATITUDE, element_buf ) )
        {
            static uint8_t wait_for_fix_cnt = 0;
            if ( strlen( element_buf ) > 0 )
            {
                log_printf( &logger, "\r\n Latitude: %.2s degrees, %s minutes \r\n", element_buf, &element_buf[ 2 ] );
                lteiot11_parse_gga( app_buf, LTEIOT11_GGA_LONGITUDE, element_buf );
                log_printf( &logger, " Longitude: %.3s degrees, %s minutes \r\n", element_buf, &element_buf[ 3 ] );
                memset( element_buf, 0, sizeof( element_buf ) );
                lteiot11_parse_gga( app_buf, LTEIOT11_GGA_ALTITUDE, element_buf );
                log_printf( &logger, " Altitude: %s m \r\n", element_buf );
                wait_for_fix_cnt = 0;
            }
            else
            {
                if ( wait_for_fix_cnt % 5 == 0 )
                {
                    log_printf( &logger, " Waiting for the position fix...\r\n\n" );
                    wait_for_fix_cnt = 0;
                }
                wait_for_fix_cnt++;
            }
            lteiot11_clear_app_buf(  );
        }
    }
#else
    #error "No demo example selected"
#endif
    return func_error;
}

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

额外支持

资源

喜欢这个项目吗?

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