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

Add generic_onoff_server Model to Provisioner Node in light_switch example, then subscribe this Model to a Server in the same Mesh Network.

Hi, I have run light switch example in SDK 15.2 and SDK for Mesh version 3.1.0, and it run OK, I can use Configuration Model in Provisioner Node to config 1 Client and 2 Server then send On-Off message from Client (Node have Switch) to Server (Node have the Light), but now I want the Provisioner Node can add generic_onoff_server model, then subscribe this model to an PUBLIC address. I have add generic_onoff_server model in Provisioner Node but when I run node_setup_start() with address is PROVISIONER_ADDRESS = 0x0001 in example_network_config.h  or I fixed an address is: 0x0104 for this Provisioner Node it run failed with message:
"Configuration of device 2 failed. Press Button 1 to retry". Here is my Model which I add to Provisioner 

uint8_t* tqt_appkey;
static uint16_t m_appkey_idx = 0;
#define APP_ONOFF_ELEMENT_INDEX (0)
#define LOCK_STATUS (LED_2)
static void app_onoff_server_set_cb(const app_onoff_server_t * p_server, bool onoff);
static void app_onoff_server_get_cb(const app_onoff_server_t * p_server, bool * p_present_onoff);

static void app_onoff_server_set_cb(const app_onoff_server_t * p_server, bool onoff)
{
/* Resolve the server instance here if required, this example uses only 1 instance. */
if(onoff) {
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "TQT SUBSCRIBE OK\n");
nrf_gpio_pin_set(LOCK_STATUS);
} else {
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "TQT SUBSCRIBE OK\n");
nrf_gpio_pin_clear(LOCK_STATUS);
}
}

/* Callback for reading the hardware state */
static void app_onoff_server_get_cb(const app_onoff_server_t * p_server, bool * p_present_onoff)
{
/* Resolve the server instance here if required, this example uses only 1 instance. */

*p_present_onoff = hal_led_pin_get(LOCK_STATUS);
}

APP_ONOFF_SERVER_DEF(server_in_prov_node,
false,
0,
app_onoff_server_set_cb,
app_onoff_server_get_cb)

void tqt_run_config_server() {
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "TQT\n");
node_setup_start(PROVISIONER_ADDRESS, PROVISIONER_RETRY_COUNT,
tqt_appkey, APPKEY_INDEX, EX_URI_LS_CLIENT);
}
Can someone please help me to add generic_onoff_server model to Provisioner Node, then subscribe this model to an Server Node.

Thank you!

Parents Reply
  • Thank you very much for your help, It very detail and now it run for me. This is my function to local setup subscribe:

    void tqt_run_config_server() {
    static access_model_id_t model_id;
    model_id.model_id = GENERIC_ONOFF_SERVER_MODEL_ID;
    model_id.company_id = ACCESS_COMPANY_ID_NONE;
    access_model_handle_t model_handle;
    access_handle_get(1,model_id,&model_handle);

    dsm_handle_t subscription_address_handle;
    dsm_address_subscription_add(GROUP_ADDRESS_ODD, &subscription_address_handle);

    access_model_subscription_add(model_handle, subscription_address_handle);
    }

Children
Related