通过我们的网关解决方案体验最优质的创新,安全连接到Click Cloud,这是将您的创意变为现实的理想平台。
A
A
硬件概览
它是如何工作的?
Go to Cloud (G2C) Click是一款Click板™,允许通过WiFi网络连接到功能丰富的Click Cloud平台。Go to Cloud (G2C) Click旨在让用户可以轻松添加云连接,并使用一组简单的AT命令开发自己的基于云的应用程序,而无需深入研究与网页、硬件和通信相关的复杂开发。由于这种简化的方法,任何人都可以使用Go to Cloud (G2C) Click和Click Cloud解决方案获益,因为该Click板™的固件中已经实现了所有必要的协议和通信设置。这节省了本来会浪费在固件开发上的大量时间,以及适应第三方解决方案的时间。更不用说,这样的努力还需要嵌入式和网页编程的熟练程度,以及其他多项工程技能。而G2C Click与Click Cloud解决方案紧密配
合,开箱即用。Go to Cloud (G2C) Click在其端执行若干任务,这些任务是连接到Click Cloud平台所必需的。要建立连接,需要访问具有Internet连接的WiFi网络。为了可靠的WiFi网络连接,Click板™采用了ESP WROOM-02 WiFi模块,这是一个成熟的集成WiFi解决方案。Click板™使用一个强大的MCU来管理连接参数,初始化ESP-WROOM-02 WiFi模块,并与Click Cloud平台建立连接。这使得通过发出一组简短的AT命令(例如SSID、密码、device_ID等)可以在几个简单步骤内设置连接。每个AT命令及其响应的详细解释可以在AT命令手册中找到。除了用于设置基本连接参数的AT命令外,还有AT命令允许存储连接参数,包括连
接密码、网络SSID、device_ID和其他相关连接数据。这些参数可以存储在Go to Cloud (G2C) Click的非易失性存储器中。可以通过一个宏命令恢复它们,从而简化连接过程。Go to Cloud (G2C) Click的功能将在未来不断改进。因此,Go to Cloud (G2C) Click支持通过板载USB连接器升级其固件。固件更新过程非常简单,使用MikroElektronika熟悉的“HID Bootloader”软件工具。Go to Cloud (G2C) Click配备了四个LED指示灯,用于指示电源、WiFi网络连接、USB连接和Click Cloud解决方案连接的状态。这些LED提供有关Go to Cloud (G2C) Click状态的视觉反馈。此Click板™需要3.3V和5V电源轨以正常运行。
功能概述
开发板
Nucleo-64 搭载 STM32G071RB MCU 提供了一种经济高效且灵活的平台,供开发者探索新想法并原型设计他们的项目。该板利用 STM32 微控制器的多功能性,使用户能够为他们的项目选择最佳的性能与功耗平衡。它配备了 LQFP64 封装的 STM32 微控制器,并包含了如用户 LED(同时作为 ARDUINO® 信号)、用户和复位按钮,以及 32.768kHz 晶体振荡器用于精确的计时操作等基本组件。Nucleo-64 板设计考虑到扩展性和灵活性,它特有的 ARDUINO® Uno
V3 扩展连接器和 ST morpho 扩展引脚头,提供了对 STM32 I/O 的完全访问,以实现全面的项目整合。电源供应选项灵活,支持 ST-LINK USB VBUS 或外部电源,确保在各种开发环境中的适应性。该板还配备了一个具有 USB 重枚举功能的板载 ST-LINK 调试器/编程器,简化了编程和调试过程。此外,该板设计旨在简化高级开发,它的外部 SMPS 为 Vcore 逻辑供电提供高效支持,支持 USB 设备全速或 USB SNK/UFP 全速,并内置加密功能,提升了项目的功效
和安全性。通过外部 SMPS 实验的专用连接器、 用于 ST-LINK 的 USB 连接器以及 MIPI® 调试连接器,提供了更多的硬件接口和实验可能性。开发者将通过 STM32Cube MCU Package 提供的全面免费软件库和示例得到广泛支持。这些,加上与多种集成开发环境(IDE)的兼容性,包括 IAR Embedded Workbench®、MDK-ARM 和 STM32CubeIDE,确保了流畅且高效的开发体验,使用户能够充分利用 Nucleo-64 板在他们的项目中的能力。
微控制器概述
MCU卡片 / MCU

