中级
30 分钟

使用SIM868和STM32F031K6,通过Thingstream的即时全球连接提升您的物联网设备

一个网关,无限连接

Thingstream Click with Nucleo 32 with STM32F031K6 MCU

已发布 10月 01, 2024

点击板

Thingstream Click

开发板

Nucleo 32 with STM32F031K6 MCU

编译器

NECTO Studio

微控制器单元

STM32F031K6

我们的物联网网关解决方案配备Thingstream客户端SDK,通过即时访问Thingstream全球MQTT网络和一套连接工具,彻底改变设备连接方式,实现开箱即用的便捷连接。

A

A

硬件概览

它是如何工作的?

Thingstream Click基于SIMCom的SIM868,这是一个802.11b/g/n四频GPS/GLONASS/GSM定位跟踪和移动通信模块。该设备通过GSM连接到Thingstream全球MQTT网络。Thingstream Click使智能物联网应用的快速开发成为可能,并通过使用少量AT命令和流程图样式的应用程序构建器(数据流管理器)简化了与云平台的连接,从而消除了与网页、硬件和通信相关的开发复杂性。此Click板™预配置了连接Thingstream全球MQTT网络和数据流管理器所需的协议和通信设置。通过Thingstream客

户端SDK可以在板载STM32F407 MCU上开发固件,即使没有深入的软件工程和网页编程知识,也能快速实现结果。Thingstream Click配备了各种LED指示灯。单独的LED指示电源供应的存在、网络状态和每秒脉冲指示(1PPS)。此外,此Click板™还包含一个通用RGB LED,用于显示Thingstream Click状态的其他反馈。此Click板™需要5V电源轨以确保正常运行。除了板载USB连接器之外,此Click板™上的所有mikroBUS™引脚都路由到板载STM32F407 MCU的相应引脚。这样确保了用户在未来升级和开发中有充足

的空间。这使得支持I2C和SPI通信接口的广泛定制应用成为可能。所有可用的接口都可以连接到mikroBUS头。默认情况下,板仅支持使用AT命令的UART通信。固件更新可以支持其他接口,如SPI、I2C、PWM和模拟。此Click板™只能在3.3V逻辑电压水平下运行。在使用具有不同逻辑电平的MCU之前,必须进行适当的逻辑电压电平转换。此外,它还配备了一个库,包含函数和示例代码,可用作进一步开发的参考。

Thingstream 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

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

Thingstream Click accessories 1 image

这款GSM直角橡胶天线是我们GSM Click板™的完美搭配。它具有宽带宽,适用于GSM/GPRS模块,配有2米长的电缆和SMA公头连接器,便于定位。其工作频率范围为824-894/1710-1990MHz或890-960/1710-1890MHz,保持50Ohm阻抗,提供3dB增益。其90/280MHz带宽确保了可靠的连接,而其垂直极化优化了信号接收。最大输入功率为60W,表现强劲。天线长度仅为90mm,紧凑而强大。其SMA公头连接器确保了安全稳定的连接,是与任何GSM Click板™无缝集成的理想选择。

Thingstream Click accessories 2 image

使用的MCU引脚

mikroBUS™映射器

Analog Output
PA0
AN
Reset
PA11
RST
SPI Chip Enable
PA4
CS
SPI Clock
PB3
SCK
SPI Data OUT
PB4
MISO
SPI Data IN
PB5
MOSI
NC
NC
3.3V
Ground
GND
GND
PWM Signal
PA8
PWM
Interrupt
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™ 原理图

Thingstream 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”替换为要显示的参数。

软件支持

库描述

此库包含Thingstream Click驱动程序的API。

关键功能:

  • thingstream_reset_pin_state - 设置RST引脚状态

  • thingstream_send_command - 发送命令

  • thingstream_generic_parser - 通用解析函数

开源

代码示例

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

