中级
30 分钟

体验最真实的物联网,使用EXS62-W和PIC18LF27K42

我们的LTE解决方案助力您的连接

LTE IoT 9 Click with EasyPIC v8

已发布 6月 24, 2024

点击板

LTE IoT 9 Click

开发板

EasyPIC v8

编译器

NECTO Studio

微控制器单元

PIC18LF27K42

您的连接设备之旅从这里开始。我们的LTE物联网解决方案不仅在设备之间建立连接,还为超越界限和释放未开发潜力的互联未来铺平了道路。

A

A

硬件概览

它是如何工作的?

LTE IoT 9 Click基于Thales的EXS62-W,这是一个支持3GPP Release 14的蜂窝物联网模块,适用于全球机器类型通信(MTC)技术、NB-IoT、LTE M和5G启用的LPWA连接,用于工业应用。它提供集成的GNSS支持,提供高达20dBm的功率,提供高达300Kbps的下行数据速度和高达1.1Mbps的上行数据速度。最先进的安全功能保护设备和数据,并提供在云平台中的安全注册,增强了物联网生态系统中的信任。模块的简化电源设计和先进的管理系统延长了电池寿命。该Click板™配有USB Type C连接器,允许模块通过FT230X(一种紧凑的USB到串行UART接口设备)连接到个人电脑(PC)进行供电和配置。与可用的USB带宽相比,它使用尽可能少的带宽。此外,它还具有两个SMA天线连接器,阻抗为50Ω,标记为

GNSS和LTE,用于连接MIKROE提供的合适天线。集成的GNSS接收器支持NMEA协议,代表了各种电子设备之间通信的综合电气和数据规范,包括GNSS接收器。默认情况下,GNSS接收器处于关闭状态,如果用户想激活它,可以通过AT命令切换到开启状态。GNSS天线还提供3V或5V的电源选择,通过适当的跳线J2或J3选择。除了这些SMA连接器外,这款Click板™还有一个nano-SIM卡插槽,提供多种连接和接口选项。LTE IoT 9 Click通过UART接口与MCU通信,作为其默认通信协议,用于与主机交换AT命令、数据传输和固件更新。它还具有RX/TX LED指示灯,指示桥是否处于RX或TX功能状态。用户还可以使用其他接口,例如SPI或I2C,通过填充Click板底部的适当跳线(J4 – J9)自行配置模块和编写库。这款Click板™可以使用

电池供电并作为独立设备使用。它还包含MC34671,一款全集成的锂离子或锂聚合物电池充电器,允许在Click板™插入mikroBUS™插座或插入USB端口时进行电池充电,充电进度由CHG LED指示灯指示。电池充电完成后,CHG LED将关闭。另一个指示灯是标记为STAT的黄色LED,指示模块的不同工作模式,标记为PWI的蓝色LED报告模块的电源状态并显示其是否处于活动或断电模式。板载标记为ON的按钮路由到mikroBUS™上的RST引脚,代表点火按钮。此Click板™可以与3.3V和5V MCU一起使用。适当的电压电平转换器执行正确的逻辑电压电平转换,而板载LDO确保电源模块的推荐电压水平。然而,该Click板™配有包含易于使用的函数和示例代码的库,可作为进一步开发的参考。

LTE IoT 9 Click hardware overview image

功能概述

开发板

EasyPIC v8 是一款专为快速开发嵌入式应用的需求而特别设计的开发板。它支持许多高引脚计数的8位PIC微控制器,来自Microchip,无论它们的引脚数量如何,并且具有一系列独特功能,例如首次集成的调试器/程序员。开发板布局合理,设计周到,使得最终用户可以在一个地方找到所有必要的元素,如开关、按钮、指示灯、连接器等。得益于创新的制造技术,EasyPIC v8 提供了流畅而沉浸式的工作体验,允许在任何情况下、任何地方、任何时候都能访问。

EasyPIC v8 开发板的每个部分都包含了使同一板块运行最高效的必要组件。除了先进的集成CODEGRIP程 序/调试模块,该模块提供许多有价值的编程/调试选项和与Mikroe软件环境的无缝集成外,该板还包括一个干净且调节过的开发板电源供应模块。它可以使用广泛的外部电源,包括电池、外部12V电源供应和通过USB Type-C(USB-C)连接器的电源。通信选项如USB-UART、USB DEVICE和CAN也包括在内,包括 广受好评的mikroBUS™标准、两种显示选项(图形和

基于字符的LCD)和几种不同的DIP插座。这些插座覆盖了从最小的只有八个至四十个引脚的8位PIC MCU的广泛范围。EasyPIC v8 是Mikroe快速开发生态系统的一个组成部分。它由Mikroe软件工具原生支持,得益于大量不同的Click板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作和开发的许多方面。

EasyPIC v8 horizontal image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC

MCU 内存 (KB)

128

硅供应商

Microchip

引脚数

28

RAM (字节)

8192

你完善了我!

配件

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

LTE IoT 9 Click accessories 1 image

GNSS L1/L5 Active External Antenna (YB0017AA) 是来自Quectel的一款主动贴片天线,支持GNSS L1/L5、BD B1/B2和GLONASS L1,凭借其高增益和高效率在车队管理、导航、RTK以及许多其他追踪应用中表现出色。这款磁性安装天线,尺寸为61.5×56.5×23mm,设计为可与各种地平面尺寸或在自由空间中工作,通过3米长的电缆和SMA公头连接器与设备连接。

LTE IoT 9 Click accessories 2 image

使用的MCU引脚

mikroBUS™映射器

SUSPEND Mode
RA3
AN
Ignition
RA0
RST
UART CTS
RA5
CS
SPI Clock
RC3
SCK
SPI Data OUT
RC4
MISO
SPI Data IN
RC5
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
SPI Chip Select
RC1
PWM
UART RTS
RB1
INT
UART RX
RC6
TX
UART TX
RC7
RX
I2C Clock
RC3
SCL
I2C Data
RC4
SDA
Power Supply
5V
5V
Ground
GND
GND
2

“仔细看看!”

Click board™ 原理图

LTE IoT 9 Click Schematic schematic

一步一步来

项目组装

EasyPIC v8 front image hardware assembly

从选择您的开发板和Click板™开始。以EasyPIC v8作为您的开发板开始。

EasyPIC v8 front image hardware assembly
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
EasyPIC v8 Access DIPMB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
NECTO Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 hardware assembly
Necto image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image 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 9 Click 驱动程序的 API。

关键功能:

  • lteiot9_generic_read - 此函数使用UART串行接口读取所需数量的数据字节。

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

  • lteiot9_set_sim_apn - 此函数设置SIM卡的APN。

开源

代码示例

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

