Skip to main content
Associate II
January 5, 2024
Solved

STM32WB5MM-DK, connecting to Tuya gateway with zigbee

  • January 5, 2024
  • 3 replies
  • 9386 views

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

 

Best answer by Ouadi

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

3 replies

Technical Moderator
January 12, 2024

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

 

eskomjAuthor
Associate II
January 13, 2024

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.

 

eskomjAuthor
Associate II
January 13, 2024

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

Technical Moderator
January 15, 2024

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

 

eskomjAuthor
Associate II
January 16, 2024

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.

eskomjAuthor
Associate II
January 16, 2024

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.

 

Technical Moderator
January 17, 2024

Have you been able to join the network ? if so, could you please click on "accepted as solution" ?

Best regards,

Ouadi