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);
}
Extended models
None.
Persistent storage
None.
Shell commands
The Bluetooth Mesh shell subsystem provides a set of commands to interact with the Scheduler Client model instantiated on a device.
To make these commands available, enable the following Kconfig options:
- mesh models sched instance get-all
Print all instances of the Scheduler Client model on the device.
- mesh models sched instance set <ElemIdx>
Select the Scheduler 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 sched get
Get the current Schedule Register status.
- mesh models sched action-get <Idx>
Get the appropriate Scheduler Action status.
Idx
- Index of the Schedule Register entry to get.
- mesh models sched action-ctx-set <Year> <Month> <Day> <Hour> <Minute> <Second> <DayOfWeek> <Action> <TransTime(ms)> <SceneNumber>
Set the appropriate Scheduler Action. Used in combination with
mesh models sched action-set
ormesh models sched action-set-unack
.Year
- Two last digits of the scheduled year for the action, or 0x64 for any year.Month
- Scheduled month for the action.Day
- Scheduled day of the month for the action.Hour
- Scheduled hour for the action.Minute
- Scheduled minute for the action.Second
- Scheduled second for the action.DayOfWeek
- Scheduled days of the week for the action.Action
- Action to be performed at the scheduled time.TransTime
- Transition time for this action in milliseconds.SceneNumber
- Scene number to be used for some actions.
- mesh models sched action-set <Idx>
Send the current Scheduler Action context and wait for a response.
Idx
- Index of the Schedule Register entry to set.
- mesh models sched action-set-unack <Idx>
Send the current Scheduler Action context without requesting a response.
Idx
- Index of the Schedule Register entry to set.
API documentation
include/bluetooth/mesh/scheduler_cli.h
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:
_cli – [in] Pointer to a Scheduler Client model instance.
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.
- Return values:
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.
-ETIMEDOUT – 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.
- Return values:
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.
-ETIMEDOUT – 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.
- Return values:
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.
-ETIMEDOUT – 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.
- Return values:
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.
- Param cli:
[in] Scheduler client model.
- Param ctx:
[in] Message context parameters.
- Param 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.
- Param cli:
[in] Scheduler client model.
- Param ctx:
[in] Message context parameters.
- Param idx:
[in] Index of the received action.
- Param action:
[in] Received Scheduler action or NULL if there is only index in the reply.
-
void (*status_handler)(struct bt_mesh_scheduler_cli *cli, struct bt_mesh_msg_ctx *ctx, uint16_t schedules)
-
BT_MESH_MODEL_SCHEDULER_CLI(_cli)