/*!
 * @file main.c
 * @brief LTE IoT 9 Click Example.
 *
 * # Description
 * This application shows capability of LTE IoT 9 click board.
 * It connects to network with standard "AT" commands, then
 * sends SMS whit SIM card, and then logs GNNS data.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes driver and wake-up module and checks
 * communication and device version.
 *
 * ## Application Task
 * Application taks is split in few stages:
 *  - CONFIGURATION_FOR_NETWORK : Sets configuration to device to
 *                                be able to connect to newtork.
 *
 *  - CHECK_NETWORK_CONNECTION  : Checks device connection status
 *                                till device is connected to network.
 *
 *  - SENDING_SMS               : Sends SMS message to desired number in text mode.
 *
 *  - CONFIGURATION_FOR_GNSS    : Sets configuration to device to enable GNSS data.
 *
 *  - GNSS_DATA                 : Reads and parses data from device to
 *                                get latitude, longitude and altitude from device
 *
 * ## Additional Function
 * - lteiot9_clear_app_buf      : Function clears memory of app_buf.
 *
 * - lteiot9_process            : Function collects data from module and
 *                                concat that data to app_buf.
 *
 * - lteiot9_error_check        : Function checks for different types of
 *                                errors and logs them on UART.
 *
 * - lteiot9_log_app_buf        : Function logs data from application buffer.
 *
 * - lteiot9_rsp_check          : Function checks for response and returns
 *                                the status of response.
 *
 * - lteiot9_check_connection   : Function checks connection to the network and
 *                                logs that status to UART.
 *
 * - lteiot9_cmd_parser         : Function searches application buffer for command
 *                                and logs data of that command.
 *
 * - lteiot9_element_parser     : Function searches application buffer for command and its
 *                                element and copies data to element_data buffer.
 *
 * - lteiot9_power_up_wait      : Function loops process function untill device respond with
 *                                "^SYSSTART" that device sends on power up/restart.
 *
 * - lteiot9_config_device_for_network  : Function sends commands for enableing network.
 *
 * - lteiot9_check_connection_to_network : Function sends commands for checking connection to network.
 *
 * - lteiot9_send_sms           : Function sends SMS via network in text mode.
 *
 * - lteiot9_config_device_for_gnss : Function sends commands for enableing GNSS.
 *
 * - lteiot9_gnss_data          : Function reads data from device and parses data
 *                                to find latitude, longitude and altitude.
 *
 * @note
 * In order for the example to work,
   user needs to set the phone number and sim apn to which he wants to send an SMS
 * Enter valid data for the following macros: SIM_APN and PHONE_NUMBER_TO_MESSAGE.
 * E.g.
    SIM_APN "vipmobile"
    PHONE_NUMBER_TO_MESSAGE "+381659999999"
 *
 * @author Luka FIlipovic
 *
 */

#include "board.h"
#include "log.h"
#include "lteiot9.h"

#define SIM_APN                             ""  // Set valid SIM APN
#define PHONE_NUMBER_TO_MESSAGE             ""  // Set Phone number to message
#define MESSAGE_CONTENT                     "LTE IoT 9 Click"   // Messege content

#define PROCESS_BUFFER_SIZE                 500

#define CONFIGURATION_FOR_NETWORK           0
#define CHECK_NETWORK_CONNECTION            1
#define SENDING_SMS                         2
#define CONFIGURATION_FOR_GNSS              3
#define GNSS_DATA                           4

static lteiot9_t lteiot9;
static log_t logger;

static char app_buf[ PROCESS_BUFFER_SIZE ]  = { 0 };
static int32_t app_buf_len                  = 0;
static int32_t app_buf_cnt                  = 0;

static uint8_t app_connection_status        = CHECK_NETWORK_CONNECTION;

static char latitude_data[ 30 ]             = { 0 };
static char longitude_data[ 30 ]            = { 0 };
static char altitude_data[ 30 ]             = { 0 };

static err_t app_error_flag;
static err_t last_error_flag;

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

/**
 * @brief LTE IoT 9 data reading function.
 * @details This function reads data from device and concatenates data to application buffer.
 *
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - Nothing is read.
 *         @li @c -2 - Application buffer overflow.
 *
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t lteiot9_process ( void );

/**
 * @brief LTE IoT 9 check for errors.
 * @details This function checks for different types of errors and logs them on UART.
 * @note None.
 */
static void lteiot9_error_check( err_t error_flag );

/**
 * @brief LTE IoT 9 logs application buffer.
 * @details This function logs data from application buffer.
 * @note None.
 */
static void lteiot9_log_app_buf ( void );

/**
 * @brief LTE IoT 9 response check.
 * @details This function checks for response and returns the status of response.
 *
 * @return application status.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t lteiot9_rsp_check ( void );

/**
 * @brief LTE IoT 9 chek connection.
 * @details This function checks connection to the network and
 *          logs that status to UART.
 *
 * @note None.
 */
static void lteiot9_check_connection( void );

