Intermediate
20 min

Build a fully functional Wireless Mesh Network node with NC2400 and ATmega328

Ultra low power Ad-Hoc Wireless Mesh Networking intended for 2.4GHz frequency band

NeoMesh 2 Click with Arduino UNO Rev3

Published Feb 14, 2024

Click board™

NeoMesh 2 Click

Dev. board

Arduino UNO Rev3

Compiler

NECTO Studio

MCU

ATmega328

Create a complete, autonomous, self-containing wireless mesh network targeting sensor-type applications

A

A

Hardware Overview

How does it work?

NeoMesh 2 Click is based on the NC2400, a wireless Mesh network module from NeoCortec. Besides being controlled by the host MCU, NeoMesh 2 Click can be used as a standalone device. You can configure the module over the System API (SAPI), a UART-based interface with hardware flow control. This interface is configured to ensure direct compatibility with the FTDI serial to USB cable. When using the NeoMesh 2 Click as a standalone board, the application interface of the NeoMesh module can be easily accessed through the pin header located at the side of the module. There are eight pins, six in the header labeled P2-7, which allows you to use up to 6 channels of 12-bit ADC, GPIOs, I2C sensors, and UART application APIs. Specific pins of this header can be used to interface with an external microcontroller through UART. The module also can be configured wirelessly. At the bottom side, there is an unconnected WES jumper. You can use the Wireless Encrypted Setup by connecting it, but only if it is already configured through the WES

procedure. Every WES channel has a specified AES 128 encryption key. Just beside is another jumper, VCC, this one connected. The NeoMesh 2 Click is optimized for ultra-low power operation and allows operation on small batteries for several years. If you want to make an ultra-low power node, consider using the NeoMesh 2 Click with some low-power development board with battery management, such as the Clicker 2 series or something similar. This scenario is ideal where the node can send data infrequently, and the payload size is small. NeoMesh is a wireless system designed with versatility in mind, allowing users to build products in many different application areas. This system can handle data transmission, lost neighbor nodes, moving nodes, and more. Data transmission through the network is done sequentially from node to node until the data reaches its destination. There are three types of NeoMesh devices: coordinator, router, and end device. You can configure your device according to your needs. NeoMesh 2 Click uses a standard

UART serial interface to communicate with the host MCU, with commonly used UART RX and TX pins and a transfer speed of 115200bps. Hardware control flow is available through the CTS pin. You can also use an I2C interface as a virtual UART. The I2C interface can be enabled over the I2C SEL jumper. While disabled, you can use the WUP pin to indicate the WakeUp activity state of the module; otherwise, the WUP function is unavailable. The module can be reset over the RST pin. The generic application activity is indicated over the APP pin with logic Low state when active. If the Wireless Encrypted Setup JP2 jumper is closed, you can enable the WES client over the WES pin. This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, it comes equipped with a library containing functions and an example code that can be used as a reference for further development.

NeoMesh 2 Click hardware overview image

Features overview

Development board

Arduino UNO is a versatile microcontroller board built around the ATmega328P chip. It offers extensive connectivity options for various projects, featuring 14 digital input/output pins, six of which are PWM-capable, along with six analog inputs. Its core components include a 16MHz ceramic resonator, a USB connection, a power jack, an

ICSP header, and a reset button, providing everything necessary to power and program the board. The Uno is ready to go, whether connected to a computer via USB or powered by an AC-to-DC adapter or battery. As the first USB Arduino board, it serves as the benchmark for the Arduino platform, with "Uno" symbolizing its status as the

first in a series. This name choice, meaning "one" in Italian, commemorates the launch of Arduino Software (IDE) 1.0. Initially introduced alongside version 1.0 of the Arduino Software (IDE), the Uno has since become the foundational model for subsequent Arduino releases, embodying the platform's evolution.

Arduino UNO Rev3 double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

AVR

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

32

RAM (Bytes)

2048

