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

Device runs wrong after goto sleep on awhile

Hi every one,

I'm a development product with chipset NRF52811, using soft device S112 and SDK 15.3.0.

My device will wake up and send data whenever I press the button or one-timer interrupt every 30 minutes.

Everything run is fine when startup and most of the time.

But, when the device goes into state Sleep On for a while, It doesn't work properly.

When I press and hold the button, I wakeup from state Sleep On and set an app timer to call function node_handle_btn_pair every 100ms to check the state of the button, If total time hold button > 3000ms I will advertise and implement pair, If total time hold button > 5000ms I will advertise and implement unpair.

Everything worked fine at first, But when the device goes into a sleep state for a while, I have just pressed the button for a very short time, about 100ms the timeline counting time (in the picture, the time jumped from 500 to 2100 immediately) jumped very high and intermittently, and after that, the device wants to advertise to perform unpair. But not a success.

I see error <error> nrf_ble_gatt: sd_ble_gatts_exchange_mtu_reply () returned NRF_ERROR_INVALID_STATE.
I don't know what this error is, hope you help me

Thank every one!

/* Function handle BTN Unpair */

void node_handle_btn_pair(void)
{
    NRF_LOG_INFO("Interupt timer");
    if(!nrfx_gpiote_in_is_set(NODE_GPIO_PIN_PAIR))
    {
        timeline += 100;
        NRF_LOG_INFO("Timeline is %d", timeline);
        if(timeline > 3000){
            if(!Node_GetStateOriginPaired() && !SW_Device_GetStateConnectedOnBLE()){
                // advertising
                (void)node_btn_instance.fnAdvertising();
                NRF_LOG_INFO("Node implement pair");
                // handle led
                gpioIndicateClear(NODE_GPIO_PIN_INDICATE);
                SW_SetLedBlinkNomal(NODE_GPIO_PIN_INDICATE, 900, 200);
                node_timer_handle_btn_pair_stop();
                timeline = 0;
            }
        }

        if(timeline > 5000){
            // handle unpair
            if(Node_GetStateOriginPaired() && !SW_Device_GetStateConnectedOnBLE()){
                // Advertising for send a packet unpair
                (void)node_btn_instance.fnAdvertising();
                // Set state unpair, on main loop update db
                stateSendData = true;
                gpioIndicateClear(NODE_GPIO_PIN_INDICATE);
                node_imp_unpair = true;
                SW_SetLedBlinkNomal(NODE_GPIO_PIN_INDICATE, 900, 200);
                node_timer_handle_btn_pair_stop();
                timeline = 0;

            }
            else if(Node_GetStateOriginPaired() && SW_Device_GetStateConnected_Final())
            {
                // Send MSG Unpair
                stateSendData = true;
                node_imp_unpair = true;
                gpioIndicateClear(NODE_GPIO_PIN_INDICATE);
                (void)node_btn_instance.fnImplementUnpair();
                (void)node_btn_instance.fnImplementUnpairLocal();
                SW_SetLedBlinkNomal(NODE_GPIO_PIN_INDICATE, 900, 200);
                
                node_timer_handle_btn_pair_stop();
                timeline = 0;
            }
        }
    }
    else{
        NRF_LOG_WARNING("Stop timer btn pair");
        timeline = 0;
        // Stop timer
        gpioIndicateClear(NODE_GPIO_PIN_INDICATE);
        node_timer_handle_btn_pair_stop();
    }
}

Related