连接到Click Cloud从未如此简单。我们的解决方案旨在作为您的Click Cloud连接点,通过3.75G UMTS/HSPA网络的速度和效率增强,确保为企业提供优化的云体验。
A
A
硬件概览
它是如何工作的?
G2C 3G Click基于Trasna的SARA-U201 HSPA模块,支持2G回退,可以通过3.75G UMTS/HSPA网络连接到功能丰富的Click Cloud平台。G2C 3G Click的设计旨在让用户能够轻松添加云连接,并仅使用一组简单的AT命令开发基于云的应用程序,而无需深入了解与网页、硬件和通信相关的复杂开发。由于这种简化的方法,所有人都可以从G2C 3G Click中受益,因为这个Click板™已经在其固件中实现了所有必要的协议和通信设置。这节省了本来会浪费在固件开发和适应第三方解决方案上的时间。此外,这种努力还需要嵌入式和网页编程的熟练程度以及其他几种工程技能。另一方面,G2C 3G Click可以立即与
Click Cloud解决方案无缝协作。G2C 3G Click执行了连接到Click Cloud平台所需的几项任务。通过使用SIM卡访问本地UMTS/HSPA网络来建立连接。为了获得可靠的3G(UMTS/HSPA)网络连接,Click板™使用了可以全球使用的Trasna SARA U-201模块。Click板™使用一个强大的MCU来管理连接参数、初始化SARA U-201模块并与Click Cloud平台建立连接。这允许您通过发出简短的AT命令(如SSID、密码、设备ID等)在几个简单步骤中设置连接。每个AT命令及其响应的详细解释可以在AT命令手册中找到。除了用于设置基本连接参数的AT命令外,还有允许存储连接参数的AT命令,包括连接密
码、网络SSID、设备ID和其他相关连接数据。这些参数可以存储在G2C 3G Click的非易失性存储器中,可以通过一个宏命令恢复,从而简化连接过程。G2C 3G Click的功能将不断改进。因此,G2C 3G Click支持通过板载USB连接器升级其固件。固件更新过程很简单,使用MikroElektronika熟悉的“HID Bootloader”软件工具。G2C 3G Click配备了五个LED指示灯,指示电源供应的存在、UMTS/HSPA连接、USB连接、数据传输流量和与Click Cloud解决方案的连接。这些LED提供了关于G2C 3G Click状态的视觉反馈。此Click板™仅需5V电源轨即可正常运行。
功能概述
开发板
Clicker 2 for Kinetis 是一款紧凑型入门开发板,它将 Click 板™的灵活性带给您喜爱的微控制器,使其成为实现您想法的完美入门套件。它配备了一款板载 32 位 ARM Cortex-M4F 微控制器,NXP 半导体公司的 MK64FN1M0VDC12,两个 mikroBUS™ 插槽用于 Click 板™连接,一个 USB 连接器,LED 指示灯,按钮,一个 JTAG 程序员连接器以及两个 26 针头用于与外部电子设备的接口。其紧凑的设计和清晰、易识别的丝网标记让您能够迅速构建具有独特功能和特性
的小工具。Clicker 2 for Kinetis 开发套件的每个部分 都包含了使同一板块运行最高效的必要组件。除了可以选择 Clicker 2 for Kinetis 的编程方式,使用 USB HID mikroBootloader 或外部 mikroProg 连接器进行 Kinetis 编程外,Clicker 2 板还包括一个干净且调节过的开发套件电源供应模块。它提供了两种供电方式;通过 USB Micro-B 电缆,其中板载电压调节器为板上每个组件提供适当的电压水平,或使用锂聚合物 电池通过板载电池连接器供电。所有 mikroBUS™ 本
身支持的通信方法都在这块板上,包括已经建立良好的 mikroBUS™ 插槽、重置按钮和几个用户可配置的按钮及 LED 指示灯。Clicker 2 for Kinetis 是 Mikroe 生态系统的一个组成部分,允许您在几分钟内创建新的应用程序。它由 Mikroe 软件工具原生支持,得益于大量不同的 Click 板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作的许多方面。
微控制器概述
MCU卡片 / MCU

建筑
ARM Cortex-M4
MCU 内存 (KB)
1024
硅供应商
NXP
引脚数
121
RAM (字节)
262144
你完善了我!
配件
GPS/3G外部天线是我们GPS/GSM/3G Click boards™的理想选择。它在提供强大的GSM和3G信号接收以及出色的GPS定位能力方面表现出色。其坚固的设计具有螺钉安装和粘贴底座,确保牢固的固定和最佳的性能。该天线具有用于GPS、GSM和3G的独立线路,是需要可靠通信和精确定位的应用的多功能选择。其广泛的频率范围覆盖850/900/1800/1900/2100MHz和50Ω阻抗,保证了在各种网络频段的连接性。其2:1的VSW比和1到1.5dBic(取决于频率)的峰值增益进一步增强了信号强度。天线提供超过10MHz的带宽,确保一致的接收能力,同时其线性极化和全向方位覆盖提供全面的信号可及性。
使用的MCU引脚
mikroBUS™映射器
“仔细看看!”
Click board™ 原理图

