Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: Mesh: Add timeout for ambient light level report #11579

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ Bluetooth libraries and services

* :ref:`bt_mesh` library:

* Added:

* The :kconfig:option:`BT_MESH_LIGHT_CTRL_AMB_LIGHT_LEVEL_TIMEOUT` Kconfig option that configures a timeout before resetting the ambient light level to zero.

* Updated:

* The :kconfig:option:`BT_MESH_MODEL_SRV_STORE_TIMEOUT` Kconfig option, that is controlling timeout for storing of model states, is replaced by the :kconfig:option:`BT_MESH_STORE_TIMEOUT` Kconfig option.
Expand Down
4 changes: 4 additions & 0 deletions include/bluetooth/mesh/light_ctrl_srv.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ struct bt_mesh_light_ctrl_srv {
BT_MESH_LIGHT_CTRL_OP_LIGHT_ONOFF_STATUS, 3)];
/** Resume control timeout (in seconds) */
uint16_t resume;
#if CONFIG_BT_MESH_LIGHT_CTRL_AMB_LIGHT_LEVEL_TIMEOUT
/* Time when the last ambient light level report was received. */
int64_t amb_light_level_timestamp;
#endif
/** Setup model publish parameters */
struct bt_mesh_model_pub setup_pub;
/* Publication buffer */
Expand Down
12 changes: 12 additions & 0 deletions subsys/bluetooth/mesh/Kconfig.models
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,18 @@ config BT_MESH_LIGHT_CTRL_REG_SPEC_INTERVAL
Update interval of the specification-defined illuminance regulator (in milliseconds).

endif #BT_MESH_LIGHT_CTRL_REG_SPEC

config BT_MESH_LIGHT_CTRL_AMB_LIGHT_LEVEL_TIMEOUT
int "Ambient light level report timeout (seconds)"
default 300
range 0 16777
Balaklaka marked this conversation as resolved.
Show resolved Hide resolved
help
Defines time in seconds the Light Lightness Control Server waits after receiving the
Sensor Status message with the present ambient light level property ID before setting
the ambient light level to zero and passing it to the regulator. This option helps
avoiding an issue with the regulator getting stuck with an old output value, and not
triggering new report from the sensor. When set to zero, the timeout is disabled.

endif #BT_MESH_LIGHT_CTRL_REG

menuconfig BT_MESH_LIGHT_CTRL_SRV
Expand Down
13 changes: 13 additions & 0 deletions subsys/bluetooth/mesh/light_ctrl_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,16 @@ static void reg_updated(struct bt_mesh_light_ctrl_reg *reg, float value)
*/
uint16_t lvl = to_linear(light_get(srv));

#if CONFIG_BT_MESH_LIGHT_CTRL_AMB_LIGHT_LEVEL_TIMEOUT
int64_t timestamp_temp;

timestamp_temp = srv->amb_light_level_timestamp;
if (k_uptime_delta(&timestamp_temp) >=
CONFIG_BT_MESH_LIGHT_CTRL_AMB_LIGHT_LEVEL_TIMEOUT * MSEC_PER_SEC) {
srv->reg->measured = 0;
}
#endif

/* Output value is max out of regulator and configured level. */
if (output <= lvl) {
output = lvl;
Expand Down Expand Up @@ -977,6 +987,9 @@ static int handle_sensor_status(struct bt_mesh_model *model, struct bt_mesh_msg_
#if CONFIG_BT_MESH_LIGHT_CTRL_SRV_REG
if (id == BT_MESH_PROP_ID_PRESENT_AMB_LIGHT_LEVEL && srv->reg) {
srv->reg->measured = sensor_to_float(&value);
#if CONFIG_BT_MESH_LIGHT_CTRL_AMB_LIGHT_LEVEL_TIMEOUT
srv->amb_light_level_timestamp = k_uptime_get();
#endif
if (!atomic_test_and_set_bit(&srv->flags, FLAG_AMBIENT_LUXLEVEL_SET)) {
reg_start(srv);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/subsys/bluetooth/mesh/light_ctrl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ target_compile_options(app
-DCONFIG_BT_MESH_LIGHT_CTRL_SRV_REG_LUX_ON=500
-DCONFIG_BT_MESH_LIGHT_CTRL_SRV_REG_LUX_PROLONG=200
-DCONFIG_BT_MESH_LIGHT_CTRL_SRV_REG_LUX_STANDBY=100
-DCONFIG_BT_MESH_LIGHT_CTRL_AMB_LIGHT_LEVEL_TIMEOUT=20
)

zephyr_linker_sources(SECTIONS ${NRF_DIR}/subsys/bluetooth/mesh/sensor_types.ld)

zephyr_ld_options(
${LINKERFLAGPREFIX},--allow-multiple-definition
)
Loading