Skip to content

Commit 9929b0f

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 9929b0f

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

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

Lines changed: 6 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.
@@ -325,6 +329,8 @@ Bluetooth Mesh samples
325329
* :ref:`bluetooth_mesh_light_lc`
326330
* :ref:`bluetooth_mesh_sensor_server`
327331
* :ref:`bluetooth_mesh_sensor_client`
332+
* Button functions shifted down one position to accommodate the new polling toggle.
333+
* Descriptor action removed from buttons (still available via mesh shell commands).
328334

329335
Bluetooth Fast Pair samples
330336
---------------------------

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: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,32 @@ 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_start(void)
171+
{
172+
if (!poll_active) {
173+
poll_active = true;
174+
k_work_schedule(&get_data_work, K_NO_WAIT);
175+
printk("Sensor polling started\n");
176+
}
177+
}
178+
179+
static void poll_stop(void)
180+
{
181+
if (poll_active) {
182+
poll_active = false;
183+
k_work_cancel_delayable(&get_data_work);
184+
printk("Sensor polling stopped\n");
185+
}
186+
}
168187

169188
static void get_data(struct k_work *work)
170189
{
171190
if (!bt_mesh_is_provisioned()) {
172-
k_work_schedule(&get_data_work, K_MSEC(GET_DATA_INTERVAL));
191+
if (poll_active) {
192+
k_work_schedule(&get_data_work, K_MSEC(GET_DATA_INTERVAL));
193+
}
173194
return;
174195
}
175196

@@ -231,11 +252,13 @@ static void get_data(struct k_work *work)
231252
}
232253
}
233254

234-
if (sensor_idx % 6) {
235-
k_work_schedule(&get_data_work, K_MSEC(GET_DATA_INTERVAL_QUICK));
236-
} else {
237-
k_work_schedule(&get_data_work, K_MSEC(GET_DATA_INTERVAL));
238-
sensor_idx = 0;
255+
if (poll_active) {
256+
if (sensor_idx % 6) {
257+
k_work_schedule(&get_data_work, K_MSEC(GET_DATA_INTERVAL_QUICK));
258+
} else {
259+
k_work_schedule(&get_data_work, K_MSEC(GET_DATA_INTERVAL));
260+
sensor_idx = 0;
261+
}
239262
}
240263
}
241264

@@ -278,14 +301,21 @@ static void button_handler_cb(uint32_t pressed, uint32_t changed)
278301
int err;
279302

280303
if (pressed & changed & BIT(0)) {
304+
if (poll_active) {
305+
poll_stop();
306+
} else {
307+
poll_start();
308+
}
309+
}
310+
if (pressed & changed & BIT(1)) {
281311
err = bt_mesh_sensor_cli_setting_get(&sensor_cli, NULL,
282312
&bt_mesh_sensor_present_dev_op_temp,
283313
&bt_mesh_sensor_dev_op_temp_range_spec, NULL);
284314
if (err) {
285315
printk("Error getting range setting (%d)\n", err);
286316
}
287317
}
288-
if (pressed & changed & BIT(1)) {
318+
if (pressed & changed & BIT(2)) {
289319
err = setting_set_int(&bt_mesh_sensor_present_dev_op_temp,
290320
&bt_mesh_sensor_dev_op_temp_range_spec,
291321
temp_ranges[temp_idx++]);
@@ -294,13 +324,6 @@ static void button_handler_cb(uint32_t pressed, uint32_t changed)
294324
}
295325
temp_idx = temp_idx % ARRAY_SIZE(temp_ranges);
296326
}
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-
}
304327
if (pressed & changed & BIT(3)) {
305328
err = setting_set_int(&bt_mesh_sensor_presence_detected,
306329
&bt_mesh_sensor_motion_threshold,
@@ -391,7 +414,6 @@ const struct bt_mesh_comp *model_handler_init(void)
391414
k_work_init_delayable(&motion_timeout_work, motion_timeout);
392415

393416
dk_button_handler_add(&button_handler);
394-
k_work_schedule(&get_data_work, K_MSEC(GET_DATA_INTERVAL));
395417

396418
return &comp;
397419
}

0 commit comments

Comments
 (0)