Back

Bluetooth_Mesh

Loading views...

Bluetooth Mesh

Overview

Bluetooth Mesh is a many-to-many Bluetooth topology standardized in 2017 that enables creating large-scale device networks for building automation, industrial IoT, and smart lighting. It uses BLE advertising channels for message flooding with managed flooding via message cache and TTL.


1. Theory & Fundamentals

  • Uses BLE 4.0+ (advertising channels 37, 38, 39) for communication
  • Topology: Many-to-many publish/subscribe mesh
  • Range: Per BLE hop (10โ€“100m); mesh extends via relays
  • Node types: Unprovisioned, Provisioned (Node, Relay, Proxy, Friend, Low Power)
  • Models: Server/Client models define behavior (Generic On Off, Level, Lighting)
  • Addresses: Unicast, Group (multicast), Virtual
  • Security: Network key + App key; message integrity check (MIC)

2. Frame / Packet Structure

Bluetooth Mesh Network PDU:
  IVI(1b) | NID(7b) | CTL(1b) | TTL(7b) | SEQ(24b) | SRC(16b) | DST(16b) | TransportPDU | NetMIC

Access Message (Transport PDU):
  AID(6b) | SZMIC(1b) | AKF(1b) | UpperTransportPDU | TransMIC

UpperTransportPDU (Access Layer):
  Opcode(1โ€“3B) | Parameters

Key opcodes:
  0x8202 = Generic On Off Get
  0x8203 = Generic On Off Set
  0x8204 = Generic On Off Set Unacknowledged
  0x8201 = Generic On Off Status

3. Protocol Mechanics

  • Managed flooding: All nodes relay messages (TTL decrements per hop)
  • Message cache: Each node caches recent SEQ numbers to avoid re-relaying duplicates
  • Friendship: Low Power Node (LPN) polls Friend node to receive messages while sleeping
  • Provisioning: OOB (Out-of-Band) provisioning using ECDH for security
  • Heartbeat: Periodic messages to monitor node availability
  • Configuration: Done via Configuration Client/Server model over unicast

4. Hardware Implementation

  • Nordic nRF52840 with Bluetooth Mesh SDK (Zephyr)
  • Silicon Labs EFR32BG22 with Bluetooth Mesh SDK
  • Espressif ESP32 with ESP-BLE-MESH
  • nRF Mesh app (Android/iOS): Provision and control mesh nodes
  • Proxy node: Connects smartphone to mesh via GATT (phone can't do advertising mesh directly)

5. Register-Level / Configuration

// Nordic nRF52 Zephyr Bluetooth Mesh
#include <bluetooth/mesh.h>
static struct bt_mesh_cfg_srv cfg_srv = { .relay=BT_MESH_RELAY_ENABLED, ... };
static void gen_onoff_set(struct bt_mesh_model *model, ..., bool on_off) {
    board_led_set(on_off);
}
static const struct bt_mesh_model_op gen_onoff_srv_op[] = {
    {BT_MESH_MODEL_OP_GEN_ONOFF_GET, 0, gen_onoff_get},
    {BT_MESH_MODEL_OP_GEN_ONOFF_SET, 2, gen_onoff_set},
};
bt_mesh_init(&prov, &comp);

6. Driver / Software Development

  • Initialize hardware peripheral or SoC block
  • Implement send/receive with interrupt or DMA
  • Handle errors: timeout, CRC, NAK, bus-off
  • Use circular buffers for RX data flow
  • Implement retry logic for reliability

7. Debugging & Testing

  • nRF Mesh app: Provision nodes, configure subscriptions, send commands
  • Bluetooth mesh sniffer: Ellisys Bluetooth Analyzer, Frontline Sodera
  • Common issues: Provisioning fail (OOB mismatch); messages not relaying (TTL too low); publication not set up
  • Check relay and proxy enabled on appropriate nodes

8. Real-World Applications

  1. Commercial building lighting control (Silvair, Casambi)
  2. Office smart lighting (Bluetooth mesh + Philips/Osram)
  3. Industrial sensor networks
  4. Hotel room control
  5. Retail store automation

9. Advanced Topics & Edge Cases

  • Directed Forwarding (Bluetooth 5.4): Unicast routing instead of flooding
  • Large Composition Data: Support for large models
  • Enhanced Provisioning: Certificate-based provisioning
  • Mesh Manager: Bluetooth SIG reference implementation
  • Scene models: Recall saved states across multiple nodes

10. Standards & Variants

Protocol Mesh Stack Transport Power
BT Mesh Flooding BLE adv BLE Ultra-low
Zigbee AODV 802.15.4 802.15.4 Ultra-low
Thread RPL 802.15.4 IPv6 Ultra-low
Z-Wave Source Sub-GHz Sub-GHz Ultra-low

๐Ÿ’ก Practical Examples

Ex 1: Provision a light node

nRF Mesh app โ†’ Add Node โ†’ Select unprovisioned node โ†’ Provision โ†’ Configure publication to group 0xC000.

Ex 2: Send on/off command

bt_mesh_model_publish(&onoff_cli); // Publish Generic On Off Set to group address

Ex 3: Low Power Node setup

bt_mesh_lpn_set(true); // Enable LPN mode; polls Friend node

๐Ÿงช Practice Questions

Beginner

  1. What BLE channels does Bluetooth Mesh use?
  2. What is TTL in Bluetooth Mesh?
  3. What is a Relay node?
  4. What is provisioning?
  5. What is the difference between unicast and group address?

Intermediate

  1. Explain Bluetooth Mesh managed flooding and message cache.
  2. How does Friendship between LPN and Friend node work?
  3. Implement Generic On Off Server model on nRF52.
  4. How do you configure publication and subscription in mesh?
  5. What is a Proxy node and why is it needed?

Advanced

  1. Design a 500-node Bluetooth Mesh network for a large building.
  2. Implement Directed Forwarding for reduced flooding overhead.
  3. Build a Bluetooth Mesh gateway to cloud via MQTT.
  4. Optimize LPN polling interval for minimum power.
  5. Implement custom vendor model for proprietary sensor.

Projects

  1. Smart Lighting: 5 nRF52 nodes, on/off via phone app using Bluetooth Mesh.
  2. Scene Controller: Switch between 5 preset lighting scenes.
  3. Mesh Gateway: Proxy node โ†’ Raspberry Pi โ†’ MQTT โ†’ cloud dashboard.

Checklist

  • [ ] Explain Bluetooth Mesh roles and node types
  • [ ] Provision a node using nRF Mesh app
  • [ ] Implement Generic On Off Server model
  • [ ] Configure publication and subscription
  • [ ] Enable relay on appropriate nodes
  • [ ] Set up Proxy for phone connectivity
  • [ ] Implement Low Power Node
  • [ ] Build vendor model
  • [ ] Debug with Bluetooth sniffer
  • [ ] Connect mesh to cloud via MQTT