Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to send data to UART for the provisioner example of mesh sdk.

Hi,

I am using nrf17.02 sdk and nrf mesh 5.0 sdk for nrf52832 dev kit.

1) I want to send the data to UART not on RTT while using the mesh example "provisioner" example of mesh sdk in place "meshsdk/example/provisioner". How to procees with it, can anyone help me?

2) I combined uart example of nrf 17.0 sdk with the provisioner example of mesh sdk but not able to receive the data over UART. Is this the right way to do, can i use uart example with the provisioner, if yes then can you please provide me the source code, as for me it is not working, i am not sure if having some issues in combining both the project of both sdks.

3) Can i use the provisioner code for dongle nrf52840(PCA10059) where i want to get data over USB, as it is mentioned in nordic infocenter that we can not. If we can then can you please provide me with required source code.

If anyone can help me, it is very helpful for me to proceed. Can anyone help me with high priority?

Thanks & Regards,

Ela

Parents
  • Hi,

    1) I suggest you look at the proximity coexist example you can see how the logging over UART is initialized instead of RTT. Then try to merge this logging functionality over to your application. 

    2) We do have an example in the SDK that combines UART with the light switch example. You can use this as a reference for how you can combine the uart example and the provisioner example. This is not something we have done so you have to try implementing yourself.

    3) Like it is mentioned here, only a few examples supports the dongle but with limited functionalities. It might be possible to modify the example so that it can run on the dongle, I would not recommend using the dongle since it lacks a onboard debugger and only light switch server example has been tested with the dongle.

  • Hi Mttrinh,

    1) I was using coexist example but i am not able to compile the code as throwing some of the errors, i have done the same way it is mentioned in the infocenter for coexist example, but still not able to test the coexist example.

    2) I have tried merging the code, but it did not work for me. I have doubt about logging module, as we do have backend logging too in the sdk. In mesh sdk we are using log.c file for logging via RTT but in nrf sdk we are using backend logging via RTT as in file nrf_backend_rtt.c . As, i want tio use provisioner code of the mesh sdk, which logging shall i used, shall i made changes only in log.c file  or shall i add backend logging via UART. I have tried both but nothing worked, when tried doing changes in log.c file having lot of errors when added backend logging for UART. Can you please help me in achieving this, if possible by providing changes need to be done or added in the provisioner code, it will be of great help.

    Thanks & Regards,

    Ela 

  • Hi Mttrinh,

    I want to know how to send and receive data via serial terminal and initiate the command of scanning the devices in provisioner code. is there any different way to do so. Can we use the same RTT interface that is been already used with existing code examples to send and receive commands as we are doing using RTT. I want to use the same functinality that we rae using by RTT with UART for sending and getting the data .

    Thanks & Regards,

    Ela 

  • Hi,

    1) What kind of errors do you get? You run the example unmodified, correct?

    2) You shouldn't need to add backend logging via UART. I haven't tried to add UART logging to the provisioner example myself, so I would need some time to try this. In the mean time I would suggest you study the proximity coexist example and see how things are done there. 

    Ela said:
    I want to know how to send and receive data via serial terminal and initiate the command of scanning the devices in provisioner code. is there any different way to do so. Can we use the same RTT interface that is been already used with existing code examples to send and receive commands as we are doing using RTT. I want to use the same functinality that we rae using by RTT with UART for sending and getting the data .

    I think it should be possible to do the same with UART, but you have to implement how the received commands are handled yourself. 

  • Hi Mttrinh,

    1) I am getting compiling errors and not able to resolve it, i have used in the same way as mentioned in the infocenter. 

    2) Can you please elaborate about when you mean have to handle how received command is being handled? For example : if i want to send press 1 to initiate the scanning of unprovisioned device as same in provisioner example code and want to send press button 4 to reset all the provisioned nodes using UART. In the existing example code we are sending using RTT same i want to do using UART.What do you mean that handle the received commands. Shall i put uart event handler with the case 1 calling funcciton to scan the unprovisioned nodes and case 4 call function to reset the provisioned node? Can you just help me with this at high priority, it will be very helpful.

    Thanks & Regards,

    Ela  

  • Hi Mttrinh,

    1) In our provisioner example code, segger_printf.c, segger_print.c, rttinput.c these files have been used for writing or reading data to RTT. "SEGGER_RTT_Read" and "SEGGER_RTT_Write" these functions are used for getting and sending data by RTT, so can i use these functions for the same operation with UART,  i think we can not use these functions, if not then how shall we do it?

    2) I have created "uart_event_handler" to handle 2 commands for press 1 and 4 for initiating some commands using "app_uart_get" and "app_uart_put" to send and get data from serial terminal, i am using putty for this. Can i use this way, as i tried but not getting the desired result as mentioned in above point. 

    Attaching the code snippet which i have implemented for the uart_event_handler:

    /* Copyright (c) 2010 - 2020, Nordic Semiconductor ASA
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     * list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    #include <stdint.h>
    #include <string.h>
    
    /* HAL */
    #include "boards.h"
    #include "nrf_delay.h"
    #include "simple_hal.h"
    #include "app_timer.h"
    
    /* Core */
    #include "nrf_mesh.h"
    #include "nrf_mesh_events.h"
    #include "nrf_mesh_assert.h"
    #include "access_config.h"
    #include "device_state_manager.h"
    #include "mesh_stack.h"
    #include "net_state.h"
    #include "mesh_opt_provisioner.h"
    #include "mesh_config_entry.h"
    #include "mesh_opt.h"
    
    /* Provisioning and configuration */
    #include "provisioner_helper.h"
    #include "node_setup.h"
    #include "mesh_app_utils.h"
    
    /* Models */
    #include "config_client.h"
    #include "config_server.h"
    #include "health_client.h"
    
    /* Logging and RTT */
    #include "rtt_input.h"
    #include "log.h"
    
    #include"nrf_log_ctrl.h"
    #include "nrf_uart.h"
    #include "app_uart.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    //#include "nrf_log_backend_interface.h"
    
    
    /* Example specific includes */
    #include "example_network_config.h"
    #include "nrf_mesh_config_examples.h"
    #include "ble_softdevice_support.h"
    #include "example_common.h"
    
    /*****************************************************************************
     * Definitions
     *****************************************************************************/
    #define APP_PROVISIONING_LED            BSP_LED_0
    #define APP_CONFIGURATION_LED           BSP_LED_1
    
    
    
    
    
    #define UART_TX_BUF_SIZE                256                                         /**< UART TX buffer size. */
    #define UART_RX_BUF_SIZE                256                                         /**< UART RX buffer size. */
    #include "app_uart.h"
    #include "nrf_uart.h"
    static bool m_device_provisioned;
    
    /*****************************************************************************
     * Forward declaration of static functions
     *****************************************************************************/
    static uint32_t provisioner_setter(mesh_config_entry_id_t id, const void * p_entry);
    static void provisioner_getter(mesh_config_entry_id_t id, void * p_entry);
    static void provisioner_deleter(mesh_config_entry_id_t id);
    static void app_health_event_cb(const health_client_t * p_client, const health_client_evt_t * p_event);
    static void app_config_successful_cb(void);
    static void app_config_failed_cb(void);
    static void app_mesh_core_event_cb (const nrf_mesh_evt_t * p_evt);
    
    static void app_start(void);
    
    
    /*****************************************************************************
     * Static variables
     *****************************************************************************/
    /* Required for the provisioner helper module */
    static network_dsm_handles_data_volatile_t m_dev_handles;
    
    static network_stats_data_stored_t m_nw_state;
    static bool m_node_prov_setup_started;
    static nrf_mesh_evt_handler_t m_mesh_core_event_handler = { .evt_cb = app_mesh_core_event_cb };
    
    NRF_MESH_STATIC_ASSERT(MESH_OPT_FIRST_FREE_ID <= MESH_APP_FILE_ID);
    MESH_CONFIG_FILE(m_provisioner_file, MESH_APP_FILE_ID, MESH_CONFIG_STRATEGY_CONTINUOUS);
    
    MESH_CONFIG_ENTRY(provisioner,
                      PROVISIONER_ENTRY_ID,
                      1,
                      sizeof(network_stats_data_stored_t),
                      provisioner_setter,
                      provisioner_getter,
                      provisioner_deleter,
                      false);
    
    static uint32_t provisioner_setter(mesh_config_entry_id_t id, const void * p_entry)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_DBG1, "Provisioner setter ...\n");
        NRF_MESH_ASSERT_DEBUG(PROVISIONER_RECORD == id.record);
    
        network_stats_data_stored_t * p_nsds = (network_stats_data_stored_t *) p_entry;
        memcpy(&m_nw_state, p_nsds, sizeof(network_stats_data_stored_t));
    
        return NRF_SUCCESS;
    }
    
    static void provisioner_getter(mesh_config_entry_id_t id, void * p_entry)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_DBG1, "Provisioner getter ...\n");
        NRF_MESH_ASSERT_DEBUG(PROVISIONER_RECORD == id.record);
    
        network_stats_data_stored_t * p_nw_state = (network_stats_data_stored_t *) p_entry;
        memcpy(p_nw_state, &m_nw_state, sizeof(m_nw_state));
    }
    
    static void provisioner_deleter(mesh_config_entry_id_t id)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_DBG1, "Provisioner deleter ...\n");
        NRF_MESH_ASSERT_DEBUG(PROVISIONER_RECORD == id.record);
    
        /* Clear and set default values. */
        memset(&m_nw_state, 0x00, sizeof(m_nw_state));
    }
    
    static void provisioner_store(void)
    {
        mesh_config_entry_id_t id = PROVISIONER_ENTRY_ID;
    
        NRF_MESH_ERROR_CHECK(mesh_config_entry_set(id, &m_nw_state));
    }
    
    static void provisioner_invalidate(void)
    {
        /* Stop scanner. */
        prov_helper_scan_stop();
        /* Delete all old values and remove from mesh config. */
        (void)mesh_config_entry_delete(PROVISIONER_ENTRY_ID);
    }
    
    /*****************************************************************************/
    
    static void app_data_store_cb(void)
    {
        provisioner_store();
    }
    
    /*****************************************************************************/
    /**** Configuration process related callbacks ****/
    
    static void app_config_successful_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Configuration of device %u successful\n", m_nw_state.configured_devices);
    
        hal_led_pin_set(APP_CONFIGURATION_LED, 0);
        hal_led_pin_set(APP_PROVISIONING_LED, 1);
    
        m_nw_state.configured_devices++;
        provisioner_store();
        prov_helper_provision_next_device();
        prov_helper_scan_start();
    }
    
    static void app_config_failed_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Configuration of device %u failed.\n", m_nw_state.configured_devices);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Press Button/RTT 1 to retry configuration.\n");
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Press Button/RTT 2 to start provisioning new nodes.\n");
        m_node_prov_setup_started = false;
        hal_led_pin_set(APP_CONFIGURATION_LED, 0);
    }
    
    static void app_prov_success_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Provisioning successful\n");
    
        hal_led_pin_set(APP_PROVISIONING_LED, 0);
        hal_led_pin_set(APP_CONFIGURATION_LED, 1);
    
        provisioner_store();
    }
    
    static void app_prov_failed_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Provisioning failed. Press Button 1 to retry.\n");
    
        m_node_prov_setup_started = false;
    
        hal_led_pin_set(APP_PROVISIONING_LED, 0);
    }
    
    
    /*****************************************************************************/
    /**** Model related callbacks ****/
    static void app_health_event_cb(const health_client_t * p_client, const health_client_evt_t * p_event)
    {
        switch (p_event->type)
        {
            case HEALTH_CLIENT_EVT_TYPE_CURRENT_STATUS_RECEIVED:
                __LOG(LOG_SRC_APP,
                      LOG_LEVEL_INFO,
                      "Node 0x%04x alive with %u active fault(s), RSSI: %d\n",
                      p_event->p_meta_data->src.value,
                      p_event->data.fault_status.fault_array_length,
                      ((p_event->p_meta_data->p_core_metadata->source == NRF_MESH_RX_SOURCE_SCANNER)
                           ? p_event->p_meta_data->p_core_metadata->params.scanner.rssi
                           : 0));
                break;
            default:
                break;
        }
    }
    
    static void app_config_server_event_cb(const config_server_evt_t * p_evt)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "config_server Event %d.\n", p_evt->type);
    
        if (p_evt->type == CONFIG_SERVER_EVT_NODE_RESET)
        {
            /* This should never return */
            hal_device_reset(0);
        }
    }
    
    static void app_config_client_event_cb(config_client_event_type_t event_type, const config_client_event_t * p_event, uint16_t length)
    {
        /* USER_NOTE: Do additional processing of config client events here if required */
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Config client event\n");
    
        /* Pass events to the node setup helper module for further processing */
        node_setup_config_client_event_process(event_type, p_event, length);
    }
    
    
    static void provisioning_start(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Start provisioning procedure ...\n");
    
        prov_helper_provision_next_device();
        prov_helper_scan_start();
    
        hal_led_pin_set(APP_PROVISIONING_LED, 1);
    }
    
    static void provisioning_resume(void)
    {
        if (!m_node_prov_setup_started)
        {
            /* If previously provisioned device is not configured. */
            if (m_nw_state.configured_devices < m_nw_state.provisioned_devices)
            {
                m_nw_state.provisioned_devices--;
                provisioning_start();
                m_node_prov_setup_started = true;
            }
        }
    }
    
    /** Check if all devices have been provisioned. If not, provision remaining devices.
     *  Check if all devices have been configured. If not, start configuring them.
     */
    static void check_network_state(void)
    {
        if (!m_node_prov_setup_started)
        {
            /* If previously provisioned device is not configured, start node setup procedure. */
            if (m_nw_state.configured_devices < m_nw_state.provisioned_devices)
            {
                /* Execute configuration */
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Waiting for provisioned node to be configured ...\n");
    
                node_setup_start(m_nw_state.last_device_address, PROVISIONER_RETRY_COUNT,
                                m_nw_state.appkey, APPKEY_INDEX, NETKEY_INDEX, m_nw_state.current_uri);
    
                hal_led_pin_set(APP_CONFIGURATION_LED, 1);
            }
            else
            {
                provisioning_start();
            }
    
            m_node_prov_setup_started = true;
        }
        else
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Waiting for previous procedure to finish ...\n");
        }
    }
    
    static void app_mesh_core_event_cb (const nrf_mesh_evt_t * p_evt)
    {
        /* USER_NOTE: User can insert mesh core event processing here */
        switch(p_evt->type)
        {
            /* Start user application specific functions only when stack is enabled */
            case NRF_MESH_EVT_ENABLED:
                __LOG(LOG_SRC_APP, LOG_LEVEL_DBG1, "Mesh evt: NRF_MESH_EVT_ENABLED\n");
    #if (PERSISTENT_STORAGE)
                /* Mesh stack initialization has been completed */
                app_start();
    #endif
                break;
    
            case NRF_MESH_EVT_CONFIG_LOAD_FAILURE:
                if (p_evt->params.config_load_failure.id.file == MESH_APP_FILE_ID)
                {
                    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Persistent provisioner data was corrupted. Set default values. \n");
                    /* Clear and set default values. */
                    memset(&m_nw_state, 0x00, sizeof(m_nw_state));
                }
                break;
    
            default:
                break;
        }
    }
    
    /* Binds the local models correctly with the desired keys */
    void app_default_models_bind_setup(void)
    {
        /* Bind health client to App key, and configure publication key */
        ERROR_CHECK(access_model_application_bind(m_dev_handles.m_health_client_instance.model_handle, m_dev_handles.m_appkey_handle));
        ERROR_CHECK(access_model_publish_application_set(m_dev_handles.m_health_client_instance.model_handle, m_dev_handles.m_appkey_handle));
    
        /* Bind self-config server to the self device key */
        ERROR_CHECK(config_server_bind(m_dev_handles.m_self_devkey_handle));
    }
    
    static void node_reset(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- Node reset  -----\n");
    
        hal_led_blink_ms(HAL_LED_MASK, LED_BLINK_INTERVAL_MS, LED_BLINK_CNT_RESET);
        /* This function may return if there are ongoing flash operations. */
        mesh_stack_device_reset();
    }
    
    #if NRF_MESH_LOG_ENABLE
    static const char m_usage_string[] =
        "\n"
        "\t\t--------------------------------------------------------------------------------\n"
        "\t\t Button/RTT 1) Initiate provisioning and configuration of unprovisioned devices.\n"
        "\t\t Button/RTT 4) Clear all the states to reset the node.\n"
        "\t\t--------------------------------------------------------------------------------\n";
    #endif
    
    static void button_event_handler(uint32_t button_number)
    {
        /* Increase button number because the buttons on the board is marked with 1 to 4 */
        button_number++;
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Button %u pressed\n", button_number);
        switch (button_number)
        {
            case 1:
            {
                /* Check if all devices have been provisioned or not */
                check_network_state();
                break;
            }
    
            case 2:
            {
                provisioning_resume();
                break;
            }
    
            /* Initiate node reset */
            case 4:
            {
                if (mesh_stack_is_device_provisioned())
                {
                    /* Clear all the states to reset the node. */
                    provisioner_invalidate();
                    mesh_stack_config_clear();
                }
                node_reset();
                break;
            }
    
            default:
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, m_usage_string);
                break;
        }
    }
    
    static void app_rtt_input_handler(int key)
    {
        if (key >= '1' && key <= '4')
        {
            uint32_t button_number = key - '1';
            button_event_handler(button_number);
        }
        else
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, m_usage_string);
        }
    }
    
    void models_init_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing and adding models\n");
        m_dev_handles.m_netkey_handle = DSM_HANDLE_INVALID;
        m_dev_handles.m_appkey_handle = DSM_HANDLE_INVALID;
        m_dev_handles.m_self_devkey_handle = DSM_HANDLE_INVALID;
    
        /* This app requires following models :
         * config client : To be able to configure other devices
         * health client : To be able to interact with other health servers */
        ERROR_CHECK(config_client_init(app_config_client_event_cb));
        ERROR_CHECK(health_client_init(&m_dev_handles.m_health_client_instance, 0, app_health_event_cb));
    }
    
    static void mesh_init(void)
    {
        bool device_provisioned;
        mesh_stack_init_params_t init_params =
        {
            .core.irq_priority       = NRF_MESH_IRQ_PRIORITY_LOWEST,
            .core.lfclksrc           = DEV_BOARD_LF_CLK_CFG,
            .models.models_init_cb   = models_init_cb,
            .models.config_server_cb = app_config_server_event_cb
        };
    
        nrf_mesh_evt_handler_add(&m_mesh_core_event_handler);
        uint32_t status = mesh_stack_init(&init_params, &device_provisioned);
        switch (status)
        {
            case NRF_ERROR_INVALID_DATA:
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Data in the persistent memory was corrupted.\n");
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Reboot device before starting of the provisioning process.\n");
                break;
            case NRF_SUCCESS:
                break;
            default:
                ERROR_CHECK(status);
        }
    
        if (status == NRF_SUCCESS)
        {
            /* Initialize the provisioner */
            mesh_provisioner_init_params_t m_prov_helper_init_info =
            {
                .p_dev_data = &m_dev_handles,
                .p_nw_data = &m_nw_state,
                .netkey_idx = NETKEY_INDEX,
                .attention_duration_s = ATTENTION_DURATION_S,
                .p_data_store_cb  = app_data_store_cb,
                .p_prov_success_cb = app_prov_success_cb,
                .p_prov_failed_cb = app_prov_failed_cb
            };
            prov_helper_init(&m_prov_helper_init_info);
    
            if (!device_provisioned)
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Setup defaults: Adding keys, addresses, and bindings \n");
    
                prov_helper_provision_self();
                app_default_models_bind_setup();
                app_data_store_cb();
            }
            else
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Restored: Handles \n");
                prov_helper_device_handles_load();
            }
    
            node_setup_cb_set(app_config_successful_cb, app_config_failed_cb);
        }
    }
    
    
    
    
    
    void uart_event_handle(app_uart_evt_t * p_event)
    {
           while (true)
        {
            uint8_t cr;
            while (app_uart_get(&cr) != NRF_SUCCESS);
            while (app_uart_put(cr) != NRF_SUCCESS);
    
            if (cr == '1')
            {
                printf(" \r\n 1 pressed \r\n");
                check_network_state();
    
                while (true)
                {
                    // Do nothing.
                }
            if (cr == '2')
            {
            printf("\r\n 2 pressed ");
            provisioning_resume();
    
             while (true)
                {
                    // Do nothing.
                }
    
            }
            if (cr=='4')
            {
                printf("\r\n 4 pressed \r\n");
                if (mesh_stack_is_device_provisioned())
                {
                    /* Clear all the states to reset the node. */
                    provisioner_invalidate();
                    mesh_stack_config_clear();
                }
                node_reset();
    
                 while (true)
                {
                    // Do nothing.
                }
    
            }
             
    
            }
        }
        
    #if 0    
        uint32_t i;
        switch(i)
        {
        case 1:
        {
         printf("\r\n Pressing 1 for scanning the unprovisioned nodes Uart event handler provisioner code .\r\n");
         check_network_state();
         break;
    
        }
        
        case 2: 
    
          {
                provisioning_resume();
                break;
           }
    
        case 4:
             {
                printf("\r\n Pressing 4 for resetting the provisioned nodes Uart event handler provisioner code .\r\n");
                 if (mesh_stack_is_device_provisioned())
                {
                    /* Clear all the states to reset the node. */
                    provisioner_invalidate();
                    mesh_stack_config_clear();
                }
                node_reset();
                break;
            }
        break;
        default:
    
        }
    #endif
    
    
     //printf("\r\nUART started uart event handler provisioner code .\r\n");
    
    }
    
    
    
    /**@brief  Function for initializing the UART module.
     */
    /**@snippet [UART Initialization] */
    static void uart_init(void)
    {
        uint32_t                     err_code;
        app_uart_comm_params_t const comm_params =
        {
            .rx_pin_no    = RX_PIN_NUMBER,
            .tx_pin_no    = TX_PIN_NUMBER,
            .rts_pin_no   = RTS_PIN_NUMBER,
            .cts_pin_no   = CTS_PIN_NUMBER,
            .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
            .use_parity   = false,
    #if defined (UART_PRESENT)
            .baud_rate    = NRF_UART_BAUDRATE_115200
    #else
            .baud_rate    = NRF_UARTE_BAUDRATE_115200
    #endif
        };
    
      APP_UART_FIFO_INIT(&comm_params,
                           UART_RX_BUF_SIZE,
                           UART_TX_BUF_SIZE,
                           uart_event_handle,
                           APP_IRQ_PRIORITY_LOWEST,
                           err_code);
        APP_ERROR_CHECK(err_code);
    }
    /**@snippet [UART Initialization] */
    
    
    
    
    
    
    
    
    static void initialize(void)
    {
        
          uart_init();
       
       // __LOG_INIT(LOG_SRC_APP | LOG_SRC_ACCESS, LOG_LEVEL_INFO, LOG_CALLBACK_DEFAULT);
        __LOG_INIT(LOG_SRC_APP | LOG_SRC_FRIEND, LOG_LEVEL_DBG1, log_callback_rtt);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- BLE Mesh Static Provisioner Demo -----\n");
    
        ERROR_CHECK(app_timer_init());
        hal_leds_init();
    
    #if BUTTON_BOARD
        ERROR_CHECK(hal_buttons_init(button_event_handler));
    #endif
    
        ble_stack_init();
        mesh_init();
        node_setup_uri_check();
    }
    
    static void app_start(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Starting application ...\n");
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Provisioned Nodes: %d, Configured Nodes: %d\n",
              m_nw_state.provisioned_devices, m_nw_state.configured_devices);
        __LOG_XB(LOG_SRC_APP, LOG_LEVEL_INFO, "Dev key ", m_nw_state.self_devkey, NRF_MESH_KEY_SIZE);
        __LOG_XB(LOG_SRC_APP, LOG_LEVEL_INFO, "Net key ", m_nw_state.netkey, NRF_MESH_KEY_SIZE);
        __LOG_XB(LOG_SRC_APP, LOG_LEVEL_INFO, "App key ", m_nw_state.appkey, NRF_MESH_KEY_SIZE);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Press Button/RTT 1 to start provisioning and configuration process. \n");
    }
    
    static void start(void)
    {
        rtt_input_enable(app_rtt_input_handler, RTT_INPUT_POLL_PERIOD_MS);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "<start> \n");
    
        ERROR_CHECK(mesh_stack_start());
    
    #if (!PERSISTENT_STORAGE)
        app_start();
    #endif
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, m_usage_string);
    
        hal_led_mask_set(HAL_LED_MASK, LED_MASK_STATE_OFF);
        hal_led_blink_ms(HAL_LED_MASK, LED_BLINK_INTERVAL_MS, LED_BLINK_CNT_START);
    }
    
    
    
    /**@brief Function for initializing the nrf log module.
     */
     #if 0
    static void log1_init(void)
    {
        ret_code_t err_code = NRF_LOG_INIT(NULL);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    }
    #endif
    
    
    
    
    
    
    
    
    #if 0
    void my_uart_callback(nrfx_uarte_event_t const * p_event,
                          void *                     p_context)
    {
        //TODO: Handle 'p_event'
    }
    #endif
    
    int main(void)
    {
        
    
       // nrfx_uarte_t m_uart = NRFX_UARTE_INSTANCE(0); 
        //nrfx_uarte_config_t m_uart_config = NRFX_UARTE_DEFAULT_CONFIG;
        
       // nrfx_uarte_init(&m_uart, &m_uart_config, my_uart_callback);
    
    
    
        // uart_init();
         //log1_init();
    
     //   ret_code_t err_code = NRF_LOG_INIT(NULL);
      //  APP_ERROR_CHECK(err_code);
    
        // NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        initialize();
         printf("\r\nUART started main provisioner code .\r\n");
        start();
    
        for (;;)
        {
            (void)sd_app_evt_wait();
        }
    }
    

    Is this the right way i have implemented if not then how shall i proceed with it.

    Thanks & Regards,

    Ela

