Last Updated on : 2022-03-29 03:53:21download
Tuya’s Wi-Fi HomeKit general solution allows your device that has an embedded MCU to be integrated with the Tuya IoT Platform and Apple HomeKit Platform. Your MCU can communicate with Tuya’s Wi-Fi module through serial communication so that your device can be connected to the cloud. Tuya provides one-stop services including network modules, mobile apps, and cloud services, to help you easily build an IoT-enabled product. Integration with HomeKit enables your product to be interconnected with all HomeKit-compatible products and controlled by using devices in Apple’s ecosystem.
Wi-Fi HomeKit module is connected to the cloud through a router without a gateway, which means you can provide users with fast and easy interaction with smart devices. The following block diagram shows how communication works.
This section describes operations on the Tuya IoT Platform and considerations for development.
This section provides important information you can use to create products on the Tuya IoT Platform. For more information, see the MCU Low-Code Development.
Log in to the Tuya IoT Platform and create a product.
Select the desired product that supports the HomeKit solution.
After you create a product, you can configure the function, panel, module, and firmware based on your requirements. Then, download the MCU SDK accordingly.
The platform recommends applicable Wi-Fi modules that adopt PCB antennas and common packagings, such as TYWE3SE and CR3L.
After you select the module and firmware, you can purchase modules online and proceed with the PCB layout. References:
The operating current of the module is within 100 mA on average but the peak current is more than 400 mA with a duration in microseconds. The consideration for electricity allowance is required in your circuit design.
Before proceeding with coding, you can use the MCU simulation mode of Tuya’s module debugging assistant to test the communication between the Wi-Fi HomeKit module and the MCU.
In the MCU simulation mode, the debugging assistant simulates the MCU and responds to the command from the module. After you pair the module with the mobile app, you can test whether the data point (DP) reporting and sending works properly. This section briefly describes how to test data communication by using the debugging assistant. For more information, see Module Debugging Assistant.
A step-by-step guide to test pairing.
Set up the peripheral circuit according to the minimal system schematics.
If you want to perform a simple test, you can use the jump wire to set up the testing environment.
Open the debugging assistant and import the debugging file. Choose MCU Simulation and in the Protocol field, select Wi-Fi > HomeKit.
Connect the module to your computer by using a USB-to-TTL adapter. Set the Serial Port and Baud Rate. Click Open and then Start Debugging to start the data communication.
Reset the module to enter pairing mode.
The module can be connected to the Tuya IoT Platform and the Apple HomeKit platform, hereinafter referred to as Tuya binding and HomeKit Accessory Protocol (HAP) binding respectively.
Things to note:
Since Tuya binding and HAP binding are performed by using the Tuya Smart app and Apple’s Home app respectively, the Tuya account is isolated and independent of the Apple account.
A device that has been paired with the Tuya Smart app for Android still can be added to the Home app on the iPhone that is connected to the same LAN as is the Android phone.
Removing a device from the Tuya Smart app or the Home app will clear the binding status.
Resetting a device will clear the binding status and trigger restoring defaults. The device will enter pairing mode.
Tuya binding: cloud-based binding that only applies to pairing over Bluetooth. The mobile app initiates a binding request, and the device does not know which account it is to be bound with.
HAP binding: LAN-based binding. Both the mobile app and the device know their binding status.
For more information about two Wi-Fi pairing modes, go to Help Center.
The following steps show how to pair a HomeKit device.
Scan QR code with the Home app to pair a HomeKit device.
Open the Home app and scan the setup code.
Add the device to the Home app.
Tap the setting icon on the control panel of the device.
Navigate to the Tuya Smart app.
Tuya Smart app discovers and binds a HomeKit device.
Open the Home app. Tap Add Accessory to discover HomeKit devices.
Select a device to add to Home.
The device is added.
Bind a HomeKit device with the Tuya Smart app.
The device must have been added to the Home app.
Open the Tuya Smart app and tap Me > HomeKit.
Select the discovered HomeKit device and bind it.
Discover a HomeKit device pending pairing with the Tuya Smart app.
In the previous testing step, the left interface of Tuya’s debugging assistant shows you the data communication between the MCU and the module. For more information about communication logic, see the protocol documentation included in the development document.
The basic protocol is product-neutral and shared by the modules. It consists of commands for module initialization and extended functions. For more information, see Wi-Fi HomeKit Serial Protocol.
The function protocol works to report and send commands based on the basic protocol and specifies the DP data format.
Tuya provides two methods to implement the communication between your MCU and Tuya’s module.
Interface with the protocol yourself
If your MCU does not have sufficient resources or porting SDK is not feasible, you can interface the serial protocol yourself. For more information, see Wi-Fi HomeKit Serial Protocol.
Port the MCU SDK
If your MCU has sufficient resources, we recommend you port the MCU SDK for efficiency purposes. The MCU SDK is written in C language. You can directly import it to your project. The MCU SDK requires the following MCU hardware resources:
4 KB flash memory.
About 100 bytes of the RAM are required, depending on the data length of the data point (DP). If you enable OTA updates, it must be greater than 260 bytes.
The 9-level nested function is adopted. The functions in the SDK can be your reference.
For more information, see Port MCU SDK.
After you port the MCU SDK, you can use the module simulation mode in the debugging assistant to verify the code.
In the module simulation mode, the debugging assistant automatically sends the initial data to the MCU to check whether the communication works properly. An error message will be returned if any issue occurs. After initialization, you can test different functions.
The module simulation mode only verifies the communication between the MCU and the module and does not provide real networking capability. After finishing the test, you can connect the MCU to the actual module and test pairing functionality and specific features.
In the MCU simulation mode, before you start debugging, you must complete the initial configuration on the debugging assistant such as the HomeKit device category, services, and functions. Otherwise, the initialization might fail.
After the code is verified, you can pair the module with the app and test DP data communication.
You can query device logs by device ID on the Tuya IoT Platform. For more information, see Operation Management.
Is this page helpful?YesFeedback
Is this page helpful?YesFeedback