You complete me!

Accessories

Click Shield for Arduino UNO has two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the Arduino UNO board without effort. The Arduino Uno, a microcontroller board based on the ATmega328P, provides an affordable and flexible way for users to try out new concepts and build prototypes with the ATmega328P microcontroller from various combinations of performance, power consumption, and features. The Arduino Uno has 14 digital input/output pins (of which six can be used as PWM outputs), six analog inputs, a 16 MHz ceramic resonator (CSTCE16M0V53-R0), a USB connection, a power jack, an ICSP header, and reset button. Most of the ATmega328P microcontroller pins are brought to the IO pins on the left and right edge of the board, which are then connected to two existing mikroBUS™ sockets. This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the Arduino UNO board with our Click Shield for Arduino UNO, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Arduino UNO accessories 1 image

WiFi Rubber 2.4GHz Antenna is a versatile accessory designed for Click board™ applications featuring WiFi modules. This antenna is tailor-made to enhance wireless connectivity, making it an essential choice for developers and engineers. Featuring a right-angle SMA male connector at its tip, the antenna offers seamless integration with Click boards™ or female SMA module connectors. This user-friendly design simplifies installation and ensures flexibility in various setups. Operating within the 2400-2500MHz frequency range, this antenna guarantees reliable connectivity across a broad spectrum of WiFi networks. Its 50-Ohm impedance facilitates efficient signal transfer, while the 2dB gain significantly enhances signal strength and range. With a 100MHz bandwidth, it easily accommodates data transfer and communication stability. Vertical polarization further improves signal reception capabilities. The antenna can handle a maximum input power of 50W, making it suitable for high-power applications without compromising performance. Its compact 50mm length ensures a discreet and unobtrusive presence. Whether you're designing IoT devices, smart home applications, or industrial equipment, the WiFi Rubber Antenna, with its SMA male connector, is the ideal choice to ensure optimal wireless connectivity. It's a powerful tool that keeps your devices reliably connected and communicating effectively in wireless technology.

NeoMesh 2 Click accessories 1 image

IPEX-SMA cable is a type of RF (radio frequency) cable assembly. "IPEX" refers to the IPEX connector, a miniature coaxial connector commonly used in small electronic devices. "SMA" stands for SubMiniature Version A and is another coaxial connector commonly used in RF applications. An IPEX-SMA cable assembly has an IPEX connector on one end and an SMA connector on the other, allowing it to connect devices or components that use these specific connectors. These cables are often used in applications like WiFi or cellular antennas, GPS modules, and other RF communication systems where a reliable and low-loss connection is required.

NeoMesh 2 Click accessories 2 image

Used MCU Pins

mikroBUS™ mapper

Generic APP Activity
PC0
AN
Reset / ID SEL
PD2
RST
WES Client / ID COMM
PB2
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
UART CTS
PD6
PWM
WakeUp Time
PC3
INT
UART TX
PD0
TX
UART RX
PD1
RX
I2C Clock
PC5
SCL
I2C Data
PC4
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

NeoMesh 2 Click Schematic schematic

Step by step

Project assembly

Click Shield for Arduino UNO front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Arduino UNO Rev3 as your development board.

Click Shield for Arduino UNO front image hardware assembly
Arduino UNO Rev3 front image hardware assembly
Charger 27 Click front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Board mapper by product8 hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Arduino UNO MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Software Support

Library Description

This library contains API for NeoMesh 2 Click driver.

Key functions:

  • neomesh2_send_aapi_frame - This function sends a desired AAPI frame by using UART serial interface.

  • neomesh2_read_aapi_frame - This function reads an AAPI frame by using UART serial interface.

  • neomesh2_send_sapi_frame - This function sends a desired SAPI frame by using UART serial interface.

Open Source

Code example

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.

