cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WB5MM-DK, connecting to Tuya gateway with zigbee

eskomj
Associate III

Hello,

How should I make connection to the Tuya gateway with zigbee? I have read zigbee wiki dokumentation about zigbee binding. I have understand that I should use "find and bind" mechanism in that case. I tried to find suitable example from github, but I'm not shure, which one is the closest to my case. The goal is to make some sensor value to be seen on Tuya smart home app.

Connectivity:Zigbee Binding - stm32mcu

STM32CubeWB/Projects/P-NUCLEO-WB55.Nucleo/Applications/Zigbee at master · STMicroelectronics/STM32CubeWB · GitHub

I understood that I should use method ZbStartupFindBindStart()

Esko

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @eskomj,

Thanks for the update.

Effectively, it seems that the end device doesn't send the association request due probably to the quality of the beacon frame as " lqi = 56 , cost = 5"

Indeed, the STM32WB Zigbee device is supposed to only select parent with a good beacon request cost =3 or lower.

To disable this check you need to enable the flag ZB_BDB_FLAG_IGNORE_COST_DURING_JOIN :

Please find below the change to apply in the function APP_ZIGBEE_StackLayersInit file (app_zigbee.c)

/**
* @brief Initialize Zigbee stack layers
* @param None
* @retval None
*/
static void APP_ZIGBEE_StackLayersInit(void)
{
APP_DBG("APP_ZIGBEE_StackLayersInit");

zigbee_app_info.zb = ZbInit(0U, NULL, NULL);
assert(zigbee_app_info.zb != NULL);

/* Create the endpoint and cluster(s) */
APP_ZIGBEE_ConfigEndpoints();

/* Configure the joining parameters */
zigbee_app_info.join_status = (enum ZbStatusCodeT) 0x01; /* init to error status */
zigbee_app_info.join_delay = HAL_GetTick(); /* now */
zigbee_app_info.startupControl = ZbStartTypeJoin;
enum ZbStatusCodeT status;
uint32_t val32 = ZB_BDB_FLAG_IGNORE_COST_DURING_JOIN;
status = ZbBdbSet(zigbee_app_info.zb, ZB_BDB_Flags, &val32, sizeof(val32));
/* Initialization Complete */
zigbee_app_info.has_init = true;

/* run the task */
UTIL_SEQ_SetTask(1U << CFG_TASK_ZIGBEE_NETWORK_FORM, CFG_SCH_PRIO_0);
} /* APP_ZIGBEE_StackLayersInit */

Could you please try with this new config and update the status ?

Best regards,

Ouadi

View solution in original post

12 REPLIES 12
Ouadi
ST Employee

Hello @eskomj,

For your application, you can configure the device based on STM32WB5MM-DK as an End device using the needed clusters to report sensor measured values to the Tuya Gateway over Zigbee.

Find and Bind feature is an automatic process of binding  making communication between clusters very simple in a Zigbee network, the mentioned wiki page describes the principle of the feature and the different ways to implement it.

You can refer to the following project examples to help you building your own application:

Also, please find below the link to the application note to get started with Zigbee: 

 https://www.st.com/resource/en/application_note/an5506-getting-started-with-zigbee-on-stm32wb-series-stmicroelectronics.pdf 

Best regards,

Ouadi

 

I am getting following error when application tries to join zigbee network:

nwk_scan_req : Error, interface wpan0 doesn't support any of the channels selected.

Setup is as follow:

/* Using the default HA preconfigured Link Key */

memcpy(config.security.preconfiguredLinkKey, sec_key_ha, ZB_SEC_KEYSIZE);

 

config.channelList.count = 1;

config.channelList.list[0].page = 0;

config.channelList.list[0].channelMask = 1 << WPAN_CHANNELMASK_2400MHZ; /*Channel in use */

 

During compile, I get warning:

C:/STM32Cube_FW_WB_V1.18.0/Projects/STM32WB5MM-DK/Applications/Zigbee/Zigbee_OnOff_Client_Router/STM32_WPAN/App/app_zigbee.c:252:48: warning: left shift count >= width of type [-Wshift-count-overflow]

252 | config.channelList.list[0].channelMask = 1 << WPAN_CHANNELMASK_2400MHZ; 

|

That warning comes on all zigbee examples. The error comes, because config variable is 32bit and

shift value is more. Does these two error relates each other?

 

The application which I try to get joining to zigbee gateway is zigbee_onoff_client_router.

 

If I try with channelMask value CHANNEL (original in example), then there is no compile error, but joining won't work. The log is then as follows:

