Last Updated on : 2020-09-28 12:29:02download
Wi-Fi general solution is one of the major MCU connection solutions. Connect the MCU to the Wi-Fi module through the serial port to enable device network access. Tuya provides the complete development services from modules, apps to cloud services.
Compared to other communication solutions, the Wi-Fi module delivers a better user experience. It can directly connect to the cloud through a router without the gateway, which ensures easier data operation and faster data transmission.
The communication diagram of Wi-Fi general module connection is as follows:
Log in to the IoT console and create a product. Select the desired product, and select Wi-Fi for net pairing mode. After finishing creation, you select the functions, panel, module, and firmware based on your product, and download the MCU development documents accordingly. For certain product categories, a power type is an option. You select the standard power for products powered from mains electricity. For battery-powered products, low power is recommended.
Note: Power type determines the subsequent selection of modules and firmware.
The platform recommends the common module models when you create a product. The mostly used Wi-Fi modules for Wi-Fi general solutions are described as follows. According to the packaging types, the Wi-Fi module is classified into three series, namely series one, two, and three. The common models are as follows:
After selecting the module and firmware, you can purchase the module sample online. The hardware engineer will proceed with the board layout design. See the documentation related to hardware development in the documentation center.
Datasheet: TYWE1S Module Datasheet
Schematic diagram of the minimum module: TYWE1S Module
Note: The average working electric current of Wi-Fi common modules is within 100mA and the peak electric current reaches over 400mA (sustained current in microseconds). Take the electric allowance into consideration during power design.
When receiving the module, it is suggested that, before start coding, you run the provided module debugging assistant, and connect the Wi-Fi module in MCU simulation mode to check if the module can work properly. Meanwhile, you can get familiar with the protocol interaction process, which will help you to proceed with development debugging.
In the MCU simulation mode, the debugging assistant simulates the MCU to automatically respond to the module with the correct protocol data. After you configure the network through the mobile phone, you can test DP data reporting and sending. The procedure of operating the assistant and module network configuration is as follows. Before the operation, you need to learn about the operation instruction of the Tuya module debugging assistant. For beginners, you can refer to Module Debugging Assistant Instruction.
Based on the schematic diagram of the minimum system, you build the peripheral circuit of the module and jump the wire directly in case of simple testing.
Open the debugging assistant in the development documents and import the debugging file. Select the Wi-Fi general protocol and MCU simulation mode.
Connect the module serial port to the computer through USB-to-TTL adapter and select the corresponding serial port and Baud in the assistant. After you open the serial port and click Start, you will see the initial protocol interaction between the module and the host.
Note: Wi-Fi module will constantly send heartbeat packets after power on. When receiving the correct response, it will proceed with the initial protocol interaction. If the module does not send data after power on, check if the peripheral circuit of the module is correct.
Click the Reset Module, and the module enters the network configuration mode. The module supports two network configuration modes, EZ and AP (The difference between EZ and AP modes). When you click Reset Module, the mode will be switched. Configure the network on the app according to the status. Refer to the app operation instruction for network configuration operation.
During hardware debugging, you will see a sequence of serial port protocol interaction data between the module and MCU. To understand this data, refer to the protocol documentation in the development documents.
The protocol consists of the basic protocol and function protocol.
The basic protocol is product neutral and shared by the modules. It consists of module initial command and certain extension function command. The basic protocol is updated in real-time in the documentation center. See Tuya Cloud Universal Serial Port Access Protocol.
The function protocol works to report and send commands based on the basic protocol and specifies the DP data format.
There are two methods to connect the MCU to the Tuya module protocol, migrating MCU SDK, or connecting the protocol by yourself.
Connect the protocol by yourself
If the MCU resource is limited or migrating the MCU SDK is inapplicable, you can connect the protocol by yourself. For the description of the serial port protocol, see Wi-Fi Module General Protocol Parsing.
Migrate MCU SDK
If the MCU resource is sufficient, it is recommended to directly migrate MCU SDK, which facilitates the development process. MCU SDK in the development documents is the protocol application code in C language, and it can be directly imported to the MCU project. MCU SDK requirements for MCU hardware resources are 4 KB Flash and about 100 bytes of RAM. RAM is related to DP data length. For example, the OTA function takes more than 260 bytes. A 9-level nested function is adopted. If the resource is limited, you can connect the protocol by yourself. The function in the SDK package can act as references.
MCU SDK migration tutorial: Overview of migrating Tuya’s MCU SDK
After migrating MCU SDK, you can use the module debugging assistant in module simulation mode to verify the MCU code. The operation is similar to the MCU simulation mode. In the module simulation mode, the assistant automatically sends the initial data flow to verify whether the MCU response is correct, and send prompts for data error. After the initial interaction, you can test other extension functions.
Note: The module simulation mode only verifies the MCU serial port protocol, and does not support networking. After finishing the test, connect the MCU to the actual module and proceed with joint network configuration debugging.
After the assistant verifies the code, connect the MCU to the module, and configure the network on the app. You will enter function joint debugging. Joint debugging is used to test whether the DPs reporting and sending work properly. The links of useful tools adopted in the debugging are as follows:
Online support center: Tuya provides online services. If the documentation cannot solve your problems, raise your questions online and our technical team will help you troubleshoot problems.