TI中文支持网
TI专业的中文技术问题咨询交流网站

Z-Stack 3.0.2 建网和入网问题

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);
#endifzdpExternalStateTaskID = zclSampleLight_TaskID;// Add on 5 Jan 2021
#if defined( ZDO_COORDINATOR )bdb_StartCommissioning(BDB_COMMISSIONING_MODE_NWK_FORMATION);
#elsebdb_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 yetbdb_StartCommissioning(BDB_COMMISSIONING_MODE_NWK_STEERING | bdbCommissioningModeMsg->bdbRemainingCommissioningModes);printf("nwk is ready\r\n");}else{//Want to try other channels?//try with bdb_setChannelAttributeprintf("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);
#elsebdb_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_setChannelAttributeprintf("No suitable networks found\r\n");}break;

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

YiKai Chen:

協調器只有在要組網時需要調用bdb_StartCommissioning(BDB_COMMISSIONING_MODE_NWK_FORMATION)、終端無法入網成功建議抓包分析

user6008379:

回复 YiKai Chen:

現在的問題是還未到終端入網那一步。協調器,SampleLight初始化的時候,調用bdb_StartCommissioning(BDB_COMMISSIONING_MODE_NWK_FORMATION)。然後去zclSampleLight_ProcessCommissioningStatus()中查詢網絡狀態,發現網絡並沒有建立成功。

YiKai Chen:

回复 user6008379:

協調器只有在沒有組網過的狀況下才要調用bdb_StartCommissioning(BDB_COMMISSIONING_MODE_NWK_FORMATION)、曾經組網過的話只要調用bdb_StartCommissioning(0);

Viki Shi:

回复 user6008379:

"No suitable networks found\r\n"是否有查看具体的错误原因?bdbCommissioningStatus是什么状态?

user6008379:

回复 Viki Shi:

Z-Stack 3.0.2 仍在继续研究。目前量产产品用的是Z-Stack 2.5.1a

YiKai Chen:

回复 user6008379:

那你現在的問題是?

赞(0)
未经允许不得转载:TI中文支持网 » Z-Stack 3.0.2 建网和入网问题
分享到: 更多 (0)