Skip to main content
Associate II
January 19, 2024
Solved

STM32WB5MM-DK, connecting to Tuya gateway with zigbee, part 2

  • January 19, 2024
  • 4 replies
  • 9231 views

Hello,

I have still connection problem to Tuya gateway. Simple OnOff application can connect to Tuya gateway, but when I try to connect STM32WB5MM-DK as a temperature sensor, connection fails.

Connection to Tuya gateway succeeds with STM32WB5MM-DK example OnOff_Server_Coordinator and On/Off button comes visible on SmartLife app. But with temperature sensor application connection won't work. The application things that it has succeed to connect, but nothing comes visible in SmartLife app. Little display shows "Join ok". According to Wireshark logs, temperature sensor won't reply to gateway's read attributes request where it wants to read basic attributes:

Command: Read Attributes (0x00)
Attribute: Manufacturer Name (0x0004)
Attribute: ZCL Version (0x0000)
Attribute: Application Version (0x0001)
Attribute: Model Identifier (0x0005)
Attribute: Power Source (0x0007)
Attribute: Unknown (0xfffe)

OnOff application responds for that, but not quite like should. Anyway connection succeed.

Connection shoud go according to that specification:

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

I attached three Wireshark log; WB5MM_OnOff__Server_Coord, WB5MM_TempMeas_Server_Coord and Nedis_capture. In both Server_Coord applications, I changed starttype --> join and also channel change to WPAN_2400MHZ.

I'am not shure is that the reason why connection fail, but this is at least first difference. 

Best answer by Ouadi

Hello,

The join process works fine also with Temperature application according to the logs and Wireshark capture, From WB device side, I don't observe any issue which may disturb the join, no leave request is sent after the association.

For me the investigation should be directed on the Tuya side to know why the SmartLife app does not display the device after a successful join.

Kind regards,

Ouadi

4 replies

eskomjAuthor
Associate II
January 21, 2024

It looks like handling of basic attribute request hapens in that portion of code:

IPC_CLUSTER_REQ_CALLBACK_FUNC(ZbZclReadReq, MSG_M4TOM0_ZCL_READ_REQ, ZbZclReadReqT, ZbZclReadRspT);

-->

#define IPC_CLUSTER_REQ_CALLBACK_FUNC(name, cmd_id, req_type, rsp_type)

.....

Whole message handling is based on that define construction. Now I am  wandering how I can modify the code so, that I get better loggin. The code  is in zigbee_core_wb.c which is read only. I think, it's not meant to be changed.

Technical Moderator
January 24, 2024

Hello @eskomj,

From the logs I observe that the device leave the network just after the join, and it may be explained by the fact that the device does not implement the attributes required by the coordinator.

In fact, Zigbee_TempMeas_Server_Coord and OnOff_Server_Coordinator does not handle the listed attributes as the Manufacturer Name, Stack Version ,Model Identifier.., these applications are developed in order to demonstrate the use of ZigBee network and to help designers to build their specific Zigbee applications based on STM32WB series.

Therefore, you have to modify the application according to Tuya Gateway specification so that your device is supported.

To implement these attributes, you can use following APIs : ZbZclBasicServerConfigDefaults and ZbZclBasicWriteDirect.

You can refer to this post which describes the steps to follow.

Kind regards,

Ouadi

eskomjAuthor
Associate II
January 27, 2024

Thank you Ouadi! I got basic cluster working according to the instructions. But connecting to the Tuya network won't work yet. Now it looks like the application won't send TC link key request, which is point 12 in Tuya guide (link above). Such attention also, that instead of setting basic cluster before creating any ZCL endpoints I had to do it after endpoint creation. That is also said in post . When I tried to add ZbZclBasicWriteDirect calls before creating end points, writeDirect call returned STATUS_FAILURE. I moved the basic cluster setting after that 

USER CODE BEGIN CONFIG_ENDPOINT 

in the function APP_ZIGBEE_ConfigEndpoints()

then it worked. Now the problem seems to be that the application won't send TC link key request  I attached latest Wireshark capture. For comparison, Nedis capture can be found in ealier post above. It shoud look like that (from filtered Wireshark capture from Nedis device):

191 157.916257 0xbde5 ZigBee 0x0000 84 Request Key
198 158.226943 0x0000 ZigBee 0xbde5 116 Transport Key
200 158.237543 0xbde5 ZigBee 0x0000 91 Verify Key
201 158.242451 0xbde5 ZigBee 0x0000 91 Verify Key
202 158.247377 0xbde5 ZigBee 0x0000 91 Verify Key

 

