Skip to content

Latest commit

 

History

History

neomesh915mhz

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

NeoMesh 915MHz Click

NeoMesh 915MHz Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.


Click Library

  • Author : Stefan Filipovic
  • Date : Sep 2023.
  • Type : UART type

Software Support

Example Description

This example demonstrates the use of NeoMesh 915MHz Click board by showing the communication between the two Click boards.

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.NeoMesh915MHz

Example Key Functions

  • neomesh915mhz_cfg_setup Config Object Initialization function.
void neomesh915mhz_cfg_setup ( neomesh915mhz_cfg_t *cfg );
  • neomesh915mhz_init Initialization function.
err_t neomesh915mhz_init ( neomesh915mhz_t *ctx, neomesh915mhz_cfg_t *cfg );
  • neomesh915mhz_send_aapi_frame This function sends a desired AAPI frame by using UART serial interface.
err_t neomesh915mhz_send_aapi_frame ( neomesh915mhz_t *ctx, neomesh915mhz_aapi_frame_t *frame );
  • neomesh915mhz_read_aapi_frame This function reads an AAPI frame by using UART serial interface.
err_t neomesh915mhz_read_aapi_frame ( neomesh915mhz_t *ctx, neomesh915mhz_aapi_frame_t *frame );
  • neomesh915mhz_send_sapi_frame This function sends a desired SAPI frame by using UART serial interface.
err_t neomesh915mhz_send_sapi_frame ( neomesh915mhz_t *ctx, neomesh915mhz_sapi_frame_t *frame );

Application Init