一步一步来
项目组装
软件支持
库描述
该库包含 G2C 3G Click 驱动程序的 API。
关键功能:
g2c3g_reset_device- 此功能通过切换RST引脚来重置设备g2c3g_set_net_creds- 此功能设置输入的SIM卡的APN、用户名和密码g2c3g_set_broker_creds- 此功能设置经纪人凭据(设备密钥和密码)。
开源
代码示例
完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio。 应用程序代码也可以在MIKROE的GitHub账户中找到。
/*!
* @file main.c
* @brief G2C 3G 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:
* - G2C3G_CONNECT_TO_NETWORK:
* Sends commands to configure device to connect to the specified network.
*
* - G2C3G_CONNECT_TO_CLOUD:
* Sends commands to configure device to connect to the specified device on the cloud.
*
* - G2C3G_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 g2c3g_clear_app_buf ( void )
* - static err_t g2c3g_process ( void )
* - static void g2c3g_error_check( err_t error_flag )
* - static void g2c3g_log_app_buf ( void )
* - static err_t g2c3g_rsp_check ( uint8_t *rsp )
* - static err_t g2c3g_connect_to_network( void )
* - static err_t g2c3g_connect_to_cloud( void )
* - static err_t g2c3g_example( void )
*
* @note
* In order for the example to work, user needs to set the SIM card and the cloud device parameters.
* Enter valid values for the following macros:
* SIM_APN, SIM_USERNAME, SIM_PASSWORD, DEVICE_KEY, DEVICE_PASSWORD, DEVICE_SENSOR_REF.
* Example:
* SIM_APN "internet"
* SIM_USERNAME "internet"
* SIM_PASSWORD "internet"
* 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 "g2c3g.h"
#include "conversions.h"
// SIM card config parameters
#define SIM_APN "" // Set valid SIM APN
#define SIM_USERNAME "" // Set valid SIM username
#define SIM_PASSWORD "" // Set valid SIM 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
{
G2C3G_CONNECT_TO_NETWORK = 1,
G2C3G_CONNECT_TO_CLOUD,
G2C3G_EXAMPLE
} g2c3g_example_state_t;
static g2c3g_t g2c3g;
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 g2c3g_example_state_t example_state;
/**
* @brief G2C 3G clearing application buffer.
* @details This function clears memory of application buffer and reset its length.
* @note None.
*/
static void g2c3g_clear_app_buf ( void );
/**
* @brief G2C 3G 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 g2c3g_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 g2c3g_error_check ( err_t error_flag );
/**
* @brief Logs application buffer.
* @details This function logs data from application buffer.
*/
static void g2c3g_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 g2c3g_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 g2c3g_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 g2c3g_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 g2c3g_example ( void );
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
g2c3g_cfg_t g2c3g_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.
g2c3g_cfg_setup( &g2c3g_cfg );
G2C3G_MAP_MIKROBUS( g2c3g_cfg, MIKROBUS_1 );
if ( UART_ERROR == g2c3g_init( &g2c3g, &g2c3g_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
// Clear RX buffer
g2c3g_process( );
g2c3g_clear_app_buf( );
Delay_ms ( 100 );
// Reset device
g2c3g_reset_device ( &g2c3g );
error_flag = g2c3g_rsp_check( G2C3G_RSP_DEVICE_READY );
g2c3g_error_check( error_flag );
// Check communication
g2c3g_send_cmd( &g2c3g, G2C3G_CMD_AT );
error_flag = g2c3g_rsp_check( G2C3G_RSP_OK );
g2c3g_error_check( error_flag );
log_info( &logger, " Application Task " );
example_state = G2C3G_CONNECT_TO_NETWORK;
}
void application_task ( void )
{
switch ( example_state )
{
case G2C3G_CONNECT_TO_NETWORK:
{
if ( G2C3G_OK == g2c3g_connect_to_network( ) )
{
example_state = G2C3G_CONNECT_TO_CLOUD;
}
break;
}
case G2C3G_CONNECT_TO_CLOUD:
{
if ( G2C3G_OK == g2c3g_connect_to_cloud( ) )
{
example_state = G2C3G_EXAMPLE;
}
break;
}
case G2C3G_EXAMPLE:
{
g2c3g_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 g2c3g_clear_app_buf ( void )
{
memset( app_buf, 0, app_buf_len );
app_buf_len = 0;
}
static err_t g2c3g_process ( void )
{
uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
int32_t rx_size = 0;
rx_size = g2c3g_generic_read( &g2c3g, 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 G2C3G_OK;
}
return G2C3G_ERROR;
}
static err_t g2c3g_rsp_check ( uint8_t *rsp )
{
uint32_t timeout_cnt = 0;
uint32_t timeout = 120000;
g2c3g_clear_app_buf( );
g2c3g_process( );
while ( ( 0 == strstr( app_buf, rsp ) ) &&
( 0 == strstr( app_buf, G2C3G_RSP_ERROR ) ) )
{
g2c3g_process( );
if ( timeout_cnt++ > timeout )
{
g2c3g_clear_app_buf( );
return G2C3G_ERROR_TIMEOUT;
}
Delay_ms ( 1 );
}
Delay_ms ( 100 );
g2c3g_process( );
if ( strstr( app_buf, rsp ) )
{
return G2C3G_OK;
}
else if ( strstr( app_buf, G2C3G_RSP_ERROR ) )
{
return G2C3G_ERROR_CMD;
}
else
{
return G2C3G_ERROR_UNKNOWN;
}
}
static void g2c3g_error_check ( err_t error_flag )
{
switch ( error_flag )
{
case G2C3G_OK:
{
g2c3g_log_app_buf( );
break;
}
case G2C3G_ERROR:
{
log_error( &logger, " Overflow!" );
break;
}
case G2C3G_ERROR_TIMEOUT:
{
log_error( &logger, " Timeout!" );
break;
}
case G2C3G_ERROR_CMD:
{
log_error( &logger, " CMD!" );
break;
}
case G2C3G_ERROR_UNKNOWN:
default:
{
log_error( &logger, " Unknown!" );
break;
}
}
Delay_ms ( 500 );
}
static void g2c3g_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 g2c3g_connect_to_network ( void )
{
err_t func_error = G2C3G_OK;
uint32_t timeout_cnt = 0;
uint32_t timeout = 120000;
Delay_ms ( 500 );
// Enable connector module
#define ENABLE_CONNECTOR_MODULE "1"
g2c3g_send_cmd_with_par( &g2c3g, G2C3G_CMD_CEN, ENABLE_CONNECTOR_MODULE );
error_flag = g2c3g_rsp_check( G2C3G_RSP_OK );
func_error |= error_flag;
g2c3g_error_check( error_flag );
// Set network credentials
g2c3g_set_net_creds( &g2c3g, SIM_APN, SIM_USERNAME, SIM_PASSWORD );
error_flag = g2c3g_rsp_check( G2C3G_RSP_OK );
func_error |= error_flag;
g2c3g_error_check( error_flag );
// Connect to network
#define CONNECT_TO_NETWORK "1"
g2c3g_send_cmd_with_par( &g2c3g, G2C3G_CMD_NWC, CONNECT_TO_NETWORK );
error_flag = g2c3g_rsp_check( G2C3G_RSP_OK );
func_error |= error_flag;
g2c3g_error_check( error_flag );
// Check for the network connect indication pin
while ( !g2c3g_get_gp1_pin ( &g2c3g ) )
{
if ( timeout_cnt++ > timeout )
{
g2c3g_clear_app_buf( );
func_error = G2C3G_ERROR_TIMEOUT;
break;
}
Delay_ms ( 1 );
}
return func_error;
}
static err_t g2c3g_connect_to_cloud ( void )
{
err_t func_error = G2C3G_OK;
uint32_t timeout_cnt = 0;
uint32_t timeout = 120000;
Delay_ms ( 500 );
g2c3g_set_broker_creds( &g2c3g, DEVICE_KEY, DEVICE_PASSWORD );
error_flag = g2c3g_rsp_check( G2C3G_RSP_OK );
func_error |= error_flag;
g2c3g_error_check( error_flag );
// Connect to broker
#define CONNECT_TO_BROKER "1"
g2c3g_send_cmd_with_par( &g2c3g, G2C3G_CMD_BRC, CONNECT_TO_BROKER );
error_flag = g2c3g_rsp_check( G2C3G_RSP_OK );
func_error |= error_flag;
g2c3g_error_check( error_flag );
// Check for the cloud connect indication pin
while ( !g2c3g_get_gp0_pin ( &g2c3g ) )
{
if ( timeout_cnt++ > timeout )
{
g2c3g_clear_app_buf( );
func_error = G2C3G_ERROR_TIMEOUT;
break;
}
Delay_ms ( 1 );
}
return func_error;
}
static err_t g2c3g_example ( void )
{
err_t func_error = G2C3G_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 );
g2c3g_send_cmd_with_par( &g2c3g, G2C3G_CMD_DSET, cmd_buf );
error_flag = g2c3g_rsp_check( G2C3G_RSP_OK );
func_error |= error_flag;
g2c3g_error_check( error_flag );
Delay_ms ( 500 );
// Publish data to the cloud
g2c3g_send_cmd( &g2c3g, G2C3G_CMD_PUB );
error_flag = g2c3g_rsp_check( G2C3G_RSP_OK );
func_error |= error_flag;
g2c3g_error_check( error_flag );
g2c3g_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++ )
{
g2c3g_process ( );
if ( app_buf_len )
{
g2c3g_log_app_buf ( );
g2c3g_clear_app_buf ( );
}
Delay_1ms ( );
}
return func_error;
}
// ------------------------------------------------------------------------ END
额外支持
资源
类别:GSM/LTE

































