Skip to content

Commit 58e7f86

Browse files
committed
samples: bluetooth: mesh: add poll toggle to sensor cli
* Added polling toggle on first button. This was done to avoid messaging traffic when not needed. * Updated button mapping. * Removed descriptor action from buttons. This is still available via shell. * Updated docs. Signed-off-by: Stine Åkredalen <stine.akredalen@nordicsemi.no>
1 parent b1cee3e commit 58e7f86

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ Bluetooth Mesh samples
316316

317317
* :ref:`bluetooth_mesh_sensor_client` sample:
318318

319+
* Added:
320+
321+
* Polling toggle to Button 1 (Button 0 on nRF54 DKs) to start/stop the periodic Sensor Get loop, ensuring the functionality is available on all supported devices including single-button hardware.
322+
319323
* Updated:
320324

321325
* To demonstrate the Bluetooth :ref:`ug_bt_mesh_nlc` HVAC Integration profile.
@@ -326,6 +330,9 @@ Bluetooth Mesh samples
326330
* :ref:`bluetooth_mesh_sensor_server`
327331
* :ref:`bluetooth_mesh_sensor_client`
328332

333+
* Button functions. Assignments are shifted down one index to accommodate the new polling toggle.
334+
The descriptor action has been removed from button actions but is still available via mesh shell commands.
335+
329336
Bluetooth Fast Pair samples
330337
---------------------------
331338

samples/bluetooth/mesh/sensor_client/README.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ The models are used for the following purposes:
8686
* Sensor Client gets sensor data from one or more :ref:`Sensor Servers <bt_mesh_sensor_srv_readme>`.
8787

8888
The model handling is implemented in :file:`src/model_handler.c`.
89-
A :c:struct:`k_work_delayable` item is submitted recursively to periodically request sensor data.
89+
Sensor data can be periodically requested using a :c:struct:`k_work_delayable` loop, which can be started and stopped with a button press.
9090

9191
User interface
9292
**************
@@ -102,27 +102,27 @@ Once the provisioning procedure has completed, the buttons will have the followi
102102
.. group-tab:: nRF21 and nRF52 DKs
103103

104104
Button 1:
105-
Sends a get message for the :c:var:`bt_mesh_sensor_dev_op_temp_range_spec` setting of the :c:var:`bt_mesh_sensor_present_dev_op_temp` sensor.
105+
Toggles the periodic Sensor Get data loop on/off.
106106

107107
Button 2:
108-
Sends a set message for the :c:var:`bt_mesh_sensor_dev_op_temp_range_spec` setting of the :c:var:`bt_mesh_sensor_present_dev_op_temp` sensor, switching between the ranges specified in the :c:var:`temp_ranges` variable.
108+
Sends a get message for the :c:var:`bt_mesh_sensor_dev_op_temp_range_spec` setting of the :c:var:`bt_mesh_sensor_present_dev_op_temp` sensor.
109109

110110
Button 3:
111-
Sends a get message for a descriptor, requesting information about the :c:var:`bt_mesh_sensor_present_dev_op_temp` sensor.
111+
Sends a set message for the :c:var:`bt_mesh_sensor_dev_op_temp_range_spec` setting of the :c:var:`bt_mesh_sensor_present_dev_op_temp` sensor, switching between the ranges specified in the :c:var:`temp_ranges` variable.
112112

113113
Button 4:
114114
Sends a set message for the :c:var:`bt_mesh_sensor_motion_threshold` setting of the :c:var:`bt_mesh_sensor_presence_detected` sensor, switching between the ranges specified in the :c:var:`presence_motion_threshold` variable.
115115

116116
.. group-tab:: nRF54 DKs
117117

118118
Button 0:
119-
Sends a get message for the :c:var:`bt_mesh_sensor_dev_op_temp_range_spec` setting of the :c:var:`bt_mesh_sensor_present_dev_op_temp` sensor.
119+
Toggles the periodic Sensor Get loop (start/stop).
120120

