Generic Battery Client

The Generic Battery Client model can query the state of a Generic Battery Server model remotely, but does not have any ability to control the Battery state.

Extended models

None.

Persistent storage

None.

Shell commands

The Bluetooth Mesh shell subsystem provides a set of commands to interact with the Generic Battery Client model instantiated on a device.

To make these commands available, enable the following Kconfig options:

mesh models battery instance get-all

Print all instances of the Generic Battery Client model on the device.

mesh models battery instance set <ElemIdx>

Select the Generic Battery Client model instantiated on the specified element ID. This instance will be used in message sending. If no model instance is selected, the first model instance found on the device will be used by default.

  • ElemIdx - Element index where the model instance is found.

mesh models battery get

Get the battery status of the bound server.

API documentation

Header file: include/bluetooth/mesh/gen_battery_cli.h
Source file: subsys/bluetooth/mesh/gen_battery_cli.c
group bt_mesh_battery_cli

API for the Generic Battery Client model.

Defines

BT_MESH_BATTERY_CLI_INIT(_status_handler)

Initialization parameters for a Generic Battery Client model instance.

Parameters:
  • _status_handler[in] Optional status message handler.

BT_MESH_MODEL_BATTERY_CLI(_cli)

Generic Battery Client model composition data entry.

Parameters:

Functions

int bt_mesh_battery_cli_get(struct bt_mesh_battery_cli *cli, struct bt_mesh_msg_ctx *ctx, struct bt_mesh_battery_status *rsp)

Get the status of the bound srv.

This call is blocking if the rsp buffer is non-NULL. Otherwise, this function will return, and the response will be passed to the bt_mesh_battery_cli::status_handler callback.

Parameters:
  • cli[in] Client model to send on.

  • ctx[in] Message context, or NULL to use the configured publish parameters.

  • rsp[out] Status response buffer, or NULL to keep from blocking.

Return values:
  • 0 – Successfully sent the message and populated the rsp buffer.

  • -EALREADY – A blocking request is already in progress.

  • -EADDRNOTAVAIL – A message context was not provided and publishing is not configured.

  • -EAGAIN – The device has not been provisioned.

  • -ETIMEDOUT – The request timed out without a response.

struct bt_mesh_battery_cli
#include <gen_battery_cli.h>

Generic Battery Client structure.

Should be initialized with the BT_MESH_BATTERY_CLI_INIT macro.

Public Members

void (*const status_handler)(struct bt_mesh_battery_cli *cli, struct bt_mesh_msg_ctx *ctx, const struct bt_mesh_battery_status *status)

Battery status message handler.

Param cli:

[in] Client that received the status message.

Param ctx:

[in] Context of the incoming message.

Param status:

[in] Battery Status of the Generic Battery Server that published the message.

struct bt_mesh_msg_ack_ctx ack_ctx

Response context for tracking acknowledged messages.

struct bt_mesh_model_pub pub

Publish parameters.

const struct bt_mesh_model *model

Composition data model entry pointer.