Reply
  • Hi Mttrinh,

    1) In our provisioner example code, segger_printf.c, segger_print.c, rttinput.c these files have been used for writing or reading data to RTT. "SEGGER_RTT_Read" and "SEGGER_RTT_Write" these functions are used for getting and sending data by RTT, so can i use these functions for the same operation with UART,  i think we can not use these functions, if not then how shall we do it?

    2) I have created "uart_event_handler" to handle 2 commands for press 1 and 4 for initiating some commands using "app_uart_get" and "app_uart_put" to send and get data from serial terminal, i am using putty for this. Can i use this way, as i tried but not getting the desired result as mentioned in above point. 

    Attaching the code snippet which i have implemented for the uart_event_handler:

    /* Copyright (c) 2010 - 2020, Nordic Semiconductor ASA
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     * list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    #include <stdint.h>
    #include <string.h>
    
    /* HAL */
    #include "boards.h"
    #include "nrf_delay.h"
    #include "simple_hal.h"
    #include "app_timer.h"
    
    /* Core */
    #include "nrf_mesh.h"
    #include "nrf_mesh_events.h"
    #include "nrf_mesh_assert.h"
    #include "access_config.h"
    #include "device_state_manager.h"
    #include "mesh_stack.h"
    #include "net_state.h"
    #include "mesh_opt_provisioner.h"
    #include "mesh_config_entry.h"
    #include "mesh_opt.h"
    
    /* Provisioning and configuration */
    #include "provisioner_helper.h"
    #include "node_setup.h"
    #include "mesh_app_utils.h"
    
    /* Models */
    #include "config_client.h"
    #include "config_server.h"
    #include "health_client.h"
    
    /* Logging and RTT */
    #include "rtt_input.h"
    #include "log.h"
    
    #include"nrf_log_ctrl.h"
    #include "nrf_uart.h"
    #include "app_uart.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    //#include "nrf_log_backend_interface.h"
    
    
    /* Example specific includes */
    #include "example_network_config.h"
    #include "nrf_mesh_config_examples.h"
    #include "ble_softdevice_support.h"
    #include "example_common.h"
    
    /*****************************************************************************
     * Definitions
     *****************************************************************************/
    #define APP_PROVISIONING_LED            BSP_LED_0
    #define APP_CONFIGURATION_LED           BSP_LED_1
    
    
    
    
    
    #define UART_TX_BUF_SIZE                256                                         /**< UART TX buffer size. */
    #define UART_RX_BUF_SIZE                256                                         /**< UART RX buffer size. */
    #include "app_uart.h"
    #include "nrf_uart.h"
    static bool m_device_provisioned;
    
    /*****************************************************************************
     * Forward declaration of static functions
     *****************************************************************************/
    static uint32_t provisioner_setter(mesh_config_entry_id_t id, const void * p_entry);
    static void provisioner_getter(mesh_config_entry_id_t id, void * p_entry);
    static void provisioner_deleter(mesh_config_entry_id_t id);
    static void app_health_event_cb(const health_client_t * p_client, const health_client_evt_t * p_event);
    static void app_config_successful_cb(void);
    static void app_config_failed_cb(void);
    static void app_mesh_core_event_cb (const nrf_mesh_evt_t * p_evt);
    
    static void app_start(void);
    
    
    /*****************************************************************************
     * Static variables
     *****************************************************************************/
    /* Required for the provisioner helper module */
    static network_dsm_handles_data_volatile_t m_dev_handles;
    
    static network_stats_data_stored_t m_nw_state;
    static bool m_node_prov_setup_started;
    static nrf_mesh_evt_handler_t m_mesh_core_event_handler = { .evt_cb = app_mesh_core_event_cb };
    
    NRF_MESH_STATIC_ASSERT(MESH_OPT_FIRST_FREE_ID <= MESH_APP_FILE_ID);
    MESH_CONFIG_FILE(m_provisioner_file, MESH_APP_FILE_ID, MESH_CONFIG_STRATEGY_CONTINUOUS);
    
    MESH_CONFIG_ENTRY(provisioner,
                      PROVISIONER_ENTRY_ID,
                      1,
                      sizeof(network_stats_data_stored_t),
                      provisioner_setter,
                      provisioner_getter,
                      provisioner_deleter,
                      false);
    
    static uint32_t provisioner_setter(mesh_config_entry_id_t id, const void * p_entry)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_DBG1, "Provisioner setter ...\n");
        NRF_MESH_ASSERT_DEBUG(PROVISIONER_RECORD == id.record);
    
        network_stats_data_stored_t * p_nsds = (network_stats_data_stored_t *) p_entry;
        memcpy(&m_nw_state, p_nsds, sizeof(network_stats_data_stored_t));
    
        return NRF_SUCCESS;
    }
    
    static void provisioner_getter(mesh_config_entry_id_t id, void * p_entry)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_DBG1, "Provisioner getter ...\n");
        NRF_MESH_ASSERT_DEBUG(PROVISIONER_RECORD == id.record);
    
        network_stats_data_stored_t * p_nw_state = (network_stats_data_stored_t *) p_entry;
        memcpy(p_nw_state, &m_nw_state, sizeof(m_nw_state));
    }
    
    static void provisioner_deleter(mesh_config_entry_id_t id)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_DBG1, "Provisioner deleter ...\n");
        NRF_MESH_ASSERT_DEBUG(PROVISIONER_RECORD == id.record);
    
        /* Clear and set default values. */
        memset(&m_nw_state, 0x00, sizeof(m_nw_state));
    }
    
    static void provisioner_store(void)
    {
        mesh_config_entry_id_t id = PROVISIONER_ENTRY_ID;
    
        NRF_MESH_ERROR_CHECK(mesh_config_entry_set(id, &m_nw_state));
    }
    
    static void provisioner_invalidate(void)
    {
        /* Stop scanner. */
        prov_helper_scan_stop();
        /* Delete all old values and remove from mesh config. */
        (void)mesh_config_entry_delete(PROVISIONER_ENTRY_ID);
    }
    
    /*****************************************************************************/
    
    static void app_data_store_cb(void)
    {
        provisioner_store();
    }
    
    /*****************************************************************************/
    /**** Configuration process related callbacks ****/
    
    static void app_config_successful_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Configuration of device %u successful\n", m_nw_state.configured_devices);
    
        hal_led_pin_set(APP_CONFIGURATION_LED, 0);
        hal_led_pin_set(APP_PROVISIONING_LED, 1);
    
        m_nw_state.configured_devices++;
        provisioner_store();
        prov_helper_provision_next_device();
        prov_helper_scan_start();
    }
    
    static void app_config_failed_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Configuration of device %u failed.\n", m_nw_state.configured_devices);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Press Button/RTT 1 to retry configuration.\n");
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Press Button/RTT 2 to start provisioning new nodes.\n");
        m_node_prov_setup_started = false;
        hal_led_pin_set(APP_CONFIGURATION_LED, 0);
    }
    
    static void app_prov_success_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Provisioning successful\n");
    
        hal_led_pin_set(APP_PROVISIONING_LED, 0);
        hal_led_pin_set(APP_CONFIGURATION_LED, 1);
    
        provisioner_store();
    }
    
    static void app_prov_failed_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Provisioning failed. Press Button 1 to retry.\n");
    
        m_node_prov_setup_started = false;
    
        hal_led_pin_set(APP_PROVISIONING_LED, 0);
    }
    
    
    /*****************************************************************************/
    /**** Model related callbacks ****/
    static void app_health_event_cb(const health_client_t * p_client, const health_client_evt_t * p_event)
    {
        switch (p_event->type)
        {
            case HEALTH_CLIENT_EVT_TYPE_CURRENT_STATUS_RECEIVED:
                __LOG(LOG_SRC_APP,
                      LOG_LEVEL_INFO,
                      "Node 0x%04x alive with %u active fault(s), RSSI: %d\n",
                      p_event->p_meta_data->src.value,
                      p_event->data.fault_status.fault_array_length,
                      ((p_event->p_meta_data->p_core_metadata->source == NRF_MESH_RX_SOURCE_SCANNER)
                           ? p_event->p_meta_data->p_core_metadata->params.scanner.rssi
                           : 0));
                break;
            default:
                break;
        }
    }
    
    static void app_config_server_event_cb(const config_server_evt_t * p_evt)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "config_server Event %d.\n", p_evt->type);
    
        if (p_evt->type == CONFIG_SERVER_EVT_NODE_RESET)
        {
            /* This should never return */
            hal_device_reset(0);
        }
    }
    
    static void app_config_client_event_cb(config_client_event_type_t event_type, const config_client_event_t * p_event, uint16_t length)
    {
        /* USER_NOTE: Do additional processing of config client events here if required */
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Config client event\n");
    
        /* Pass events to the node setup helper module for further processing */
        node_setup_config_client_event_process(event_type, p_event, length);
    }
    
    
    static void provisioning_start(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Start provisioning procedure ...\n");
    
        prov_helper_provision_next_device();
        prov_helper_scan_start();
    
        hal_led_pin_set(APP_PROVISIONING_LED, 1);
    }
    
    static void provisioning_resume(void)
    {
        if (!m_node_prov_setup_started)
        {
            /* If previously provisioned device is not configured. */
            if (m_nw_state.configured_devices < m_nw_state.provisioned_devices)
            {
                m_nw_state.provisioned_devices--;
                provisioning_start();
                m_node_prov_setup_started = true;
            }
        }
    }
    
    /** Check if all devices have been provisioned. If not, provision remaining devices.
     *  Check if all devices have been configured. If not, start configuring them.
     */
    static void check_network_state(void)
    {
        if (!m_node_prov_setup_started)
        {
            /* If previously provisioned device is not configured, start node setup procedure. */
            if (m_nw_state.configured_devices < m_nw_state.provisioned_devices)
            {
                /* Execute configuration */
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Waiting for provisioned node to be configured ...\n");
    
                node_setup_start(m_nw_state.last_device_address, PROVISIONER_RETRY_COUNT,
                                m_nw_state.appkey, APPKEY_INDEX, NETKEY_INDEX, m_nw_state.current_uri);
    
                hal_led_pin_set(APP_CONFIGURATION_LED, 1);
            }
            else
            {
                provisioning_start();
            }
    
            m_node_prov_setup_started = true;
        }
        else
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Waiting for previous procedure to finish ...\n");
        }
    }
    
    static void app_mesh_core_event_cb (const nrf_mesh_evt_t * p_evt)
    {
        /* USER_NOTE: User can insert mesh core event processing here */
        switch(p_evt->type)
        {
            /* Start user application specific functions only when stack is enabled */
            case NRF_MESH_EVT_ENABLED:
                __LOG(LOG_SRC_APP, LOG_LEVEL_DBG1, "Mesh evt: NRF_MESH_EVT_ENABLED\n");
    #if (PERSISTENT_STORAGE)
                /* Mesh stack initialization has been completed */
                app_start();
    #endif
                break;
    
            case NRF_MESH_EVT_CONFIG_LOAD_FAILURE:
                if (p_evt->params.config_load_failure.id.file == MESH_APP_FILE_ID)
                {
                    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Persistent provisioner data was corrupted. Set default values. \n");
                    /* Clear and set default values. */
                    memset(&m_nw_state, 0x00, sizeof(m_nw_state));
                }
                break;
    
            default:
                break;
        }
    }
    
    /* Binds the local models correctly with the desired keys */
    void app_default_models_bind_setup(void)
    {
        /* Bind health client to App key, and configure publication key */
        ERROR_CHECK(access_model_application_bind(m_dev_handles.m_health_client_instance.model_handle, m_dev_handles.m_appkey_handle));
        ERROR_CHECK(access_model_publish_application_set(m_dev_handles.m_health_client_instance.model_handle, m_dev_handles.m_appkey_handle));
    
        /* Bind self-config server to the self device key */
        ERROR_CHECK(config_server_bind(m_dev_handles.m_self_devkey_handle));
    }
    
    static void node_reset(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- Node reset  -----\n");
    
        hal_led_blink_ms(HAL_LED_MASK, LED_BLINK_INTERVAL_MS, LED_BLINK_CNT_RESET);
        /* This function may return if there are ongoing flash operations. */
        mesh_stack_device_reset();
    }
    
    #if NRF_MESH_LOG_ENABLE
    static const char m_usage_string[] =
        "\n"
        "\t\t--------------------------------------------------------------------------------\n"
        "\t\t Button/RTT 1) Initiate provisioning and configuration of unprovisioned devices.\n"
        "\t\t Button/RTT 4) Clear all the states to reset the node.\n"
        "\t\t--------------------------------------------------------------------------------\n";
    #endif
    
    static void button_event_handler(uint32_t button_number)
    {
        /* Increase button number because the buttons on the board is marked with 1 to 4 */
        button_number++;
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Button %u pressed\n", button_number);
        switch (button_number)
        {
            case 1:
            {
                /* Check if all devices have been provisioned or not */
                check_network_state();
                break;
            }
    
            case 2:
            {
                provisioning_resume();
                break;
            }
    
            /* Initiate node reset */
            case 4:
            {
                if (mesh_stack_is_device_provisioned())
                {
                    /* Clear all the states to reset the node. */
                    provisioner_invalidate();
                    mesh_stack_config_clear();
                }
                node_reset();
                break;
            }
    
            default:
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, m_usage_string);
                break;
        }
    }
    
    static void app_rtt_input_handler(int key)
    {
        if (key >= '1' && key <= '4')
        {
            uint32_t button_number = key - '1';
            button_event_handler(button_number);
        }
        else
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, m_usage_string);
        }
    }
    
    void models_init_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing and adding models\n");
        m_dev_handles.m_netkey_handle = DSM_HANDLE_INVALID;
        m_dev_handles.m_appkey_handle = DSM_HANDLE_INVALID;
        m_dev_handles.m_self_devkey_handle = DSM_HANDLE_INVALID;
    
        /* This app requires following models :
         * config client : To be able to configure other devices
         * health client : To be able to interact with other health servers */
        ERROR_CHECK(config_client_init(app_config_client_event_cb));
        ERROR_CHECK(health_client_init(&m_dev_handles.m_health_client_instance, 0, app_health_event_cb));
    }
    
    static void mesh_init(void)
    {
        bool device_provisioned;
        mesh_stack_init_params_t init_params =
        {
            .core.irq_priority       = NRF_MESH_IRQ_PRIORITY_LOWEST,
            .core.lfclksrc           = DEV_BOARD_LF_CLK_CFG,
            .models.models_init_cb   = models_init_cb,
            .models.config_server_cb = app_config_server_event_cb
        };
    
        nrf_mesh_evt_handler_add(&m_mesh_core_event_handler);
        uint32_t status = mesh_stack_init(&init_params, &device_provisioned);
        switch (status)
        {
            case NRF_ERROR_INVALID_DATA:
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Data in the persistent memory was corrupted.\n");
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Reboot device before starting of the provisioning process.\n");
                break;
            case NRF_SUCCESS:
                break;
            default:
                ERROR_CHECK(status);
        }
    
        if (status == NRF_SUCCESS)
        {
            /* Initialize the provisioner */
            mesh_provisioner_init_params_t m_prov_helper_init_info =
            {
                .p_dev_data = &m_dev_handles,
                .p_nw_data = &m_nw_state,
                .netkey_idx = NETKEY_INDEX,
                .attention_duration_s = ATTENTION_DURATION_S,
                .p_data_store_cb  = app_data_store_cb,
                .p_prov_success_cb = app_prov_success_cb,
                .p_prov_failed_cb = app_prov_failed_cb
            };
            prov_helper_init(&m_prov_helper_init_info);
    
            if (!device_provisioned)
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Setup defaults: Adding keys, addresses, and bindings \n");
    
                prov_helper_provision_self();
                app_default_models_bind_setup();
                app_data_store_cb();
            }
            else
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Restored: Handles \n");
                prov_helper_device_handles_load();
            }
    
            node_setup_cb_set(app_config_successful_cb, app_config_failed_cb);
        }
    }
    
    
    
    
    
    void uart_event_handle(app_uart_evt_t * p_event)
    {
           while (true)
        {
            uint8_t cr;
            while (app_uart_get(&cr) != NRF_SUCCESS);
            while (app_uart_put(cr) != NRF_SUCCESS);
    
            if (cr == '1')
            {
                printf(" \r\n 1 pressed \r\n");
                check_network_state();
    
                while (true)
                {
                    // Do nothing.
                }
            if (cr == '2')
            {
            printf("\r\n 2 pressed ");
            provisioning_resume();
    
             while (true)
                {
                    // Do nothing.
                }
    
            }
            if (cr=='4')
            {
                printf("\r\n 4 pressed \r\n");
                if (mesh_stack_is_device_provisioned())
                {
                    /* Clear all the states to reset the node. */
                    provisioner_invalidate();
                    mesh_stack_config_clear();
                }
                node_reset();
    
                 while (true)
                {
                    // Do nothing.
                }
    
            }
             
    
            }
        }
        
    #if 0    
        uint32_t i;
        switch(i)
        {
        case 1:
        {
         printf("\r\n Pressing 1 for scanning the unprovisioned nodes Uart event handler provisioner code .\r\n");
         check_network_state();
         break;
    
        }
        
        case 2: 
    
          {
                provisioning_resume();
                break;
           }
    
        case 4:
             {
                printf("\r\n Pressing 4 for resetting the provisioned nodes Uart event handler provisioner code .\r\n");
                 if (mesh_stack_is_device_provisioned())
                {
                    /* Clear all the states to reset the node. */
                    provisioner_invalidate();
                    mesh_stack_config_clear();
                }
                node_reset();
                break;
            }
        break;
        default:
    
        }
    #endif
    
    
     //printf("\r\nUART started uart event handler provisioner code .\r\n");
    
    }
    
    
    
    /**@brief  Function for initializing the UART module.
     */
    /**@snippet [UART Initialization] */
    static void uart_init(void)
    {
        uint32_t                     err_code;
        app_uart_comm_params_t const comm_params =
        {
            .rx_pin_no    = RX_PIN_NUMBER,
            .tx_pin_no    = TX_PIN_NUMBER,
            .rts_pin_no   = RTS_PIN_NUMBER,
            .cts_pin_no   = CTS_PIN_NUMBER,
            .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
            .use_parity   = false,
    #if defined (UART_PRESENT)
            .baud_rate    = NRF_UART_BAUDRATE_115200
    #else
            .baud_rate    = NRF_UARTE_BAUDRATE_115200
    #endif
        };
    
      APP_UART_FIFO_INIT(&comm_params,
                           UART_RX_BUF_SIZE,
                           UART_TX_BUF_SIZE,
                           uart_event_handle,
                           APP_IRQ_PRIORITY_LOWEST,
                           err_code);
        APP_ERROR_CHECK(err_code);
    }
    /**@snippet [UART Initialization] */
    
    
    
    
    
    
    
    
    static void initialize(void)
    {
        
          uart_init();
       
       // __LOG_INIT(LOG_SRC_APP | LOG_SRC_ACCESS, LOG_LEVEL_INFO, LOG_CALLBACK_DEFAULT);
        __LOG_INIT(LOG_SRC_APP | LOG_SRC_FRIEND, LOG_LEVEL_DBG1, log_callback_rtt);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- BLE Mesh Static Provisioner Demo -----\n");
    
        ERROR_CHECK(app_timer_init());
        hal_leds_init();
    
    #if BUTTON_BOARD
        ERROR_CHECK(hal_buttons_init(button_event_handler));
    #endif
    
        ble_stack_init();
        mesh_init();
        node_setup_uri_check();
    }
    
    static void app_start(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Starting application ...\n");
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Provisioned Nodes: %d, Configured Nodes: %d\n",
              m_nw_state.provisioned_devices, m_nw_state.configured_devices);
        __LOG_XB(LOG_SRC_APP, LOG_LEVEL_INFO, "Dev key ", m_nw_state.self_devkey, NRF_MESH_KEY_SIZE);
        __LOG_XB(LOG_SRC_APP, LOG_LEVEL_INFO, "Net key ", m_nw_state.netkey, NRF_MESH_KEY_SIZE);
        __LOG_XB(LOG_SRC_APP, LOG_LEVEL_INFO, "App key ", m_nw_state.appkey, NRF_MESH_KEY_SIZE);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Press Button/RTT 1 to start provisioning and configuration process. \n");
    }
    
    static void start(void)
    {
        rtt_input_enable(app_rtt_input_handler, RTT_INPUT_POLL_PERIOD_MS);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "<start> \n");
    
        ERROR_CHECK(mesh_stack_start());
    
    #if (!PERSISTENT_STORAGE)
        app_start();
    #endif
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, m_usage_string);
    
        hal_led_mask_set(HAL_LED_MASK, LED_MASK_STATE_OFF);
        hal_led_blink_ms(HAL_LED_MASK, LED_BLINK_INTERVAL_MS, LED_BLINK_CNT_START);
    }
    
    
    
    /**@brief Function for initializing the nrf log module.
     */
     #if 0
    static void log1_init(void)
    {
        ret_code_t err_code = NRF_LOG_INIT(NULL);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    }
    #endif
    
    
    
    
    
    
    
    
    #if 0
    void my_uart_callback(nrfx_uarte_event_t const * p_event,
                          void *                     p_context)
    {
        //TODO: Handle 'p_event'
    }
    #endif
    
    int main(void)
    {
        
    
       // nrfx_uarte_t m_uart = NRFX_UARTE_INSTANCE(0); 
        //nrfx_uarte_config_t m_uart_config = NRFX_UARTE_DEFAULT_CONFIG;
        
       // nrfx_uarte_init(&m_uart, &m_uart_config, my_uart_callback);
    
    
    
        // uart_init();
         //log1_init();
    
     //   ret_code_t err_code = NRF_LOG_INIT(NULL);
      //  APP_ERROR_CHECK(err_code);
    
        // NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        initialize();
         printf("\r\nUART started main provisioner code .\r\n");
        start();
    
        for (;;)
        {
            (void)sd_app_evt_wait();
        }
    }
    

    Is this the right way i have implemented if not then how shall i proceed with it.

    Thanks & Regards,

    Ela

