This example shows energy profiling of different types of nodes in a Bluetooth® mesh network using the Communications Toolbox™ Library for the Bluetooth® Protocol. Energy is computed based on the time profiled by End nodes, Low Power nodes (LPNs), Friend nodes, and Relay nodes in transmission, listen, sleep, and idle state. Using this example, you can:
Create and configure a Bluetooth mesh network
Visualize the impact of mesh message exchange on the energy performance of End node, LPN, Friend node, and Relay node
Observe the energy consumption of mesh nodes by varying the number of source-destination pair, Friend node-LPN pair, and the application traffic.
Estimate the node lifetime based on the hardware-specific energy parameters
Modify the hardware-specific energy parameters to suit your requirements
Explore the impact of poll timeout and receive window size on the node lifetime
The simulation calculates the lifetime of an LPN with the specified configuration and the hardware-specific energy parameters. The results validate that LPN always consume less energy by spending more time in sleep, resulting in energy conservation and increased lifetime.
The Bluetooth Core Specification [ 1 ] includes a Low Energy version for low-rate wireless personal area networks, referred to as Bluetooth low energy (BLE) or Bluetooth Smart. The BLE stack consists of generic attribute profile (GATT), attribute protocol (ATT), security manager protocol (SMP), logical link control and adaptation protocol (L2CAP), link layer (LL) and physical layer. The Special Interest Group (SIG) added BLE to the Bluetooth standard for low energy devices which generate small amounts of data such as notification alerts used in such applications as home automation, health-care, fitness, and Internet of Things (IoT). For more information about BLE protocol stack, see Bluetooth Protocol Stack.
The Bluetooth mesh profile [ 2 ] defines the fundamental requirements to implement a mesh networking solution for BLE. The mesh stack is located on top of the BLE core specification and consists of model layer, foundation model layer, access layer, upper transport layer, lower transport layer, network layer and bearer layer. Bluetooth mesh networking enables large-scale device networks in the applications such as smart lighting, industrial automation, sensor networking, asset tracking, and many other IoT solutions. For more information about Bluetooth mesh stack, see Bluetooth Mesh Networking.
Each Bluetooth mesh node can possess some optional features enabling them to acquire additional, special capabilities. These features include the Relay, Proxy, Friend, and the Low Power features. The Bluetooth mesh nodes possessing these features are known as Relay nodes, Proxy nodes, Friend nodes, and Low Power nodes (LPNs), respectively. To reduce the duty cycles of the LPN and conserve energy, the LPN must establish a Friendship with a mesh node supporting the Friend feature. This Friendship between the LPN and the Friend nodes (mesh nodes supporting the Friend feature) enables the Friend node to store and forward messages addressed to the LPN. Forwarding by the Friend node occurs only when the LPN wakes up and polls the Friend node for messages awaiting delivery. This mechanism enables all of the LPNs to conserve energy and operate for longer durations.
For more information about devices, nodes, and the Friendship in Bluetooth mesh network, see Bluetooth Mesh Networking.
The main objectives of this example are:
Create and configure a Bluetooth mesh network
Visualize message flooding
Analyze the behavior of Friendship in the Bluetooth mesh network
Profile the energy consumed by each node in the Bluetooth mesh network
% Check if the 'Communications Toolbox Library for the Bluetooth Protocol' % support package is installed or not. commSupportPackageCheck('BLUETOOTH');
In the simulation, a source node initiates and relays a sample mesh message to a destination node. To relay mesh messages to multiple destination nodes, the source nodes transmits the messages to a common group address. During the simulation, the Friend nodes and LPNs exchange Friendship messages. Each node computes the time spent in various states (transmission, listen, idle and sleep) and calculates its lifetime.
To create and visualize the mesh network, use helperBLEMeshNode and helperBLEMeshVisualizeNetwork classes. Specify the number of nodes (
NumberofNodes) and the type of node position (
NodePositionType) in helperBLEMeshVisualizeNetwork function. The default type of node position is 'Grid'. To specify your own network, set the value of
NodePositionType to 'UserInput' and node positions to
% Set random number generator seed to 'default' sprev = rng('default'); % Specify the number of nodes in the mesh network totalNodes = 55; % Initialize 'bleMeshNodes' vector with objects of type helperBLEMeshNode meshNodes(1, totalNodes) = helperBLEMeshNode(); % Configure each mesh node with unique identifier for nodeIdx = 1:totalNodes meshNode = helperBLEMeshNode(); meshNode.Identifier = nodeIdx; meshNodes(nodeIdx) = meshNode; end % Load node positions from the MAT file load('bleMeshNodesPositions.mat'); % Create and Configure the visualization object for Bluetooth mesh network meshNetworkGraph = helperBLEMeshVisualizeNetwork(); meshNetworkGraph.NumberOfNodes = totalNodes; % Set the type of the node position allocation as 'Grid' or 'UserInput' meshNetworkGraph.NodePositionType = 'UserInput'; % Set node positions based on number of nodes (applicable for 'UserInput'), % in meters meshNetworkGraph.Positions = bleMeshNodesPositions; % Set vicinity range (in meters) based on node positions, in meters meshNetworkGraph.VicinityRange = 25; % Set title to the network visualization meshNetworkGraph.Title = 'Energy Profiling in Bluetooth Mesh Network';
Specify the number of source and destination pairs by using
sourceDestinationPairs variable. To specify Friend node and LPN pairs, use
friendLowPowerPairs variable. To specify the Relay nodes in the network, use
relayNodeIDs variable. Configure the mesh node objects related to each mesh node. The
paths variable store the paths obtained for each source and destination pair.
% Specify the simulation time (in milliseconds) simulationTime = 6000; % Enable or disable visualization enableVisualization = true; % Enable or disable the animation in the visualization. If % "enableVisualization" is set to false, the simulation does not considers % "enableAnimation". enableAnimation = false; % Specify the source and destination pairs. Source node transmits sample % mesh message to destination node. sourceDestinationPairs = [1 52; 1 17; 12 7; 6 53; 54 51; 9 33; 18 52; ... 29 52; 31 7; 12 9; 54 53; 55 1; 9 17; 18 35]; % Specify the time to live (TTL) value (in the range [0, 127]) for each % source and destination pair ttl = [20 23 35 21 23 30 22 20 23 35 21 23 30 22]; % Specify the Friend node and LPN friendLowPowerPairs = [16 52]; % Specify the receive window (in milliseconds) for each Friend and LPN % pair. This value is in the range [120, 255] receiveWindow = 180; % Specify the poll timeout (in seconds) for each Friend and LPN pair. The % value is in the range [2 seconds, 95.9 hours]. pollTimeout = 20; % Specify the relay nodes relayNodeIDs = [3 4 5 8 10 11 15 19 20 21 23 25 28 30 32 34 36 37 38 39 41 ... 42 43 44 45 46 47 48 49 26 2 16 13 27]; % Simulate the Bluetooth mesh network [meshNodes, paths] = helperBLEMeshSimulation(meshNodes, totalNodes, meshNetworkGraph, ... simulationTime, sourceDestinationPairs, ttl, friendLowPowerPairs, receiveWindow, ... pollTimeout, relayNodeIDs, enableVisualization, enableAnimation); % Restore the previous setting of random number generation rng(sprev);
At each mesh node, the simulation captures these statistics.
Time spent in transmission state
Time spent in listening state
Time spent in sleep state
Time spent in idle state
Number of messages transmitted from the node
Number of messages received by the node
Number of messages relayed by the node
Number of messages dropped at the node
Number of messages received with cyclic redundancy check (CRC) failures
The workspace variable,
statisticsAtEachNode, contains the cumulative value of the preceding statistics for all the nodes in the network. For a given simulation run, you can view the statistics for first five nodes. The network statistics for the first five nodes in the network are:
% Statistics for first five nodes statisticsAtEachNode = helperBLEMeshNodesStatistics(meshNodes); statisticsForFirstFiveNodes = statisticsAtEachNode(1:min(totalNodes, 5), :)
statisticsForFirstFiveNodes = 5x14 table NodeType TransmittedMsgs ReceivedMsgs ReceivedMsgsFromLPN ReceivedApplicationMsgs RelayedMsgs DroppedMsgs CRCFailedMsgs TotalTransmittedBytes TotalReceivedBytes SleepTime (milliseconds) IdleTime (milliseconds) ListenTime (milliseconds) TransmissionTime (milliseconds) ________ _______________ ____________ ___________________ _______________________ ___________ ___________ _____________ _____________________ __________________ ________________________ _______________________ _________________________ _______________________________ Node_1 End 6 10 0 1 0 9 0 171 284 0 123.5 5871 1.368 Node_2 Relay 15 6 0 0 5 1 0 426 170 0 187 5800 3.408 Node_3 Relay 15 24 0 0 5 19 0 426 685 0 178 5809 3.408 Node_4 Relay 12 20 0 0 4 14 2 339 566 0 168 5821.5 2.712 Node_5 Relay 12 10 0 0 4 4 2 339 285 0 168 5821.5 2.712
This plot shows the average time spent by different type of mesh nodes in different states. The results conclude that the LPN spend most of the time in sleep state, resulting in energy conservation and increased lifetime.
fprintf('Average time statistics of different Bluetooth mesh nodes are:\n'); meshNodesAvgStats = helperBLEMeshNodeAverageTime(meshNodes)
Average time statistics of different Bluetooth mesh nodes are: meshNodesAvgStats = 4x5 table Type of Bluetooth mesh node Transmission time (milliseconds) Listen time (milliseconds) Idle time (milliseconds) Sleep time (milliseconds) ___________________________ ________________________________ __________________________ ________________________ _________________________ Low Power node 2.304 720 103 5166.5 Friend node 6.192 5771.5 205.5 0 Relay node 3.3869 5801.4 185.7 0 End node 0.4836 5907.4 90.3 0
The simulation consists of single message transmission from source node to destination node. Configure the traffic between the mesh nodes by using the pushModelMessage function periodically. The transmission time at the End node depends on the application traffic. The transmission time at the LPN depends on the poll timeout value.
Calculate Lifetime of LPN:
Use helperBLEMeshNodeLifetime function to calculate the lifetime of a node in the Bluetooth mesh network at the end of simulation. To compute node lifetime, the
simulationTime and the mesh node object of type helperBLEMeshNode is given as an input to the helperBLEMeshNodeLifetime function. The node lifetime is calculated by using the energy parameters that are hardware dependent. To update these hardware parameters, use helperBLEMeshNodeLifetime function.
% Fetch one of the Low Power nodes for calculating the lifetime meshNode = meshNodes(52); lifeTime = helperBLEMeshNodeLifetime(meshNode, simulationTime); fprintf('Lifetime of node %d is %.4f days.\n', meshNode.Identifier, lifeTime);
Configured hardware parameters for a 1200 mAh battery are: hardwareParameters = 7x2 table Hardware parameters Configured values (mA) __________________________ ______________________ Self-discharge 0.0013699 Transmission on channel 37 7.57 Transmission on channel 38 7.77 Transmission on channel 39 7.7 Listening 10.3 Sleep 0.2 Idle 1.19 Statistics at node 52 are: statisticsAtNode = 4x2 table Time variables Time (milliseconds) _________________ ___________________ Transmission time 2.304 Listen time 720 Sleep time 5166.5 Idle time 103 Lifetime of node 52 is 34.8927 days.
Lifetime of LPN by Varying Poll Timeout
The lifetime of a LPN depends on the time for which the node is in the listen state. In a given poll timeout, a LPN is in listen or sleep state for most of the time. The receive window for each poll request of a LPN determines the time spent in listen state. The time spent in transmission state is negligible.
Visualize the impact of the poll timeout and receive window on the lifetime of LPN by using the helperBLEMeshLPNLifetimeVSPolltimeout function.
The preceding plot concludes that the lifetime of LPN is directly proportional to the poll timeout. The poll timeout specifies the maximum time between two consecutive requests from an LPN to Friend node. As the poll timeout increases, the LPN spends more time in sleep state that results in increasing the lifetime of the LPN.
This example shows how to create and configure a multinode Bluetooth mesh network and analyze the message exchange in the network. This example also enables you to analyze the behavior and the advantages of the Friendship between Friend node and LPN. To calculate the time spent by each node on different states the Bluetooth mesh node is simulated with multiple Friend and Low Power node pairs. The plot of the average time spent by each node in different states show that the LPNs always consume less energy by spending more time in sleep state. You can further explore the energy profiling of LPN by varying the poll timeout and receive window values.
The example uses these features:
The example uses these helpers:
helperBLEMeshNode: Create an object for Bluetooth mesh node
helperBLEMeshAccessLayer: Create an object for Bluetooth mesh access layer functionality
helperBLEMeshNetworkLayer: Create an object for Bluetooth mesh network layer functionality
helperBLEMeshTransportLayer: Create an object for Bluetooth mesh transport (upper and lower) layer functionality
helperBLEMeshLowPowerNode: Create an object for Bluetooth mesh Low Power node functionality
helperBLEMeshFriendNode: Create an object for Bluetooth mesh Friend node functionality
helperBLEMeshFriendTimer: Create an object for Bluetooth mesh friend timer
helperBLEMeshLLGAPBearer: Create an object for BLE LL advertising bearer functionality
helperBLEMeshAppGenericPDU: Generate Bluetooth mesh generic PDU
helperBLEMeshAppGenericPDUDecode: Decode Bluetooth mesh generic PDU
helperBLEMeshLightnessPDU: Generate Bluetooth mesh lightness PDU
helperBLEMeshLightnessPDUDecode: Decode Bluetooth mesh lightness PDU
helperBLEMeshAccessPDU: Generate Bluetooth mesh access PDU
helperBLEMeshAccessPDUDecode: Decode Bluetooth mesh access PDU
helperBLEMeshNetworkPDU: Generate Bluetooth mesh network PDU
helperBLEMeshNetworkPDUDecode: Decode Bluetooth mesh network PDU
helperBLEMeshTransportControlMessage: Generate Bluetooth mesh transport control message
helperBLEMeshTransportControlMessageDecode: Decode Bluetooth mesh transport control message
helperBLEMeshTransportDataMessage: Generate Bluetooth mesh transport data message
helperBLEMeshTransportDataMessageDecode: Decode Bluetooth mesh transport data message
helperBLEMeshGAPDataBlock: Generate advertising data with Bluetooth mesh network PDU
helperBLEMeshGAPDataBlockDecode: Decode advertising data with Bluetooth mesh network PDU
helperBluetoothQueue: Create an object for Bluetooth queue functionality
helperBLEMeshRetransmissions: Create an object for retransmissions in Bluetooth mesh
helperBLEMeshNetworkChannelMessage: Receive message from Bluetooth mesh network channel
helperBLEMeshPath: Return the path between source and destination within Bluetooth mesh network
helperBLEMeshVicinityNodes: Obtain the vicinity nodes of a given node
helperBLEMeshGraphCursorCallback: Display the node statistics on mouse hover action
helperBLEMeshVisualizeNetwork: Create an object for Bluetooth mesh network visualization
helperBLEMeshSimulation: Simulate a Bluetooth mesh network
helperBLEMeshNodesStatistics: Collect statistics at each node into a table
helperBLEMeshNodeLifetime: Compute lifetime of a Bluetooth mesh node
helperBLEMeshNodeAverageTime: Compute average time spent in various states by the Bluetooth mesh nodes
helperBLEMeshLPNLifetimeVSPolltimeout: Script to compute the lifetime of Bluetooth mesh Low Power node for different poll timeout and receive window values
helperBLEPrependAccessAddress: Prepend the PDU with the access address