/**
 * @brief IRNSS command data parser.
 * @details This function searches @b app_buf for @b cmd and logs data of that command.
 *
 * @param[in] cmd : Command to parese.
 *
 * @return @li @c  0 - Parsed data succes.
 *         @li @c -1 - No @b cmd in application buffer.
 *
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t lteiot9_cmd_parser ( char *cmd );

/**
 * @brief IRNSS element of command data parser.
 * @details This function searches @b app_buf for @b cmd and it's
 *          @b element and copies data to @b element_data buffer.
 *
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - No @b cmd in application buffer.
 *         @li @c -2 - No data for @b element in @b cmd.
 *         @li @c -3 - Data buffer overflow.
 *
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t lteiot9_element_parser ( char *cmd, uint8_t element, char *element_data );

/**
 * @brief LTE IoT 9 waits device to respond with @b LTEIOT9_SYSSTART.
 * @details This function loops process function untill device respond with
 *          @b LTEIOT9_SYSSTART that device sends on power up/restart.
 * @note None.
 */
static void lteiot9_power_up_wait ( void );

/**
 * @brief LTE IoT 9 set up device for network.
 * @details This function sends commands for enableing network.
 * @note None.
 */
static void lteiot9_config_device_for_network( void );

/**
 * @brief LTE IoT 9 check connection commands.
 * @details This function sends commands for checking connection to network.
 * @note None.
 */
static void lteiot9_check_connection_to_network( void );

/**
 * @brief LTE IoT 9 sends SMS via network.
 * @details This function sends SMS via network in text mode.
 * @note None.
 */
static void lteiot9_send_sms( void );

/**
 * @brief LTE IoT 9 set up device for GNSS.
 * @details This function sends commands for enableing GNSS.
 * @note None.
 */
static void lteiot9_config_device_for_gnss( void );

/**
 * @brief LTE IoT 9 reads data from device and parses that data.
 * @details This function reads data from device and parses data
 *          to find latitude, longitude and altitude.
 * @note None.
 */
static void lteiot9_gnss_data( void );

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    lteiot9_cfg_t lteiot9_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 " );
    Delay_ms( 1000 );

    // Click initialization.

    lteiot9_cfg_setup( &lteiot9_cfg );
    LTEIOT9_MAP_MIKROBUS( lteiot9_cfg, MIKROBUS_1 );
    err_t init_flag  = lteiot9_init( &lteiot9, &lteiot9_cfg );
    if ( init_flag == UART_ERROR ) {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }

    log_info( &logger, " Power on device... " );
    lteiot9_default_cfg ( &lteiot9 );
    lteiot9_process(  );
    lteiot9_clear_app_buf(  );

    lteiot9_send_cmd_with_parameter( &lteiot9, LTEIOT9_CMD_CFUN, "1,1" );
    lteiot9_power_up_wait();
    app_buf_len = 0;
    app_buf_cnt = 0;

    //AT
    lteiot9_send_cmd( &lteiot9, LTEIOT9_CMD_AT );
    app_error_flag = lteiot9_rsp_check();
    lteiot9_error_check( app_error_flag );
    Delay_ms( 500 );
    //ATI
    lteiot9_send_cmd( &lteiot9, LTEIOT9_CMD_ATI );
    app_error_flag = lteiot9_rsp_check();
    lteiot9_error_check( app_error_flag );
    Delay_ms( 500 );

    app_connection_status = CONFIGURATION_FOR_NETWORK;
    log_info( &logger, " Application Task " );
    Delay_ms( 2000 );
}

