This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Z-Stack 3.0.2 建网和入网问题

Other Parts Discussed in Thread: Z-STACK, CC2530

CC2530芯片,开始修改Z-Stack 3.0.2中的SampleSwitch和SampleLight例程,去掉UI和按键建网/入网,让协调器上电自己建立网络,终端上电自行入网。

1. 首先修改协调器,使用SampleLight例程提供的工程代码

1)去掉UI相关文件和代码行,编译无误;

2)在zcl_samplelight.c文件之zclSampleLight_Init()函数的最后添加协调器建网代码:

//GP_UPDATE  
#if (ZG_BUILD_RTR_TYPE)  
  gp_RegisterCommissioningModeCB(gp_CommissioningMode);
  gp_RegisterGPChangeChannelReqCB(gp_ChangeChannelReq);
#endif
  
  zdpExternalStateTaskID = zclSampleLight_TaskID;
  
  // Add on 5 Jan 2021
#if defined( ZDO_COORDINATOR )
  bdb_StartCommissioning(BDB_COMMISSIONING_MODE_NWK_FORMATION);
#else
  bdb_StartCommissioning(BDB_COMMISSIONING_MODE_NWK_STEERING);
#endif

  // UI_Init(zclSampleLight_TaskID, SAMPLEAPP_LCD_AUTO_UPDATE_EVT, SAMPLEAPP_KEY_AUTO_REPEAT_EVT, &zclSampleLight_IdentifyTime, APP_TITLE, &zclSampleLight_UiUpdateLcd, zclSampleLight_UiStatesMain);

  // UI_UpdateLcd();

3) 在zcl_samplelight.c文件之zclSampleLight_ProcessCommissioningStatus()函数添加网络状态打印:

switch(bdbCommissioningModeMsg->bdbCommissioningMode)
  {
    case BDB_COMMISSIONING_FORMATION:
      if(bdbCommissioningModeMsg->bdbCommissioningStatus == BDB_COMMISSIONING_SUCCESS)
      {
        //After formation, perform nwk steering again plus the remaining commissioning modes that has not been process yet
        bdb_StartCommissioning(BDB_COMMISSIONING_MODE_NWK_STEERING | bdbCommissioningModeMsg->bdbRemainingCommissioningModes);
        printf("nwk is ready\r\n");
      }
      else
      {
        //Want to try other channels?
        //try with bdb_setChannelAttribute
        printf("nwk failed\r\n");
      }
    break;
    case BDB_COMMISSIONING_NWK_STEERING:
      if(bdbCommissioningModeMsg->bdbCommissioningStatus == BDB_COMMISSIONING_SUCCESS)
      {
        //YOUR JOB:
        //We are on the nwk, what now?
      }
      else
      {
        //See the possible errors for nwk steering procedure
        //No suitable networks found
        //Want to try other channels?
        //try with bdb_setChannelAttribute
      }
    break;

4) 上电测试,复位后查看串口打印,均打印nwk failed,偶尔打印nwk is ready。

2. 其次修改终端,使用SampleSwitch工程来修改。

1)去掉UI,编译无误;

2)在zclSampleSw_Init()函数的末尾添加如下代码:

// Add on 5 Jan 2021
#if defined( ZDO_COORDINATOR )
  bdb_StartCommissioning(BDB_COMMISSIONING_MODE_NWK_FORMATION);
#else
  bdb_StartCommissioning(BDB_COMMISSIONING_MODE_NWK_STEERING);
#endif

3)在zclSampleSw_ProcessCommissioningStatus()函数中添加网络状态打印:

case BDB_COMMISSIONING_NWK_STEERING:
      if(bdbCommissioningModeMsg->bdbCommissioningStatus == BDB_COMMISSIONING_SUCCESS)
      {
        //YOUR JOB:
        //We are on the nwk, what now?
        printf("We are on the nwk\r\n");
      }
      else
      {
        //See the possible errors for nwk steering procedure
        //No suitable networks found
        //Want to try other channels?
        //try with bdb_setChannelAttribute
        printf("No suitable networks found\r\n");
      }
    break;

4) 测试结果,在协调器偶尔出现nwk is ready后,给终端上电,但是发现还是打印No suitable networks found