Skip to content

Commit

Permalink
Mesh: Chat: Check additional elements
Browse files Browse the repository at this point in the history
Add one more element to sample for testing purpose.

Signed-off-by: Omkar Kulkarni <omkar.kulkarni@nordicsemi.no>
  • Loading branch information
omkar3141 committed Jun 25, 2024
1 parent 44dc310 commit 21d2a40
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions samples/bluetooth/mesh/chat/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ CONFIG_BT_MESH_TX_SEG_MAX=10
CONFIG_BT_MESH_PB_GATT=y
CONFIG_BT_MESH_GATT_PROXY=y
CONFIG_BT_MESH_DK_PROV=y
CONFIG_BT_MESH_SENSOR_SRV=y
CONFIG_BT_MESH_SENSOR_SRV_SENSORS_MAX=5
CONFIG_BT_MESH_SENSOR_USE_LEGACY_SENSOR_VALUE=n


# Enable Bluetooth Mesh models debug logs
CONFIG_BT_MESH_LOG_LEVEL_DBG=y
Expand Down
53 changes: 53 additions & 0 deletions samples/bluetooth/mesh/chat/src/model_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <zephyr/bluetooth/bluetooth.h>
#include <bluetooth/mesh/models.h>
#include <dk_buttons_and_leds.h>
#include <bluetooth/mesh/sensor_types.h>

#include <zephyr/shell/shell.h>
#include <zephyr/shell/shell_uart.h>
Expand Down Expand Up @@ -223,14 +224,66 @@ static struct bt_mesh_chat_cli chat = {
.handlers = &chat_handlers,
};

static int amb_light_level_get(struct bt_mesh_sensor_srv *srv,
struct bt_mesh_sensor *sensor,
struct bt_mesh_msg_ctx *ctx,
struct bt_mesh_sensor_value *rsp)
{
int err;

/* Report ambient light as dummy value, and changing it by pressing
* a button. The logic and hardware for measuring the actual ambient
* light usage of the device should be implemented here.
*/
float reported_value = 1234;

err = bt_mesh_sensor_value_from_float(sensor->type->channels[0].format,
reported_value, rsp);
if (err && err != -ERANGE) {
printk("Error encoding ambient light level sensor data (%d)\n", err);
return err;
}

printk("Ambient light level: %s\n", bt_mesh_sensor_ch_str(rsp));
return 0;
}

static const struct bt_mesh_sensor_descriptor present_amb_light_desc = {
.tolerance = {
.negative = BT_MESH_SENSOR_TOLERANCE_ENCODE(0),
.positive = BT_MESH_SENSOR_TOLERANCE_ENCODE(0),
},
.sampling_type = BT_MESH_SENSOR_SAMPLING_UNSPECIFIED,
.period = 0,
.update_interval = 0,
};


static struct bt_mesh_sensor present_amb_light_level = {
.type = &bt_mesh_sensor_present_amb_light_level,
.get = amb_light_level_get,
.descriptor = &present_amb_light_desc
};

static struct bt_mesh_sensor *const ambient_light_sensor[] = {
&present_amb_light_level,
};

static struct bt_mesh_sensor_srv sensor_srv =
BT_MESH_SENSOR_SRV_INIT(ambient_light_sensor, ARRAY_SIZE(ambient_light_sensor));

static struct bt_mesh_elem elements[] = {
BT_MESH_ELEM(
1,
BT_MESH_MODEL_LIST(
BT_MESH_MODEL_CFG_SRV,
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub)),
BT_MESH_MODEL_LIST(BT_MESH_MODEL_CHAT_CLI(&chat))),
BT_MESH_ELEM(2,
BT_MESH_MODEL_LIST(BT_MESH_MODEL_SENSOR_SRV(&sensor_srv)),
BT_MESH_MODEL_NONE),
};

/* .. include_endpoint_model_handler_rst_1 */

static void print_client_status(void)
Expand Down

0 comments on commit 21d2a40

Please sign in to comment.