Generic OnOff Server

The Generic OnOff Server contains a single controllable On/Off state.

States

The Generic OnOff Server model contains the following state:

Generic OnOff: boolean

Generic boolean state representing an On/Off state. Your application is expected to hold the state memory and provide access to the state through the bt_mesh_onoff_srv_handlers handler structure.

Changes to the Generic OnOff state may include transition parameters. When transitioning to a new OnOff state:

  • The state should be on during the entire transition, regardless of the target state. This ensures that any bound non-binary states can have non-zero values during the transition. Any request to read out the current OnOff state while in a transition should report the current OnOff value being on.

  • The remaining_time parameter should be reported in milliseconds (including an optional delay).

If the transition parameters include a delay, the state must remain unchanged until the delay expires.

Extended models

None.

Persistent storage

None.

API documentation

Header file: include/bluetooth/mesh/gen_onoff_srv.h
Source file: subsys/bluetooth/mesh/gen_onoff_srv.c
group bt_mesh_onoff_srv

API for the Generic OnOff Server model.

Defines

BT_MESH_ONOFF_SRV_INIT(_handlers)

Init parameters for a Generic OnOff Server model instance.

Parameters:
  • _handlers[in] State access handlers to use in the model instance.

BT_MESH_MODEL_ONOFF_SRV(_srv)

Generic OnOff Server model composition data entry.

Parameters:

Functions

int bt_mesh_onoff_srv_pub(struct bt_mesh_onoff_srv *srv, struct bt_mesh_msg_ctx *ctx, const struct bt_mesh_onoff_status *status)

Publish the Generic OnOff Server model status.

Asynchronously publishes a Generic OnOff 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 OnOff Status message.

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

  • -EAGAIN – The device has not been provisioned.

struct bt_mesh_onoff_srv_handlers
#include <gen_onoff_srv.h>

Generic OnOff Server state access handlers.

Public Members

void (*const set)(struct bt_mesh_onoff_srv *srv, struct bt_mesh_msg_ctx *ctx, const struct bt_mesh_onoff_set *set, struct bt_mesh_onoff_status *rsp)

Set the OnOff state.

When a set message is received, the model publishes a status message, with the response set to rsp. When an acknowledged set message is received, the model also sends a response back to a client. If a state change is non-instantaneous, for example when bt_mesh_model_transition_time returns a nonzero value, the application is responsible for publishing a value of the OnOff state at the end of the transition.

Note

This handler is mandatory.

Param srv:

[in] Server instance to set 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 set:

[in] Parameters of the state change.

Param rsp:

[out] Response structure to be filled.

void (*const get)(struct bt_mesh_onoff_srv *srv, struct bt_mesh_msg_ctx *ctx, struct bt_mesh_onoff_status *rsp)

Get the OnOff 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.

struct bt_mesh_onoff_srv
#include <gen_onoff_srv.h>

Generic OnOff Server instance. Should primarily be initialized with the BT_MESH_ONOFF_SRV_INIT macro.

Public Members

struct bt_mesh_tid_ctx prev_transaction

Transaction ID tracker.

const struct bt_mesh_onoff_srv_handlers *handlers

Handler function structure.

struct bt_mesh_model *model

Access model pointer.

struct bt_mesh_model_pub pub

Publish parameters.

atomic_t flags

Internal flag state.