121121
Button 1:
122-
Sends a set message for the :c:var:`bt_mesh_sensor_dev_op_temp_range_spec` setting of the :c:var:`bt_mesh_sensor_present_dev_op_temp` sensor, switching between the ranges specified in the :c:var:`temp_ranges` variable.
122+
Sends a get message for the :c:var:`bt_mesh_sensor_dev_op_temp_range_spec` setting of the :c:var:`bt_mesh_sensor_present_dev_op_temp` sensor.
123123

124124
Button 2:
125-
Sends a get message for a descriptor, requesting information about the :c:var:`bt_mesh_sensor_present_dev_op_temp` sensor.
125+
Sends a set message for the :c:var:`bt_mesh_sensor_dev_op_temp_range_spec` setting of the :c:var:`bt_mesh_sensor_present_dev_op_temp` sensor, switching between the ranges specified in the :c:var:`temp_ranges` variable.
126126

127127
Button 3:
128128
Sends a set message for the :c:var:`bt_mesh_sensor_motion_threshold` setting of the :c:var:`bt_mesh_sensor_presence_detected` sensor, switching between the ranges specified in the :c:var:`presence_motion_threshold` variable.

samples/bluetooth/mesh/sensor_client/src/model_handler.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,27 @@ static const struct bt_mesh_comp2 comp_p2 = {
165165
#endif
166166

167167
static struct k_work_delayable get_data_work;
168+
static bool poll_active;
169+
170+
static void poll_toggle(void)
171+
{
172+
if (poll_active) {
173+
poll_active = false;
174+
k_work_cancel_delayable(&get_data_work);
175+
printk("Sensor polling stopped\n");
176+
} else {
177+
poll_active = true;
178+
k_work_schedule(&get_data_work, K_NO_WAIT);
179+
printk("Sensor polling started\n");
180+
}
181+
}
168182

169183
static void get_data(struct k_work *work)
170184
{
185+
if (!poll_active) {
186+
return;
187+
}
188+
171189
if (!bt_mesh_is_provisioned()) {
172190
k_work_schedule(&get_data_work, K_MSEC(GET_DATA_INTERVAL));
173191
return;
@@ -278,14 +296,17 @@ static void button_handler_cb(uint32_t pressed, uint32_t changed)
278296
int err;
279297

280298
if (pressed & changed & BIT(0)) {
299+
poll_toggle();
300+
}
301+
if (pressed & changed & BIT(1)) {
281302
err = bt_mesh_sensor_cli_setting_get(&sensor_cli, NULL,
282303
&bt_mesh_sensor_present_dev_op_temp,
283304
&bt_mesh_sensor_dev_op_temp_range_spec, NULL);
284305
if (err) {
285306
printk("Error getting range setting (%d)\n", err);
286307
}
287308
}
288-
if (pressed & changed & BIT(1)) {
309+
if (pressed & changed & BIT(2)) {
289310
err = setting_set_int(&bt_mesh_sensor_present_dev_op_temp,
290311
&bt_mesh_sensor_dev_op_temp_range_spec,
291312
temp_ranges[temp_idx++]);
@@ -294,13 +315,6 @@ static void button_handler_cb(uint32_t pressed, uint32_t changed)
294315
}
295316
temp_idx = temp_idx % ARRAY_SIZE(temp_ranges);
296317
}
297-
if (pressed & changed & BIT(2)) {
298-
err = bt_mesh_sensor_cli_desc_get(&sensor_cli, NULL,
299-
&bt_mesh_sensor_present_dev_op_temp, NULL);
300-
if (err) {
301-
printk("Error getting sensor descriptor (%d)\n", err);
302-
}
303-
}
304318
if (pressed & changed & BIT(3)) {
305319
err = setting_set_int(&bt_mesh_sensor_presence_detected,
306320
&bt_mesh_sensor_motion_threshold,
@@ -391,7 +405,6 @@ const struct bt_mesh_comp *model_handler_init(void)
391405
k_work_init_delayable(&motion_timeout_work, motion_timeout);
392406

393407
dk_button_handler_add(&button_handler);
394-
k_work_schedule(&get_data_work, K_MSEC(GET_DATA_INTERVAL));
395408

396409
return &comp;
397410
}

0 commit comments

Comments
 (0)