Initializes the driver and configures the Click board for the selected application mode.

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    neomesh915mhz_cfg_t neomesh915mhz_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.
    neomesh915mhz_cfg_setup( &neomesh915mhz_cfg );
    NEOMESH915MHZ_MAP_MIKROBUS( neomesh915mhz_cfg, MIKROBUS_1 );
    if ( UART_ERROR == neomesh915mhz_init( &neomesh915mhz, &neomesh915mhz_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    log_printf( &logger, "\r\n Enable SAPI over AAPI\r\n" );
    aapi_frame.cmd = NEOMESH915MHZ_CMD_SAPI_TO_AAPI;
    aapi_frame.len = 0;
    neomesh915mhz_send_aapi_frame ( &neomesh915mhz, &aapi_frame );
    neomesh915mhz_parse_sapi_rsp ( NEOMESH915MHZ_SAPI_RSP_BOOTLOADER_START );
    
    log_printf( &logger, "\r\n Login with password\r\n" );
    sapi_frame.cmd = NEOMESH915MHZ_SAPI_CMD_LOGIN;
    sapi_frame.len = 5;
    sapi_frame.payload[ 0 ] = NEOMESH915MHZ_SAPI_LOGIN_PASSWORD_0;
    sapi_frame.payload[ 1 ] = NEOMESH915MHZ_SAPI_LOGIN_PASSWORD_1;
    sapi_frame.payload[ 2 ] = NEOMESH915MHZ_SAPI_LOGIN_PASSWORD_2;
    sapi_frame.payload[ 3 ] = NEOMESH915MHZ_SAPI_LOGIN_PASSWORD_3;
    sapi_frame.payload[ 4 ] = NEOMESH915MHZ_SAPI_LOGIN_PASSWORD_4;
    neomesh915mhz_send_sapi_frame ( &neomesh915mhz, &sapi_frame );
    neomesh915mhz_parse_sapi_rsp ( NEOMESH915MHZ_SAPI_RSP_OK );
    
    log_printf( &logger, "\r\n Set NODE ID to: " );
    sapi_frame.cmd = NEOMESH915MHZ_SAPI_CMD_SET_SETTING;
    sapi_frame.len = 3;
    sapi_frame.payload[ 0 ] = NEOMESH915MHZ_SAPI_SETTINGS_ID_NODE_ID;
#if ( DEMO_APP == APP_RECEIVER_1 )
    log_printf( &logger, "%.4X\r\n", ( uint16_t ) NODE_ID_RECEIVER_1 );
    sapi_frame.payload[ 1 ] = ( uint8_t ) ( ( NODE_ID_RECEIVER_1 >> 8 ) & 0xFF );
    sapi_frame.payload[ 2 ] = ( uint8_t ) ( NODE_ID_RECEIVER_1 & 0xFF );
#elif ( DEMO_APP == APP_RECEIVER_2 )
    log_printf( &logger, "%.4X\r\n", ( uint16_t ) NODE_ID_RECEIVER_2 );
    sapi_frame.payload[ 1 ] = ( uint8_t ) ( ( NODE_ID_RECEIVER_2 >> 8 ) & 0xFF );
    sapi_frame.payload[ 2 ] = ( uint8_t ) ( NODE_ID_RECEIVER_2 & 0xFF );
#elif ( DEMO_APP == APP_ORIGINATOR )
    log_printf( &logger, "%.4X\r\n", ( uint16_t ) NODE_ID_ORIGINATOR );
    sapi_frame.payload[ 1 ] = ( uint8_t ) ( ( NODE_ID_ORIGINATOR >> 8 ) & 0xFF );
    sapi_frame.payload[ 2 ] = ( uint8_t ) ( NODE_ID_ORIGINATOR & 0xFF );
#endif
    neomesh915mhz_send_sapi_frame ( &neomesh915mhz, &sapi_frame );
    neomesh915mhz_parse_sapi_rsp ( NEOMESH915MHZ_SAPI_RSP_OK );
    
    log_printf( &logger, "\r\n Commit settings\r\n" );
    sapi_frame.cmd = NEOMESH915MHZ_SAPI_CMD_COMMIT_SETTINGS;
    sapi_frame.len = 0;
    neomesh915mhz_send_sapi_frame ( &neomesh915mhz, &sapi_frame );
    neomesh915mhz_parse_sapi_rsp ( NEOMESH915MHZ_SAPI_RSP_OK );
    
    log_printf( &logger, "\r\n Start protocol stack\r\n" );
    sapi_frame.cmd = NEOMESH915MHZ_SAPI_CMD_START_PROTOCOL_STACK;
    sapi_frame.len = 0;
    neomesh915mhz_send_sapi_frame ( &neomesh915mhz, &sapi_frame );
    neomesh915mhz_parse_sapi_rsp ( NEOMESH915MHZ_SAPI_RSP_PROTOCOL_STACK_START );
    // Wait for the device to actually switch back to application layer
    while ( !neomesh915mhz_get_cts_pin ( &neomesh915mhz ) );
    
    log_printf( &logger, "\r\n Get NODE info\r\n" );
    aapi_frame.cmd = NEOMESH915MHZ_CMD_NODE_INFO;
    aapi_frame.len = 0;
    neomesh915mhz_send_aapi_frame ( &neomesh915mhz, &aapi_frame );
    neomesh915mhz_parse_aapi_rsp ( NEOMESH915MHZ_RSP_NODE_INFO );
    
    log_printf( &logger, "\r\n Get neighbour list\r\n" );
    aapi_frame.cmd = NEOMESH915MHZ_CMD_NEIGHBOUR_LIST;
    aapi_frame.len = 0;
    neomesh915mhz_send_aapi_frame ( &neomesh915mhz, &aapi_frame );
    neomesh915mhz_parse_aapi_rsp ( NEOMESH915MHZ_RSP_NEIGHBOUR_LIST );
    
#if ( DEMO_APP == APP_RECEIVER_1 )
    log_printf( &logger, "\r\n Application Mode: Receiver 1\r\n" );
#elif ( DEMO_APP == APP_RECEIVER_2 )
    log_printf( &logger, "\r\n Application Mode: Receiver 2\r\n" );
#elif ( DEMO_APP == APP_ORIGINATOR )
    log_printf( &logger, "\r\n Application Mode: Originator\r\n" );
#else
    #error "Selected application mode is not supported!"
#endif
    
    log_info( &logger, " Application Task " );
}

Application Task

One Click board should be set to originator mode and the others to receiver 1 or 2. If the SINGLE_RECEIVER_MODE is enabled, the originator device sends a desired message to RECEIVER_1 node and waits for an acknowledge response, otherwise it sends the same message to both RECEIVER_1 and RECEIVER_2 nodes. The receiver devices reads and parses all incoming AAPI frames and displays them on the USB UART.

void application_task ( void )
{
#if ( DEMO_APP == APP_ORIGINATOR )
    log_printf( &logger, "\r\n Send message to node: %.4X\r\n", ( uint16_t ) NODE_ID_RECEIVER_1 );
    aapi_frame.cmd = NEOMESH915MHZ_CMD_ACK_SEND;
    aapi_frame.len = 3 + strlen ( DEMO_TEXT_MESSAGE );
    aapi_frame.payload[ 0 ] = ( uint8_t ) ( ( NODE_ID_RECEIVER_1 >> 8 ) & 0xFF );
    aapi_frame.payload[ 1 ] = ( uint8_t ) ( NODE_ID_RECEIVER_1 & 0xFF );
    aapi_frame.payload[ 2 ] = DEFAULT_PORT;
    strcpy ( &aapi_frame.payload[ 3 ], DEMO_TEXT_MESSAGE );
    if ( NEOMESH915MHZ_OK == neomesh915mhz_send_aapi_frame ( &neomesh915mhz, &aapi_frame ) )
    {
        neomesh915mhz_parse_aapi_rsp ( NEOMESH915MHZ_RSP_ACK );
    }
    #ifndef SINGLE_RECEIVER_MODE
        log_printf( &logger, "\r\n Send message to node: %.4X\r\n", ( uint16_t ) NODE_ID_RECEIVER_2 );
        aapi_frame.cmd = NEOMESH915MHZ_CMD_ACK_SEND;
        aapi_frame.len = 3 + strlen ( DEMO_TEXT_MESSAGE );
        aapi_frame.payload[ 0 ] = ( uint8_t ) ( ( NODE_ID_RECEIVER_2 >> 8 ) & 0xFF );
        aapi_frame.payload[ 1 ] = ( uint8_t ) ( NODE_ID_RECEIVER_2 & 0xFF );
        aapi_frame.payload[ 2 ] = DEFAULT_PORT;
        strcpy ( &aapi_frame.payload[ 3 ], DEMO_TEXT_MESSAGE );
        if ( NEOMESH915MHZ_OK == neomesh915mhz_send_aapi_frame ( &neomesh915mhz, &aapi_frame ) )
        {
            neomesh915mhz_parse_aapi_rsp ( NEOMESH915MHZ_RSP_ACK );
        }
    #endif
#else
   neomesh915mhz_parse_aapi_rsp ( NULL );
#endif
}

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
  • UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.

Additional Notes and Information

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.