Generic OnOff Client

The Generic OnOff Client model remotely controls the state of a Generic OnOff Server model.

Extended models

None.

Persistent storage

None.

Shell commands

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

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

mesh models onoff instance get-all

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

mesh models onoff instance set <ElemIdx>

Select the Generic OnOff 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 onoff get

Get the OnOff state value of the bound server.

mesh models onoff set <OnOff> [TransTime(ms) [Delay(ms)]]

Set the OnOff state value of the server and wait for a response.

  • OnOff - OnOff state value to set. Use on, enable, or any non-zero value to enable the state.

  • TransTime - If present, defines the transition time in the message in milliseconds.

  • Delay - If present, defines the delay in the message in milliseconds.

mesh models onoff set-unack <onOff> [TransTime(ms) [Delay(ms)]]

Set the OnOff state value of the server without requesting a response.

  • OnOff - OnOff state value to set. Use on, enable, or any non-zero value to enable the state.

  • TransTime - If present, defines the transition time in the message in milliseconds.

  • Delay - If present, defines the delay in the message in milliseconds.

API documentation

Header file: include/bluetooth/mesh/gen_onoff_cli.h
Source file: subsys/bluetooth/mesh/gen_onoff_cli.c
group bt_mesh_onoff_cli

API for the Generic OnOff Client model.

Defines

BT_MESH_ONOFF_CLI_INIT(_status_handler)

Initialization parameters for a Generic OnOff Client model instance.

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

BT_MESH_MODEL_ONOFF_CLI(_cli)

Generic OnOff Client model composition data entry.

Parameters:

Functions

int bt_mesh_onoff_cli_get(struct bt_mesh_onoff_cli *cli, struct bt_mesh_msg_ctx *ctx, struct bt_mesh_onoff_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_onoff_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.

int bt_mesh_onoff_cli_set(struct bt_mesh_onoff_cli *cli, struct bt_mesh_msg_ctx *ctx, const struct bt_mesh_onoff_set *set, struct bt_mesh_onoff_status *rsp)

Set the OnOff state in the 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_onoff_cli::status_handler callback.

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

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

  • set[in] New OnOff parameters to set. set::transition can either point to a transition structure, or be left to NULL to use the default transition parameters on the server.

  • 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.

int bt_mesh_onoff_cli_set_unack(struct bt_mesh_onoff_cli *cli, struct bt_mesh_msg_ctx *ctx, const struct bt_mesh_onoff_set *set)

Set the OnOff state in the srv without requesting a response.

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

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

  • set[in] New OnOff parameters to set. set::transition can either point to a transition structure, or be left to NULL to use the default transition parameters on the server.

Return values:
  • 0 – Successfully sent the message.

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

  • -EAGAIN – The device has not been provisioned.

struct bt_mesh_onoff_cli
#include <gen_onoff_cli.h>

Generic OnOff Client structure.

Should be initialized with the BT_MESH_ONOFF_CLI_INIT macro.

Public Members

void (*const status_handler)(struct bt_mesh_onoff_cli *cli, struct bt_mesh_msg_ctx *ctx, const struct bt_mesh_onoff_status *status)

OnOff status message handler.

Param cli:

[in] Client that received the status message.

Param ctx:

[in] Context of the incoming message.

Param status:

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

uint8_t tid

Current Transaction ID.

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

Access model pointer.