@@ -14,32 +14,84 @@ data is being sent. It is important to understand when radio is active.
14
14
15
15
### Connections
16
16
17
- The most intuitive power consumption rate to understand is when using connections. Each device needs to send a packet at
18
- below supervision timeout frequency to maintain a connection regardless of data transfer. This is the absolute minimum
19
- power consumption. Additionally, normally power is consumed at every connection event (exchange of packets between
20
- central and peripheral).
17
+ The most intuitive power consumption rate to understand is when using connections. Each take turns sending and receiving
18
+ packets at set interval.
19
+
20
+
21
+ CENTRAL
22
+ ┌────┐ ┌────┐ ┌────┐ ┌────┐ ┌────┐ ┌────┐ ┌────┐ ┌────┐
23
+ │send│ │recv│ │send│ │recv│ │send│ │recv│ │send│ │recv│
24
+ └────┘ └────┘ └────┘ └────┘ └────┘ └────┘ └────┘ └────┘
25
+ connection interval
26
+ ◄─────────────────────►
27
+
28
+ PERIPHERAL
29
+ ┌────┐ ┌────┐ ┌────┐ ┌────┐ ┌────┐ ┌────┐
30
+ │recv│ │send│ │recv│ │send│ │recv│ │send│
31
+ └────┘ └────┘ └────┘ └────┘ └────┘ └────┘
32
+ slave latency
33
+ ◄───────────────────────────────────────────►
34
+
35
+ ▲ ▲ ▲
36
+ connection event connection event connection event
37
+
38
+
39
+ To maintain a connection, regardless if there is data transfer to be transferred, the central needs to transmit and
40
+ receive once very connection interval.
41
+
42
+ The peripheral needs to receive and may transmit data if it has any. It may skip a number of these connection events
43
+ set by ` slaveLatency ` . If it has no data to transmit empty packets are sent.
44
+
45
+ More power is consumed if there is data to be exchanged. The exchange can continue until the next connection event would
46
+ take place.
21
47
22
48
It's worth considering if keeping the connection active is worth it. Connection in BLE is extremely fast and if you plan
23
49
to only send a quick burst of data every minute it is better to connect and disconnect each time.
24
50
25
51
The cost of the connection is proportionate to the negotiable connection interval. This can be set during ` connect ` or
26
- later through ` updateConnectionParameters ` . The higher the interval the more often radio is active. This is especially
52
+ later through ` updateConnectionParameters ` . The lower the interval the more often radio is active. This is especially
27
53
important for the peripheral which needs to enable the radio to receive packets.
28
54
29
55
This can be further helped through setting a high ` slaveLatency ` parameter. This allows the peripheral to skip
30
56
connection events and save power not just by not sending any packets but by not even listening. This is not free for
31
- central as it increases latency of data transmission. Central may have to attempt sending data multiple times before the
32
- peripheral accepts the transmission.
57
+ central as it increases latency of data transmission from central to peripheral. Central may have to attempt sending
58
+ data multiple times before the peripheral accepts the transmission. The peripheral may send data at any connection event
59
+ as the central must listen after every transmission.
33
60
34
61
### Advertising and scanning
35
62
36
- Power draw during advertising is proportional to the advertising interval. Additionally, if the advertising is
37
- connectable or scannable it means the advertiser needs to listen on the radio after each advertisement for potential
38
- connection of scan requests.
63
+ Power draw during advertising affected by:
64
+ - the advertising interval - lower interval uses more power,
65
+ - amount of data sent,
66
+ - number of channels used - each advertising event is sent by default to three channels which you can limit to 2 or 1,
67
+ - whether extended advertising is used - this will send additional packets on regular channels,
68
+ - whether the type is connectable or scannable - it means the advertiser needs to listen on the radio after each
69
+ advertisement for potential connection of scan requests.
70
+
39
71
40
- Scanning power draw is proportional to time spent scanning. The interaction between scanning an advertising means that
41
- the less power the advertiser spends advertising, the more power the scanner will have to spend to see the advertising
42
- packets. The decision on balance will be dictated by your design of your devices (which one is more constrained).
72
+ PERIPHERAL
73
+ ┌────┐ advertising interval ┌────┐
74
+ channel 37 │adv │◄───────────────────────────────────────────►│adv │
75
+ └────┘ └────┘
76
+ ┌────┐ ┌────┐
77
+ channel 38 │adv │ │adv │
78
+ └────┘ └────┘
79
+ ┌────┐ ┌────┐
80
+ channel 39 │adv │ │adv │
81
+ └────┘ └────┘
82
+
83
+ non-advertising ┌────────────────────┐
84
+ channel │extended advertising│
85
+ (indicated in regular └────────────────────┘
86
+ advertising payload)
87
+
88
+
89
+ Scanning power draw is proportional to time spent scanning. Additional power will be used if you run active scanning
90
+ which will send a scan request and listen for the reply.
91
+
92
+ The interaction between scanning an advertising means that the less power the advertiser spends advertising, the more
93
+ power the scanner will have to spend to see the advertising packets. The decision on balance will be dictated by your
94
+ design of your devices (which one is more constrained).
43
95
44
96
### Connection vs advertising
45
97
@@ -89,6 +141,11 @@ Larger data length greatly increases throughput (although diminishing returns qu
89
141
potential drawback is in noisy environments where longer packets may cause slower effective transfer due to
90
142
retransmissions (this is only related to data length, ATT_MTU does not affect this).
91
143
144
+ ### ATT protocol
145
+
146
+ GATT client writes and GATT server updates come in two versions - with and without confirmation. Requiring confirmations
147
+ limits the throughput severely so to maximise throughput you can move reliability up from the stack to your application.
148
+
92
149
### Packet timings
93
150
94
151
If you're not constrained by battery power it might be tempting to use maximum/minimum values where possible.
@@ -104,7 +161,13 @@ The connection interval shouldn't be shorter than what your data requires in ter
104
161
# Test and measure
105
162
106
163
Due to complexity of the stack the only reliable way to truly maximise performance is to test your application with
107
- representative data and measure the throughput and power usage. It's important to keep it mind that tweaking
108
- parameters by trial and error and fine tuning them will only be reliable as long as you control both devices (and even
109
- then the environment can change). If your device needs to communicate with an unknown device your fine-tuning should
110
- give way to sound principles since stack behaviour varies and you cannot test against all stacks.
164
+ representative data and measure the throughput and power usage. It's important to keep in mind that tweaking
165
+ parameters by trial and error and fine-tuning them will only be reliable for sequential operations on known stacks.
166
+
167
+ Many behaviours are implementation dependant and many operations are best effort and not guaranteed to succeed. The
168
+ stack has a lot of latitude to change its behaviour in accordance with resource constrains and other commitments. For
169
+ example your advertising may be severely affected by other operations that take precedence like keeping up a connection.
170
+
171
+ If your device needs to communicate with an unknown device or you run a non-trivial combination of concurrent
172
+ operations your fine-tuning should give way to sound principles since stack behaviours vary and you cannot test against
173
+ all stacks and sequences of operations.
0 commit comments