Bluetooth Mesh

Last Updated on : 2024-07-05 10:01:35download

In terms of Bluetooth mesh development, Tuya provides one-stop services including network modules, mobile apps, and cloud services, to help you implement an internet connection for your current product.

The Bluetooth mesh generic firmware provided by Tuya has been integrated with the Bluetooth mesh protocol. After integration with the protocol, the MCU can implement the network connection. You only need to implement serial communication between the MCU and the module and bind the device with the app. The Bluetooth mesh devices will automatically form a mesh network without any additional operations on the MCU.

Background information

On July 19, 2017, the Bluetooth Special Interest Group (SIG) announced to provide Bluetooth mesh technologies to enable mesh networking. The new mesh technology can support many-to-many transmission between devices, thus improving communication efficiency by building large-scale network coverage.

Mesh technology adapts to scenarios such as building automation and wireless sensor networks, allowing tens of thousands of devices to exchange data in a safe, reliable, and stable environment.

Bluetooth mesh features

  • Benefits

    • The international standard protocol provided by the Bluetooth SIG achieves true interconnection.
    • Microampere-level low power technology.
    • Enable local control over Bluetooth or remote control through a gateway.
    • Get certified by the Bluetooth SIG.
    • Easy to operate, flexible networking, high robustness, and a more stable system.
    • With frequency hopping technology, it is insusceptible to interference from 2.4 GHz communications.
  • Limitations

    • Not good at concurrent message processing, which might cause network congestion.
    • Remote control becomes impossible without a gateway.
    • Poor wall penetration performance.
  • Application scenarios

    • Local scene linkage suitable for the field of high-end lighting.
    • Large-scale group control for commercial lighting solutions.
    • Highly cost-effective lighting solutions.

Tuya’s development solutions

Tuya Bluetooth mesh development solution enables simple integration and convenient SDK porting. The following two figures show how the communication works.

  • Schematic diagram of Bluetooth mesh communication without gateway

    Bluetooth Mesh
  • Schematic diagram of Bluetooth mesh communication with gateway

    Bluetooth Mesh

Development process

Step 1: Create product

This section describes how to create a product on the Tuya Developer Platform. For more information, see the MCU SDK Development.

  1. Log in to the Tuya Developer Platform and create a product. Select the desired product category. Choose Bluetooth Mesh(SIG) for Protocol.

    Bluetooth Mesh
  2. After you create a product, you can configure the functions and panel based on your requirements. Then, click the Hardware Development tab and download the MCU SDK accordingly.

    Bluetooth Mesh
  3. Select the desired module and build firmware.

    Bluetooth Mesh
    1. The platform recommends popular modules when you create a product. After you select the module and build firmware, you can purchase the sample module on the platform.

    2. During the hardware development, you can proceed with the board layout design. For more information about hardware development, see related documents in Tuya’s documentation center.

      When batteries are used as power supply and the supply voltage is below the operating voltage, operations on the flash memory of the module might cause errors in firmware or user data. When the MCU detects that the battery voltage is too low, you can take the following steps:

      • Power off the module.
      • Turn off advertising and system timer to allow the module to enter deep-sleep mode. For example, if the minimum operating voltage for the module is 1.8V, you can set the threshold of power-off to 2.0V.

Step 2: Debug hardware

Background information

The following figure shows how Tuya’s Bluetooth mesh module communicates with an MCU.

Bluetooth Mesh

Things to note

You can check whether your received module can work as expected and start encoding. Tuya’s Module Debugging Assistant (in MCU simulation mode) will simulate the MCU to automatically reply the correct protocol data to the module. After the module is paired using a mobile phone, you can test the reporting and sending of DP data. While verifying the module, you can get familiar with the protocol interaction process, which will greatly improve the efficiency of later development and debugging.

The following figure shows the connection method of the Module Debugging Assistant in MCU simulation mode.

Bluetooth Mesh

Procedure

The following steps describe how to pair the module and use the Module Debugging Assistant. For more information, see Module Debugging Assistant.

  1. Set up the peripheral circuit according to the schematic for a minimum system.

  2. Open Tuya’s Module Debugging Assistant in the development kit, import the debugging file, and then select Bluetooth mesh generic protocol and MCU simulation mode.

  3. Connect the module to your computer by using a USB to TTL converter. Set the Serial Port and Baud Rate. Click Open and then Start Debugging to start the data communication.

    The module constantly sends heartbeats to the MCU after power-on. It will start initialization on receiving the correct response from the MCU. If the module does not send data upon powering on, check whether the peripheral circuit of the module works as expected.

  4. In the section of Distribution Network Function, reset the module to enter pairing mode. The module will disconnect and unbind from Bluetooth, clear cache information, and then restart.

    Bluetooth Mesh

Step 3: Develop software

Protocol description

In the previous testing step, the left screen 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 protocol consists of the basic protocol and the function protocol.

  • The basic protocol is product-neutral and shared by the modules. It consists of commands for module initialization and extended functions.

  • The function protocol works to report and send commands based on the basic protocol and specifies the DP data format. For more information, see Bluetooth Mesh Serial Communication Protocol.

Integration method

You can interface with the Tuya module protocol by porting the MCU SDK or interfacing with the protocol yourself. The MCU SDK is written in C language. You can directly import it to your project.

  • Port the MCU SDK
    • If your MCU has sufficient resources, we recommend you port the MCU SDK for efficiency purposes.
    • If your MCU does not have sufficient resources, you can refer to the functions in the SDK for interfacing with Tuya’s protocol.
    • The requirements for MCU resources:
      • 4 KB flash memory.
      • About 100 bytes of 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.
      • 9-level nested function.
  • Interface with the protocol yourself
    If your MCU does not have sufficient resources or porting SDK is not feasible, you can interface with the serial protocol yourself.

Step 4: Verify protocol

After you port the MCU SDK, you can use the module simulation mode in the Module Debugging Assistant to verify the code.
In the module simulation mode, the 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.

The following figure shows the connection in module simulation mode.

Bluetooth Mesh Bluetooth Mesh

Step 5: Debug functionality

After the code is verified, you can pair the module with the app and test DP data communication. You can check the device logs as shown below:

  • Device logs: Based on the device ID, you can check the device logs on the Developer Platform to identify problems.
  • Service & Support: Tuya provides online support services. If the documentation cannot resolve your questions, you can submit a ticket to request technical support.