Generic Battery Server
The Generic Battery Server model provides information about the current battery status of the device.
States
The Generic Battery Server model contains the following state:
- Generic Battery Status:
bt_mesh_battery_status
The Generic Battery Status is a composite state, which means that it contains various information about the battery state. The battery state can only be changed locally, so a Generic Battery Client is only able to observe it.
Your application is expected to hold the Generic Battery Status state memory and provide access to the state through the
bt_mesh_battery_srv.get
handler function. All the fields in the Generic Battery Status have special unknown values, which are used by default.
Extended models
None.
Persistent storage
None.
API documentation
include/bluetooth/mesh/gen_battery_srv.h
subsys/bluetooth/mesh/gen_battery_srv.c
- group bt_mesh_battery_srv
API for the Generic Battery Server model.
Defines
-
BT_MESH_BATTERY_SRV_INIT(_get_handler)
Init parameters for a Generic Battery Server model instance.
- Parameters:
_get_handler – [in] Get handler function for the Battery state.
-
BT_MESH_MODEL_BATTERY_SRV(_srv)
Generic Battery Server model composition data entry.
- Parameters:
_srv – [in] Pointer to a Generic Battery Server model instance.
Functions
-
int bt_mesh_battery_srv_pub(struct bt_mesh_battery_srv *srv, struct bt_mesh_msg_ctx *ctx, const struct bt_mesh_battery_status *status)
Publish the Generic Battery Server model status.
Asynchronously publishes a Generic Battery status message with the configured publish parameters.
Note
This API is only used for publishing unprompted status messages. Response messages for get and set messages are handled internally.
- Parameters:
srv – [in] Server instance to publish on.
ctx – [in] Message context to send with, or NULL to send with the default publish parameters.
status – [in] Current status.
- Return values:
0 – Successfully published a Generic Battery Status message.
-EADDRNOTAVAIL – A message context was not provided and publishing is not configured.
-EAGAIN – The device has not been provisioned.
-
struct bt_mesh_battery_srv
- #include <gen_battery_srv.h>
Generic Battery Server instance. Should primarily be initialized with the BT_MESH_BATTERY_SRV_INIT macro.
Public Members
-
struct bt_mesh_model *model
Pointer to the model entry in the composition data.
-
struct bt_mesh_model_pub pub
Publication parameters.
-
void (*const get)(struct bt_mesh_battery_srv *srv, struct bt_mesh_msg_ctx *ctx, struct bt_mesh_battery_status *rsp)
Get the Battery state.
Note
This handler is mandatory.
- Param srv:
[in] Server instance to get the state of.
- Param ctx:
[in] Message context for the message that triggered the change, or NULL if the change is not coming from a message.
- Param rsp:
[out] Response structure to be filled. All fields are initialized to special unknown values before calling, so only states that have known values need to be filled.
-
struct bt_mesh_model *model
-
BT_MESH_BATTERY_SRV_INIT(_get_handler)