Main Content

Energy Profiling of Bluetooth Mesh Nodes in Wireless Sensor Networks

This example shows how to perform energy profiling of nodes in a Bluetooth® mesh network.

Using this example, you can:

  • Create and configure a Bluetooth mesh network.

  • Compute energy consumption of mesh nodes in transmission, listen, sleep, and idle states by varying the number of Relay nodes, source-destination node pairs, Friend node-Low Power node (LPN) pair, and the application traffic.

  • Estimate the lifetime of mesh node based on the configured hardware-specific energy parameters.

  • Explore the impact of poll timeout and receive window size on the LPN lifetime.

The results confirm the expectation that LPN always consume less energy by spending more time in sleep, resulting in energy conservation and increased lifetime.

Bluetooth Mesh Energy Profiling

The Bluetooth mesh profile [ 3 ] defines the fundamental requirements to implement a mesh networking solution for Bluetooth LE. Bluetooth mesh networking enables large-scale device networks in the applications such as smart lighting, industrial automation, sensor networking, and asset tracking. For information about Bluetooth LE protocol stack, see Bluetooth Protocol Stack.

Each Bluetooth mesh node possess some optional features enabling them to acquire additional 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 LPNs, respectively. To reduce the duty cycles of the LPN and conserve energy, the LPN must establish a Friendship with a Friend node (mesh nodes supporting the Friend feature). For more information about devices, nodes, and the Friendship in Bluetooth mesh network, see Bluetooth Mesh Networking.

In this example, the source nodes initiates mesh communication to a destination node and an LPN. During the simulation, the Friend node and LPN exchange Friendship messages. Each node computes the time spent in various states (transmission, listen, idle and sleep) and calculates its lifetime.

Check for Support Package Installation

Check if the Communications Toolbox™ Wireless Network Simulation Library support package is installed. If the support package is not installed, MATLAB® returns an error with a link to download and install the support package.

wirelessnetworkSupportPackageCheck;

Configure Simulation Parameters

Set the seed for the random number generator to 1. The seed value controls the pattern of random number generation. For high fidelity simulation results, change the seed value for each run and average the results over multiple simulations.

rng(1,"twister");

Specify the simulation time.

simulationTime = 5; % In seconds

Specify total number of nodes in the mesh network.

numNodes = 21;

Get the node positions from the MAT file. Specify the positions of Bluetooth mesh nodes as a numNodes-by-2 array, where numNodes is the number of nodes in the network. Each row specifies the Cartesian coordinates of a node, starting from the first node.

load("bleMeshNetworkNodePositions.mat");
if numNodes ~= size(bleMeshNetworkNodePositions,1)
    error("Invalid Bluetooth mesh node position value. Specify 'bleMeshNetworkNodePositions' value in the MAT file as a "...
        +num2str(numNodes)+"-by-2 array.");
end

Set some of the nodes as relay nodes, source-destination node pairs, friend node and LPN.

relayNodes = [3 6 7 8 9 12 13 14 17];
sourceDestinationPairs = [1 20; 21 16];
friend = 15;
lpn = 16;

Create a wireless network simulator object.

networkSimulator = wirelessNetworkSimulator.init;

Create and Configure Bluetooth Mesh Nodes

Initialize array to store Bluetooth mesh nodes.

meshNodes = bluetoothLENode.empty(0,numNodes);

Create Bluetooth mesh network. Use bluetoothMeshProfileConfig to create mesh profile configuration object. To create a Bluetooth mesh node, use the bluetoothLENode object. Specify the role as "broadcaster-observer" and assign the mesh profile to MeshConfig.