Children
  • Hi,

    Ela said:
    I am getting compiling errors and not able to resolve it, i have used in the same way as mentioned in the infocenter. 

    Can you provide more details about the compiling errors? Any logs?

    Ela said:
    In our provisioner example code, segger_printf.c, segger_print.c, rttinput.c these files have been used for writing or reading data to RTT. "SEGGER_RTT_Read" and "SEGGER_RTT_Write" these functions are used for getting and sending data by RTT, so can i use these functions for the same operation with UART,  i think we can not use these functions, if not then how shall we do it?

    No, these functions are for RTT. You can't use the same functions for UART. 

    Yes, you have to create a UART event handler that handles the incoming commands. I suggest you look at the uart_event_handler from the UART example from the nRF5 SDK. It will show you how to get data from the serial terminal. Implement something similar to app_rtt_input_handler(), which is how the RTT input is handled, inside the uart_event_handler to handle your inputs via UART.

  • Hi Mttrinh,

    1) I am attaching the compiling error i got:

    Rebuilding 'ble_app_uart_pca10040_s132' from solution 'ble_app_uart_pca10040_s132' in configuration 'Release'
      Assembling 'thumb_crt0.s'
      Compiling 'nrf_log_backend_rtt.c'
      Compiling 'nrf_log_backend_serial.c'
      Compiling 'nrf_log_default_backends.c'
      Compiling 'nrf_log_frontend.c'
      Compiling 'nrf_log_str_formatter.c'
      Compiling 'app_button.c'
      Compiling 'app_error.c'
      Compiling 'app_error_handler_gcc.c'
      Compiling 'app_error_weak.c'
      Compiling 'app_fifo.c'
      Compiling 'app_scheduler.c'
      Compiling 'hardfault_implementation.c'
      Compiling 'app_util_platform.c'
      Compiling 'app_uart_fifo.c'
      Compiling 'nrf_atfifo.c'
      Compiling 'nrf_assert.c'
      Compiling 'nrf_atflags.c'
      Compiling 'nrf_atomic.c'
      Compiling 'nrf_fprintf.c'
      Compiling 'nrf_balloc.c'
      Compiling 'nrf_memobj.c'
      Compiling 'nrf_fprintf_format.c'
      Compiling 'nrf_pwr_mgmt.c'
      Compiling 'nrf_ringbuf.c'
      Compiling 'nrf_section_iter.c'
      Compiling 'nrf_sortlist.c'
      Compiling 'nrf_strerror.c'
      Compiling 'retarget.c'
      Assembling 'ses_startup_nrf52.s'
      Compiling 'system_nrf52.c'
      Assembling 'ses_startup_nrf_common.s'
      Compiling 'nrf_drv_clock.c'
      Compiling 'boards.c'
      Compiling 'nrf_drv_uart.c'
      Compiling 'nrfx_atomic.c'
      Compiling 'nrfx_clock.c'
      Compiling 'nrfx_gpiote.c'
      Compiling 'nrfx_prs.c'
      Compiling 'nrfx_uart.c'
      Compiling 'nrfx_uarte.c'
      Compiling 'bsp.c'
      Compiling 'bsp_btn_ble.c'
      Compiling 'main.c'
      Compiling 'SEGGER_RTT.c'
      Compiling 'mesh_main.c'
      Compiling 'SEGGER_RTT_Syscalls_SES.c'
      Compiling 'SEGGER_RTT_printf.c'
      Compiling 'ble_advertising.c'
      Compiling 'ble_advdata.c'
      Compiling 'ble_conn_params.c'
      Compiling 'ble_conn_state.c'
      Compiling 'ble_link_ctx_manager.c'
      Compiling 'ble_srv_common.c'
      Compiling 'nrf_ble_gatt.c'
      Compiling 'nrf_ble_qwr.c'
      Compiling 'utf.c'
      Compiling 'ble_nus.c'
      Compiling 'nrf_sdh.c'
      Compiling 'nrf_sdh_ble.c'
      Compiling 'model_common.c'
      Compiling 'nrf_sdh_soc.c'
      Compiling 'config_server.c'
      Compiling 'composition_data.c'
      Compiling 'health_server.c'
      Compiling 'packed_index_list.c'
      Compiling 'generic_onoff_client.c'
      Compiling 'app_timer_mesh.c'
      Compiling 'uECC.c'
      Compiling 'app_timer_workaround.c'
      Compiling 'assertion_handler_weak.c'
      Compiling 'mesh_provisionee.c'
      Compiling 'mesh_app_utils.c'
      Compiling 'mesh_adv.c'
      Generating linker script 'ble_app_uart_pca10040_s132.ld'
      Linking ble_app_uart_pca10040_s132.elf
        Output/Release/Obj/ble_app_uart_pca10040_s132/mesh_main.o: in function `app_generic_onoff_client_status_cb':
        undefined reference to `log_printf'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/examples/ble_peripheral/ble_app_uart_coexist/mesh_main.c:182: undefined reference to `log_printf'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/examples/ble_peripheral/ble_app_uart_coexist/mesh_main.c:182: undefined reference to `g_log_dbg_msk'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/examples/ble_peripheral/ble_app_uart_coexist/mesh_main.c:182: undefined reference to `g_log_dbg_lvl'
        Output/Release/Obj/ble_app_uart_pca10040_s132/mesh_main.o: in function `mesh_soc_evt_handler':
        undefined reference to `nrf_mesh_on_sd_evt'
        Output/Release/Obj/ble_app_uart_pca10040_s132/mesh_main.o: in function `node_reset':
        undefined reference to `mesh_stack_device_reset'
        Output/Release/Obj/ble_app_uart_pca10040_s132/mesh_main.o: in function `unicast_address_print':
        undefined reference to `dsm_local_unicast_addresses_get'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/examples/ble_peripheral/ble_app_uart_coexist/mesh_main.c:126: undefined reference to `log_printf'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/examples/ble_peripheral/ble_app_uart_coexist/mesh_main.c:126: undefined reference to `g_log_dbg_msk'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/examples/ble_peripheral/ble_app_uart_coexist/mesh_main.c:126: undefined reference to `g_log_dbg_lvl'
        Output/Release/Obj/ble_app_uart_pca10040_s132/mesh_main.o: in function `mesh_main_button_event_handler':
        undefined reference to `log_printf'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/examples/ble_peripheral/ble_app_uart_coexist/mesh_main.c:241: undefined reference to `access_model_reliable_cancel'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/examples/ble_peripheral/ble_app_uart_coexist/mesh_main.c:279: undefined reference to `g_log_dbg_msk'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/examples/ble_peripheral/ble_app_uart_coexist/mesh_main.c:279: undefined reference to `g_log_dbg_lvl'
        Output/Release/Obj/ble_app_uart_pca10040_s132/mesh_main.o: in function `mesh_init':
        undefined reference to `mesh_stack_init'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/examples/ble_peripheral/ble_app_uart_coexist/mesh_main.c:311: undefined reference to `log_printf'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/examples/ble_peripheral/ble_app_uart_coexist/mesh_main.c:312: undefined reference to `log_printf'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/examples/ble_peripheral/ble_app_uart_coexist/mesh_main.c:319: undefined reference to `g_log_dbg_msk'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/examples/ble_peripheral/ble_app_uart_coexist/mesh_main.c:319: undefined reference to `g_log_dbg_lvl'
        Output/Release/Obj/ble_app_uart_pca10040_s132/mesh_main.o: in function `mesh_main_initialize':
        undefined reference to `log_init'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/examples/ble_peripheral/ble_app_uart_coexist/mesh_main.c:325: undefined reference to `log_callback_rtt'
        Output/Release/Obj/ble_app_uart_pca10040_s132/mesh_main.o: in function `mesh_main_start':
        undefined reference to `nrf_mesh_configure_device_uuid_get'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/examples/ble_peripheral/ble_app_uart_coexist/mesh_main.c:353: undefined reference to `mesh_stack_start'
        Output/Release/Obj/ble_app_uart_pca10040_s132/health_server.o: in function `health_server_setter':
        undefined reference to `access_model_publish_period_divisor_set'
        Output/Release/Obj/ble_app_uart_pca10040_s132/generic_onoff_client.o: in function `generic_onoff_client_init':
        undefined reference to `access_model_add'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nrf5MeshSDK/models/model_spec/generic_onoff/src/generic_onoff_client.c:156: undefined reference to `access_model_subscription_list_alloc'
        Output/Release/Obj/ble_app_uart_pca10040_s132/generic_onoff_client.o: in function `generic_onoff_client_set':
        undefined reference to `access_reliable_model_is_free'
        Output/Release/Obj/ble_app_uart_pca10040_s132/generic_onoff_client.o: in function `message_create':
        undefined reference to `nrf_mesh_unique_token_get'
        Output/Release/Obj/ble_app_uart_pca10040_s132/generic_onoff_client.o: in function `generic_onoff_client_set':
        undefined reference to `access_model_reliable_publish'
        Output/Release/Obj/ble_app_uart_pca10040_s132/generic_onoff_client.o: in function `message_create':
        undefined reference to `nrf_mesh_unique_token_get'
        Output/Release/Obj/ble_app_uart_pca10040_s132/generic_onoff_client.o: in function `generic_onoff_client_set_unack':
        undefined reference to `access_model_publish'
        Output/Release/Obj/ble_app_uart_pca10040_s132/mesh_provisionee.o: in function `provisionee_start':
        undefined reference to `nrf_mesh_prov_generate_keys'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nrf5MeshSDK/examples/common/src/mesh_provisionee.c:226: undefined reference to `nrf_mesh_prov_listen'
        Output/Release/Obj/ble_app_uart_pca10040_s132/mesh_provisionee.o: in function `prov_evt_handler':
        undefined reference to `nrf_mesh_prov_auth_data_provide'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nrf5MeshSDK/examples/common/src/mesh_provisionee.c:285: undefined reference to `mesh_stack_provisioning_data_store'
        Output/Release/Obj/ble_app_uart_pca10040_s132/mesh_provisionee.o: in function `mesh_provisionee_prov_start':
        undefined reference to `nrf_mesh_prov_init'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nrf5MeshSDK/examples/common/src/mesh_provisionee.c:324: undefined reference to `nrf_mesh_prov_bearer_adv_interface_get'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nrf5MeshSDK/examples/common/src/mesh_provisionee.c:324: undefined reference to `nrf_mesh_prov_bearer_add'
        /home/ekta/Desktop/26_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nrf5MeshSDK/examples/common/src/mesh_provisionee.c:336: undefined reference to `nrf_mesh_evt_handler_add'
    Build failed

    2) I have implemented the uart_event_handler, i press 1 from serial terminal i am able to scan all the unprovisioned nodes and then provisioned them, when press 4 reset all the provisioned nodes, attaching the code implementation i have added : 

    void uart_event_handle(app_uart_evt_t * p_event)
    {
      //   printf("\r\nUART started uart event handler provisioner code .\r\n");
    
           while (true)
        {
            uint8_t cr;
            while (app_uart_get(&cr) != NRF_SUCCESS);
            printf("\r\n cr \r\n %d",cr);
            while (app_uart_put(cr) != NRF_SUCCESS);
     
            if (cr == '1')
            {
                printf(" \r\n 1 pressed \r\n");
                check_network_state();
    
                while (true)
                {
                    // Do nothing.
                }
            if (cr == '2')
            {
            printf("\r\n 2 pressed ");
            provisioning_resume();
    
             while (true)
                {
                    // Do nothing.
                }
    
            }
            if (cr == '4')
            {
                printf("\r\n 4 pressed \r\n");
                if (mesh_stack_is_device_provisioned())
                {
                    /* Clear all the states to reset the node. */
                    provisioner_invalidate();
                    mesh_stack_config_clear();
                }
                node_reset();
    
                 while (true)
                {
                    // Do nothing.
                }
    
            }
            else
            {
            printf("\r\n else\r\n");
            }
             
    
            }
        }
        
    #if 0    
        uint32_t i;
        switch(i)
        {
        case 1:
        {
         printf("\r\n Pressing 1 for scanning the unprovisioned nodes Uart event handler provisioner code .\r\n");
         check_network_state();
         break;
    
        }
        
        case 2: 
    
          {
                provisioning_resume();
                break;
           }
    
        case 4:
             {
                printf("\r\n Pressing 4 for resetting the provisioned nodes Uart event handler provisioner code .\r\n");
                 if (mesh_stack_is_device_provisioned())
                {
                    /* Clear all the states to reset the node. */
                    provisioner_invalidate();
                    mesh_stack_config_clear();
                }
                node_reset();
                break;
            }
        break;
        default:
    
        }
    #endif
    }

    But here i am not able to get the desired result, is this the right way to do, if not hen how shall i do this, can you attach code implementation for my application for reference.

    Response to this at high priority is really a great help..

    Thanks & Regards,

    Ela

  • Hi Mtrrinh,

    In uart example of nrf sdk, there is no uart_event_handler, there is uart_error_handler. In ble_app_uart example of nrf sdk there is uart_event_handler where it is sending uart recieved data over ble, can you tell me how to not include the sending data over ble in that event handler.

    Thanks & Regards,

    Ela

  • Hi,

    1) Did you copy the coexist folder into the examples/ble_peripheral folder at your nRF5 SDK installation path? Did you add the MESH_ROOT macro to the Global macros in SES?

    2) The function is called uart_event_handle in the UART example. ble_nus_data_send() is the function that sends the data over BLE, you can remove this.

  • Hi Mttrinh,

    1) Yes i have copied the ble_app_uart_coexist folder into ble_peripheral folder and set the MESH_ROOT in global macros to the mesh sdk path.

    2) In UART example there is not uart_event_handle function. I have implemented the uart_event_handler as per my application, attaching that code : 

    void uart_event_handler(app_uart_evt_t * p_event)
    {
        static uint8_t data_array[244];
        static uint8_t index = 0;
       // static uint8_t val = 0;
        uint32_t       err_code;
    
         //printf("\r\nUART started uart event handler.\r\n");
        switch (p_event->evt_type)
        {
            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&data_array[index]));
                printf("Data array in switch %c\r\n",data_array[index]);
    
                index++;
    
                 if ( data_array[index - 1] == '1')
                {
                   printf("Sucess pressed 1 \r\n");
                   check_network_state();
                   index = 0;
                   memset(data_array[index], 0 , sizeof(data_array[index]));
    
                }
    
                if ( data_array[index - 1] == '2')
                {
                   printf("Sucess pressed 2\r\n");
                   provisioning_resume();
                   index = 0;
                   memset(data_array[index], 0 , sizeof(data_array[index]));
    
                }
    
                 if ( data_array[index - 1] == '4')
                  {
                   printf("Sucess pressed 4 \r\n");
                 
                     if (mesh_stack_is_device_provisioned())
                     {
                       /* Clear all the states to reset the node. */
                       provisioner_invalidate();
                       mesh_stack_config_clear();
                    }
                   node_reset();
                   index = 0;
                   memset(data_array[index], 0 , sizeof(data_array[index]));
    
                  }
    
                    
                #if 0
                if ( data_array[index - 1] == ';')
                {
                   printf("sucess \r\n");
                   index = 0;
                   memset(data_array[index], 0 , sizeof(data_array[index]));
    
                }
                #endif
    
                    
                break;
    
            case APP_UART_COMMUNICATION_ERROR:
                APP_ERROR_HANDLER(p_event->data.error_communication);
                break;
    
            case APP_UART_FIFO_ERROR:
                APP_ERROR_HANDLER(p_event->data.error_code);
                break;
    
            default:
                break;
        }
      }

    Is this the right way to do this? As i am not able to get command response after sometime. If i am pressing 4 nothing is happening some random letter is getting printed. If i am pressing 2 not able to recive back any command. What i am missing here, can you please let me know?

    Thanks & Regards,

    Ela

Related