Understanding Mi Home BLE Mesh: Unlocking New Approaches to Smart Home Development

Friends engaged in IoT development are certainly familiar with BLE Mesh technology, especially in the smart home field, where it plays a crucial role. Today, we will specifically discuss Mi Home BLE Mesh, packed with valuable information, so get your notebooks ready and take note of the key points!1. Basic Concepts of SIG BLE MeshUnderstanding Mi Home BLE Mesh: Unlocking New Approaches to Smart Home DevelopmentBLE Mesh is built on top of the BLE protocol stack, forming a multi-to-multi transmission network that achieves message transmission through broadcast flooding.The BLE Mesh specification defines four features: Relay, Proxy, Low Power, and Friend.Understanding Mi Home BLE Mesh: Unlocking New Approaches to Smart Home Development

Elements are addressable entities in nodes, with each node containing at least one Primary Element. The address of the primary element is assigned by the Config Client during network configuration, with other elements added sequentially.

Models define the basic functions of nodes and can be categorized into Server Model, Client Model, and Control Model. The standard models defined by the Bluetooth SIG (Sig Model) and vendor-defined models (Vendor Model).

Understanding Mi Home BLE Mesh: Unlocking New Approaches to Smart Home Development

This article will not delve deeply into the principles of BLE Mesh itself. If you wish to learn more about the principles of BLE Mesh, you can visit the official Bluetooth SIG website (www.bluetooth.com) for further information.

2. Principles of Mi Home BLE Mesh

Mi Home BLE Mesh is based on the SIG Mesh and implements a Mi Home-defined Profile function, enabling remote control of devices through a Bluetooth Mesh gateway. The gateway acts as the Client Model, while the devices act as the Server Model (since devices only support the Server Model and do not support the Control Model, local inter-control cannot be achieved through Mesh messages, but only through broadcast adv and scan methods).

2.1 Supported Features

Understanding Mi Home BLE Mesh: Unlocking New Approaches to Smart Home Development

  • Direct Connection Configuration and OTA Functionality

Provides a standard GATT-based direct connection configuration method and a unified OTA function for modules (this module upgrade function is integrated into the SDK, so developers do not need to develop it separately).

  • Direct Control Interface

Equipped with a direct control interface between the phone and the device, this interface allows for control of the device within the local area network and status feedback.

  • Message Up and Down Transmission and Relay

BLE Mesh devices can achieve up and down message transmission. Moreover, non-low-power devices default to support message relay functionality (the low-power feature is controlled on the device side by the MI_MESH_LOW_POWER_NODE macro).2.2 SDK Framework

Understanding Mi Home BLE Mesh: Unlocking New Approaches to Smart Home Development

To reduce the difficulty for developers in understanding the underlying principles, Mi Home has encapsulated a large number of interfaces related to the chip SDK. In actual development, developers mainly need to focus on the Spec interface and MIoT Spec protocol.

2.3 Communication Message Flow

Understanding Mi Home BLE Mesh: Unlocking New Approaches to Smart Home Development

Commands based on Spec issued by plugins or Xiao Ai speakers are converted into Mesh messages by the Mi Home BLE Mesh gateway after passing through the cloud and sent to the devices. Mesh messages actively sent by devices will also be converted into Spec commands by the Mi Home BLE Mesh gateway and sent to the cloud.2.3.1 Downstream Message – get_propertiesUnderstanding Mi Home BLE Mesh: Unlocking New Approaches to Smart Home DevelopmentWhen a Mi Home BLE Mesh device is first bound, since the gateway does not cache the device’s attribute values, an error will occur when the App tries to retrieve the device’s attribute values -4004. Therefore, it is recommended that after the device is bound, it actively reports the attribute values or the App repeatedly retrieves them (generally, after the first retrieval fails, it can succeed after an interval of 1-2 seconds).2.3.2 Downstream Message – set_propertiesUnderstanding Mi Home BLE Mesh: Unlocking New Approaches to Smart Home DevelopmentThe spec message issued by the cloud, after being received by the gateway, will first reply to the cloud with code:1, indicating that the message has been received and is being sent to the device, then the gateway will convert it into a Mesh format message and send it to the device. After receiving it, the device needs to reply with a code based on the actual execution situation, where 0 represents success.2.3.3 Downstream Message – actionUnderstanding Mi Home BLE Mesh: Unlocking New Approaches to Smart Home DevelopmentDue to packet length limitations, the BLE Mesh device’s action cannot carry output out parameters, and can only carry a maximum of 1 input in parameter.2.3.4 Upstream Message – properties_changedUnderstanding Mi Home BLE Mesh: Unlocking New Approaches to Smart Home DevelopmentThe gateway will cache the reported attributes, and will only report them to the cloud after meeting the interval or delta (interval || delta).2.3.5 Upstream Message – event_occurredUnderstanding Mi Home BLE Mesh: Unlocking New Approaches to Smart Home DevelopmentThe gateway does not cache events; upon receiving an event reported by the BLE Mesh device, it will immediately report it to the cloud.2.4 Network TopologyUnderstanding Mi Home BLE Mesh: Unlocking New Approaches to Smart Home Development

  • To achieve remote control of Mi Home BLE Mesh devices, a Mesh gateway is required. In the absence of a gateway, Bluetooth direct connection functionality can be developed as needed to control devices.Mesh devices can send and receive messages, thus also supporting Xiao Ai voice control.
  • Non-low-power devices can relay Mesh messages, extending the message transmission distance, but devices cannot control each other through Mesh messages.
  • To avoid repeated reporting of Mesh device status data to the server when the data has not been updated, thereby reducing server pressure, the gateway has set up filtering rules for reporting Mesh device attribute data. The default rules for attributes are: interval (interval)==86400, delta (change amount)==1, and reporting can occur if either condition is met. If the default rules do not meet product requirements, modifications can be requested online:

    Understanding Mi Home BLE Mesh: Unlocking New Approaches to Smart Home Development

