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

Getting nRF DK52 with simple thingy server - model provisioned

Hello everyone, 

as indicated by this question https://devzone.nordicsemi.com/f/nordic-q-a/35692/adding-nrf52-dk-to-github-mesh-demo-for-thingys/138327#138327 I am trying to get the nRF 52 DK provisioned with the simple thingy model of the https://github.com/NordicPlayground/Nordic-Thingy52-mesh-demo/

So far I managed to initialize the model and I was told that as soon as the model is initialized the provisioner node should provision the nRF DK 52 and add it to the bluetooth mesh network. However, although it seems to be intitalized it is not provisioned. Is there something else I need to do to get the dk provisioned? 

I added the code of my new main.c of the light_switch_server, where I adjusted the configutation_setup-method so I get a new server variable which can be initialized by simple_thingy_server_init(). 

Regards Michael

 

#include <stdint.h>
#include <string.h>
#include "simple_thingy_server.h"
#include "ble_uis.h"

/* HAL */
#include "nrf.h"
#include "boards.h"
#include "nrf_mesh_sdk.h"
#include "nrf_delay.h"
#include "simple_hal.h"

/* Core */
#include "nrf_mesh.h"
#include "nrf_mesh_events.h"
#include "log.h"

#include "access.h"
#include "access_config.h"
#include "device_state_manager.h"
#include "nrf_mesh_node_config.h"

#include "simple_on_off_server.h"

#include "light_switch_example_common.h"

/*****************************************************************************
 * Definitions
 *****************************************************************************/

#define LED_PIN_NUMBER (BSP_LED_0)
#define LED_PIN_MASK   (1u << LED_PIN_NUMBER)

/*****************************************************************************
 * Static data
 *****************************************************************************/

//static simple_on_off_server_t m_server;
static simple_thingy_server_t m_server; 

/* Forward declaration */
static bool get_cb(const simple_on_off_server_t * p_server);
static bool set_cb(const simple_on_off_server_t * p_server, bool value);

static ble_uis_led_t led_get_cb(); 
static ble_uis_led_t led_set_cb(const simple_thingy_server_t * server, ble_uis_led_t led_config);
static void sensor_set_cb(const simple_thingy_server_t * server, sensor_config_t sensor_cfg);

/*****************************************************************************
 * Static utility functions
 *****************************************************************************/

static void configuration_setup(void * p_unused)
{
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing and adding models\n");
//    m_server.get_cb = get_cb;
//    m_server.set_cb = set_cb;
    m_server.led_get_cb = led_get_cb; 
    m_server.led_set_cb = led_set_cb; 
    m_server.sensor_set_cb = sensor_set_cb; 
//    ERROR_CHECK(simple_on_off_server_init(&m_server, 0));
    ERROR_CHECK(simple_thingy_server_init(&m_server,0));
    ERROR_CHECK(access_model_subscription_list_alloc(m_server.model_handle));
   
   // hal_led_mask_set(LEDS_MASK, true);
}

static void provisioning_complete(void * p_unused)
{
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Successfully provisioned\n");
    hal_led_mask_set(LEDS_MASK, false);
    hal_led_blink_ms(LED_PIN_MASK, 200, 4);

}

/*****************************************************************************
 * Simple OnOff Callbacks
 *****************************************************************************/

//static bool get_cb(const simple_on_off_server_t * p_server)
//{
//    return hal_led_pin_get(LED_PIN_NUMBER);
//}

static ble_uis_led_t led_get_cb()
{
    // Dummy method just to get nRF5 DK initialized and provisioned
    ble_uis_led_t led_cmd;
    led_cmd.mode = BLE_UIS_LED_MODE_CONST;
    led_cmd.data.mode_const.r = 0x0f;
    led_cmd.data.mode_const.g = 0x0f;
    led_cmd.data.mode_const.b = 0x0f;
    return led_cmd; 
}

static ble_uis_led_t led_set_cb(const simple_thingy_server_t * server, ble_uis_led_t led_config)
{
    // Dummy method just to get nRF5 DK initialized and provisioned
    return led_config; 
}

static void sensor_set_cb(const simple_thingy_server_t * server, sensor_config_t sensor_cfg)
{
  // Dummy method just to get nRF5 DK initialized and provisioned
  
}
//static bool set_cb(const simple_on_off_server_t * p_server, bool value)
//{
//    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Got SET command to %u\n", value);
//    hal_led_pin_set(LED_PIN_NUMBER, value);
//    return value;
//}

int main(void)
{
    __LOG_INIT(LOG_SRC_APP | LOG_SRC_ACCESS, LOG_LEVEL_INFO, LOG_CALLBACK_DEFAULT);
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- BLE Mesh Light Switch Server Demo -----\n");

    hal_leds_init();

    static const uint8_t static_auth_data[NRF_MESH_KEY_SIZE] = STATIC_AUTH_DATA;
    static nrf_mesh_node_config_params_t config_params =
        {.prov_caps = NRF_MESH_PROV_OOB_CAPS_DEFAULT(ACCESS_ELEMENT_COUNT)};
    config_params.p_static_data = static_auth_data;
    config_params.complete_callback = provisioning_complete;
    config_params.setup_callback = configuration_setup;
    config_params.irq_priority = NRF_MESH_IRQ_PRIORITY_LOWEST;

#if defined(S110)
    config_params.lf_clk_cfg = NRF_CLOCK_LFCLKSRC_XTAL_20_PPM;
#elif SD_BLE_API_VERSION >= 5
    config_params.lf_clk_cfg.source = NRF_CLOCK_LF_SRC_XTAL;
    config_params.lf_clk_cfg.accuracy = NRF_CLOCK_LF_ACCURACY_20_PPM;
#else
    config_params.lf_clk_cfg.source = NRF_CLOCK_LF_SRC_XTAL;
    config_params.lf_clk_cfg.xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM;
#endif

    ERROR_CHECK(nrf_mesh_node_config(&config_params));
    
     hal_led_mask_set(LEDS_MASK, true);
    while (true)
    {
        (void)sd_app_evt_wait();
    }
}

Related