Tuya Zigbee EFR32 SDK is used to develop Zigbee 3.0 standard products. This SDK is abstracted again based on the Silicon Labs SDK ,The complex Zigbee technical details are shielded, which is convenient for developers to get started quickly. The SDK mainly includes three parts: hardware interface, network interface and tool interface,And provide some types of sample code to demonstrate the use of various interfaces and the basic development specifications of Zigbee device access to the Tuya system.
The entry path of the application project, which contains example codes of various categories
doc
Zigbee related files
include
SDK interface file
lib
SDK library files are divided into IAR version library and GCC version library
sdk
Some tools and link scripts
tools
Related tools and scripts used in compilation
SDK Overall process
User-implemented function interface
dev_power_on_init()
/**
* @note (MUST) This is the first function after the hardware starts.
* The CPU and base clock are initialized before calling this function.
* You need to implement the creation of Zigbee devices and
* determine the parameters of Zigbee device behavior.
* Include device roles(router, end device), device networking(join),
* rejoin parameters, and more. Refer to the TUYA Zigbee SDK demo for details.
* @param none
* @return none
*/
void dev_power_on_init(void);
Instructions
Zigbee SDK will call this function according to the system flowchart,Users need to at least create Zigbee devices,network parameter setting。
/**
* @note (MUST) This is the first function after system startup.
* Before calling this function, Zigbee stack and some basic
* components have been started. You can use all API except individual ones.
* API limits refer to the API limits description table
* @param none
* @return none
*/
void dev_system_on_init(void);
Instructions Zigbee SDK will call this function according to the system flowchart,Users can realize Zigbee attribute operation, hardware initialization, software timing processing and other initialization. Sample code snippet
/**
* @note (MUST) This function is invoked when the network state changes.
* Handling network-related matters at this function is recommended.
* @param[in] {state} Refer to NET_EVT_T for more detal.
* @return none
*/
void nwk_state_changed_callback(NET_EVT_T state);
Instructions Zigbee SDK will call this function according to the system flowchart,Users can implement Zigbee network status processing. Sample code snippet
void nwk_state_changed_callback(NET_EVT_T state)
{
switch(state) {
case NET_POWER_ON_LEAVE: {
//TODO: No network status after power on
break;
}
case NET_JOIN_START: {
//TODO: Start networking
break;
}
case NET_JOIN_TIMEOUT: {
//TODO: Start networking
break;
}
case NET_POWER_ON_ONLINE: {
//TODO: Power up has network status
break;
}
case NET_JOIN_OK: {
//TODO: Successful networking
break;
}
case NET_REJOIN_OK: {
//TODO: Reconnect successful
break;
}
case NET_LOST: {
//TODO: Lost with parent
break;
}
case NET_REMOTE_LEAVE: {
//TODO: Remote off-net notification
break;
}
case NET_LOCAL_LEAVE: {
//TODO: Local off-net notification break;
}
case NET_MF_TEST_LEAVE: {
//TODO: Production Test Off-Grid Notification
break;
}
default: {
break;
}
}
}
Quick development guide
The SDK development kit contains documentation and examples, and the use of and attribute sample code is the only rule of quick start. It is recommended to compile, run, and network with the sample code first, and then try to modify the code to achieve personalized functions.
Example description
Directory
Explanation
light
Projects including Zigbee lamps, including lamp switching and brightness adjustment functions
sensor
The project including Zigbee door sensor, including door sensor opening, closing and battery power reporting function
smart_plug
Including the Zigbee socket project, including the opening and closing function of the socket
switch
Including Zigbee relay switch project, including relay on and off functions
Document description
Document directory
Explanation
datasheet
Zigbee chip data sheet
SPEC
Contains Zigbee Alliance Standard Reference Manual
Development Manual
All documents used for development
API call restrictions
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>dev_timer_start</strong></span></td>
<td class="confluenceTd"><strong>Start a delayed execution event,If the event has set an event handler function,</strong><br /><strong>The subsequent call does not need to set the event handler function every time
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>dev_timer_get_valid_flag</strong></span></td>
<td class="confluenceTd"><strong>Determine whether an event is valid (that is, the event has not been reached)
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>dev_timer_get_remaining_time</strong></span></td>
<td class="confluenceTd"><strong>Get how many ms remain before an event is executed
</tr>
<tr>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
</tr>
<tr>
<td rowspan="3" class="confluenceTd"><span style="color: rgb(0,128,0);"><strong>zigbeeDevice creation</strong></span><br /><span style="color: rgb(0,128,0);"><strong> basic configuration</strong></span></td>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>dev_register_zg_ep_infor</strong></span></td>
<td class="confluenceTd"><strong>Register a complete zigbee device, including an endpoint describing the zigbee device,</strong><br /><strong>cluster,attributes etc. </strong></td>
<td class="confluenceTd"><strong>Can only be called in dev_power_on_init</strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>dev_register_zg_dev_config</strong></span></td>
<td class="confluenceTd"><strong>Configure the device role of zigbee, whether it is routing or end device and join, rejoin parameters</strong></td>
<td class="confluenceTd"><strong>Can only be called in dev_power_on_init</strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>dev_zg_join_config</strong></span></td>
<td class="confluenceTd"><strong>Configure networking policies for power-on and remote deletion</strong></td>
<td class="confluenceTd"><strong>Can only be called in dev_power_on_init</strong></td>
</tr>
<tr>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
</tr>
<tr>
<td rowspan="2" class="confluenceTd"><span style="color: rgb(0,128,0);"><strong>Network operation</strong></span></td>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>dev_zigbee_join_start</strong></span></td>
<td class="confluenceTd"><strong>Exit the network and enter the network</strong></td>
Call after<td class="confluenceTd"><strong>dev_system_on_init ,It will involve the handling of events and network status</strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>dev_zigbee_join_stop</strong></span></td>
<td class="confluenceTd"><strong>Stop networking early</strong></td>
Call after<td class="confluenceTd"><strong>dev_system_on_init ,It will involve the handling of events and network status</strong></td>
</tr>
<tr>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
</tr>
<tr>
<td rowspan="6" class="confluenceTd"><span style="color: rgb(0,128,0);"><strong>zigbee 3.0 related</strong></span></td>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>zg_report_table_init</strong></span></td>
<td class="confluenceTd"><strong>Configure the default report table</strong></td>
<td class="confluenceTd"><strong>Can only be called in dev_power_on_init, Called after dev_register_zg_ep_infor</strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>ext_plugin_identify_client_enable</strong></span></td>
<td class="confluenceTd"><strong>zigbee 3.0 used,Open the identify client service</strong></td>
<td class="confluenceTd"><strong>Can only be called in dev_power_on_init, Called after dev_register_zg_ep_infor</strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>ext_plugin_identify_server_enable</strong></span></td>
<td class="confluenceTd"><strong>zigbee 3.0 used,Open the identify service
<td class="confluenceTd"><strong>Can only be called in dev_power_on_init, Called after dev_register_zg_ep_infor</strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>ext_plugin_green_power_client_enable</strong></span></td>
<td class="confluenceTd"><strong>zigbee 3.0 used,Start green power client service</strong></td>
<td class="confluenceTd"><strong>Can only be called in dev_power_on_init, Called after dev_register_zg_ep_info</strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>ext_plugin_reporting_enable</strong></span></td>
<td class="confluenceTd"><strong>zigbee 3.0 used,Open reporting service
<td class="confluenceTd"><strong>Can only be called in dev_power_on_init, Called after dev_register_zg_ep_infor </strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>ext_plugin_register_cmd_handle</strong></span></td>
<td class="confluenceTd"><strong>Register cluster command processing</strong></td>
<td class="confluenceTd"><strong>Can only be called in dev_power_on_init</strong></td>
</tr>
<tr>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
</tr>
<tr>
<td rowspan="3" class="confluenceTd"><span style="color: rgb(0,128,0);"><strong>电池采集相关</strong></span></td>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>hal_battery_config</strong></span></td>
<td class="confluenceTd"><strong>Configuration of battery collection function</strong></td>
<td class="confluenceTd"><strong>Need to be called after dev_system_on_init </strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>hal_battery_set_battery_type</strong></span></td>
<td class="confluenceTd"><strong>Dynamically configure battery type and whether the device wakes up frequently,</strong><br /><strong>SDK According to these parameters, the internal collection strategy will be made internally</strong></td>
<td class="confluenceTd"><strong>call afer hal_battery_config </strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>hal_battery_report_policy_config</strong></span></td>
<td class="confluenceTd"><strong>Battery special strategy configuration</strong></td>
<td class="confluenceTd"><strong> call after hal_battery_config </strong></td>
</tr>
<tr>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
</tr>
<tr>
<td rowspan="7" class="confluenceTd"><span style="color: rgb(0,128,0);"><strong>flash 操作</strong></span></td>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>flash_block_raw_write</strong></span></td>
<td class="confluenceTd"><strong>Write flash in blocks,One block is 250 bytes</strong></td>
<td rowspan="4" class="confluenceTd"><strong>Currently only the big flash version of lib is available该函数,目前只有门锁在用</strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>flash_block_raw_read</strong></span></td>
<td class="confluenceTd"><strong>Read flash by block,One block is 250 bytes</strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>flash_addr_raw_write</strong></span></td>
<td class="confluenceTd"><strong>Write flash according to virtual address</strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>flash_addr_raw_read</strong></span></td>
<td class="confluenceTd"><strong>Write flash according to virtual address</strong></td>
</tr>
<tr>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>user_flash_data_write</strong></span></td>
<td class="confluenceTd"><strong>Application flash write,Leave 250 bytes of bottom flash area for APP development</strong></td>
<td rowspan="2" class="confluenceTd"><strong>Call after dev_system_on_init
</tr>
<tr>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
</tr>
<tr>
<td rowspan="3" class="confluenceTd"><span style="color: rgb(0,128,0);"><strong>General configuration</strong></span></td>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>dev_heartbeat_set</strong></span></td>
<td class="confluenceTd"><strong>Heartbeat configuration</strong></td>
<td class="confluenceTd"><strong>Call after dev_system_on_init </strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>dev_change_power</strong></span></td>
<td class="confluenceTd"><strong>Configure transmit power</strong></td>
<td class="confluenceTd"><strong>Call afterdev_system_on_init </strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>disable_gw_change_power</strong></span></td>
<td class="confluenceTd"><strong>Disable the gateway to change the transmit power</strong></td>
<td class="confluenceTd"><strong>Called in dev_power_on_init</strong></td>
</tr>
<tr>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
</tr>
<tr>
<td rowspan="4" class="confluenceTd"><span style="color: rgb(0,128,0);"><strong>poll 相关</strong></span></td>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>zg_poll_interval_change</strong></span></td>
<td class="confluenceTd"><strong>Change poll interval</strong></td>
<td rowspan="4" class="confluenceTd"><strong>Called in dev_register_zg_dev_config</strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>zg_poll_start</strong></span></td>
<td class="confluenceTd"><strong>The call will always be poll</strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>zg_poll_end</strong></span></td>
<td class="confluenceTd"><strong>Stop generating new polls,Stop after sending the remaining polls</strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>zg_poll_clear</strong></span></td>
<td class="confluenceTd"><strong>Stop poll now ,</strong></td>
</tr>
<tr>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
<td class="confluenceTd"><br /></td>
</tr>
<tr>
<td rowspan="3" class="confluenceTd"><span style="color: rgb(0,128,0);"><strong>属性,endpoint</strong></span></td>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>dev_set_endpoint_alias</strong></span></td>
<td class="confluenceTd"><strong>Append an alias to an endpoint ,Mainly solves the compatibility problem of endpoint processing when docking with other gateways and Tuya gateways</strong><br /><strong></strong></td>
<td class="confluenceTd"><strong>Called after dev_register_zg_ep_infor</strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>dev_endpint_enable_disable</strong></span></td>
<td class="confluenceTd"><strong>Dynamically disable and enable an endpoint,After disabling an endpoint,</strong><br /><strong>Remote and local cannot access the endpoint</strong></td>
<td class="confluenceTd"><strong>call after dev_system_on_init ,It will involve the handling of events</strong></td>
</tr>
<tr>
<td class="confluenceTd"><span style="color: rgb(0,0,255);"><strong>dev_attr_recovery</strong></span></td>
<td class="confluenceTd"><strong>Do not use it for the time being, the PID will be restored to the default value instead of the PID value of the production test</strong></td>
<td class="confluenceTd"><br /></td>
</tr>
Call after Call after
Functional category
Function name
Features
Restrictions
hardware
user_uart_init
Single serial port configuration, including serial port hardware parameters and serial port data receiving callback function,The receiving function is already a function after receiving queue processing,n ot interrupting the environment
dev_system_on_init ,Don't call it in dev_power_on_init ,It will be conflicted with the serial port production test
gpio_raw_init
gpio Original initialization
If it is multiplexed with serial port IO, it needs to be called after dev_system_on_init and after. If there is no multiplexing, there is no limit to call
gpio_int_register
gpio Interrupt initialization
If it is multiplexed with serial port IO, it needs to be called after dev_system_on_init and after. If there is no multiplexing, there is no calling limit
Software delay event
dev_timer_stop
Stop a delayed execution event early
dev_system_on_init ,Don't call it in dev_power_on_init,Calling too early will cause an exception,The event frame has not been initialized。If called in an interrupt,At least ensure that the interrupt is generated after dev_system_on_init </ strong> </ td>
dev_timer_start_with_callback
Start a delayed execution event and set the event processing function
appendix
Glossary
noun
Explanation
IoT platform
iot.tuya.com
Zigbee SDK
Based on Silicon branch Zigbee protocol stack after cutting、Optimized packaged Tuya’s Zigbee SDK
Attribute
Attribute (属性)Is a data value reflecting the physical quantity or state
Cluster
Cluster (群集)Is a cluster containing one or more attributes
EndPoint
EndPoint (端点)It is the entrance of the application layer of the protocol stack, that is, the entrance address, and it can also understand where the application object exists. It is a group of clusters defined for the realization of a device description.
Device Id
The serial number defined for each device in Zigbee
Weak current equipment
Refers to battery-powered equipment,A device called sleep end device in the Zigbee protocol
Powerful equipment
Refers to a device that uses mains electricity or is powered from a mains voltage-stabilized power supply, which is called a router in the Zigbee protocol
PID
product ID,Each product created on the Tuya IoT platform will generate a unique product number, which is associated with the product specific function points, APP control panel, shipping information, etc.
SOC
system on chip,The hardware itself has no MCU, and the control program is written into the network module
SDK
Software Development Kit,A software development kit, a collection of related documents, examples, and tools to assist in the development of a certain type of software. In order to encourage developers to use their systems or languages, many SDKs are provided free of charge, as are Tuya's
Firmware
Firmware is a program written in EROM (Erasable Read Only Memory) or EEPROM (Electrically Erasable Programmable Read Only Memory). Firmware refers to the device "driver" stored inside the device. Through the firmware, the operating system can implement the operation of a specific machine according to the standard device driver. For example, the optical drive and the recorder have internal firmware. Firmware is the software that serves as the most basic and lowest level of a system