g2c 2.1.0.0
main.c File Reference

G2C Click Example. More...

#include "board.h"
#include "log.h"
#include "g2c.h"
#include "conversions.h"

Macros

#define WIFI_SSID   "MikroE Public"
 
#define WIFI_PASS   "mikroe.guest"
 
#define DEVICE_KEY   ""
 
#define DEVICE_PASSWORD   ""
 
#define DEVICE_SENSOR_REF   ""
 
#define APP_BUFFER_SIZE   300
 
#define PROCESS_BUFFER_SIZE   300
 
#define ENABLE_CONNECTOR_MODULE   "1"
 
#define ENABLE_DHCP   "1"
 
#define CONNECT_TO_NETWORK   "1"
 
#define CONNECT_TO_BROKER   "1"
 
#define ACTUATOR_WAIT_TIME_MS   10000
 
#define TEMPERATURE_MIN   -20
 
#define TEMPERATURE_MAX   80
 
#define TEMPERATURE_STEP   5
 

Enumerations

enum  g2c_example_state_t { G2C_CONNECT_TO_NETWORK = 1 , G2C_CONNECT_TO_CLOUD , G2C_EXAMPLE }
 Example states. More...
 

Functions

void application_init (void)
 
void application_task (void)
 
int main (void)
 

Detailed Description

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

Macro Definition Documentation

◆ ACTUATOR_WAIT_TIME_MS

#define ACTUATOR_WAIT_TIME_MS   10000

◆ APP_BUFFER_SIZE

#define APP_BUFFER_SIZE   300

◆ CONNECT_TO_BROKER

#define CONNECT_TO_BROKER   "1"

◆ CONNECT_TO_NETWORK

#define CONNECT_TO_NETWORK   "1"

◆ DEVICE_KEY

#define DEVICE_KEY   ""

◆ DEVICE_PASSWORD

#define DEVICE_PASSWORD   ""

◆ DEVICE_SENSOR_REF

#define DEVICE_SENSOR_REF   ""

◆ ENABLE_CONNECTOR_MODULE

#define ENABLE_CONNECTOR_MODULE   "1"

◆ ENABLE_DHCP

#define ENABLE_DHCP   "1"

◆ PROCESS_BUFFER_SIZE

#define PROCESS_BUFFER_SIZE   300

◆ TEMPERATURE_MAX

#define TEMPERATURE_MAX   80

◆ TEMPERATURE_MIN

#define TEMPERATURE_MIN   -20

◆ TEMPERATURE_STEP

#define TEMPERATURE_STEP   5

◆ WIFI_PASS

#define WIFI_PASS   "mikroe.guest"

◆ WIFI_SSID

#define WIFI_SSID   "MikroE Public"

Enumeration Type Documentation

◆ g2c_example_state_t

Example states.

Predefined enum values for application example state.

Enumerator
G2C_CONNECT_TO_NETWORK 
G2C_CONNECT_TO_CLOUD 
G2C_EXAMPLE 

Function Documentation

◆ application_init()

void application_init ( void )

< Logger config object.

< 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 LOG_MAP_USB_UART macro definition for detailed explanation.

◆ application_task()

void application_task ( void )

◆ main()

int main ( void )