Forums - How to initialize zigbee network with persistent data?

3 posts / 0 new
Last post
How to initialize zigbee network with persistent data?
steven
Join Date: 26 Feb 20
Posts: 14
Posted: Fri, 2020-08-07 13:14

Hi,

I have spend several days trying to initialize a network with persistent data. Meaning: Save the zigbee network settings and joined devices and load them again after a reboot/power loss.

Below the code I use to initialize it. But after that the devicelist is empty/stays empty. If I store it aswell and load that again I get the error that the deviceID is not found in the APS address map.

The flow of the code is:

  1. The network is initialized
  2. network is formed and device can join.
  3. device join and are added to the devicelist
  4. the persistnotify is called and stores data
  5. reboot: network is initialized and loads data with code below.
  6. Device are not joining and list stays empty...
  •  

apparently I miss something in the flow, but I cannot find this anywhere in the documentation. Really looking for some suggestions :)

 

 /* 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 == QAPI_OK) && (ZigBee_Demo_Context.ZigBee_Handle != NULL))
         {
 
/* Attempt to load the persist data. */
LOG_VERBOSE("Attempt to initialize the persist data\n");
 
Result = qapi_Persist_Initialize(&(ZigBee_Demo_Context.PersistHandle), ZIGBEE_PERSIST_DIRECTORY, ZIGBEE_PERSIST_PREFIX, ZIGBEE_PERSIST_SUFFIX, NULL, 0);
 
if(Result == QAPI_OK)
{
LOG_VERBOSE("Initialize persistent ok\n");
LOG_VERBOSE("Attempt to get the persist data\n");
 
Result = qapi_Persist_Get(ZigBee_Demo_Context.PersistHandle, &PersistLength, &PersistData);
if(Result == QAPI_OK)
{
LOG_VERBOSE("get persistent zigbee data\n");
 
Result = qapi_ZB_Restore_Persistent_Data(ZigBee_Demo_Context.ZigBee_Handle, PersistData, PersistLength);
if(Result == QAPI_OK)
{
LOG_VERBOSE("Persist Data Loaded.\n");
}
else
{
LOG_ERROR("qapi_ZB_Restore_Persistent_Data\n"); //, Result);
}
 
free(PersistData);
//qapi_Persist_Free(ZigBee_Demo_Context.PersistHandle, PersistData);
}
else if(Result == QAPI_ERR_NO_ENTRY)
{
  LOG_VERBOSE("persistent error:  No entry\n");
}
 
/* 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_ERROR("ERROR: qapi_ZB_Register_Persist_Notify_CB\n");
}
else if (Result == QAPI_OK)
{
LOG_VERBOSE("persistent notify register ok\n");
} else
{
LOG_ERROR("Something goes wron with the persistent notify callback register \n");
}
}
else
{
LOG_ERROR("qapi_Persist_Initialize\n");
}
 
 
            if(Result == QAPI_OK)
            {
        Result = qapi_ZB_ZDP_Register_Callback(ZigBee_Demo_Context.ZigBee_Handle, ZB_ZDP_Event_CB, 0);
            if (Result == QAPI_OK)
                {
   LOG_VERBOSE("zdp register callback ok, next is extended address\n");
      /* Register the ZDP callback. */
                  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);
                   LOG_INFO(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
                   LOG_INFO("Zigbeehandle: %p\n", ZigBee_Demo_Context.ZigBee_Handle);
                      Ret_Val = SUCCESS;
                  }
                  else
                  {
                   LOG_ERROR("qapi_ZB_Get_Extended_Address\n");
                     Ret_Val = QCLI_STATUS_ERROR_E;
                  }
               }
               else
               {
                LOG_ERROR("zdp register callback error\n");
                  Ret_Val = QCLI_STATUS_ERROR_E;
               }
            }
            else
            {
             LOG_ERROR("qapi_ZB_ZDP_Register_Callback\n");
   Ret_Val = QCLI_STATUS_ERROR_E;
            }
 
            if(Ret_Val != QCLI_STATUS_SUCCESS_E)
            {
              LOG_ERROR("shutdown zigbee\n");
               qapi_ZB_Shutdown(ZigBee_Demo_Context.ZigBee_Handle);
               ZigBee_Demo_Context.ZigBee_Handle = NULL;
 
               if(ZigBee_Demo_Context.PersistHandle != NULL)
               {
                LOG_ERROR("cleanup persistance\n");
                  qapi_Persist_Cleanup(ZigBee_Demo_Context.PersistHandle);
               }
            }
         }
         else
         {
          LOG_ERROR("qapi_ZB_Initialize \n");
            Ret_Val = QCLI_STATUS_ERROR_E;
         }
      }
   else
   {
    LOG_ERROR("ZigBee stack already initialized.\n");
      Ret_Val = QCLI_STATUS_ERROR_E;
   }
 
   return(Ret_Val);
}
 
  • Up0
  • Down0
