Hey
This is sumanth. I have worked on mesh beaconing example and saw the output of continuous scanning advertisement of nearby devices in RTT, I made changes in light_switch_server program with the help of beaconing example to scan the advertisements when i press the button 1 in nRF52 DK. It worked well, but it continuously scanning the advertisement of nearby devices like it is in a infinate loop. I want to know how can i stop the scanning data. My requirement is like below mentioned.
The nRf52 DK should start Scanning the advertisments and print in RTT when i press button 1 and stop scanning when i press button 2, It should also able to do its light_switch_example. What are the changes i have to do.
The modified server program is shown below.
static void rx_cb(const nrf_mesh_adv_packet_rx_data_t * p_rx_data)
{
LEDS_OFF(BSP_LED_0_MASK); /* @c LED_RGB_RED_MASK on pca10031 */
char msg[64];
(void) sprintf(msg, "RX [@%u]: RSSI: %3d ADV TYPE: %x ADDR: [%02x:%02x:%02x:%02x:%02x:%02x]",
p_rx_data->p_metadata->params.scanner.timestamp,
p_rx_data->p_metadata->params.scanner.rssi,
p_rx_data->adv_type,
p_rx_data->p_metadata->params.scanner.adv_addr.addr[0],
p_rx_data->p_metadata->params.scanner.adv_addr.addr[1],
p_rx_data->p_metadata->params.scanner.adv_addr.addr[2],
p_rx_data->p_metadata->params.scanner.adv_addr.addr[3],
p_rx_data->p_metadata->params.scanner.adv_addr.addr[4],
p_rx_data->p_metadata->params.scanner.adv_addr.addr[5]);
__LOG_XB(LOG_SRC_APP, LOG_LEVEL_INFO, msg, p_rx_data->p_payload, p_rx_data->length);
LEDS_ON(BSP_LED_0_MASK); /* @c LED_RGB_RED_MASK on pca10031 */
}
static void button_event_handler(uint32_t button_number)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Button %u pressed\n", button_number);
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:
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "User action \n");
hal_led_pin_set(ONOFF_SERVER_0_LED, !hal_led_pin_get(ONOFF_SERVER_0_LED));
app_onoff_status_publish(&m_onoff_server_0);
break;
}
case 1:
{
nrf_mesh_rx_cb_set(rx_cb);
}
/* Initiate node reset */
case 3:
{
/* Clear all the states to reset the node. */
if (mesh_stack_is_device_provisioned())
{
#if MESH_FEATURE_GATT_PROXY_ENABLED
(void) proxy_stop();
#endif
mesh_stack_config_clear();
node_reset();
}
else
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "The device is unprovisioned. Resetting has no effect.\n");
}
break;
}
default:
break;
}
}
I used the rx_cb function from beconing example and placed in the main.c of server and called that function in button_event_handler under case 1.