for nodeIndex = 1:numNodes
    % Create and configure Bluetooth mesh profile by specifying the element
    % address (unique to each node in the network). Set relay and network
    % message repetitions.
    meshCfg = bluetoothMeshProfileConfig(ElementAddress=dec2hex(nodeIndex,4),...
        NetworkTransmissions=3,RelayRetransmissions=3);

    % Enable Relay feature of the configured relay nodes
    if any(nodeIndex==relayNodes)
        meshCfg.Relay = true;
    elseif nodeIndex==friend % Enable Friend feature of the configured Friend nodes
        meshCfg.Friend = true;
    elseif nodeIndex==lpn % Enable Low Power feature of the configured Low Power nodes
        meshCfg.LowPower = true;
    end

    % Create and configure Bluetooth mesh node by assigning the mesh profile.
    % Set receiver range, advertising interval (seconds) and scan interval (seconds).
    meshNodes(nodeIndex) = bluetoothLENode("broadcaster-observer",MeshConfig=meshCfg, ...
        Position=[bleMeshNetworkNodePositions(nodeIndex,:) 0],Name="Node"+num2str(nodeIndex),...
        ReceiverRange=25,AdvertisingInterval=20e-3,ScanInterval=30e-3);
end

Configure Friendship Between Friend Node and LPN

Set friendship timing parameters (in seconds) such as poll timeout, receive window, and receive delay by using the bluetoothMeshFriendshipConfig object.

friendshipConfig = bluetoothMeshFriendshipConfig(PollTimeout=2,ReceiveWindow=180e-3,...
    ReceiveDelay=50e-3);

Configure the friendship between the friend node and LPN by using the configureFriendship object function of bluetoothMeshFriendshipConfig.

configureFriendship(friendshipConfig,meshNodes(friend),meshNodes(lpn)); 

Add Application Traffic to Source Nodes

Create a networkTrafficOnOff object to generate an On-Off application traffic pattern. Configure the On-Off application traffic pattern by specifying the application data rate, packet size, on, and off state duration. Use addTrafficSource object function to attach the application traffic source between the specified source-destination node pairs.

for srcIdx = 1:numel(sourceDestinationPairs)/2
    % Set data rate, packet size, on time, and off time based on the
    % simulation time
    traffic = networkTrafficOnOff(DataRate=1,PacketSize=15,GeneratePacket=true,...
        OnTime=simulationTime*0.3,OffTime=simulationTime*0.7);

    % Maximum number of hops for a packet is controlled by setting
    % time-to-live (TTL) value
    ttl = 10;

    % Attach application traffic to source
    addTrafficSource(meshNodes(sourceDestinationPairs(srcIdx,1)),traffic,...                         % Traffic object
        SourceAddress=meshNodes(sourceDestinationPairs(srcIdx,1)).MeshConfig.ElementAddress,...      % Source element address
        DestinationAddress=meshNodes(sourceDestinationPairs(srcIdx,2)).MeshConfig.ElementAddress,... % Destination element address
        TTL=ttl);
end

Visualize Mesh Network

Visualize the mesh network scenario by using the helperBLEMeshVisualizeNetwork helper object.

plotNetwork = helperBLEMeshVisualizeNetwork(NumberOfNodes=numNodes,...
    NodePositionType="UserInput",Positions=bleMeshNetworkNodePositions,...
    ReceiverRange=25,SimulationTime=simulationTime,...
    SourceDestinationPairs=sourceDestinationPairs,FriendPairs=[friend lpn],...
    Title="Energy Profiling in Bluetooth Mesh Network");

Assign the helper object to the NetworkPlot parameter in the helperBLEMeshEventCallback helper object. For information about how to visualize the message flow in the mesh network, see Bluetooth Mesh Flooding in Wireless Sensor Networks.

networkEvents = helperBLEMeshEventCallback(meshNodes,plotNetwork);

Figure Energy Profiling in Bluetooth Mesh Network contains an axes object. The axes object with title Energy Profiling in Bluetooth Mesh Network, xlabel X-position (meters), ylabel Y-position (meters) contains 92 objects of type line, scatter, text. One or more of the lines displays its values using only markers These objects represent Node, Relay node, Friend node, Low Power node, Source-Destination pair (1, 20), Source-Destination pair (21, 16).