/*!
 * \file 
 * \brief Thingstream Click example
 * 
 * # Description
 * This example reads and processes data from Thingstream Clicks.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes driver and power module.
 * 
 * ## Application Task  
 * Reads the received data and parses it.
 * 
 * ## Additional Function
 * - thingstream_process ( ) - The general process of collecting data the module sends.
 * 
 * @note
 * The Click board needs to be registered with a redemption code to a Thingstream Domain.
 * For more information please refer to the Thingstream Click user manual available on the product page.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "thingstream.h"
#include "string.h"

#define PROCESS_COUNTER 600
#define PROCESS_RX_BUFFER_SIZE 600
#define PROCESS_PARSER_BUFFER_SIZE 600

#define THINGSTREAM_INFO      "AT+IOTINFO"
#define THINGSTREAM_CREATE    "AT+IOTCREATE"
#define THINGSTREAM_CONNECT   "AT+IOTCONNECT=true"
#define THINGSTREAM_GPS_PWR   "AT+IOTCGNSPWR=1"
#define THINGSTREAM_SUBSCRIBE "AT+IOTSUBSCRIBE=\"home/temperature\",1"
#define THINGSTREAM_PUBLISH   "AT+IOTPUBLISH=\"home/temperature\",0,\"23 degrees\""
#define THINGSTREAM_GPS_INFO  "AT+IOTCGNSINF"

// ------------------------------------------------------------------ VARIABLES

static thingstream_t thingstream;
static log_t logger;

static char current_parser_buf[ PROCESS_PARSER_BUFFER_SIZE ];
static uint8_t send_data_cnt = 0; 

// ------------------------------------------------------- ADDITIONAL FUNCTIONS

static void thingstream_process ( void )
{
    int32_t rsp_size = 0;
    uint16_t rsp_cnt = 0;
    
    char uart_rx_buffer[ PROCESS_RX_BUFFER_SIZE ] = { 0 };
    uint16_t check_buf_cnt = 0;
    uint16_t process_cnt = PROCESS_COUNTER;
    // Clear parser buffer
    memset( current_parser_buf, 0, PROCESS_PARSER_BUFFER_SIZE ); 
    
    while ( process_cnt != 0 )
    {
        rsp_size = thingstream_generic_read( &thingstream, uart_rx_buffer, PROCESS_RX_BUFFER_SIZE );

        if ( rsp_size > 0 )
        {  
            // Validation of the received data
            for ( check_buf_cnt = 0; check_buf_cnt < rsp_size; check_buf_cnt++ )
            {
                if ( uart_rx_buffer[ check_buf_cnt ] == 0 ) 
                {
                    uart_rx_buffer[ check_buf_cnt ] = 13;
                }
            }
            // Storages data in parser buffer
            rsp_cnt += rsp_size;
            if ( rsp_cnt < PROCESS_PARSER_BUFFER_SIZE )
            {
                strncat( current_parser_buf, uart_rx_buffer, rsp_size );
            }
            if ( strchr( uart_rx_buffer, '+' ) )
            {
                process_cnt = 20;
            }
            // Clear RX buffer
            memset( uart_rx_buffer, 0, PROCESS_RX_BUFFER_SIZE );
        } 
        else 
        {
            process_cnt--;
            
            // Process delay 
            Delay_ms ( 100 );
        }
    }
}

static void parser_application ( char *rsp )
{
    char element_buf[ 200 ] = { 0 };
    
    log_printf( &logger, "\r\n-----------------------\r\n" ); 
    thingstream_generic_parser( rsp, THINGSTREAM_NEMA_CGNSINF, THINGSTREAM_CGNSINF_LATITUDE, element_buf );
    if ( strlen( element_buf ) > 0 )
    {
        log_printf( &logger, "Latitude: %s degrees \r\n", element_buf );
        thingstream_generic_parser( rsp, THINGSTREAM_NEMA_CGNSINF, THINGSTREAM_CGNSINF_LONGITUDE, element_buf );
        log_printf( &logger, "Longitude: %s degrees \r\n", element_buf );
        memset( element_buf, 0, sizeof( element_buf ) );
        thingstream_generic_parser( rsp, THINGSTREAM_NEMA_CGNSINF, THINGSTREAM_CGNSINF_ALTITUDE, element_buf );
        log_printf( &logger, "Altitude: %s m", element_buf );  
    }
    else
    {
        log_printf( &logger, "Waiting for the position fix..." );
    }
}

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    thingstream_cfg_t cfg;

    /** 
     * 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.
    thingstream_cfg_setup( &cfg );
    THINGSTREAM_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    thingstream_init( &thingstream, &cfg );

    thingstream_module_power( &thingstream, true );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );

    log_printf( &logger, " --->>> INFO.. \r\n" );
    thingstream_send_command( &thingstream, THINGSTREAM_INFO );
    thingstream_process( );
    log_printf( &logger, "%s", current_parser_buf );
        
    log_printf( &logger, " --->>> CREATE.. \r\n" );
    thingstream_send_command( &thingstream, THINGSTREAM_CREATE );
    thingstream_process( );
    log_printf( &logger, "%s", current_parser_buf );

    log_printf( &logger, " --->>> CONNECT.. \r\n" );
    thingstream_send_command( &thingstream, THINGSTREAM_CONNECT );
    thingstream_process( );
    log_printf( &logger, "%s", current_parser_buf );

    log_printf( &logger, " --->>> GPS POWER.. \r\n" );
    thingstream_send_command( &thingstream, THINGSTREAM_GPS_PWR );
    thingstream_process( );
    log_printf( &logger, "%s", current_parser_buf );

    log_printf( &logger, " --->>> SUBSCRIBE.. \r\n" );
    thingstream_send_command( &thingstream, THINGSTREAM_SUBSCRIBE );
    thingstream_process( );
    log_printf( &logger, "%s", current_parser_buf );

    log_printf( &logger, " --->>> PUBLISH.. \r\n" );
    thingstream_send_command( &thingstream, THINGSTREAM_PUBLISH );
    thingstream_process( );
    log_printf( &logger, "%s", current_parser_buf );

    log_printf( &logger, " --->>> APP INIT <<<--- \r\n" );
}

void application_task ( void )
{
    thingstream_send_command( &thingstream, THINGSTREAM_GPS_INFO );  
    thingstream_process( );
    parser_application( current_parser_buf );
}

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;
}

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

额外支持

资源

喜欢这个项目吗?

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

想查看更多

类似项目