void application_task ( void )
{
    switch( app_connection_status )
    {
        case CONFIGURATION_FOR_NETWORK:
        {
            lteiot9_config_device_for_network( );
            break;
        }
        case CHECK_NETWORK_CONNECTION:
        {
            lteiot9_check_connection_to_network( );
            break;
        }
        case SENDING_SMS:
        {
            lteiot9_send_sms( );
            break;
        }
        case CONFIGURATION_FOR_GNSS:
        {
            lteiot9_config_device_for_gnss( );
            break;
        }
        case GNSS_DATA:
        {
            lteiot9_gnss_data();

            break;
        }
        default:
        {
            log_error( &logger, "Application status error!" );
            app_connection_status = CHECK_NETWORK_CONNECTION;
            Delay_ms( 1000 );
            break;
        }
    }
}

void main ( void ) {
    application_init( );

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

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

static err_t lteiot9_process ( void )
{
    err_t return_flag = LTEIOT9_ERROR;
    int32_t rx_size;
    char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };

    rx_size = lteiot9_generic_read( &lteiot9, rx_buff, PROCESS_BUFFER_SIZE );

    if ( rx_size > 0 )
    {
        int32_t buf_cnt = 0;
        return_flag = LTEIOT9_OK;

        if ( app_buf_len + rx_size >= PROCESS_BUFFER_SIZE )
        {
            lteiot9_clear_app_buf(  );
            return_flag = LTEIOT9_ERROR_OVERFLOW;
        }
        else
        {
            buf_cnt = app_buf_len;
            app_buf_len += rx_size;
        }

        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ )
        {
            if ( rx_buff[ rx_cnt ] != 0 )
            {
                app_buf[ ( buf_cnt + rx_cnt ) ] = rx_buff[ rx_cnt ];
            }
            else
            {
                app_buf_len--;
            }
        }
    }

    return return_flag;
}

static err_t lteiot9_rsp_check ( void )
{
    uint32_t timeout_cnt = 0;
    uint32_t timeout = 60000;

    volatile err_t error_flag = lteiot9_process(  );
    if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
    {
        return error_flag;
    }

    while ( ( strstr( app_buf, LTEIOT9_RSP_OK ) == 0 ) &&
            ( strstr( app_buf, LTEIOT9_RSP_ERROR ) == 0 ) )
    {
        error_flag = lteiot9_process(  );
        if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
        {
            return error_flag;
        }

        timeout_cnt++;
        if ( timeout_cnt > timeout )
        {
            while ( ( strstr( app_buf, LTEIOT9_RSP_OK ) == 0 ) &&
                    ( strstr( app_buf, LTEIOT9_RSP_ERROR ) == 0 ) )
            {
                lteiot9_send_cmd( &lteiot9, LTEIOT9_CMD_AT );
                Delay_ms( 100 );
                lteiot9_process(  );
                Delay_ms( 100 );
            }
            lteiot9_clear_app_buf(  );
            return LTEIOT9_ERROR_TIMEOUT;
        }

        Delay_ms( 1 );
    }

    lteiot9_check_connection();

    error_flag = LTEIOT9_OK;

    if ( strstr( app_buf, LTEIOT9_RSP_ERROR ) != 0 )
    {
        error_flag = LTEIOT9_ERROR;
    }

    lteiot9_log_app_buf();

    log_printf( &logger, "-----------------------------------\r\n" );

    return error_flag;
}

static void lteiot9_error_check( err_t error_flag )
{
    if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
    {
        switch ( error_flag )
        {
            case -2:
                log_error( &logger, " Overflow!" );
                break;
            case -3:
                log_error( &logger, " Timeout!" );
                break;
            default:
                break;
        }
    }
}

static void lteiot9_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 ] );
    }
    log_printf( &logger, "\r\n" );
    lteiot9_clear_app_buf(  );
}

static void lteiot9_check_connection( void )
{
    #define CONNECTED "+CGATT: 1"

    if ( strstr( app_buf, CONNECTED ) != 0 )
    {
        app_connection_status = SENDING_SMS;
    }
}

