This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Serial example in mesh without Interactive pyACI

Greetings,

I am working with serial mesh (nrfSDk 15.2 for mesh 3.1 with softdevice s132_nrf52_6.1.0) .

1. I followed the serial example available and its working.

2. I want to use serial mesh without Interactive pyACI, so tried with light switch server client example, I added serial part and can provision and the serial mesh is initialised and enabled.

 After this I want to transmit string with nrf_mesh_serial_tx function, only when the client and server are binded with appkey and  publication adrress is applied via the nrf mesh app.

I have two dk nrf51 and 52, for server(code I am using same as the example lightswitch server with serial intialisation and enabling) and client (as attached) respectively.

In server configuration app_key binding is not working as, in callback it is used to rest the node.

Please tell me if I am doing it right to achieve the communication without Interactive pyACI

Thanking you in advance

Best Regards

Deepa



*********** CLIENT*****************

#include <stdint.h>
#include <string.h>

/* HAL */
#include "boards.h"
#include "simple_hal.h"
#include "app_timer.h"
#include "mesh_opt_prov.h"

/* Core */
#include "nrf_mesh_config_core.h"
#include "nrf_mesh_gatt.h"
#include "nrf_mesh_configure.h"
#include "nrf_mesh.h"
#include "mesh_stack.h"
#include "device_state_manager.h"
#include "access_config.h"

/* Provisioning and configuration */
#include "mesh_provisionee.h"
#include "mesh_app_utils.h"

/* Models */
#include "generic_onoff_client.h"

/* Logging and RTT */
#include "log.h"
#include "rtt_input.h"

/* Example specific includes */
#include "app_config.h"
#include "nrf_mesh_config_examples.h"
#include "light_switch_example_common.h"
#include "example_common.h"
#include "ble_softdevice_support.h"
#include "example_network_config.h"
#include "network_setup_types.h"
#include "provisioner_helper.h"
#include "node_setup.h"

#ifndef NRF_MESH_SERIAL_ENABLE
#define NRF_MESH_SERIAL_ENABLE 1
#endif

#if NRF_MESH_SERIAL_ENABLE
#include "nrf_mesh_serial.h"
#endif


#define APP_STATE_OFF                (0)
#define APP_STATE_ON                 (1)

#define APP_UNACK_MSG_REPEAT_COUNT   (2)

static bool                   m_device_provisioned;

void nrf_mesh_rx_cb(const uint8_t* p_data, uint32_t length) { 
	__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Rx received\r\n"); 
}

static void device_identification_start_cb(uint8_t attention_duration_s)
{
    hal_led_mask_set(LEDS_MASK, false);
    hal_led_blink_ms(BSP_LED_2_MASK  | BSP_LED_3_MASK,
                     LED_BLINK_ATTENTION_INTERVAL_MS,
                     LED_BLINK_ATTENTION_COUNT(attention_duration_s));
}

static void provisioning_aborted_cb(void)
{
    hal_led_blink_stop();
}

static void provisioning_complete_cb(void)
{
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Successfully provisioned\n");

#if MESH_FEATURE_GATT_ENABLED
    /* Restores the application parameters after switching from the Provisioning
     * service to the Proxy  */
    gap_params_init();
    conn_params_init();
#endif

    dsm_local_unicast_address_t node_address;
    dsm_local_unicast_addresses_get(&node_address);
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Node Address: 0x%04x \n", node_address.address_start);

    hal_led_blink_stop();
    hal_led_mask_set(LEDS_MASK, LED_MASK_STATE_OFF);
    hal_led_blink_ms(LEDS_MASK, LED_BLINK_INTERVAL_MS, LED_BLINK_CNT_PROV);



    }



static void node_reset(void)
{
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- Node reset  -----\n");
    hal_led_blink_ms(LEDS_MASK, LED_BLINK_INTERVAL_MS, LED_BLINK_CNT_RESET);
    /* This function may return if there are ongoing flash operations. */
    mesh_stack_device_reset();
}

static void config_server_evt_cb(const config_server_evt_t * p_evt)
{
    if (p_evt->type == CONFIG_SERVER_EVT_NODE_RESET)
    {
        node_reset();
    }
}


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 models_init_cb(void)
{
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing and adding models\n");
  
     ERROR_CHECK(config_client_init(app_config_client_event_cb));
}

static void mesh_init(void)
{
    mesh_stack_init_params_t init_params =
    {
        .core.irq_priority       = NRF_MESH_IRQ_PRIORITY_LOWEST,
        .core.lfclksrc           = DEV_BOARD_LF_CLK_CFG,
        .core.p_uuid             = NULL,
        .models.models_init_cb   = models_init_cb,
        .models.config_server_cb = config_server_evt_cb
    };
    ERROR_CHECK(mesh_stack_init(&init_params, &m_device_provisioned));

    
#if NRF_MESH_SERIAL_ENABLE
    ERROR_CHECK(nrf_mesh_serial_init(NULL));
#endif
}

static void initialize(void)
{
    __LOG_INIT(LOG_SRC_APP | LOG_SRC_ACCESS | LOG_SRC_BEARER, LOG_LEVEL_INFO, LOG_CALLBACK_DEFAULT);
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- BLE Mesh Light Switch Client Demo -----\n");

    ERROR_CHECK(app_timer_init());
    hal_leds_init();

    ble_stack_init();

#if MESH_FEATURE_GATT_ENABLED
    gap_params_init();
    conn_params_init();
#endif

    mesh_init();
}

