This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How can i Rejoin with the previously paired network after power goes off for the device?

Hi Team, In my project i am using nrf52833 and i have established a network using Open Thread protocol to communicate . I am able to pair my device with the network. One scenario i wanted to implement for my project are described below.

Generally when power goes off device got disconnected from the network. I wanted to rejoin the device with the previously paired thread network when device powered  again. Is there any possibilities to rejoin with the network when power ON with out doing any physical activities with the device. If so, then what are the possible way we can rejoin the device with the network.

Thank you.

Parents
  • Hi

    How are you setting up your Thread device when you first connect to the network?

    Regards,
    Sigurd Hellesvik

  • after getting request from parent device i am initializing child pairing by pressing a key into it . Then we start the RF state machine for the joining and pairing process.  

  • Hi

    When using OpenThread, the network information should be saved into flash.
    If Thread is configured to automatically start at boot, it should connect to the previously connected network automatically as well.

    Regards,
    Sigurd Hellesvik

  • 1. By pressing key we are starting RF state machine 

    if((THSM_key_pressed_for_joining_b) && (MCDC_GetReadyToSleep_U8() == TRUE))
    {
    THSM_knxiot_running_b = TRUE;
    THSM_key_pressed_for_joining_b = FALSE;
    if (!THSM_initialize_otcomm_b ) //THSM_initialize_otcomm_b ensures thread initalization is done only once
    {
    THSM_initialize_otcomm_b = TRUE;
    COMWIRELESS_InitCommunication();
    }
    if (OT_JOINER_STATE_IDLE == otJoinerGetState(COMWIRELESS_ot_instance))
    {
    if (!THSM_teached_gateway_b)
    {
    /*enable recieve state of radio to check if there are anything to update on wakeup*/
    // COMWIRELESS_ReceiveEnable();
    // Start pairing
    THSM_WirelessState = THSM_START_JOINING_e;
    }
    }

    2. Then we are starting the joining process

    if ((THSM_joining_in_progress_b == FALSE) && (THSM_joining_try_done_b == FALSE))
    {
    if (OT_ERROR_NONE == otJoinerStart(COMWIRELESS_ot_instance, "SEMENS", NULL, NULL, NULL, NULL, NULL, JoinerCallback, NULL))
    {
    THSM_joining_try_done_b = FALSE;
    THSM_joining_in_progress_b = TRUE;
    THSM_start_pairing_b = TRUE;
    #ifdef DEBUG
    ConsolePrint("\n\r Start joining ...\n\r");
    #endif
    //LED Start glowing
    GENAPP_GpioAppSetLedR(TRUE);
    }

    }
    else
    {
    if (THSM_joining_try_done_b == TRUE)
    {
    if(THSM_joining_successful_b)
    {
    THSM_WirelessState = THSM_PAIR_SUCCESS_e;
    }
    else
    {
    THSM_WirelessState = THSM_PAIR_UNSUCCESS_e;
    }
    }
    }

    3. After that we started pairing process

    if(THSM_teached_gateway_b == FALSE)
    {
    GENAPP_GpioSetLedRTemporarily(THSM_LED_TOGGLE_DURATION_dU16,THSM_SUCCESSFUL_JOIN_BLINK_dU8);//LED Blink for 5 times
    // Pairing is complete -> enable Thread interface
    error = otThreadSetEnabled(COMWIRELESS_ot_instance, true);
    ASSERT(error == OT_ERROR_NONE);
    #ifdef DEBUG
    ConsolePrint("\nThread interface has been enabled.");
    #endif
    THSM_process_timeout_b = FALSE;
    THSM_teached_gateway_b = TRUE;
    TIMEAPP_StartSingleShotTimerWithCallback(TIMEAPI_RF_TIMEOUT_e, 10000, THSM_RfProcessCallback, (void *)NULL);
    }
    else
    {
    if((THSM_process_timeout_b == TRUE))
    {
    //COMWIRELESS_SetTimeoutOccured(FALSE);
    //THSM_data_request_executed_b = TRUE;
    #ifdef DEBUG
    ConsolePrint("\n\rSet new PollPeriod and disable RX when IDLE ...\n\r");
    #endif

    otLinkModeConfig mode;
    memset(&mode, 0, sizeof(mode));
    mode.mRxOnWhenIdle = false; // Join network as SED.
    mode.mSecureDataRequests = true;

    error = otThreadSetLinkMode(COMWIRELESS_ot_instance, mode);
    ASSERT(error == OT_ERROR_NONE);

    //error = otLinkSendDataRequest(COMWIRELESS_ot_instance);
    //ASSERT(error == OT_ERROR_NONE);

    error = otLinkSetPollPeriod(COMWIRELESS_ot_instance, 30000);// COMWIRELESS_GetWakeUpTime_U16()*1000);
    ASSERT(error == OT_ERROR_NONE);

    otThreadSetChildTimeout(COMWIRELESS_ot_instance, 300);
    THSM_WirelessState = THSM_PREPARE_SLEEP_e;//THSM_PREPARE_WAKEUP_e;

    test_flag = TRUE;

    }
    //THSM_WirelessState = THSM_PREPARE_WAKEUP_e;
    }

    Then state machine stay in sleep state and comes out from it when wake up time elapsed and communication is continuing .

    case THSM_PREPARE_SLEEP_e:
    {
    /*radio sleep*/
    COMWIRELESS_RadioSleep();
    COMWIRELESS_SetReadyToSleepTHSM(TRUE);
    // CSA_SetStartWirelessStateMachine_U8(FALSE);
    printf("\n In prepare Sleep State: %d", otPlatRadioGetState(COMWIRELESS_ot_instance));
    THSM_WirelessState = THSM_SLEEP_e;
    break;
    }

    case THSM_SLEEP_e:
    {

    if (CSA_GetStartWirelessStateMachine_U8() == TRUE)
    {
    COMWIRELESS_SetReadyToSleepTHSM(FALSE);

    THSM_WirelessState = THSM_IDLE_e;
    }
    break;

    case THSM_WAKEUP_e:
    {
    // if ((!otTaskletsArePending(COMWIRELESS_ot_instance)) && (THSM_wakeupIdle == TRUE) && (THSM_process_timeout_b == TRUE))
    if (((!otTaskletsArePending(COMWIRELESS_ot_instance))) || (THSM_process_timeout_b == TRUE))
    // if ((otPlatRadioGetState(COMWIRELESS_ot_instance) == 1) && (THSM_process_timeout_b == TRUE))
    {
    THSM_wakeupIdle = FALSE;
    THSM_WirelessState = THSM_PREPARE_SLEEP_e;
    }

    break;

    Things is like we are not storing the network information data . if it is needed then let me know where those information are gets stored ? and how could i get those info ? and what are the information needs to rejoin previous network?

    And we are not  configuring thread automatically at boot start. we are configuring by key press only.

Reply
  • 1. By pressing key we are starting RF state machine 

    if((THSM_key_pressed_for_joining_b) && (MCDC_GetReadyToSleep_U8() == TRUE))
    {
    THSM_knxiot_running_b = TRUE;
    THSM_key_pressed_for_joining_b = FALSE;
    if (!THSM_initialize_otcomm_b ) //THSM_initialize_otcomm_b ensures thread initalization is done only once
    {
    THSM_initialize_otcomm_b = TRUE;
    COMWIRELESS_InitCommunication();
    }
    if (OT_JOINER_STATE_IDLE == otJoinerGetState(COMWIRELESS_ot_instance))
    {
    if (!THSM_teached_gateway_b)
    {
    /*enable recieve state of radio to check if there are anything to update on wakeup*/
    // COMWIRELESS_ReceiveEnable();
    // Start pairing
    THSM_WirelessState = THSM_START_JOINING_e;
    }
    }

    2. Then we are starting the joining process

    if ((THSM_joining_in_progress_b == FALSE) && (THSM_joining_try_done_b == FALSE))
    {
    if (OT_ERROR_NONE == otJoinerStart(COMWIRELESS_ot_instance, "SEMENS", NULL, NULL, NULL, NULL, NULL, JoinerCallback, NULL))
    {
    THSM_joining_try_done_b = FALSE;
    THSM_joining_in_progress_b = TRUE;
    THSM_start_pairing_b = TRUE;
    #ifdef DEBUG
    ConsolePrint("\n\r Start joining ...\n\r");
    #endif
    //LED Start glowing
    GENAPP_GpioAppSetLedR(TRUE);
    }

    }
    else
    {
    if (THSM_joining_try_done_b == TRUE)
    {
    if(THSM_joining_successful_b)
    {
    THSM_WirelessState = THSM_PAIR_SUCCESS_e;
    }
    else
    {
    THSM_WirelessState = THSM_PAIR_UNSUCCESS_e;
    }
    }
    }

    3. After that we started pairing process

    if(THSM_teached_gateway_b == FALSE)
    {
    GENAPP_GpioSetLedRTemporarily(THSM_LED_TOGGLE_DURATION_dU16,THSM_SUCCESSFUL_JOIN_BLINK_dU8);//LED Blink for 5 times
    // Pairing is complete -> enable Thread interface
    error = otThreadSetEnabled(COMWIRELESS_ot_instance, true);
    ASSERT(error == OT_ERROR_NONE);
    #ifdef DEBUG
    ConsolePrint("\nThread interface has been enabled.");
    #endif
    THSM_process_timeout_b = FALSE;
    THSM_teached_gateway_b = TRUE;
    TIMEAPP_StartSingleShotTimerWithCallback(TIMEAPI_RF_TIMEOUT_e, 10000, THSM_RfProcessCallback, (void *)NULL);
    }
    else
    {
    if((THSM_process_timeout_b == TRUE))
    {
    //COMWIRELESS_SetTimeoutOccured(FALSE);
    //THSM_data_request_executed_b = TRUE;
    #ifdef DEBUG
    ConsolePrint("\n\rSet new PollPeriod and disable RX when IDLE ...\n\r");
    #endif

    otLinkModeConfig mode;
    memset(&mode, 0, sizeof(mode));
    mode.mRxOnWhenIdle = false; // Join network as SED.
    mode.mSecureDataRequests = true;

    error = otThreadSetLinkMode(COMWIRELESS_ot_instance, mode);
    ASSERT(error == OT_ERROR_NONE);

    //error = otLinkSendDataRequest(COMWIRELESS_ot_instance);
    //ASSERT(error == OT_ERROR_NONE);

    error = otLinkSetPollPeriod(COMWIRELESS_ot_instance, 30000);// COMWIRELESS_GetWakeUpTime_U16()*1000);
    ASSERT(error == OT_ERROR_NONE);

    otThreadSetChildTimeout(COMWIRELESS_ot_instance, 300);
    THSM_WirelessState = THSM_PREPARE_SLEEP_e;//THSM_PREPARE_WAKEUP_e;

    test_flag = TRUE;

    }
    //THSM_WirelessState = THSM_PREPARE_WAKEUP_e;
    }

    Then state machine stay in sleep state and comes out from it when wake up time elapsed and communication is continuing .

    case THSM_PREPARE_SLEEP_e:
    {
    /*radio sleep*/
    COMWIRELESS_RadioSleep();
    COMWIRELESS_SetReadyToSleepTHSM(TRUE);
    // CSA_SetStartWirelessStateMachine_U8(FALSE);
    printf("\n In prepare Sleep State: %d", otPlatRadioGetState(COMWIRELESS_ot_instance));
    THSM_WirelessState = THSM_SLEEP_e;
    break;
    }

    case THSM_SLEEP_e:
    {

    if (CSA_GetStartWirelessStateMachine_U8() == TRUE)
    {
    COMWIRELESS_SetReadyToSleepTHSM(FALSE);

    THSM_WirelessState = THSM_IDLE_e;
    }
    break;

    case THSM_WAKEUP_e:
    {
    // if ((!otTaskletsArePending(COMWIRELESS_ot_instance)) && (THSM_wakeupIdle == TRUE) && (THSM_process_timeout_b == TRUE))
    if (((!otTaskletsArePending(COMWIRELESS_ot_instance))) || (THSM_process_timeout_b == TRUE))
    // if ((otPlatRadioGetState(COMWIRELESS_ot_instance) == 1) && (THSM_process_timeout_b == TRUE))
    {
    THSM_wakeupIdle = FALSE;
    THSM_WirelessState = THSM_PREPARE_SLEEP_e;
    }

    break;

    Things is like we are not storing the network information data . if it is needed then let me know where those information are gets stored ? and how could i get those info ? and what are the information needs to rejoin previous network?

    And we are not  configuring thread automatically at boot start. we are configuring by key press only.

Children
Related