Skip to content

Commit e4cac81

Browse files
Johan Hedbergjhedberg
authored andcommitted
Bluetooth: Mesh: Proxy: Fine-tune subnet advertising rotation
Create a slightly smarter algorithm for choosing how long to advertise each subnet. This is particularly important for the mesh_shell app, since it uses a 10 second NODE_ID_TIMEOUT, meaning starting Node ID advertising through user interaction would only succeed in advertising one subnet (due to this being configured to 10 seconds). Signed-off-by: Johan Hedberg <[email protected]>
1 parent 6e89138 commit e4cac81

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

subsys/bluetooth/host/mesh/proxy.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,7 @@ static int sub_count(void)
10831083
static s32_t gatt_proxy_advertise(struct bt_mesh_subnet *sub)
10841084
{
10851085
s32_t remaining = K_FOREVER;
1086+
int subnet_count;
10861087

10871088
BT_DBG("");
10881089

@@ -1113,8 +1114,22 @@ static s32_t gatt_proxy_advertise(struct bt_mesh_subnet *sub)
11131114
}
11141115
}
11151116

1116-
if (sub_count() > 1 && (remaining > K_SECONDS(10) || remaining < 0)) {
1117-
remaining = K_SECONDS(10);
1117+
subnet_count = sub_count();
1118+
BT_DBG("sub_count %u", subnet_count);
1119+
if (subnet_count > 1) {
1120+
s32_t max_timeout;
1121+
1122+
/* We use NODE_ID_TIMEOUT as a starting point since it may
1123+
* be less than 60 seconds. Divide this period into at least
1124+
* 6 slices, but make sure that a slice is at least one
1125+
* second long (to avoid excessive rotation).
1126+
*/
1127+
max_timeout = NODE_ID_TIMEOUT / max(subnet_count, 6);
1128+
max_timeout = max(max_timeout, K_SECONDS(1));
1129+
1130+
if (remaining > max_timeout || remaining < 0) {
1131+
remaining = max_timeout;
1132+
}
11181133
}
11191134

11201135
BT_DBG("Advertising %d ms for net_idx 0x%04x", remaining, sub->net_idx);

0 commit comments

Comments
 (0)