eskomjAuthor
Associate II
January 27, 2024

I looked more closely the Wireshark capture. First difference compared to Tuya specification, is that the application won't send node descriptor request (point 10). 

It is obvious that ZbZdoNodeDescReq() call still missing. If so, where should it be inserted?

Technical Moderator
February 1, 2024

Another point, I noticed that you have configured your device to use a distributed network, which is not correct in your case, Tuya gateway use a centralized network and plays the role of the coordinator ( Trust Center) 

This leads to a conflict in the TC key exchange between your device and coordinator as in a distributed network there is no TC link key exchanged.

I have updated your file with a router configuration.

Please give it a try and keep me informed of the result. Thanks

BR,

Ouadi 

eskomjAuthor
Associate II
February 1, 2024

Hello, 

In both of those versions (3 and 4) startupControl is ZbStartTypeJoin. In original Server_Coord version it was ZbStartTypeForm. Version 4 seems to work same way. The reason why I think device is not connected is that Smartlife app won't find my end device. As I stated ealier OnOff server works and Smartlife app finds it as OnOff light switch and it also works.

Esko

eskomjAuthor
Associate II
February 2, 2024

Hello,

I tested again with example application WB5MM_OnOff_Server_Coord. I works fine. Strange thing is that it reports basic cluster info without basic cluster setup. With this application comes also error for writing attribut 0xffde, so it is not the issue, which prevents joining. I have to say, that joining don't go according what is stated in Tuya networking guide. There is no node descriptor request from server device. 

 

Here is basic cluster info which comes without any modification into app_zigbee.c.

Frame 54: 124 bytes on wire (992 bits), 124 bytes captured (992 bits) on interface COM18, id 0
IEEE 802.15.4 TAP
IEEE 802.15.4 Data, Dst: 0x0000, Src: 0xe5c2
ZigBee Network Layer Data, Dst: 0x0000, Src: 0xe5c2
ZigBee Application Support Layer Data, Dst Endpt: 1, Src Endpt: 17
ZigBee Cluster Library Frame, Command: Read Attributes Response, Seq: 23
Frame Control Field: Profile-wide (0x18)
Sequence Number: 23
Command: Read Attributes Response (0x01)
Status Record, String: STMicroelectronics
Attribute: Manufacturer Name (0x0004)
Status: Success (0x00)
Data Type: Character String (0x42)
String: STMicroelectronics
Status Record, Uint8: 8
Attribute: ZCL Version (0x0000)
Status: Success (0x00)
Data Type: 8-Bit Unsigned Integer (0x20)
Uint8: 8 (0x08)
Status Record, Uint8: 49
Attribute: Application Version (0x0001)
Status: Success (0x00)
Data Type: 8-Bit Unsigned Integer (0x20)
Uint8: 49 (0x31)
Status Record, String: STM32WB
Attribute: Model Identifier (0x0005)
Status: Success (0x00)
Data Type: Character String (0x42)
String: STM32WB
Status Record
Attribute: Power Source (0x0007)
Status: Success (0x00)
Data Type: 8-Bit Enumeration (0x30)
Power Source: DC source (0x04)

I added Wireshark capture also. The modifications into app_zigbee.c file were only these:

zigbee_app_info.startupControl = ZbStartTypeJoin;

 

// Set the TC address to be distributed. */

config.security.trustCenterAddress = ZB_DISTRIBUTED_TC_ADDR;

 

// Using the Uncertified Distributed Global Key (d0:d1:d2:d3:d4:d5:d6:d7:d8:d9:da:db:dc:dd:de:df

memcpy(config.security.distributedGlobalKey, sec_key_distrib_uncert, ZB_SEC_KEYSIZE);

 

config.channelList.count = 1;

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

config.channelList.list[0].channelMask = WPAN_CHANNELMASK_2400MHZ;

 

Next I try to modify WB5MM_OnOff_Server_Coord so, that it is temperature sensor server instead of OnOff server.

 

 

 

Associate III
April 18, 2024

Hi,

I read your comments and I wonder what is the ioc file should be to use Zigbee server/client model. Is there specific pins that I have to use Zigbee on STM32WB5MMG processor? Or it is working internally connected, so we do not need to set up any pins to use zigbee. My intension is send/receive between two Zigbee network using STM32WB5MMG processors. I am not sure how to set the ioc file from STM32CubeIDE tool.

 

thanks in advance,