/*!
 * @file main.c
 * @brief NeoMesh 2 Click Example.
 *
 * # Description
 * This example demonstrates the use of NeoMesh 2 Click board by showing
 * the communication between the two Click boards.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and configures the Click board for the selected
 * application mode.
 *
 * ## 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.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "neomesh2.h"

// Comment out the line below to add the APP_RECEIVER_2 to the APP_ORIGINATOR example.
#define SINGLE_RECEIVER_MODE

// Demo aplication selection macros
#define APP_ORIGINATOR              0
#define APP_RECEIVER_1              1
#define APP_RECEIVER_2              2
#define DEMO_APP                    APP_ORIGINATOR

// Text message to send in the originator mode
#define DEMO_TEXT_MESSAGE           "MIKROE-NeoMesh"
#define DEFAULT_PORT                0

// Node ID macros
#define NODE_ID_ORIGINATOR          0x0100u
#define NODE_ID_RECEIVER_1          0x0020u
#define NODE_ID_RECEIVER_2          0x0021u

static neomesh2_t neomesh2;
static log_t logger;
static neomesh2_aapi_frame_t aapi_frame;
static neomesh2_sapi_frame_t sapi_frame;

/**
 * @brief NeoMesh 2 parse aapi rsp function.
 * @details This function reads and parses AAPI responses until an expected response is received.
 * @param[in] exp_rsp : Expected AAPI response.
 * @return @li @c  0 - Success,
 *         @li @c -1 - Error, no expected response is received,
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t neomesh2_parse_aapi_rsp ( uint8_t exp_rsp );

/**
 * @brief NeoMesh 2 parse sapi rsp function.
 * @details This function reads and parses SAPI responses until an expected response is received.
 * @param[in] exp_rsp : Expected SAPI response.
 * @return @li @c  0 - Success,
 *         @li @c -1 - Error, no expected response is received,
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t neomesh2_parse_sapi_rsp ( uint16_t exp_rsp );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    neomesh2_cfg_t neomesh2_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.
    neomesh2_cfg_setup( &neomesh2_cfg );
    NEOMESH2_MAP_MIKROBUS( neomesh2_cfg, MIKROBUS_1 );
    if ( UART_ERROR == neomesh2_init( &neomesh2, &neomesh2_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    log_printf( &logger, "\r\n Enable SAPI over AAPI\r\n" );
    aapi_frame.cmd = NEOMESH2_CMD_SAPI_TO_AAPI;
    aapi_frame.len = 0;
    neomesh2_send_aapi_frame ( &neomesh2, &aapi_frame );
    neomesh2_parse_sapi_rsp ( NEOMESH2_SAPI_RSP_BOOTLOADER_START );
    
    log_printf( &logger, "\r\n Login with password\r\n" );
    sapi_frame.cmd = NEOMESH2_SAPI_CMD_LOGIN;
    sapi_frame.len = 5;
    sapi_frame.payload[ 0 ] = NEOMESH2_SAPI_LOGIN_PASSWORD_0;
    sapi_frame.payload[ 1 ] = NEOMESH2_SAPI_LOGIN_PASSWORD_1;
    sapi_frame.payload[ 2 ] = NEOMESH2_SAPI_LOGIN_PASSWORD_2;
    sapi_frame.payload[ 3 ] = NEOMESH2_SAPI_LOGIN_PASSWORD_3;
    sapi_frame.payload[ 4 ] = NEOMESH2_SAPI_LOGIN_PASSWORD_4;
    neomesh2_send_sapi_frame ( &neomesh2, &sapi_frame );
    neomesh2_parse_sapi_rsp ( NEOMESH2_SAPI_RSP_OK );
    
    log_printf( &logger, "\r\n Set NODE ID to: " );
    sapi_frame.cmd = NEOMESH2_SAPI_CMD_SET_SETTING;
    sapi_frame.len = 3;
    sapi_frame.payload[ 0 ] = NEOMESH2_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
    neomesh2_send_sapi_frame ( &neomesh2, &sapi_frame );
    neomesh2_parse_sapi_rsp ( NEOMESH2_SAPI_RSP_OK );
    
    log_printf( &logger, "\r\n Commit settings\r\n" );
    sapi_frame.cmd = NEOMESH2_SAPI_CMD_COMMIT_SETTINGS;
    sapi_frame.len = 0;
    neomesh2_send_sapi_frame ( &neomesh2, &sapi_frame );
    neomesh2_parse_sapi_rsp ( NEOMESH2_SAPI_RSP_OK );
    
    log_printf( &logger, "\r\n Start protocol stack\r\n" );
    sapi_frame.cmd = NEOMESH2_SAPI_CMD_START_PROTOCOL_STACK;
    sapi_frame.len = 0;
    neomesh2_send_sapi_frame ( &neomesh2, &sapi_frame );
    neomesh2_parse_sapi_rsp ( NEOMESH2_SAPI_RSP_PROTOCOL_STACK_START );
    // Wait for the device to actually switch back to application layer
    while ( !neomesh2_get_cts_pin ( &neomesh2 ) );
    
    log_printf( &logger, "\r\n Get NODE info\r\n" );
    aapi_frame.cmd = NEOMESH2_CMD_NODE_INFO;
    aapi_frame.len = 0;
    neomesh2_send_aapi_frame ( &neomesh2, &aapi_frame );
    neomesh2_parse_aapi_rsp ( NEOMESH2_RSP_NODE_INFO );
    
    log_printf( &logger, "\r\n Get neighbour list\r\n" );
    aapi_frame.cmd = NEOMESH2_CMD_NEIGHBOUR_LIST;
    aapi_frame.len = 0;
    neomesh2_send_aapi_frame ( &neomesh2, &aapi_frame );
    neomesh2_parse_aapi_rsp ( NEOMESH2_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 " );
}

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 = NEOMESH2_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 ( NEOMESH2_OK == neomesh2_send_aapi_frame ( &neomesh2, &aapi_frame ) )
    {
        neomesh2_parse_aapi_rsp ( NEOMESH2_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 = NEOMESH2_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 ( NEOMESH2_OK == neomesh2_send_aapi_frame ( &neomesh2, &aapi_frame ) )
        {
            neomesh2_parse_aapi_rsp ( NEOMESH2_RSP_ACK );
        }
    #endif
#else
   neomesh2_parse_aapi_rsp ( NULL );
#endif
}

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 err_t neomesh2_parse_aapi_rsp ( uint8_t exp_rsp )
{
    while ( NEOMESH2_OK == neomesh2_read_aapi_frame ( &neomesh2, &aapi_frame ) )
    {
        switch ( aapi_frame.cmd )
        {
            case NEOMESH2_RSP_ACK:
            {
                log_printf( &logger, "---- ACK ----\r\n" );
                log_printf( &logger, " Originator ID: %.2X%.2X\r\n", 
                            ( uint16_t ) aapi_frame.payload[ 0 ], ( uint16_t ) aapi_frame.payload[ 1 ] );
                break;
            }
            case NEOMESH2_RSP_NACK:
            {
                log_printf( &logger, "---- NACK ----\r\n" );
                log_printf( &logger, " Originator ID: %.2X%.2X\r\n", 
                            ( uint16_t ) aapi_frame.payload[ 0 ], ( uint16_t ) aapi_frame.payload[ 1 ] );
                break;
            }
            case NEOMESH2_RSP_ACK_HOST:
            {
                log_printf( &logger, "---- ACK HOST DATA ----\r\n" );
                log_printf( &logger, " Originator ID: %.2X%.2X\r\n", 
                            ( uint16_t ) aapi_frame.payload[ 0 ], ( uint16_t ) aapi_frame.payload[ 1 ] );
                log_printf( &logger, " Packet Age: %.3f sec\r\n", 
                            ( ( ( uint16_t ) aapi_frame.payload[ 2 ] << 8 ) | 
                              aapi_frame.payload[ 3 ] ) * 0.125f );
                log_printf( &logger, " Port: %u\r\n", aapi_frame.payload[ 4 ] );
                log_printf( &logger, " Payload: " );
                for ( uint8_t cnt = 5; cnt < aapi_frame.len; cnt++ )
                {
                    log_printf( &logger, "%.2X ", ( uint16_t ) aapi_frame.payload[ cnt ] );
                }
                log_printf( &logger, "\r\n" );
                aapi_frame.payload[ aapi_frame.len ] = 0;
                log_printf( &logger, " Payload (string): %s\r\n\n", &aapi_frame.payload[ 5 ] );
                break;
            }
            case NEOMESH2_RSP_ACK_HOST_HAPA:
            {
                log_printf( &logger, "---- ACK HOST DATA HAPA ----\r\n" );
                log_printf( &logger, " Originator ID: %.2X%.2X\r\n", 
                            ( uint16_t ) aapi_frame.payload[ 0 ], ( uint16_t ) aapi_frame.payload[ 1 ] );
                log_printf( &logger, " Packet Age: %.3f sec\r\n", 
                            ( ( ( uint32_t ) aapi_frame.payload[ 2 ] << 24 ) | 
                              ( ( uint32_t ) aapi_frame.payload[ 3 ] << 16 ) |
                              ( ( uint16_t ) aapi_frame.payload[ 4 ] << 8 ) | 
                              aapi_frame.payload[ 5 ] ) * pow ( 2, -19 ) );
                log_printf( &logger, " Port: %u\r\n", aapi_frame.payload[ 6 ] );
                log_printf( &logger, " Payload: " );
                for ( uint8_t cnt = 7; cnt < aapi_frame.len; cnt++ )
                {
                    log_printf( &logger, "%.2X ", ( uint16_t ) aapi_frame.payload[ cnt ] );
                }
                log_printf( &logger, "\r\n" );
                break;
            }
            case NEOMESH2_RSP_NACK_HOST:
            {
                log_printf( &logger, "---- NACK HOST DATA ----\r\n" );
                log_printf( &logger, " Originator ID: %.2X%.2X\r\n", 
                            ( uint16_t ) aapi_frame.payload[ 0 ], ( uint16_t ) aapi_frame.payload[ 1 ] );
                log_printf( &logger, " Packet Age: %.3f sec\r\n", 
                            ( ( ( uint16_t ) aapi_frame.payload[ 2 ] << 8 ) | 
                              aapi_frame.payload[ 3 ] ) * 0.125f );
                log_printf( &logger, " Port: %u\r\n", aapi_frame.payload[ 4 ] );
                log_printf( &logger, " Sequence number: %u\r\n", 
                            ( ( ( uint16_t ) aapi_frame.payload[ 5 ] << 8 ) | 
                              aapi_frame.payload[ 6 ] ) & 0x0FFFu );
                log_printf( &logger, " Payload: " );
                for ( uint8_t cnt = 7; cnt < aapi_frame.len; cnt++ )
                {
                    log_printf( &logger, "%.2X ", ( uint16_t ) aapi_frame.payload[ cnt ] );
                }
                log_printf( &logger, "\r\n" );
                break;
            }
            case NEOMESH2_RSP_NACK_HOST_HAPA:
            {
                log_printf( &logger, "---- NACK HOST DATA HAPA ----\r\n" );
                log_printf( &logger, " Originator ID: %.2X%.2X\r\n", 
                            ( uint16_t ) aapi_frame.payload[ 0 ], ( uint16_t ) aapi_frame.payload[ 1 ] );
                log_printf( &logger, " Packet Age: %.3f sec\r\n", 
                            ( ( ( uint32_t ) aapi_frame.payload[ 2 ] << 24 ) | 
                              ( ( uint32_t ) aapi_frame.payload[ 3 ] << 16 ) |
                              ( ( uint16_t ) aapi_frame.payload[ 4 ] << 8 ) | 
                              aapi_frame.payload[ 5 ] ) * pow ( 2, -19 ) );
                log_printf( &logger, " Port: %u\r\n", aapi_frame.payload[ 6 ] );
                log_printf( &logger, " Sequence number: %u\r\n", 
                            ( ( ( uint16_t ) aapi_frame.payload[ 7 ] << 8 ) | 
                              aapi_frame.payload[ 8 ] ) & 0x0FFFu );
                log_printf( &logger, " Payload: " );
                for ( uint8_t cnt = 9; cnt < aapi_frame.len; cnt++ )
                {
                    log_printf( &logger, "%.2X ", ( uint16_t ) aapi_frame.payload[ cnt ] );
                }
                log_printf( &logger, "\r\n" );
                break;
            }
            case NEOMESH2_RSP_NACK_SEND:
            {
                log_printf( &logger, "---- NACK SEND ----\r\n" );
                log_printf( &logger, " Destination ID: %.2X%.2X\r\n", 
                            ( uint16_t ) aapi_frame.payload[ 0 ], ( uint16_t ) aapi_frame.payload[ 1 ] );
                log_printf( &logger, " Sequence number: %u\r\n", 
                            ( ( ( uint16_t ) aapi_frame.payload[ 2 ] << 8 ) | 
                              aapi_frame.payload[ 3 ] ) & 0x0FFFu );
                break;
            }
            case NEOMESH2_RSP_NACK_DROP:
            {
                log_printf( &logger, "---- NACK DROP ----\r\n" );
                log_printf( &logger, " Destination ID: %.2X%.2X\r\n", 
                            ( uint16_t ) aapi_frame.payload[ 0 ], ( uint16_t ) aapi_frame.payload[ 1 ] );
                log_printf( &logger, " Sequence number: %u\r\n", 
                            ( ( ( uint16_t ) aapi_frame.payload[ 2 ] << 8 ) | 
                              aapi_frame.payload[ 3 ] ) & 0x0FFFu );
                break;
            }
            case NEOMESH2_RSP_NODE_INFO:
            {
                log_printf( &logger, "---- NODE INFO ----\r\n" );
                log_printf( &logger, " Node ID: %.2X%.2X\r\n", 
                            ( uint16_t ) aapi_frame.payload[ 0 ], ( uint16_t ) aapi_frame.payload[ 1 ] );
                log_printf( &logger, " Unique ID: %.2X%.2X%.2X%.2X%.2X\r\n", 
                            ( uint16_t ) aapi_frame.payload[ 2 ], ( uint16_t ) aapi_frame.payload[ 3 ],
                            ( uint16_t ) aapi_frame.payload[ 4 ], ( uint16_t ) aapi_frame.payload[ 5 ],
                            ( uint16_t ) aapi_frame.payload[ 6 ] );
                log_printf( &logger, " Type: %.2X\r\n", ( uint16_t ) aapi_frame.payload[ 7 ] );
                break;
            }
            case NEOMESH2_RSP_NEIGHBOUR_LIST:
            {
                log_printf( &logger, "---- NEIGHBOUR LIST ----\r\n" );
                for ( uint8_t cnt = 0; cnt < aapi_frame.len; cnt += 3 )
                {
                    log_printf( &logger, " %u# -> ", ( uint16_t ) ( ( cnt / 3 ) + 1 ) );
                    if ( ( 0xFF != aapi_frame.payload[ cnt ] ) && 
                         ( 0xFF != aapi_frame.payload[ cnt + 1 ] ) )
                    {
                        log_printf( &logger, "Node ID: %.2X%.2X, RSSI: -%u dBm\r\n", 
                                    ( uint16_t ) aapi_frame.payload[ cnt ], 
                                    ( uint16_t ) aapi_frame.payload[ cnt + 1 ], 
                                    ( uint16_t ) aapi_frame.payload[ cnt + 2 ] );
                    }
                    else
                    {
                        log_printf( &logger, "N/A\r\n" );
                    }
                }
                break;
            }
            case NEOMESH2_RSP_NETWORK_COMMAND:
            {
                log_printf( &logger, "---- NETWORK COMMAND ----\r\n" );
                log_printf( &logger, " Node ID: %.2X%.2X\r\n", 
                            ( uint16_t ) aapi_frame.payload[ 0 ], ( uint16_t ) aapi_frame.payload[ 1 ] );
                log_printf( &logger, " Command: %.2X\r\n", ( uint16_t ) aapi_frame.payload[ 2 ] );
                log_printf( &logger, " Payload: " );
                for ( uint8_t cnt = 3; cnt < aapi_frame.len; cnt++ )
                {
                    log_printf( &logger, "%.2X ", ( uint16_t ) aapi_frame.payload[ cnt ] );
                }
                log_printf( &logger, "\r\n" );
                break;
            }
            case NEOMESH2_RSP_ROUTE_INFO:
            {
                log_printf( &logger, "---- ROUTE INFO ----\r\n" );
                log_printf( &logger, " Bit Mask: " );
                for ( uint8_t cnt = 0; cnt < aapi_frame.len; cnt++ )
                {
                    log_printf( &logger, "%.2X ", ( uint16_t ) aapi_frame.payload[ cnt ] );
                }
                log_printf( &logger, "\r\n" );
                break;
            }
            case NEOMESH2_RSP_WES_STATUS:
            {
                log_printf( &logger, "---- WES STATUS ----\r\n" );
                if ( !aapi_frame.payload[ 0 ] )
                {
                    log_printf( &logger, " WES stopped\r\n" );
                }
                else
                {
                    log_printf( &logger, " WES server running\r\n" );
                }
                break;
            }
            case NEOMESH2_RSP_WES_SETUP:
            {
                log_printf( &logger, "---- WES SETUP ----\r\n" );
                log_printf( &logger, " Unique ID: %.2X%.2X%.2X%.2X%.2X\r\n", 
                            ( uint16_t ) aapi_frame.payload[ 0 ], ( uint16_t ) aapi_frame.payload[ 1 ],
                            ( uint16_t ) aapi_frame.payload[ 2 ], ( uint16_t ) aapi_frame.payload[ 3 ],
                            ( uint16_t ) aapi_frame.payload[ 4 ] );
                log_printf( &logger, " Type: %.2X\r\n", ( uint16_t ) aapi_frame.payload[ 5 ] );
                break;
            }
            case NEOMESH2_RSP_GET_SW_VERSION:
            {
                log_printf( &logger, "---- SW VERSION ----\r\n" );
                log_printf( &logger, " HW/SW Type: %.2X\r\n", ( uint16_t ) aapi_frame.payload[ 0 ] );
                log_printf( &logger, " NeoMesh Version: %.2X%.2X\r\n", 
                            ( uint16_t ) aapi_frame.payload[ 1 ], ( uint16_t ) aapi_frame.payload[ 2 ] );
                log_printf( &logger, " Bootloader Version: %.2X%.2X\r\n", 
                            ( uint16_t ) aapi_frame.payload[ 3 ], ( uint16_t ) aapi_frame.payload[ 4 ] );
                break;
            }
            case NEOMESH2_RSP_ALT_MODE:
            {
                log_printf( &logger, "---- ALT MODE ----\r\n" );
                if ( !aapi_frame.payload[ 0 ] )
                {
                    log_printf( &logger, " Network in Normal mode\r\n" );
                }
                else
                {
                    log_printf( &logger, " Network in Alternate mode\r\n" );
                }
                break;
            }
            default:
            {
                log_printf( &logger, "---- RESPONSE ----\r\n" );
                log_printf( &logger, " CMD: 0x%.2X\r\n", ( uint16_t ) aapi_frame.cmd );
                log_printf( &logger, " LEN: %u\r\n", ( uint16_t ) aapi_frame.len );
                log_printf( &logger, " Payload: " );
                for ( uint8_t cnt = 0; cnt < aapi_frame.len; cnt++ )
                {
                    log_printf( &logger, "%.2X ", ( uint16_t ) aapi_frame.payload[ cnt ] );
                }
                log_printf( &logger, "\r\n" );
                break;
            }
        }
        if ( exp_rsp == aapi_frame.cmd )
        {
            return NEOMESH2_OK;
        }
    }
    return NEOMESH2_ERROR;
}

static err_t neomesh2_parse_sapi_rsp ( uint16_t exp_rsp )
{
    while ( NEOMESH2_OK == neomesh2_read_sapi_frame ( &neomesh2, &sapi_frame ) )
    {
        switch ( sapi_frame.cmd )
        {
            case NEOMESH2_SAPI_RSP_OK:
            {
                log_printf( &logger, "---- OK ----\r\n" );
                break;
            }
            case NEOMESH2_SAPI_RSP_ERROR:
            {
                log_printf( &logger, "---- ERROR ----\r\n" );
                break;
            }
            case NEOMESH2_SAPI_RSP_BOOTLOADER_START:
            {
                log_printf( &logger, "---- Bootloader STARTED ----\r\n" );
                break;
            }
            case NEOMESH2_SAPI_RSP_PROTOCOL_STACK_START:
            {
                log_printf( &logger, "---- Protocol Stack STARTED ----\r\n" );
                break;
            }
            case NEOMESH2_SAPI_RSP_PROTOCOL_STACK_ERROR:
            {
                log_printf( &logger, "---- Protocol Stack ERROR ----\r\n" );
                break;
            }
            case NEOMESH2_SAPI_RSP_SETTINGS_LIST_OUTPUT:
            {
                log_printf( &logger, "---- Settings List Output ----\r\n" );
                log_printf( &logger, " Payload: " );
                for ( uint8_t cnt = 0; cnt < sapi_frame.len; cnt++ )
                {
                    log_printf( &logger, "%.2X ", ( uint16_t ) sapi_frame.payload[ cnt ] );
                }
                log_printf( &logger, "\r\n" );
                break;
            }
            case NEOMESH2_SAPI_RSP_SETTINGS_VALUE:
            {
                log_printf( &logger, "---- Settings Value ----\r\n" );
                log_printf( &logger, " Payload: " );
                for ( uint8_t cnt = 0; cnt < sapi_frame.len; cnt++ )
                {
                    log_printf( &logger, "%.2X ", ( uint16_t ) sapi_frame.payload[ cnt ] );
                }
                log_printf( &logger, "\r\n" );
                break;
            }
            case NEOMESH2_SAPI_RSP_RESET:
            {
                log_printf( &logger, "---- Reset EVENT ----\r\n" );
                break;
            }
            default:
            {
                log_printf( &logger, "---- RESPONSE ----\r\n" );
                log_printf( &logger, " CMD: 0x%.4X\r\n", ( uint16_t ) sapi_frame.cmd );
                log_printf( &logger, " PLEN: %u\r\n", ( uint16_t ) sapi_frame.len );
                if ( sapi_frame.len )
                {
                    log_printf( &logger, " Payload: " );
                    for ( uint8_t cnt = 0; cnt < sapi_frame.len; cnt++ )
                    {
                        log_printf( &logger, "%.2X ", ( uint16_t ) sapi_frame.payload[ cnt ] );
                    }
                    log_printf( &logger, "\r\n" );
                }
                break;
            }
        }
        if ( exp_rsp == sapi_frame.cmd )
        {
            return NEOMESH2_OK;
        }
    }
    return NEOMESH2_ERROR;
}

// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.