Scheduler Client

The Scheduler Client model remotely controls the state of a Scheduler Server model.

Unlike the Scheduler Server model, the Scheduler Client only creates a single model instance in the mesh composition data. The Scheduler Client can send messages to both the Scheduler Server and the Scheduler Setup Server, as long as it has the right application keys.

Action scheduling example

This simple example shows how the Scheduler Client can configure the Scheduler Server models managing the light system. Every year, and every working day throughout the year, the Scheduler Server will turn the light on at 8:00 and turn it off again at 16:00.

static int schedule_on_weekdays(enum bt_mesh_scheduler_action action,
                                uint8_t idx, uint8_t hour, uint8_t minute)
{
   const struct bt_mesh_schedule_entry entry = {
      .action = action,
      .minute = minute,
      .hour = hour,
      .day = BT_MESH_SCHEDULER_ANY_DAY,
      .month = (BT_MESH_SCHEDULER_JAN | BT_MESH_SCHEDULER_FEB |
                BT_MESH_SCHEDULER_MAR | BT_MESH_SCHEDULER_APR |
                BT_MESH_SCHEDULER_MAY | BT_MESH_SCHEDULER_JUN |
                BT_MESH_SCHEDULER_JUL | BT_MESH_SCHEDULER_AUG |
                BT_MESH_SCHEDULER_SEP | BT_MESH_SCHEDULER_OCT |
                BT_MESH_SCHEDULER_NOV | BT_MESH_SCHEDULER_DEC),
      .year = BT_MESH_SCHEDULER_ANY_YEAR,
      .day_of_week = (BT_MESH_SCHEDULER_MON | BT_MESH_SCHEDULER_TUE |
                      BT_MESH_SCHEDULER_WED | BT_MESH_SCHEDULER_THU |
                      BT_MESH_SCHEDULER_FRI),
   };

   return bt_mesh_scheduler_cli_action_set_unack(&scheduler_cli, NULL, idx, &entry);
}

static void schedule_office_lights(void)
{
   /* Turn lights on at 08:00 */
   (void)schedule_on_weekdays(BT_MESH_SCHEDULER_TURN_ON, 0, 8, 0);
   /* Turn lights off at 16:00 */
   (void)schedule_on_weekdays(BT_MESH_SCHEDULER_TURN_OFF, 1, 16, 0);
}

API documentation

Header file: include/bluetooth/mesh/scheduler_cli.h
Source file: subsys/bluetooth/mesh/scheduler_cli.c
group bt_mesh_scheduler_cli

API for the Scheduler Client model.

Defines

BT_MESH_MODEL_SCHEDULER_CLI(_cli)

Scheduler Client model composition data entry.

Parameters

Functions

int bt_mesh_scheduler_cli_get(struct bt_mesh_scheduler_cli *cli, struct bt_mesh_msg_ctx *ctx, uint16_t *rsp)

Get the current Schedule Register status.

This call is blocking if the rsp buffer is non-NULL. The response will always be passed to the bt_mesh_scheduler_cli::status_handler.

Parameters
  • cli[in] Scheduler client model.

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

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

Returns

  • 0 – Successfully got the Schedule Register status.

  • -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 or the request timed out without a response.

int bt_mesh_scheduler_cli_action_get(struct bt_mesh_scheduler_cli *cli, struct bt_mesh_msg_ctx *ctx, uint8_t idx, struct bt_mesh_schedule_entry *rsp)

Get the appropriate Scheduler Action status.

This call is blocking if the rsp buffer is non-NULL. The response will always be passed to the bt_mesh_scheduler_cli::action_status_handler.

Parameters
  • cli[in] Scheduler client model.

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

  • idx[in] Index of the Schedule Register entry to get.

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

Returns

  • 0 – Successfully got the Scheduler Action status.

  • -EINVAL – Invalid index.

  • -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 or the request timed out without a response.

int bt_mesh_scheduler_cli_action_set(struct bt_mesh_scheduler_cli *cli, struct bt_mesh_msg_ctx *ctx, uint8_t idx, const struct bt_mesh_schedule_entry *entry, struct bt_mesh_schedule_entry *rsp)

Set the appropriate Scheduler Action.

This call is blocking if the rsp buffer is non-NULL. The response will always be passed to the bt_mesh_scheduler_cli::action_status_handler.

Parameters
  • cli[in] Scheduler client model.

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

  • idx[in] Index of the Schedule Register entry to set.

  • entry[in] The entry of the Scheduler Register.

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

Returns

  • 0 – Successfully sent the set message and processed the response.

  • -EINVAL – Invalid parameters.

  • -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 or the request timed out without a response.

int bt_mesh_scheduler_cli_action_set_unack(struct bt_mesh_scheduler_cli *cli, struct bt_mesh_msg_ctx *ctx, uint8_t idx, const struct bt_mesh_schedule_entry *entry)

Set the appropriate Scheduler Action without requesting a response.

Parameters
  • cli[in] Scheduler client model.

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

  • idx[in] Index of the Schedule Register entry to set.

  • entry[in] The entry of the Scheduler Register.

Returns

  • 0 – Successfully sent the set message.

  • -EINVAL – Invalid parameters.

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

  • -EAGAIN – The device has not been provisioned.

struct bt_mesh_scheduler_cli
#include <scheduler_cli.h>

Scheduler client model instance.

Public Members

void (*status_handler)(struct bt_mesh_scheduler_cli *cli, struct bt_mesh_msg_ctx *ctx, uint16_t schedules)

Scheduler Status message callback.

Parameters
  • cli[in] Scheduler client model.

  • ctx[in] Message context parameters.

  • schedules[in] Received Scheduler Status.

void (*action_status_handler)(struct bt_mesh_scheduler_cli *cli, struct bt_mesh_msg_ctx *ctx, uint8_t idx, const struct bt_mesh_schedule_entry *action)

Scheduler Action Status message callback.

Parameters
  • cli[in] Scheduler client model.

  • ctx[in] Message context parameters.

  • idx[in] Index of the received action.

  • action[in] Received Scheduler action or NULL if there is only index in the reply.