2.5 Device Online and Offline Status via GatewayUnderstanding Mi Home BLE Mesh: Unlocking New Approaches to Smart Home DevelopmentUnderstanding Mi Home BLE Mesh: Unlocking New Approaches to Smart Home Development

  • For near-field devices, if the gateway does not receive broadcasts from the device for more than 1.5 minutes, the device will show as offline;
  • For far-field devices, which are usually relayed to the gateway through other devices, these devices maintain their connection through relayed Mesh messages. If the gateway does not receive Mesh messages from the device for more than 42 minutes, it will consider the device offline.

2.6 Low PowerThe low power mode of Mi Home BLE Mesh devices is achieved by reducing the device’s scan window (RX current) and increasing the number of packets sent by the gateway, thus achieving low power consumption and control success rate. It does not utilize the low power and friend features of sig mesh.It is important to note that the scan window is typically allowed to be set to a minimum of 15%. When the scan window is not 100%, the device’s relay capability will be disabled. Therefore, non-low-power devices must have their scan window set to 100%.3. Mi Home BLE Mesh ModulesMi Home BLE Mesh devices only support access through Xiaomi modules. The commonly used BLE Mesh modules are as follows:

Module Model Chip Platform Resource Configuration Power Consumption
MHCB05P(General)MHCB06P(Lighting Category)MHCB07P(Small Size) RTL8762CMF Flash:512KB(Remaining 140KB)SRAM:160KB(Remaining 48KB)– Resources Sufficient Mesh:15% Scan Window (Control Success Rate 99%), Power Consumption 1.3mA
MHCB09P(Low Power) EFR32BG22 Flash:512KB(Remaining about 100K)SRAM:32KB(Remaining about 4KB)– Resources Insufficient Mesh:15% Scan Window (Control Success Rate 99%), Power Consumption 0.6mA
MHCB11S/L(Low Cost) Telink8278 Restrictive module, currently only usable for constant power device development, such as lighting, permission required for use
MHCB12G/S(Mesh2.0) RTL8762EMF Flash:512KB(Remaining about 65KB) SRAM:104KB(Remaining about 10KB)– Resources Sufficient Mesh:15% Scan Window (Control Success Rate 99%), Power Consumption 1.1mA

Currently, due to certain reasons, the Mi Home platform requires that single-fire switches must use the MHCB09P module for development.4. Mi Home BLE Mesh 2.0As early as the 2023 Xiaomi Ecosystem Partner Conference, Xiaomi showcased the technology of Mi Home BLE Mesh 2.0, which includes capabilities such as large-scale lighting group control consistency, second-level configuration, remote upgrades, and ultra-low power consumption. However, as of now, it seems that only remote upgrades and consistent scene capabilities are supported, and only the latest MHCB12G/S module supports these features, which require pairing with a central gateway to utilize the capabilities of Mi Home BLE Mesh 2.0.Recently, the Xiaomi IoT Developer Platform has also launched related documentation for Mi Home BLE Mesh 2.0, which can be accessed at:https://iot.mi.com/v2/new/doc/embedded-dev/ble-mesh/mesh2_0_des.5. Precautions / Pitfall Guide

  • Currently, Mi Home does not allow BLE Mesh devices to be used for sensor-type product development, as this may lead to abnormal IV updates and device control issues.
  • If the device is a relatively niche product type, the Mi Home platform may not support Mesh access, and you will need to apply to Mi Home for the relevant Mesh definition for the product before it can be integrated.

6. ConclusionI hope this article can serve as a helpful assistant on your journey in Mi Home BLE Mesh development, aiding you in successfully creating more high-quality smart home products that provide users with a more convenient and intelligent living experience. If you have any questions or new discoveries during your practice, feel free to leave a comment for discussion!

Leave a Comment