static err_t lteiot9_cmd_parser ( char *cmd )
{
    err_t ret_flag = 0;

    if ( strstr( app_buf, cmd ) != 0 )
    {
        char * __generic_ptr gngga_ptr;

        gngga_ptr = strstr( app_buf, cmd );

        while (strchr( gngga_ptr, LTEIOT9_GNSS_START ) == 0)
        {
            lteiot9_process();
        }

        for ( ; ; )
        {
            log_printf( &logger, "%c", *gngga_ptr );
            gngga_ptr++;

            if ( ( *gngga_ptr == LTEIOT9_GNSS_START ) )
            {
                break;
            }
        }
    }
    else
    {
        ret_flag = -1;
    }

    return ret_flag;
}

static err_t lteiot9_element_parser ( char *cmd, uint8_t element, char *element_data )
{
    err_t ret_flag = 0;


    if ( strstr( app_buf, cmd ) != 0 )
    {
        uint8_t element_cnt = 0;
        char data_buf[ 30 ] = { 0 };
        uint8_t data_cnt = 0;
        char * __generic_ptr gngga_ptr;

        gngga_ptr = strstr( app_buf, cmd );

        while (strchr( gngga_ptr, LTEIOT9_GNSS_START ) == 0)
        {
            lteiot9_process();
        }

        for ( ; ; )
        {
            if ( ( *gngga_ptr == LTEIOT9_GNSS_START ) )
            {
                ret_flag = -2;
                break;
            }

            if ( *gngga_ptr == LTEIOT9_GNSS_SEPARATOR )
            {
                if (element_cnt == element)
                {
                    if ( data_cnt == 0 )
                    {
                        ret_flag = -2;
                    }
                    strcpy( element_data, data_buf );
                    break;
                }

                element_cnt++;
            }

            if ( ( element == element_cnt ) && ( *gngga_ptr != LTEIOT9_GNSS_SEPARATOR ) )
            {
                data_buf[ data_cnt ] = *gngga_ptr;
                data_cnt++;

                if ( data_cnt >= 30 )
                {
                    ret_flag = -3;
                    break;
                }
            }

            gngga_ptr++;
        }
    }
    else
    {
        ret_flag = -1;
    }

    return ret_flag;
}

static void lteiot9_power_up_wait ( void )
{
    do
    {
        lteiot9_process();
        Delay_ms( 10 );
    }while( 0 == strstr( app_buf, LTEIOT9_SYSSTART ) );

    lteiot9_log_app_buf();
}

static void lteiot9_config_device_for_network( void )
{
    //CIMI
    lteiot9_send_cmd( &lteiot9, LTEIOT9_CMD_CIMI );
    app_error_flag = lteiot9_rsp_check();
    lteiot9_error_check( app_error_flag );
    Delay_ms( 2000 );

    //CGDCONT
    lteiot9_set_sim_apn( &lteiot9, SIM_APN );
    app_error_flag = lteiot9_rsp_check();
    lteiot9_error_check( app_error_flag );
    Delay_ms( 500 );

    //CEREG
    lteiot9_send_cmd_with_parameter( &lteiot9, LTEIOT9_CMD_CREG, "2" );
    app_error_flag = lteiot9_rsp_check();
    lteiot9_error_check( app_error_flag );
    Delay_ms( 500 );

    app_connection_status = CHECK_NETWORK_CONNECTION;
}

static void lteiot9_check_connection_to_network( void )
{
    lteiot9_send_cmd_check( &lteiot9, LTEIOT9_CMD_CGATT );
    app_error_flag = lteiot9_rsp_check();
    lteiot9_error_check( app_error_flag );
    Delay_ms( 500 );

    lteiot9_send_cmd_check( &lteiot9, LTEIOT9_CMD_CEREG );
    app_error_flag = lteiot9_rsp_check();
    lteiot9_error_check( app_error_flag );
    Delay_ms( 500 );

    lteiot9_send_cmd( &lteiot9, LTEIOT9_CMD_CSQ );
    app_error_flag = lteiot9_rsp_check();
    lteiot9_error_check( app_error_flag );
    Delay_ms( 2000 );

    if ( CHECK_NETWORK_CONNECTION != app_connection_status )
    {
        log_info( &logger, "CONNECTED TO NETWORK" );
    }
}

