Hi guys,
I am trying to modify Light switch example. My goal is to create a mesh network to transfer data from server to client periodically. So far, what I have done is to create a timer in server and set it in repeated mode. When I send message on from client to server, it starts the timer and start to call the function: app_onoff_status_publish(&m_onoff_server_0);
However, when I log this function access_model_publish(); which is the function to actually send the status data, it returns 7, which is invalid params?
Here is my code in main.c in sever side:
APP_TIMER_DEF(timer_id);
static void timer_handler(void *p_context)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "handler!\r\n");
app_onoff_status_publish(&m_onoff_server_0);
}
static void timers_create()
{
ret_code_t err_code;
// timeout_id :
err_code = app_timer_create(&timer_id, APP_TIMER_MODE_REPEATED, timer_handler);
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "app_timer_create error: %d\r\n", err_code);
}
// END ---------------------------------------
static void timer_start(uint16_t time)
{
ret_code_t err_code;
err_code = app_timer_start(timer_id, APP_TIMER_TICKS(time), NULL);
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "app_timer_start error: %d\r\n", err_code);
}
static void timer_stop()
{
app_timer_stop(timer_id);
}
/* Callback for updating the hardware state */
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. */
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Setting GPIO value: %d\n", onoff)
hal_led_pin_set(ONOFF_SERVER_0_LED, onoff);
if(onoff)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "start timer here!\r\n");
timer_start(1000);
}
else
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "stop timer here!\r\n");
timer_stop();
}
}
And here is what I have in file generic_onoff_server.c, simply just log the function:
static uint32_t status_send(generic_onoff_server_t * p_server,
const access_message_rx_t * p_message,
const generic_onoff_status_params_t * p_params)
{
uint32_t error_code;
generic_onoff_status_msg_pkt_t msg_pkt;
if (p_params->present_on_off > GENERIC_ONOFF_MAX ||
p_params->target_on_off > GENERIC_ONOFF_MAX ||
p_params->remaining_time_ms > TRANSITION_TIME_STEP_10M_MAX)
{
return NRF_ERROR_INVALID_PARAM;
}
msg_pkt.present_on_off = p_params->present_on_off;
if (p_params->remaining_time_ms > 0)
{
msg_pkt.target_on_off = p_params->target_on_off;
msg_pkt.remaining_time = model_transition_time_encode(p_params->remaining_time_ms);
}
access_message_tx_t reply =
{
.opcode = ACCESS_OPCODE_SIG(GENERIC_ONOFF_OPCODE_STATUS),
.p_buffer = (const uint8_t *) &msg_pkt,
.length = p_params->remaining_time_ms > 0 ? GENERIC_ONOFF_STATUS_MAXLEN : GENERIC_ONOFF_STATUS_MINLEN,
.force_segmented = p_server->settings.force_segmented,
.transmic_size = p_server->settings.transmic_size
};
if (p_message == NULL)
{
error_code = access_model_publish(p_server->model_handle, &reply);
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "access_model_publish error_code: %d\n", error_code);
return error_code;
}
else
{
error_code = access_model_publish(p_server->model_handle, &reply);
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "access_model_publish error_code: %d\n", error_code);
return error_code;
}
}
And here is the result:

And nothing have been received from the client side.
How can I fix this?
Thank you very much guys.