static void start(void)
{
    if (!m_device_provisioned)
    {
        static const uint8_t static_auth_data[NRF_MESH_KEY_SIZE] = STATIC_AUTH_DATA;
        mesh_provisionee_start_params_t prov_start_params =
        {
            .p_static_data    = static_auth_data,
            .prov_complete_cb = provisioning_complete_cb,
            .prov_device_identification_start_cb = device_identification_start_cb,
            .prov_device_identification_stop_cb = NULL,
            .prov_abort_cb = provisioning_aborted_cb,
            .p_device_uri = EX_URI_LS_CLIENT
        };
        ERROR_CHECK(mesh_provisionee_prov_start(&prov_start_params));
    }

    #if NRF_MESH_SERIAL_ENABLE
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Enabling serial interface...\n");
    ERROR_CHECK(nrf_mesh_serial_enable());
    #endif


    mesh_app_uuid_print(nrf_mesh_configure_device_uuid_get());

    ERROR_CHECK(mesh_stack_start());

    hal_led_mask_set(LEDS_MASK, LED_MASK_STATE_OFF);
    hal_led_blink_ms(LEDS_MASK, LED_BLINK_INTERVAL_MS, LED_BLINK_CNT_START);
}

int main(void)
{
    initialize();
    start();

    char data[] = "\r\nHello from Nordic\r\n";
    uint32_t result = nrf_mesh_serial_tx(data, sizeof(data));
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Send: %d\r\n", result);
     

    for (;;)
    {
        (void)sd_app_evt_wait();
    }
}

Parents
  • I do not fully understand unfortunately. Do you still want to provision via a computer, just without using interactive PyACI? Or do you want the dev kit to be the provisioner? 

  • I want send and receive data without PyACI. Is it possible without using a model via serial mesh?

  • Yes, but do you need the computer to be the provisioner or do you want a DK to be the provisioner? You can also provision via the nRF Mesh phone app. Why do you not want to use Interactive PyACI?

  • I want to use nRF Mesh phone app to be the provisioner, Its a requirement, to use serial mesh without PyACI.

    To my understanding, I have used Phone app as provisioner, provisioned the server and client, then started serial mesh, sent a message Hello World, which should be received at the server end. Here, I have not assigned a app binding key and publication address to either server nor client. I cannot see the sent message on debug window in Segger Studio. I am not sure if am doing it right. Is appykey binding and adress publication necessary to communicate between server and client else only provisioning them is sufficient?

    I am also fllashing the serial mesh example program to an external custom board.The serial mesh example available provides timeout event, when flashed on external custom board and used with PyACI.

    Any lead would be great help

  • If you want to communicate between the client & the server via Bluetooth Mesh, you will need to bind the app key & setup the publication & subscription addresses.

    dk_07 said:
    I am also fllashing the serial mesh example program to an external custom board.The serial mesh example available provides timeout event, when flashed on external custom board and used with PyACI.

    This will be a lot easier if you have a 52 DK to test with. What timeout event do you receive? Could you upload a log please? This documentation may be helpful.

  • Thank you. May I just use the functions in config_server.c to initialise a server model and add key and subscription address? If yes, I am unable to find the config_server_appkey_add to add the app key for server. Instead I found handle_appkey_add function which are under opcode handler functions. Should I use the handle_appkey_add function else should I write my own server model defining its functions? In between I found this post  regarding self provisioning and the suggested answer to be used without any model configuration. Could please guide me with the steps to proceed with?

    I have nRF52 DK, I have connected the custom board as described in this link. The log output is as attached below.

    My problem is, the program gets flashed on the external custom board without any issues, after using command window and getting timeoutevent, I check in nrfgo studio for the board connectivity. It shows recover, I couldnt figure why the board gets disconnected, once programmed. I guess dats the reason i get timeout waiting for event.

    Even after connecting the board as per the above provided link, should I provide 3V to the board externally? to function else the connection itself is enough to drive the external board. With the help of multimeter I measured 2.6V at the terminal of extermal custom board. Is 2.6V sufficient for the custom board to function?

    Thanks in advance

     To control your device, use d[x], where x is the device index.
        Devices are indexed based on the order of the COM ports specified by the -d option.
        The first device, d[0], can also be accessed using device.
    
        Type d[x]. and hit tab to see the available methods.
    
    Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)]
    Type 'copyright', 'credits' or 'license' for more information
    IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help.
    
    In [1]:
    
    In [1]: cmd.Echo?
    Init signature: cmd.Echo(data)
    Docstring:
    A simple loopback test command, to verify that the serial transport layer is working as
    intended.
    
    Parameters
    ----------
        data : uint8_t[254]
            Data to echo back.
    File:           
    Subclasses:
    
    In [2]: send(cmd.Echo("hello world"))
    
    In [3]: 2019-05-28 08:08:30,657 - INFO - COM3: cmd Echo, timeout waiting for event

  • Regarding your first question, yes, you can use the functions provided in config_server.c. Just take a look at how the provisioner example does this in the light switch folder.

    I do not think 2.6 V is good enough for the custom board to function. Yes, you will need to power the custom board separately (see link).

Reply Children
No Data
Related