static void lteiot9_send_sms( void )
{
    lteiot9_send_cmd_with_parameter( &lteiot9, LTEIOT9_CMD_CMGF, "1" );
    app_error_flag = lteiot9_rsp_check();
    lteiot9_error_check( app_error_flag );
    Delay_ms( 2000 );

    log_printf( &logger, "> Sending message to phone number...\r\n" );
    lteiot9_send_text_message( &lteiot9, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
    app_error_flag = lteiot9_rsp_check();
    lteiot9_error_check( app_error_flag );
    if ( LTEIOT9_OK == app_error_flag )
    {
        log_printf( &logger, "> Message sent...\r\n" );
        app_connection_status = CONFIGURATION_FOR_GNSS;
    }
    Delay_ms( 2000 );
}

static void lteiot9_config_device_for_gnss( void )
{
    #define GNNS_START_MODE_EN  "AT^SGPSC=\"Engine/StartMode\",0"
    #define GNNS_START_GPS      "AT^SGPSC=\"Nmea/GPS\",\"on\""
    #define GNSS_POWER_UP       "AT^SGPSC=\"Engine\",3"

    lteiot9_send_cmd( &lteiot9, GNNS_START_GPS );
    app_error_flag = lteiot9_rsp_check();
    lteiot9_error_check( app_error_flag );
    Delay_ms( 500 );

    lteiot9_send_cmd( &lteiot9, GNNS_START_MODE_EN );
    app_error_flag = lteiot9_rsp_check();
    lteiot9_error_check( app_error_flag );
    Delay_ms( 500 );

    lteiot9_send_cmd_with_parameter( &lteiot9, LTEIOT9_CMD_CFUN, "1,1" );
    lteiot9_power_up_wait();
    Delay_ms( 3000 );

    do {
        lteiot9_send_cmd( &lteiot9, GNSS_POWER_UP );
        app_error_flag = lteiot9_rsp_check();
        lteiot9_error_check( app_error_flag );

    } while ( app_error_flag < 0 );

    app_connection_status = GNSS_DATA;
    last_error_flag = 0;
    log_info( &logger, "GNSS APP" );
}

static void lteiot9_gnss_data( void )
{
    lteiot9_process();

    err_t error_flag = lteiot9_element_parser( LTEIOT9_GNSS_GPGGA, LTEIOT9_GPGGA_LATITUDE,
                                            latitude_data );

    error_flag |= lteiot9_element_parser(  LTEIOT9_GNSS_GPGGA, LTEIOT9_GPGGA_LONGITUDE,
                                        longitude_data );

    error_flag |= lteiot9_element_parser(  LTEIOT9_GNSS_GPGGA, LTEIOT9_GPGGA_ALTITUDE,
                                        altitude_data );

    if ( error_flag == 0 )
    {
        if ( last_error_flag != 0)
        {
            log_printf( &logger, "\r\n" );
        }
        log_printf( &logger, ">Latitude:\r\n - deg: %.2s \r\n - min: %s\r\n",
                    latitude_data, &latitude_data[ 2 ] );

        log_printf( &logger, ">Longitude:\r\n - deg: %.3s \r\n - min: %s\r\n",
                    longitude_data, &longitude_data[ 3 ] );

        log_printf( &logger, ">Altitude:\r\n - %sm\r\n",
                    altitude_data );

        log_printf( &logger, "----------------------------------------\r\n" );
    }
    else if ( error_flag < -1 )
    {
        if ( last_error_flag == 0 )
        {
            log_printf( &logger, "Waiting for data" );
        }
        log_printf( &logger, "." );
    }

    if ( error_flag != -1 )
    {
        last_error_flag = error_flag;
        lteiot9_clear_app_buf(  );
    }
}

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

额外支持

资源

喜欢这个项目吗?

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