建筑
ARM Cortex-M0
MCU 内存 (KB)
128
硅供应商
STMicroelectronics
引脚数
64
RAM (字节)
36864
你完善了我!
配件
Click Shield for Nucleo-64 配备了两个专有的 mikroBUS™ 插座,使得所有的 Click board™ 设备都可以轻松地与 STM32 Nucleo-64 开发板连接。这样,Mikroe 允许其用户从不断增长的 Click boards™ 范围中添加任何功能,如 WiFi、GSM、GPS、蓝牙、ZigBee、环境传感器、LED、语音识别、电机控制、运动传感器等。您可以使用超过 1537 个 Click boards™,这些 Click boards™ 可以堆叠和集成。STM32 Nucleo-64 开发板基于 64 引脚封装的微控制器,采用 32 位 MCU,配备 ARM Cortex M4 处理器,运行速度为 84MHz,具有 512Kb Flash 和 96KB SRAM,分为两个区域,顶部区域代表 ST-Link/V2 调试器和编程器,而底部区域是一个实际的开发板。通过 USB 连接方便地控制和供电这些板子,以便直接对 Nucleo-64 开发板进行编程和高效调试,其中还需要额外的 USB 线连接到板子上的 USB 迷你接口。大多数 STM32 微控制器引脚都连接到了板子左右边缘的 IO 引脚上,然后连接到两个现有的 mikroBUS™ 插座上。该 Click Shield 还有几个开关,用于选择 mikroBUS™ 插座上模拟信号的逻辑电平和 mikroBUS™ 插座本身的逻辑电压电平。此外,用户还可以通过现有的双向电平转换器,使用任何 Click board™,无论 Click board™ 是否在 3.3V 或 5V 逻辑电压电平下运行。一旦将 STM32 Nucleo-64 开发板与我们的 Click Shield for Nucleo-64 连接,您就可以访问数百个工作于 3.3V 或 5V 逻辑电压电平的 Click boards™。
使用的MCU引脚
mikroBUS™映射器
“仔细看看!”
Click board™ 原理图

一步一步来
项目组装
实时跟踪您的结果
应用程序输出
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”替换为要显示的参数。

