wirelesssun  2.1.0.0
Main Page

Wireless SUN click

PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU

[click Product page](CLICK_PRODUCT_PAGE_LINK)


Click library

  • Author : Stefan Filipovic
  • Date : Aug 2022.
  • Type : UART type

Software Support

We provide a library for the Wireless SUN Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

This library contains API for Wireless SUN Click driver.

Standard key functions :

Example key functions :

Example Description

This example demonstrates the use of Wireless SUN click board by showing the communication between the two click boards configured as BORDER and ROUTER.

The demo application is composed of two sections :

Application Init

Initializes the driver and configures the click board by performing a hardware reset

and a clear parameters feature, and setting the device network name, device role to BORDER or ROUTER depending on the application mode. In the end, it saves settings and reboots device.

void application_init ( void )
{
log_cfg_t log_cfg;
wirelesssun_cfg_t wirelesssun_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
wirelesssun_cfg_setup( &wirelesssun_cfg );
WIRELESSSUN_MAP_MIKROBUS( wirelesssun_cfg, MIKROBUS_1 );
if ( UART_ERROR == wirelesssun_init( &wirelesssun, &wirelesssun_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
app_buf_len = 0;
app_buf_cnt = 0;
log_printf( &logger, "\r\n - Reset device -\r\n" );
wirelesssun_reset_device ( &wirelesssun );
wirelesssun_rsp_check ( );
log_printf( &logger, "\r\n - Clear parameters and reboot device -\r\n" );
wirelesssun_rsp_check ( );
log_printf( &logger, "\r\n - Set device name -\r\n" );
wirelesssun_rsp_check ( );
log_printf( &logger, "\r\n - Set device starting role -\r\n" );
#ifdef DEMO_APP_BORDER
#else
#endif
wirelesssun_rsp_check ( );
log_printf( &logger, "\r\n - Save settings and reboot device -\r\n" );
wirelesssun_rsp_check ( );
log_info( &logger, " Application Task " );
}

Application Task

Depending on the selected application mode, it reads all the received data and parses

the received TCP/UDP messages (BORDER mode) or waits for the connection, reads the parent global address, and then starts sending a desired TCP/UDP messages to the parent every 3 seconds (ROUTER mode).

void application_task ( void )
{
#ifdef DEMO_APP_BORDER
wirelesssun_process( );
if ( strstr( app_buf, WIRELESSSUN_CMD_PROMPT_SIGN ) )
{
uint8_t demo_hex_msg[ 100 ] = { 0 };
uint8_t demo_text_msg[ 50 ] = { 0 };
char * __generic_ptr start_msg_ptr = NULL;
char * __generic_ptr end_msg_ptr = NULL;
uint8_t msg_len = 0;
uint8_t msg_cnt = 0;
if ( ( strstr( app_buf, WIRELESSSUN_RSP_TCPR ) ) || ( strstr( app_buf, WIRELESSSUN_RSP_UDPR ) ) )
{
if ( strstr( app_buf, WIRELESSSUN_RSP_TCPR ) )
{
start_msg_ptr = strstr( app_buf, WIRELESSSUN_RSP_TCPR );
}
else
{
start_msg_ptr = strstr( app_buf, WIRELESSSUN_RSP_UDPR );
}
start_msg_ptr = strstr ( start_msg_ptr, ">" ) + 2;
end_msg_ptr = strstr( start_msg_ptr, WIRELESSSUN_CMD_PROMPT_SIGN );
msg_len = ( end_msg_ptr - start_msg_ptr );
memcpy ( demo_hex_msg, start_msg_ptr, msg_len );
for ( msg_cnt = 0; msg_cnt < msg_len; msg_cnt += 2 )
{
demo_text_msg[ msg_cnt / 2 ] = hex_to_uint8 ( &demo_hex_msg [ msg_cnt ] );
}
if ( strstr( app_buf, WIRELESSSUN_RSP_TCPR ) )
{
log_printf( &logger, "\r\n - Received TCP message: \"%s\" -\r\n", demo_text_msg );
}
else
{
log_printf( &logger, "\r\n - Received UDP message: \"%s\" -\r\n", demo_text_msg );
}
}
wirelesssun_clear_app_buf( );
}
#else
wirelesssun_wait_for_connection ( );
uint8_t gbl_address[ 20 ] = { 0 };
wirelesssun_get_parent_gbl_address ( gbl_address );
for ( ; ; )
{
uint8_t tcp_udp_params[ 120 ] = { 0 };
uint8_t demo_hex_msg[ 100 ] = { 0 };
uint8_t demo_text_msg[ 50 ] = { 0 };
uint8_t msg_cnt = 0;
strcpy ( demo_text_msg, DEMO_TEXT_MESSAGE );
strcpy ( tcp_udp_params, gbl_address );
strcat ( tcp_udp_params, WIRELESSSUN_CMD_DELIMITER );
strcat ( tcp_udp_params, WIRELESSSUN_DEFAULT_PORT );
strcat ( tcp_udp_params, WIRELESSSUN_CMD_DELIMITER );
for ( msg_cnt = 0; msg_cnt < strlen ( demo_text_msg ); msg_cnt++ )
{
uint8_to_hex ( demo_text_msg[ msg_cnt ], &demo_hex_msg[ msg_cnt * 2 ] );
}
strcat ( tcp_udp_params, demo_hex_msg );
log_printf( &logger, "\r\n - Sending \"%s\" message via TCP -\r\n", demo_text_msg );
wirelesssun_send_cmd_with_parameter ( &wirelesssun, WIRELESSSUN_CMD_TCPS, tcp_udp_params );
wirelesssun_rsp_check ( );
Delay_ms ( 3000 );
log_printf( &logger, "\r\n - Sending \"%s\" message via UDP -\r\n", demo_text_msg );
wirelesssun_send_cmd_with_parameter ( &wirelesssun, WIRELESSSUN_CMD_UDPS, tcp_udp_params );
wirelesssun_rsp_check ( );
Delay_ms ( 3000 );
}
#endif
}

Note

By default, the BORDER application mode is selected. comment out the DEMO_APP_BORDER macro definition in order to switch the application mode to ROUTER.

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.WirelessSUN

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.


wirelesssun_send_cmd_with_parameter
void wirelesssun_send_cmd_with_parameter(wirelesssun_t *ctx, char *cmd, char *param_buf)
Wireless SUN send cmd function.
WIRELESSSUN_CMD_NETNAME
#define WIRELESSSUN_CMD_NETNAME
Definition: wirelesssun.h:74
wirelesssun_send_cmd
void wirelesssun_send_cmd(wirelesssun_t *ctx, char *cmd)
Wireless SUN send cmd function.
wirelesssun_reset_device
void wirelesssun_reset_device(wirelesssun_t *ctx)
Wireless SUN reset device function.
WIRELESSSUN_CMD_ATSTART
#define WIRELESSSUN_CMD_ATSTART
Definition: wirelesssun.h:77
WIRELESSSUN_DEVICE_ROLE_BORDER
#define WIRELESSSUN_DEVICE_ROLE_BORDER
Definition: wirelesssun.h:130
WIRELESSSUN_CMD_TCPS
#define WIRELESSSUN_CMD_TCPS
Definition: wirelesssun.h:96
WIRELESSSUN_CMD_SVRST
#define WIRELESSSUN_CMD_SVRST
Definition: wirelesssun.h:112
application_task
void application_task(void)
Definition: main.c:163
WIRELESSSUN_RSP_TCPR
#define WIRELESSSUN_RSP_TCPR
Definition: wirelesssun.h:123
WIRELESSSUN_DEVICE_ROLE_ROUTER
#define WIRELESSSUN_DEVICE_ROLE_ROUTER
Definition: wirelesssun.h:131
WIRELESSSUN_CMD_PROMPT_SIGN
#define WIRELESSSUN_CMD_PROMPT_SIGN
Definition: wirelesssun.h:114
WIRELESSSUN_CMD_CLRST
#define WIRELESSSUN_CMD_CLRST
Definition: wirelesssun.h:113
WIRELESSSUN_DEFAULT_PORT
#define WIRELESSSUN_DEFAULT_PORT
Wireless SUN TCP/UDP port settings.
Definition: wirelesssun.h:138
DEVICE_NETWORK_NAME
#define DEVICE_NETWORK_NAME
Definition: main.c:47
WIRELESSSUN_MAP_MIKROBUS
#define WIRELESSSUN_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: wirelesssun.h:164
WIRELESSSUN_CMD_UDPS
#define WIRELESSSUN_CMD_UDPS
Definition: wirelesssun.h:97
wirelesssun_cfg_setup
void wirelesssun_cfg_setup(wirelesssun_cfg_t *cfg)
Wireless SUN configuration object setup function.
WIRELESSSUN_CMD_DELIMITER
#define WIRELESSSUN_CMD_DELIMITER
Definition: wirelesssun.h:115
wirelesssun_init
err_t wirelesssun_init(wirelesssun_t *ctx, wirelesssun_cfg_t *cfg)
Wireless SUN initialization function.
wirelesssun_t
Wireless SUN Click context object.
Definition: wirelesssun.h:179
wirelesssun_cfg_t
Wireless SUN Click configuration object.
Definition: wirelesssun.h:201
application_init
void application_init(void)
Definition: main.c:107
DEMO_TEXT_MESSAGE
#define DEMO_TEXT_MESSAGE
Definition: main.c:50
WIRELESSSUN_RSP_UDPR
#define WIRELESSSUN_RSP_UDPR
Wireless SUN UDP/TCP responses.
Definition: wirelesssun.h:122
wirelesssun_generic_read
err_t wirelesssun_generic_read(wirelesssun_t *ctx, char *data_out, uint16_t len)
Wireless SUN data reading function.