steven
Join Date: 26 Feb 20
Posts: 14
Posted: Thu, 2020-08-13 13:27

I now also tried this with the QCLI, and also there it does not seem to work. Is this an issue with the QAPI an loading or do I just miss a step?

Steps - Device 1:

ZigBee Initialize
ZigBee Setextaddress 000000FFFE000001
Zigbee ZCL CreateEndpoint 1 4
Zigbee form 1 0 18
Zigbee permitjoin 255

Device2:

ZigBee Initialize
ZigBee Setextaddress 000000FFFE000002
Zigbee ZCL CreateEndpoint 1 5
Zigbee Join 1 1

Response device 2:

> ZigBee: Join confirm:

> ZigBee:   Status:        0

> ZigBee:   NwkAddress:    0xBE9E

> ZigBee:   ExtendedPanId: 0000000000000007

> ZigBee:   Channel:       18

 

Response device 1:

> ZigBee\ZDP: Device Annce:

> ZigBee\ZDP:   ExtendedAddress: 000000FFFE000002

> ZigBee\ZDP:   NetworkAddress:  0xBE9E

> ZigBee\ZDP:   Capability:      0x8E

 

all seems well... I add both addresses both the address and extended addresses and the panid to the devicelist.

Device 1:

Zigbee AddDevice 3 000000FFFE000002 1

Zigbee AddDevice 2 0xBE9E 1

Device 2:

zigbee adddevice 3 0000000000000007 1

Now I can control the device for instance with

Zigbee levelcontrol movetolevel 1 1 1 100 10

Then shutdown one of the zigbee stacks and re-initialize it (example here is the co-ordinator):

Zigbee shutdown

Zigbee initialize 1

Zigbee ZCL CreateEndpoint 1 4

Zigbee form 1 0 18

 

But the device will never connect back. I only shutdown either the coordinator or the other device.

I tried multiple things, but most of the time I get the following error:

#define QAPI_ZB_ERR_APS_NO_SHORT_ADDRESS                 (QAPI_ZB_ERR(169)) /**< APS status indicating a transmission using a short address failed because a                                                                                 short address for the device was not found in the address map. */

  • Up0
  • Down0
c_rpedad
Profile picture
Join Date: 18 Jun 18
Location: San Jose
Posts: 317
Posted: Thu, 2020-09-10 11:42

Kindly initialize with option 1 (ZigBee Initialize 1)  to use persist data.Device 1:

ZigBee Initialize 1
ZigBee Setextaddress 000000FFFE000001
Zigbee ZCL CreateEndpoint 1 4
Zigbee form 1 0 18
Zigbee permitjoin 255

Device2:
ZigBee Initialize 1
ZigBee Setextaddress 000000FFFE000002
Zigbee ZCL CreateEndpoint 1 5
Zigbee Join 1 1
 
Device 1:
Zigbee AddDevice 3 000000FFFE000002  1
Zigbee levelcontrol movetolevel 1 1 1 100 10

 

If End Device is restarted, initialize as below and control the device: // SHUTDOWN
ZigBee Initialize 1
Zigbee ZCL CreateEndpoint 1 5

 

If CoOrdinator is restarted, initialize as below and contro EndDevice: // SHUTDOWN
Zigbee Initialize 1
Zigbee ZCL CreateEndpoint 1 4
Zigbee AddDevice 3 000000FFFE000002  1
Zigbee levelcontrol movetolevel 1 1 1 100 10

 

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.