[M4 APPLICATION] ZbStartup Callback (status = 0xca)
[M4 APPLICATION] Startup failed, attempting again after a short delay (2000 ms)
[M4 APPLICATION] Network config : APP_STARTUP_CENTRALIZED_ROUTER
[M0] [00000002.018][PLATFORM] ZbNlmeResetReq : NLME-RESET.request (warmStart = 0)
[M0] [00000000.019][PLATFORM] zb_startup_join_nwk_disc : Attempting network discovery. Scans = 3, Duration = 4
[M0] [00000000.020][PLATFORM] nwk_scan_req : MLME-SCAN.request (wpan0): type=1, page=0, mask=0x00000800, dur=4
[M0] [00000000.289][PLATFORM] nwk_scan_req : MLME-SCAN.request (wpan0): type=1, page=0, mask=0x00000800, dur=4
[M0] [00000000.557][PLATFORM] nwk_scan_req : MLME-SCAN.request (wpan0): type=1, page=0, mask=0x00000800, dur=4

I got example working, but still the SmartLife app won't find my stm32wb. I examined with wireshark and I found, that application won't send the association request after it has got the beacon. In the beacon, there is association permit:

Sequence Number: 183
Source PAN: 0xc3cb
Source: 0x0000
Superframe Specification: PAN Coordinator, Association Permit
.... .... .... 1111 = Beacon Interval: 15
.... .... 1111 .... = Superframe Interval: 15
.... 1111 .... .... = Final CAP Slot: 15
...0 .... .... .... = Battery Extension: False
.1.. .... .... .... = PAN Coordinator: True
1... .... .... .... = Association Permit: True

What could be the reason? Why application won't send the association request?

Ouadi
ST Employee

Hello @eskomj

To set the channel Mask to WPAN_CHANNELMASK_2400MHZ you have to do the following configuration :

config.channelList.list[0].channelMask = WPAN_CHANNELMASK_2400MHZ; (Without left shift as the value is encoded with uint32 type)

The error you had is related to this warning making the channel configuration incorrect.

Could you please share the Wireshark capture file and the STM32WB logs ?

Best regards,

Ouadi

 

I attached wireshark log from example application Zigbee_OnOff_Server_Distrib. I modified application so that it doesn't change startupControl if joining fails, by commenting this row:

//zigbee_app_info.startupControl = ZbStartTypeForm

According to Tuya guides, Application should send association request after receiving the beacon:

【Zigbee Popular Science Series】 - 3 Network Access Process - Tuya Developer Forum (tuyaos.com)

(chinese, I translated with google)

I'll attach application log in the next post.

I attached the application log from example Zigbee_OnOff_Server_Distrib, which was used in youtube video

https://www.youtube.com/watch?v=W2oB4AmUKr0&list=PLDmZeZUG2_1WXV4cmpT7TqtusbzTsYnSK&index=2&pp=gAQBiAQB

 

In the function APP_ZIGBEE_NwkForm() I corrected these rows:

config.channelList.list[0].channelMask = WPAN_CHANNELMASK_2400MHZ; /*Channel in use */

//zigbee_app_info.startupControl = ZbStartTypeForm;

Above change, because otherwise starttype will change and it looks like joining will work.

 

I attached the Wireshark logs. Another log is from cheap Nedis temperature sensor. Joining it goes as is described here:

【Zigbee Popular Science Series】 - 3 Network Access Process - Tuya Developer Forum (tuyaos.com)

 

I tested also with application Zigbee_OnOff_Client_Router. It works the same way:

[M4 APPLICATION] Network config : APP_STARTUP_CENTRALIZED_ROUTER
[M0] [00000000.521][PLATFORM] ZbNlmeResetReq : NLME-RESET.request (warmStart = 0)
[M0] [00000000.019][PLATFORM] zb_startup_join_nwk_disc : Attempting network discovery. Scans = 3, Duration = 4
[M0] [00000000.020][PLATFORM] nwk_scan_req : MLME-SCAN.request (wpan0): type=1, page=0, mask=0x07fff800, dur=4
[M0] [00000001.093][PLATFORM] nwk_handle_beacon_ind : BEACON addr16=0x0000, epid=0x97ce67369b790884, ch=15, pan=0xc3cb, depth= 0, lqi= 56, cost=5, pjoin=1
[M0] [00000004.243][PLATFORM] nwk_scan_req : MLME-SCAN.request (wpan0): type=1, page=0, mask=0x07fff800, dur=4
[M0] [00000005.351][PLATFORM] nwk_handle_beacon_ind : BEACON addr16=0x0000, epid=0x97ce67369b790884, ch=15, pan=0xc3cb, depth= 0, lqi= 56, cost=5, pjoin=1
[M0] [00000008.464][PLATFORM] nwk_scan_req : MLME-SCAN.request (wpan0): type=1, page=0, mask=0x07fff800, dur=4
[M0] [00000009.568][PLATFORM] nwk_handle_beacon_ind : BEACON addr16=0x0000, epid=0x97ce67369b790884, ch=15, pan=0xc3cb, depth= 0, lqi= 56, cost=5, pjoin=1
[M4 APPLICATION] ZbStartup Callback (status = 0xca)
[M4 APPLICATION] Startup failed, attempting again after a short delay (500 ms)

Although the application gets permission to join (pjoin=1?), it doesn't send the association request, which should be the next phase after beacon, according to Tuya spec.