软件支持
库描述
该库包含Go to Cloud (G2C) Click驱动程序的 API。
关键功能:
g2c_reset_device
- 通过切换RST引脚重置设备。g2c_set_net_creds
- 设置WiFi网络凭据。g2c_set_broker_creds
- 设置代理凭据(设备密钥和密码)。
开源
代码示例
完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio。 应用程序代码也可以在MIKROE的GitHub账户中找到。
/*!
* @file main.c
* @brief G2C Click Example.
*
* # Description
* This example shows the device capability of connecting to the cloud and
* updating the sensor data on the cloud and receiving data from actuators.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes the driver, restarts the device, and after that tests
* the communication by sending "AT" command.
*
* ## Application Task
* Application task is split in few stages:
* - G2C_CONNECT_TO_NETWORK:
* Sends commands to configure device to connect to the specified network.
*
* - G2C_CONNECT_TO_CLOUD:
* Sends commands to configure device to connect to the specified device on the cloud.
*
* - G2C_EXAMPLE:
* This function executes example which updates sensor data on the cloud and displays
* all data received from the module (ex. the actuator switch state change received
* from the cloud).
*
* ## Additional Function
* - static void g2c_clear_app_buf ( void )
* - static err_t g2c_process ( void )
* - static void g2c_error_check( err_t error_flag )
* - static void g2c_log_app_buf ( void )
* - static err_t g2c_rsp_check ( uint8_t *rsp )
* - static err_t g2c_connect_to_network( void )
* - static err_t g2c_connect_to_cloud( void )
* - static err_t g2c_example( void )
*
* @note
* In order for the example to work, user needs to set the WiFi credentials and the cloud device parameters.
* Enter valid values for the following macros:
* WIFI_SSID, WIFI_PASS, DEVICE_KEY, DEVICE_PASSWORD, DEVICE_SENSOR_REF.
* Example:
* WIFI_SSID "MikroE Public"
* WIFI_PASS "mikroe.guest"
* DEVICE_KEY "xxxxxxxxxxxxxxxx"
* DEVICE_PASSWORD "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
* DEVICE_SENSOR_REF "TEMP_SEN_R"
*
* DEVICE_KEY and DEVICE_PASSWORD strings should match the device credentials which
* were generated during the Click Cloud device creation step.
* DEVICE_SENSOR_REF is expected to be a reference to a temperature sensor with a data
* range from -20 to +80 degrees Celsius.
* For more information about the registration on the Click Cloud and creating the device
* refer to the following user guide:
* https://download.mikroe.com/documents/click-cloud/guide-to-click-cloud.pdf
*
* @author Stefan Filipovic
*
*/
#include "board.h"
#include "log.h"
#include "g2c.h"
#include "conversions.h"
// Network config parameters
#define WIFI_SSID "MikroE Public" // Set valid WiFi SSID
#define WIFI_PASS "mikroe.guest" // Set valid WiFi Password
// Cloud device config parameters
#define DEVICE_KEY "" // Cloud device key
#define DEVICE_PASSWORD "" // Cloud device password
#define DEVICE_SENSOR_REF "" // Cloud device sensor reference
// Application buffer size
#define APP_BUFFER_SIZE 300
#define PROCESS_BUFFER_SIZE 300
/**
* @brief Example states.
* @details Predefined enum values for application example state.
*/
typedef enum
{
G2C_CONNECT_TO_NETWORK = 1,
G2C_CONNECT_TO_CLOUD,
G2C_EXAMPLE
} g2c_example_state_t;
static g2c_t g2c;
static log_t logger;
/**
* @brief Application example variables.
* @details Variables used in application example.
*/
static uint8_t app_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;
static err_t error_flag;
static g2c_example_state_t example_state;
/**
* @brief G2C clearing application buffer.
* @details This function clears memory of application buffer and reset its length.
* @note None.
*/
static void g2c_clear_app_buf ( void );
/**
* @brief G2C 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.
* See #err_t definition for detailed explanation.
* @note None.
*/
static err_t g2c_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 g2c_error_check ( err_t error_flag );
/**
* @brief Logs application buffer.
* @details This function logs data from application buffer.
*/
static void g2c_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 g2c_rsp_check ( uint8_t *rsp );
/**
* @brief Configure device to connect to the network.
* @details Sends commands to configure device to connect 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 g2c_connect_to_network ( void );
/**
* @brief Configure device to connect to the cloud.
* @details Sends commands to configure device to connect to the specified device on the cloud.
* @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 g2c_connect_to_cloud ( void );
/**
* @brief Execute example.
* @details This function executes example which updates sensor data on the cloud and displays
* all data received from the module (ex. the actuator state change received from the cloud).
* @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 g2c_example ( void );
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
g2c_cfg_t g2c_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.
g2c_cfg_setup( &g2c_cfg );
G2C_MAP_MIKROBUS( g2c_cfg, MIKROBUS_1 );
if ( UART_ERROR == g2c_init( &g2c, &g2c_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
// Clear RX buffer
g2c_process( );
g2c_clear_app_buf( );
Delay_ms ( 100 );
// Reset device
g2c_reset_device ( &g2c );
// Check communication
log_printf( &logger, "Test communication\r\n" );
Delay_ms ( 100 );
g2c_send_cmd( &g2c, G2C_CMD_AT );
error_flag = g2c_rsp_check( G2C_RSP_OK );
g2c_error_check( error_flag );
// Enable command echo
log_printf( &logger, "Enable echo\r\n" );
Delay_ms ( 100 );
g2c_send_cmd( &g2c, G2C_CMD_ATE1 );
error_flag = g2c_rsp_check( G2C_RSP_OK );
g2c_error_check( error_flag );
log_info( &logger, " Application Task " );
example_state = G2C_CONNECT_TO_NETWORK;
}
void application_task ( void )
{
switch ( example_state )
{
case G2C_CONNECT_TO_NETWORK:
{
if ( G2C_OK == g2c_connect_to_network( ) )
{
example_state = G2C_CONNECT_TO_CLOUD;
}
break;
}
case G2C_CONNECT_TO_CLOUD:
{
if ( G2C_OK == g2c_connect_to_cloud( ) )
{
example_state = G2C_EXAMPLE;
}
break;
}
case G2C_EXAMPLE:
{
g2c_example( );
break;
}
default:
{
log_error( &logger, " Example 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 g2c_clear_app_buf ( void )
{
memset( app_buf, 0, app_buf_len );
app_buf_len = 0;
}
static err_t g2c_process ( void )
{
uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
int32_t rx_size = 0;
rx_size = g2c_generic_read( &g2c, rx_buf, PROCESS_BUFFER_SIZE );
if ( rx_size > 0 )
{
int32_t buf_cnt = app_buf_len;
if ( ( ( app_buf_len + rx_size ) > PROCESS_BUFFER_SIZE ) && ( app_buf_len > 0 ) )
{
buf_cnt = PROCESS_BUFFER_SIZE - ( ( app_buf_len + rx_size ) - PROCESS_BUFFER_SIZE );
memmove ( app_buf, &app_buf[ PROCESS_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 < PROCESS_BUFFER_SIZE )
{
app_buf_len++;
}
}
}
return G2C_OK;
}
return G2C_ERROR;
}
static err_t g2c_rsp_check ( uint8_t *rsp )
{
uint32_t timeout_cnt = 0;
uint32_t timeout = 120000;
g2c_clear_app_buf( );
g2c_process( );
while ( ( 0 == strstr( app_buf, rsp ) ) &&
( 0 == strstr( app_buf, G2C_RSP_ERROR ) ) )
{
g2c_process( );
if ( timeout_cnt++ > timeout )
{
g2c_clear_app_buf( );
return G2C_ERROR_TIMEOUT;
}
Delay_ms ( 1 );
}
Delay_ms ( 100 );
g2c_process( );
if ( strstr( app_buf, rsp ) )
{
return G2C_OK;
}
else if ( strstr( app_buf, G2C_RSP_ERROR ) )
{
return G2C_ERROR_CMD;
}
else
{
return G2C_ERROR_UNKNOWN;
}
}
static void g2c_error_check ( err_t error_flag )
{
switch ( error_flag )
{
case G2C_OK:
{
g2c_log_app_buf( );
break;
}
case G2C_ERROR:
{
log_error( &logger, " Overflow!" );
break;
}
case G2C_ERROR_TIMEOUT:
{
log_error( &logger, " Timeout!" );
break;
}
case G2C_ERROR_CMD:
{
log_error( &logger, " CMD!" );
break;
}
case G2C_ERROR_UNKNOWN:
default:
{
log_error( &logger, " Unknown!" );
break;
}
}
Delay_ms ( 500 );
}
static void g2c_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 g2c_connect_to_network ( void )
{
err_t func_error = G2C_OK;
Delay_ms ( 500 );
// Enable connector module
#define ENABLE_CONNECTOR_MODULE "1"
g2c_send_cmd_with_par( &g2c, G2C_CMD_CEN, ENABLE_CONNECTOR_MODULE );
error_flag = g2c_rsp_check( G2C_RSP_OK );
func_error |= error_flag;
g2c_error_check( error_flag );
// Enable DHCP
#define ENABLE_DHCP "1"
g2c_send_cmd_with_par( &g2c, G2C_CMD_NWP, ENABLE_DHCP );
error_flag = g2c_rsp_check( G2C_RSP_OK );
func_error |= error_flag;
g2c_error_check( error_flag );
// Set network credentials
g2c_set_net_creds( &g2c, WIFI_SSID, WIFI_PASS );
error_flag = g2c_rsp_check( G2C_RSP_OK );
func_error |= error_flag;
g2c_error_check( error_flag );
// Connect to network
#define CONNECT_TO_NETWORK "1"
g2c_send_cmd_with_par( &g2c, G2C_CMD_NWC, CONNECT_TO_NETWORK );
error_flag = g2c_rsp_check( G2C_RSP_OK );
func_error |= error_flag;
g2c_error_check( error_flag );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
return func_error;
}
static err_t g2c_connect_to_cloud ( void )
{
err_t func_error = G2C_OK;
Delay_ms ( 500 );
g2c_set_broker_creds( &g2c, DEVICE_KEY, DEVICE_PASSWORD );
error_flag = g2c_rsp_check( G2C_RSP_OK );
func_error |= error_flag;
g2c_error_check( error_flag );
// Connect to broker
#define CONNECT_TO_BROKER "1"
g2c_send_cmd_with_par( &g2c, G2C_CMD_BRC, CONNECT_TO_BROKER );
error_flag = g2c_rsp_check( G2C_RSP_OK );
func_error |= error_flag;
g2c_error_check( error_flag );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
return func_error;
}
static err_t g2c_example ( void )
{
err_t func_error = G2C_OK;
#define ACTUATOR_WAIT_TIME_MS 10000 // This setting also affects the sensor data update rate
#define TEMPERATURE_MIN -20
#define TEMPERATURE_MAX 80
#define TEMPERATURE_STEP 5
static int8_t temperature = TEMPERATURE_MIN;
uint8_t cmd_buf[ 100 ] = { 0 };
uint8_t temperature_buf[ 10 ] = { 0 };
uint8_t cmd_separator[ 2 ] = { ',', 0 };
uint8_t quote_mark[ 2 ] = { '\"', 0 };
int8_to_str( temperature, temperature_buf );
l_trim( temperature_buf );
r_trim( temperature_buf );
// Store data to the internal memory.
strcpy( cmd_buf, quote_mark );
strcat( cmd_buf, DEVICE_SENSOR_REF );
strcat( cmd_buf, quote_mark );
strcat( cmd_buf, cmd_separator );
strcat( cmd_buf, quote_mark );
strcat( cmd_buf, temperature_buf );
strcat( cmd_buf, quote_mark );
g2c_send_cmd_with_par( &g2c, G2C_CMD_DSET, cmd_buf );
error_flag = g2c_rsp_check( G2C_RSP_OK );
func_error |= error_flag;
g2c_error_check( error_flag );
Delay_ms ( 500 );
// Publish data to the cloud
g2c_send_cmd( &g2c, G2C_CMD_PUB );
error_flag = g2c_rsp_check( G2C_RSP_OK );
func_error |= error_flag;
g2c_error_check( error_flag );
g2c_clear_app_buf( );
temperature += TEMPERATURE_STEP;
if ( temperature > TEMPERATURE_MAX )
{
temperature = TEMPERATURE_MIN;
}
// Check for the actuator response
for ( uint32_t act_wait_cnt = 0; act_wait_cnt < ACTUATOR_WAIT_TIME_MS; act_wait_cnt++ )
{
g2c_process ( );
if ( app_buf_len )
{
g2c_log_app_buf ( );
g2c_clear_app_buf ( );
}
Delay_1ms ( );
}
return func_error;
}
// ------------------------------------------------------------------------ END
额外支持
资源
类别:无线网络