Hello,
When our router device is connected in network and there is a power failure on router side, we need our router to connect to its network automatically without the server inititing permit join request. To achieve this we are using zigbee persist API when the device is initialized.
Below is the code we have written referring QCLI_demo project:
int32_t Zigbee_Initialize(){int32_t Ret_Val;qapi_Status_t Result;uint64_t Extended_Address;qbool_t UsePersist;uint32_t PersistLength;uint8_t *PersistData;UsePersist = true;/* Verify the ZigBee layer had not been initialized yet. */if (ZigBee_Demo_Context.ZigBee_Handle == NULL){Result = qapi_ZB_Initialize(&(ZigBee_Demo_Context.ZigBee_Handle), ZB_Event_CB, 0);if ((Result == SUCCESS) && (ZigBee_Demo_Context.ZigBee_Handle != NULL)){if (UsePersist){/* Attempt to load the persist data. */Result = qapi_Persist_Initialize(&(ZigBee_Demo_Context.PersistHandle), ZIGBEE_PERSIST_DIRECTORY, ZIGBEE_PERSIST_PREFIX, ZIGBEE_PERSIST_SUFFIX, NULL, 0);if (Result == QAPI_OK){Result = qapi_Persist_Get(ZigBee_Demo_Context.PersistHandle, &PersistLength, &PersistData);if (Result == QAPI_OK){Result = qapi_ZB_Restore_Persistent_Data(ZigBee_Demo_Context.ZigBee_Handle, PersistData, PersistLength);if (Result == QAPI_OK){int i = 0;while(i<PersistLength){LOG_INFO("%x\n",PersistData[i]);i++;}LOG_INFO("Persist Data Loaded.\n");}else{LOG_INFO("qapi_ZB_Restore_Persistent_Data %d\n", Result);}qapi_Persist_Free(ZigBee_Demo_Context.PersistHandle, PersistData);}else if (Result != QAPI_ERR_NO_ENTRY){LOG_INFO("qapi_Persist_Get %d\n", Result);}/* If it got this far, register the persist data callback. */Result = qapi_ZB_Register_Persist_Notify_CB(ZigBee_Demo_Context.ZigBee_Handle, ZB_Persist_Notify_CB, (uint32_t) (ZigBee_Demo_Context.PersistHandle));if (Result != QAPI_OK){LOG_INFO("qapi_ZB_Register_Persist_Notify_CB %d\n", Result);}}else{LOG_INFO("qapi_Persist_Initialize %d\n", Result);}}if (Result == QAPI_OK){if (ZDP_Demo_StackInitialize(ZigBee_Demo_Context.ZigBee_Handle)){Result = qapi_ZB_Get_Extended_Address(ZigBee_Demo_Context.ZigBee_Handle, &Extended_Address);if (Result == QAPI_OK){LOG_INFO("ZigBee stack initialized.\n");LOG_INFO("Extended Address: %08X%08X\n", (uint32_t) (Extended_Address >> 32), (uint32_t) Extended_Address);}else{LOG_INFO("qapi_ZB_Get_Extended_Address %d\n", Result);Ret_Val = QCLI_STATUS_ERROR_E;}}else{Ret_Val = QCLI_STATUS_ERROR_E;}}else{LOG_INFO("Z DEBUG 15 + 1 ret = %d\n",Ret_Val);LOG_INFO("qapi_ZB_ZDP_Register_Callback %d\n", Result);Ret_Val = QCLI_STATUS_ERROR_E;}if (Ret_Val != QCLI_STATUS_SUCCESS_E){qapi_ZB_Shutdown(ZigBee_Demo_Context.ZigBee_Handle);ZigBee_Demo_Context.ZigBee_Handle = NULL;if (ZigBee_Demo_Context.PersistHandle != NULL){qapi_Persist_Cleanup(ZigBee_Demo_Context.PersistHandle);}}}else{LOG_ERROR("FAILED qapi_ZB_Initialize\n");Ret_Val = FAILURE;}}else{LOG_WARN("ZigBee stack already initialized.\n");Ret_Val = FAILURE;}return (Ret_Val);}
Kindly configure endpoint and add enddevice address to the co-ordinator after reboot.
Below are the commands I tried between two QCA4020 devices:
Kindly let us know if the above instructions works well for your use case.
Thank you raja_pedada, this solved my issue.