Run the simulation

Add nodes to the wireless network simulator.

addNodes(networkSimulator,meshNodes);

Run the network simulation for the specified simulation time.

run(networkSimulator,simulationTime);

Simulation Results

At each mesh node, the simulation captures these statistics.

  • Application end-to-end packet latency in seconds

  • Link layer (LL) throughput in Kbps

  • Time spent in listen state, transmit state, idle state and sleep state in seconds

  • Packet statistics at the application layer, network layer, transport layer, LL and physical layer

The workspace variable statisticsAtEachNode contains the cumulative value of the preceding statistics for all the nodes in the network. Use statistics object function to get the statistics of mesh nodes in the network.

% List of statistics (structure array) of the simulated mesh nodes in the network
for nodeIndex = 1:numNodes
    statisticsAtEachNode(nodeIndex) = statistics(meshNodes(nodeIndex)); %#ok<*SAGROW>
end

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");
Average time statistics of different Bluetooth mesh nodes are:
meshNodesAvgStats = helperBLEMeshNodeAverageTime(meshNodes);

Figure Average Time Statistics of Different Bluetooth Mesh Nodes contains an axes object. The axes object with title Average Time Statistics of Different Bluetooth Mesh Nodes, ylabel Average Time (seconds) - Log Scale contains 4 objects of type bar. These objects represent Transmission, Listen, Idle, Sleep.

Configure the traffic between the mesh nodes by using the addTrafficSource object function of the bluetoothLENode object. The transmission time at the mesh node depends on the application traffic. The transmission time at the LPN depends on the poll timeout value.

Further Exploration

Calculate Lifetime of LPN:

At the end of the simulation, calculate the lifetime of a node in the Bluetooth mesh network by using the helperBLEMeshNodeLifetime helper function. To compute node lifetime, the simulation time and the mesh node is given as an input to the helperBLEMeshNodeLifetime helper function. The node lifetime is calculated by using the energy parameters that are hardware dependent. To update these hardware parameters, use the helperBLEMeshNodeLifetime helper function.

lifeTime = helperBLEMeshNodeLifetime(meshNodes(lpn),simulationTime);
Configured hardware parameters for a 1200 mAh battery are:
       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       

Timing metrics at Node16 are:
     Time variables      Time (seconds)
    _________________    ______________

    Transmission time       0.016704   
    Listen time                 1.23   
    Sleep time                2.9013   
    Idle time                 0.5493   
fprintf("Lifetime of %s is %.4f days.\n",meshNodes(lpn).Name,lifeTime);
Lifetime of Node16 is 17.8087 days.

Lifetime of LPN by Varying Poll Timeout

The lifetime of an LPN depends on the time for which the node is in the listen state. In a given poll timeout, an LPN is in listen or sleep state for most of the time. The receive window for each poll request of an 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 helper function.

FEImageEnergyProfileMesh.JPG

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.

Faster Execution Using Parallel Simulation Runs

If you want to run multiple simulations, you can speed up the simulations by enabling parallel computing using the parfor loop. The parfor loop is an alternative to the for loop. The parfor loop enables you to execute multiple simulation runs in parallel, thereby reducing the total execution time. To use parfor, you need to install the Parallel Computing Toolbox™. For more information about running multiple simulations using parfor loop, see helperBLEMeshLPNLifetimeVSPolltimeout helper function.

Appendix

The example uses these helpers:

Selected Bibliography

  1. Bluetooth Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed Jan 13, 2023. https://www.bluetooth.com.

  2. Bluetooth Special Interest Group (SIG). "Bluetooth Core Specification". Version 5.3. https://www.bluetooth.com/.

  3. Bluetooth Special Interest Group (SIG). "Bluetooth Mesh Profile". Version 1.0.1. https://www.bluetooth.com/.

See Also

Functions

Objects

Related Topics