Hey,
I am working on mesh program, I am trying to send mesh message periodically for every 5 secs when i press a button in nRf52 DK. The message is being send for 3 or 4 times and suddenly getting stop. I tried different times but resulted the same. I have made the changes in program as attached in below. Please go through it and help me out to solve the problem.
void BISSendMessage (uint8_t msgid, uint8_t mac_id[6],uint16_t cut_band)
{
access_message_tx_t msg;
uint32_t status=0;
BIS_APP_MSG sBisAppMsg;
msg.opcode.opcode = 0xC1; // simple_message_OPCODE_SEND;
msg.opcode.company_id = 0x0059; // Nordic's company ID
strcpy (sBisAppMsg.name, "BIS");
sBisAppMsg.msgid = msgid; // byte0: 0=> reset msg, 1=> code blue msg, 2=> msg from patient unit
sBisAppMsg.mac_id[0] = mac_id[0];
sBisAppMsg.mac_id[1] = mac_id[1];
sBisAppMsg.mac_id[2] = mac_id[2];
sBisAppMsg.mac_id[3] = mac_id[3];
sBisAppMsg.mac_id[4] = mac_id[4];
sBisAppMsg.mac_id[5] = mac_id[5];
sBisAppMsg.Cutband = cut_band;
msg.length = sizeof (BIS_APP_MSG);
msg.p_buffer = (const uint8_t *) &sBisAppMsg;
status= access_model_publish(m_clients[0].model_handle, &msg);
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Status : %u \n", status);
if (status == NRF_ERROR_INVALID_STATE ||
status == NRF_ERROR_BUSY||status == NRF_ERROR_NO_MEM)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Cannot send. Device is busy.\n");
}
else
{
ERROR_CHECK(status);
}
}
void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
//nrf_drv_timer_disable (&TIMER_LED);
BISSendMessage (MOM_MSG, mac_id, CUT_BAND);
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "some msg\n");
//nrf_drv_timer_enable (&TIMER_LED);
}
int InitTimer (void)
{
uint32_t time_ms = 5000; //Time(in miliseconds)
uint32_t time_ticks;
uint32_t err_code = NRF_SUCCESS;
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
APP_ERROR_CHECK(err_code);
time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms);
nrf_drv_timer_extended_compare(
&TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
}
static void button_event_handler(uint32_t button_number)
{
uint32_t status = NRF_SUCCESS;
generic_onoff_set_params_t set_params;
model_transition_t transition_params;
static uint8_t tid = 0;
switch (button_number)
{
/* Pressing SW1 on the Development Kit will result in LED state to toggle and trigger
the STATUS message to inform client about the state change. This is a demonstration of
state change publication due to local event. */
case 0: // Reset switch
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "User action \n");
hal_led_blink_stop ();
hal_led_pin_set(ONOFF_SERVER_1_LED, true); // buzzer off
hal_led_pin_set(ONOFF_SERVER_0_LED, true); // led off
#if 0
set_params.on_off = false;
set_params.tid = tid++;
transition_params.delay_ms = APP_CONFIG_ONOFF_DELAY_MS;
transition_params.transition_time_ms = APP_CONFIG_ONOFF_TRANSITION_TIME_MS;
(void)access_model_reliable_cancel(m_clients[0].model_handle);
status = generic_onoff_client_set(&m_clients[0], &set_params, &transition_params);
#endif
//BISSendMessage (MOM_MSG, mac_id, CUT_BAND);
nrf_drv_timer_enable (&TIMER_LED);
//app_timer_start(m_blink_timer,APP_TIMER_TICKS(500),NULL);
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "message sent\n");
break;
}
case 1: // ignored for time being
break;
case 2: // code blue switch
{
hal_led_pin_set(ONOFF_SERVER_0_LED, false); // led on
hal_led_mask_set(LEDS_MASK, LED_MASK_STATE_OFF);
hal_led_blink_ms (LEDS_MASK, LED_BLINK_SHORT_INTERVAL_MS, LED_BLINK_CNT_START);
//BISSendMessage (CODEBLUE_MSG, WARD_NUMBER, BED_NUMBER);
break;
}
}
}