English
English
简体中文
Contact Us
Register
Log In
Language
English
English
简体中文
Contact Us
Log In
Register
Go to main website
App Develop

App Development Platform

App development platform provides multiple development methods such as no-code or IoT App SDK development to maximize the monetization of IoT apps.
layoutIndex

Bluetooth Mesh Common Solution

Last Updated on : 2021-06-07 06:30:25download

Tuya provides a complete set of modules, apps, and cloud services for Bluetooth mesh development. The Bluetooth mesh general firmware provided by Tuya is completed with the Bluetooth mesh protocol, and the MCU can be connected to the network when the serial protocol is implemented. After you implement serial protocol interaction and bind the device to the app, the Bluetooth mesh device will automatically form a mesh network without additional operation on the MCU.

Background information

On July 19, 2017, the Bluetooth Special Interest Group (SIG) announced that Bluetooth technology began to fully support mesh networks. The brand-new mesh technology supports many-to-many transmission, improving the communication efficiency of building a wide network coverage. Mesh technology applies better to building automation, wireless sensor networks, and more applications, providing a safe, reliable, and stable environment for tens of thousands of devices for information interaction.

Bluetooth mesh feature

  • Strengths

    • Comply with Bluetooth SIG standard protocol, and enable interconnection between different devices.
    • Low power consumption technology at the microampere level.
    • Support both mobile phone Bluetooth control and gateway remote control.
    • Certified by Bluetooth SIG.
    • Easy operation, flexible networking, high robustness, and a stable system.
    • Frequency-hopping spread spectrum (FHSS) ensures smooth communication without interference from the 2.4 GHz band.
  • Limitations

    • Poor concurrent message processing that may cause network congestion.
    • The remote control is unavailable without a gateway.
    • Poor penetrability.
  • Scenes

    • Local scene linkage applicable to high-standard lighting.
    • Large-scale group control suitable for commercial lighting solutions.
    • Cost-effective smart lighting solutions.

The Tuya IoT development solution

The Tuya Bluetooth mesh development solution provides easy integration and convenient SDK migration. The communication schematic diagram is as follows.

  • The communication process without a Bluetooth mesh gateway:

    Bluetooth Mesh Common Solution
  • The communication process with a Bluetooth mesh gateway:

    Bluetooth Mesh Common Solution

Development process

Step 1: Create a product

Procedure

This section describes the product creation process using the Bluetooth mesh communication solution. For more information, see MCU Connection Solution.

  1. Log in to the IoT Platform and create a product. Select the product category as needed, and select Bluetooth Mesh(SIG) for protocol type.

    Bluetooth Mesh Common Solution

  2. After finishing creation, you can select the functions and panel as needed, and download the MCU development documents from the Hardware Development page accordingly.

    Bluetooth Mesh Common Solution

  3. Select a module and generate firmware. Bluetooth Mesh Common Solution

    • The platform recommends common models when you create a product. After selecting the module and firmware, you can purchase the module sample online.

    • The hardware engineer will proceed with the board layout design. The documentation related to hardware development is as follows:

      Note: If the power is supplied by batteries when the supply voltage is lower than normal working voltage, flash operation inside the chip might have an error, thus firmware or user data might be modified abnormally. When the MCU detects that battery voltage is too low:

      • Cut off the working power supply of the module.
      • Disable the broadcast and system timer, and let the chip enter deep sleep mode to stop working. For example, if the minimum operating voltage of the module is 1.8V, when the voltage is less than 2.0V, the MCU powers off the module.

Step 2: Joint debugging

Background Information

Tuya Bluetooth mesh serial protocol architecture is as follows. Bluetooth Mesh Common Solution

Note: After receiving the module, make sure the module works properly before encoding. In the MCU simulation mode, the debugging assistant simulates the MCU to automatically respond to the module with the correct protocol data. After you pair the module with the mobile phone, you can test DP data reporting and sending. You can get familiar with the protocol interaction process while verifying the module, which will enhance development debugging efficiency in subsequent stages. The connection between the simulated MCU and the Tuya module is as follows:

Bluetooth Mesh Common Solution

Procedure

This section describes the steps of operating the assistant and pairing the module. For more information, see Module Debugging Assistant.

  1. 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.

  2. Open the debugging assistant in the development documents, and import the debugging file. Select the Bluetooth mesh general protocol and MCU simulation mode.

  3. Connect the module serial port to the computer through a USB-to-TTL adapter, and select the corresponding serial port, and baud in the assistant. After you open the serial port and click Start, and the module will automatically proceed with initial protocol interaction with the host.

    Note: The Bluetooth mesh 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.

  4. Click Reset in the Distribution Network Function area and the module enters network pairing mode. The module will disconnect Bluetooth, remove Bluetooth binding, clear cache, and then reboot.

    Bluetooth Mesh Common Solution

Step 3: Software development

Protocol introduction

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 a basic protocol and function protocol.

  • The basic protocol is product-neutral and shared by the modules. It consists of module initial commands and certain extension function commands.

  • The function protocol works to report and send commands based on the basic protocol and specifies the DP data format. For the full content of the basic protocol, see Bluetooth Mesh General Serial Protocol.

Connection mode

You can connect to the Tuya module protocol by either migrating MCU SDK or connecting the protocol by yourself. MCU SDK in the development documents is the protocol application code in C language, and it can be directly imported to the MCU project.

  • Migrate MCU SDK

    • If the MCU resource is sufficient, it is recommended to directly migrate MCU SDK, which facilitates the development process.
    • In case of insufficient resources, you can implement connection protocols by yourself, and refer to functions in the SDK.
    • MCU SDK requirements for MCU hardware resources:
      • Flash 4K bytes
      • RAM: The RAM is about 100 bytes, depending on the DP data length. The RAM shall be greater than 260 bytes if the OTA is required.
      • 9-level nested function is adopted.
  • Connect the protocol by yourself If the MCU resource is limited or migrating MCU SDK is inapplicable, you can connect the protocol by yourself.

Step 4: Protocol verification

After migrating MCU SDK, you need to use the module debugging assistant in module simulation mode to verify the MCU code. In the module simulation mode, the assistant automatically sends the initial data flow to verify whether the MCU response is correct, and sends 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 debugging of pairing. The connection schematic diagram in module simulation mode is as follows.

Bluetooth Mesh Common Solution

Bluetooth Mesh Common Solution

Step 5: Joint debugging

After the assistant verifies the code, connect the MCU to the module, and pair the module 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:

  • Query the background log: Log in to the IoT Platform and enter Operation to query device background logs according to its device ID.
  • 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.
  • FAQ: Learn about the frequently asked questions during development.

This section contains the following topics to help you quickly understand related concepts and how-to guides: