MeshX 0.3
This repository provides an implementation for Bluetooth Low Energy (BLE) Mesh network nodes. The project allows you to create BLE mesh nodes that can communicate with each other, enabling the development of smart home solutions or other IoT-based applications.
Loading...
Searching...
No Matches
meshx_ble_mesh_light_srv.h File Reference

Header file for the MeshX BLE Mesh Light Server module. This file defines the data structures, function prototypes, and callback parameters for managing the Light Server models in a BLE Mesh network. It includes support for various lighting models such as Light CTL, HSL, xyL, and LC. More...

Include dependency graph for meshx_ble_mesh_light_srv.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  meshx_state_change_light_lightness_set_t
 
struct  meshx_state_change_light_lightness_linear_set_t
 
struct  meshx_state_change_light_lightness_default_set_t
 
struct  meshx_state_change_light_lightness_range_set_t
 
struct  meshx_state_change_light_ctl_set_t
 
struct  meshx_state_change_light_ctl_temperature_set_t
 
struct  meshx_state_change_light_ctl_temperature_range_set_t
 
struct  meshx_state_change_light_ctl_default_set_t
 
struct  meshx_state_change_light_hsl_set_t
 
struct  meshx_state_change_light_hsl_hue_set_t
 
struct  meshx_state_change_light_hsl_saturation_set_t
 
struct  meshx_state_change_light_hsl_default_set_t
 
struct  meshx_state_change_light_hsl_range_set_t
 
struct  meshx_state_change_light_xyl_set_t
 
struct  meshx_state_change_light_xyl_default_set_t
 
struct  meshx_state_change_light_xyl_range_set_t
 
struct  meshx_state_change_light_lc_mode_set_t
 
struct  meshx_state_change_light_lc_om_set_t
 
struct  meshx_state_change_light_lc_light_onoff_set_t
 
struct  meshx_state_change_light_lc_property_set_t
 
struct  meshx_state_change_sensor_status_t
 
union  meshx_lighting_server_state_change_t
 Lighting Server Model state change value union. More...
 
struct  meshx_lighting_server_cb_param
 
struct  meshx_light_ctl_srv_state
 
struct  meshx_light_ctl_srv
 Structure representing the Light CTL Server model. More...
 

Typedefs

typedef struct meshx_lighting_server_cb_param meshx_lighting_server_cb_param_t
 
typedef struct meshx_light_ctl_srv_state meshx_light_ctl_srv_state_t
 
typedef struct meshx_light_ctl_srv meshx_light_ctl_srv_t
 Structure representing the Light CTL Server model.
 

Functions

meshx_err_t meshx_plat_light_srv_init (void)
 Initialize the platform-specific Light Server.
 
meshx_err_t meshx_plat_light_ctl_setup_srv_create (meshx_ptr_t p_model, meshx_ptr_t *p_pub, meshx_ptr_t *p_ctl_srv)
 Creates and initializes a Light CTL (Color Temperature Lightness) Setup Server model instance.
 
meshx_err_t meshx_plat_light_ctl_srv_create (meshx_ptr_t p_model, meshx_ptr_t *p_pub, meshx_ptr_t *p_ctl_srv)
 Create a Light CTL Server instance.
 
meshx_err_t meshx_plat_light_srv_delete (meshx_ptr_t *p_pub, meshx_ptr_t *p_ctl_srv)
 Delete a Light CTL Server instance.
 
meshx_err_t meshx_plat_set_light_ctl_srv_state (meshx_ptr_t p_model, uint16_t delta_uv, uint16_t lightness, uint16_t temperature, uint16_t temp_range_max, uint16_t temp_range_min)
 Set the state of the Light CTL Server.
 
meshx_err_t meshx_plat_light_ctl_srv_restore (meshx_ptr_t p_model, uint16_t delta_uv, uint16_t lightness, uint16_t temperature, uint16_t temp_range_max, uint16_t temp_range_min)
 Restore the state of the Light CTL Server.
 
meshx_err_t meshx_plat_gen_light_srv_send_status (const meshx_model_t *p_model, const meshx_ctx_t *p_ctx, const meshx_lighting_server_state_change_t *state_change)
 Send a status message from the Light Server. This function constructs and sends a status message containing the current state of the Light Server.
 

Detailed Description

Header file for the MeshX BLE Mesh Light Server module. This file defines the data structures, function prototypes, and callback parameters for managing the Light Server models in a BLE Mesh network. It includes support for various lighting models such as Light CTL, HSL, xyL, and LC.

Copyright (c) 2024 - 2025 MeshX

  • Defines state change event structures for different lighting models.
  • Provides APIs for initializing, creating, deleting, and managing Light Server instances.
  • Supports Light CTL Server state management, including setting and restoring states.
  • Includes callback parameters for handling received lighting messages.
Author
Pranjal Chanda

Definition in file meshx_ble_mesh_light_srv.h.

Typedef Documentation

◆ meshx_light_ctl_srv_state_t

◆ meshx_light_ctl_srv_t

Structure representing the Light CTL Server model.

This structure contains the model and state information for the Light CTL Server.

◆ meshx_lighting_server_cb_param_t

Lighting Server Model callback parameters

Function Documentation

◆ meshx_plat_gen_light_srv_send_status()

meshx_err_t meshx_plat_gen_light_srv_send_status ( const meshx_model_t * p_model,
const meshx_ctx_t * p_ctx,
const meshx_lighting_server_state_change_t * state_change )

Send a status message from the Light Server. This function constructs and sends a status message containing the current state of the Light Server.

Parameters
[in]p_modelPointer to the Light Server model.
[in]p_ctxPointer to the context containing message information.
[in]state_changeThe state change data to be sent in the status message.
Returns
  • MESHX_SUCCESS: Successfully sent the status message.
  • MESHX_INVALID_ARG: Invalid argument provided.
  • MESHX_ERR_PLAT: Platform-specific error occurred.

Definition at line 194 of file esp_light_srv_model.c.

198{
199 if (!p_model || !p_ctx || !state_change)
200 {
201 return MESHX_INVALID_ARG;
202 }
204 static esp_ble_mesh_msg_ctx_t ctx;
205 const esp_ble_mesh_msg_ctx_t *pctx = (esp_ble_mesh_msg_ctx_t *)p_ctx->p_ctx;
206 if(pctx != NULL)
207 {
208 memcpy(&ctx, pctx, sizeof(esp_ble_mesh_msg_ctx_t));
209 }
210 meshx_plat_ctl_status_t ctl_status_union;
211 uint8_t ctl_status_pack_len = 0;
212
213 switch (p_ctx->opcode)
214 {
216 ctl_status_union.ctl_status.temperature = state_change->ctl_set.temperature;
217 ctl_status_union.ctl_status.lightness = state_change->ctl_set.lightness;
218 ctl_status_pack_len = sizeof(ctl_status_union.ctl_status);
219 break;
221 ctl_status_union.ctl_temp_status.temperature = state_change->ctl_temp_set.temperature;
222 ctl_status_union.ctl_temp_status.delta_uv = state_change->ctl_temp_set.delta_uv;
223 ctl_status_pack_len = sizeof(ctl_status_union.ctl_temp_status);
224 break;
226 ctl_status_union.ctl_default.delta_uv_def = state_change->ctl_default_set.delta_uv;
227 ctl_status_union.ctl_default.lightness_def = state_change->ctl_default_set.lightness;
228 ctl_status_union.ctl_default.temperature_def = state_change->ctl_default_set.temperature;
229 ctl_status_pack_len = sizeof(ctl_status_union.ctl_default);
230 break;
232 ctl_status_union.ctl_temp_range.status_code = MESHX_SUCCESS;
233 ctl_status_union.ctl_temp_range.range_min = state_change->ctl_temp_range_set.range_min;
234 ctl_status_union.ctl_temp_range.range_max = state_change->ctl_temp_range_set.range_max;
235 ctl_status_pack_len = sizeof(ctl_status_union.ctl_temp_range);
236 break;
237 default:
238 err = MESHX_INVALID_ARG;
239 }
240
241 ctx.net_idx = p_ctx->net_idx;
242 ctx.app_idx = p_ctx->app_idx;
243 ctx.addr = p_ctx->dst_addr;
244 ctx.send_ttl = ESP_BLE_MESH_TTL_DEFAULT;
245 ctx.send_cred = 0;
246 ctx.send_tag = BIT1;
247
248 esp_err_t esp_err = esp_ble_mesh_server_model_send_msg(p_model->p_model,
249 &ctx,
250 p_ctx->opcode,
251 ctl_status_pack_len,
252 (uint8_t *)&ctl_status_union);
253 if (esp_err)
254 {
255 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Mesh Model msg send failed (err: 0x%x)", esp_err);
256 return MESHX_ERR_PLAT;
257 }
258 MESHX_LOGD(MODULE_ID_MODEL_SERVER, "Mesh Model msg sent (opcode: 0x%04x, len: %d)", p_ctx->opcode, ctl_status_pack_len);
259
260 return err;
261}
union meshx_plat_ctl_status meshx_plat_ctl_status_t
Light CTL status packet.
#define MESHX_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS
#define MESHX_MODEL_OP_LIGHT_CTL_STATUS
#define MESHX_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS
#define MESHX_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:39
@ MESHX_SUCCESS
Definition meshx_err.h:40
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
@ MESHX_ERR_PLAT
Definition meshx_err.h:43
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:73
#define MESHX_LOGD(module_id, format,...)
Definition meshx_log.h:113
@ MODULE_ID_MODEL_SERVER
Definition module_id.h:30
meshx_ptr_t p_ctx
uint16_t dst_addr
meshx_ptr_t p_model
meshx_state_change_light_ctl_temperature_set_t ctl_temp_set
meshx_state_change_light_ctl_default_set_t ctl_default_set
meshx_state_change_light_ctl_temperature_range_set_t ctl_temp_range_set
meshx_state_change_light_ctl_set_t ctl_set
struct meshx_plat_ctl_status::@245236127353215275375207066165060111051263370136 ctl_default
struct meshx_plat_ctl_status::@056332017355315015251101121062125272154151302377 ctl_temp_status
struct meshx_plat_ctl_status::@113331121155070315153135031056271051132165372174 ctl_temp_range
struct meshx_plat_ctl_status::@120032367014025213103020351221177247351027370012 ctl_status
Here is the caller graph for this function:

◆ meshx_plat_light_ctl_setup_srv_create()

meshx_err_t meshx_plat_light_ctl_setup_srv_create ( meshx_ptr_t p_model,
meshx_ptr_t * p_pub,
meshx_ptr_t * p_ctl_srv )

Creates and initializes a Light CTL (Color Temperature Lightness) Setup Server model instance.

This function sets up the Light CTL Setup Server for a given model, configuring publication and server context pointers.

Parameters
[in]p_modelPointer to the parent model instance.
[out]p_pubPointer to the publication context to be initialized.
[out]p_ctl_srvPointer to the Light CTL Setup Server context to be initialized.
Returns
meshx_err_t Error code indicating the result of the operation.
  • MESHX_OK on success
  • Appropriate error code otherwise

Definition at line 293 of file esp_light_srv_model.c.

294{
295 if (!p_model || !p_pub || !p_ctl_srv)
296 return MESHX_INVALID_ARG;
297
299
300 err = meshx_plat_create_model_pub(p_pub, 1);
301 if (err)
302 return meshx_plat_del_model_pub(p_pub);
303
305 if (!*p_ctl_srv)
306 return MESHX_NO_MEM;
307
308 /* SIG CTL Setup Server initialisation */
309 memcpy(p_model, &light_ctl_setup_sig_template, sizeof(MESHX_MODEL));
310
311 ((MESHX_LIGHT_CTL_SETUP_SRV *)*p_ctl_srv)->rsp_ctrl.get_auto_rsp = ESP_BLE_MESH_SERVER_AUTO_RSP;
312 ((MESHX_LIGHT_CTL_SETUP_SRV *)*p_ctl_srv)->rsp_ctrl.set_auto_rsp = ESP_BLE_MESH_SERVER_AUTO_RSP;
313
315 if (!((MESHX_LIGHT_CTL_SETUP_SRV *)*p_ctl_srv)->state)
316 {
317 MESHX_FREE(*p_ctl_srv);
318 return MESHX_NO_MEM;
319 }
320
321 ((MESHX_LIGHT_CTL_SETUP_SRV *)*p_ctl_srv)->state->temperature_range_max = 0;
322 ((MESHX_LIGHT_CTL_SETUP_SRV *)*p_ctl_srv)->state->temperature_range_min = 0;
323
324 ((MESHX_MODEL *)p_model)->user_data = *p_ctl_srv;
325
326 meshx_ptr_t *temp = (meshx_ptr_t *)&((MESHX_MODEL *)p_model)->pub;
327
328 *temp = *p_pub;
329
330 return err;
331}
static const MESHX_MODEL light_ctl_setup_sig_template
Template for CTL Setup Srv SIG model initialization.
meshx_err_t meshx_plat_del_model_pub(meshx_ptr_t *p_pub)
Deletes the model and publication objects.
meshx_err_t meshx_plat_create_model_pub(meshx_ptr_t *p_pub, uint16_t nmax)
Creates and initializes model and publication structures.
void * meshx_ptr_t
#define MESHX_CALOC
Definition meshx_err.h:28
@ MESHX_NO_MEM
Definition meshx_err.h:44
#define MESHX_FREE
Definition meshx_err.h:32
#define MESHX_LIGHT_CTL_STATE
#define MESHX_LIGHT_CTL_SETUP_SRV
#define MESHX_MODEL
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_plat_light_ctl_srv_create()

meshx_err_t meshx_plat_light_ctl_srv_create ( meshx_ptr_t p_model,
meshx_ptr_t * p_pub,
meshx_ptr_t * p_ctl_srv )

Create a Light CTL Server instance.

This function initializes and allocates resources for a Light CTL Server model.

Parameters
[in]p_modelPointer to the model instance.
[out]p_pubPointer to the publication context.
[out]p_ctl_srvPointer to the Light CTL Server instance.
Returns
  • MESHX_SUCCESS on success.
  • Appropriate error code on failure.

Definition at line 333 of file esp_light_srv_model.c.

334{
335 if (!p_model || !p_pub || !p_ctl_srv)
336 return MESHX_INVALID_ARG;
337
339
340 err = meshx_plat_create_model_pub(p_pub, 1);
341 if (err)
342 return meshx_plat_del_model_pub(p_pub);
343
344 *p_ctl_srv = (MESHX_LIGHT_CTL_SRV *)MESHX_CALOC(1, sizeof(MESHX_LIGHT_CTL_SRV));
345 if (!*p_ctl_srv)
346 return MESHX_NO_MEM;
347
348 /* SIG ON OFF initialisation */
349
350 memcpy(p_model, &light_ctl_sig_template, sizeof(MESHX_MODEL));
351
352 ((MESHX_LIGHT_CTL_SRV *)*p_ctl_srv)->rsp_ctrl.get_auto_rsp = ESP_BLE_MESH_SERVER_AUTO_RSP;
353 ((MESHX_LIGHT_CTL_SRV *)*p_ctl_srv)->rsp_ctrl.set_auto_rsp = ESP_BLE_MESH_SERVER_AUTO_RSP;
354
355 ((MESHX_LIGHT_CTL_SRV *)*p_ctl_srv)->state = (MESHX_LIGHT_CTL_STATE *)MESHX_CALOC(1, sizeof(MESHX_LIGHT_CTL_STATE));
356 if (!((MESHX_LIGHT_CTL_SRV *)*p_ctl_srv)->state)
357 {
358 MESHX_FREE(*p_ctl_srv);
359 return MESHX_NO_MEM;
360 }
361
362 ((MESHX_LIGHT_CTL_SRV *)*p_ctl_srv)->state->temperature = 0;
363 ((MESHX_LIGHT_CTL_SRV *)*p_ctl_srv)->state->lightness = 0;
364 ((MESHX_LIGHT_CTL_SRV *)*p_ctl_srv)->state->delta_uv = 0;
365 ((MESHX_LIGHT_CTL_SRV *)*p_ctl_srv)->state->temperature_range_min = 0;
366 ((MESHX_LIGHT_CTL_SRV *)*p_ctl_srv)->state->temperature_range_max = 0;
367
368 ((MESHX_MODEL *)p_model)->user_data = *p_ctl_srv;
369
370 meshx_ptr_t *temp = (meshx_ptr_t *)&((MESHX_MODEL *)p_model)->pub;
371
372 *temp = *p_pub;
373
374 return err;
375}
static const MESHX_MODEL light_ctl_sig_template
Template for CTL Setup Srv SIG model initialization.
#define MESHX_LIGHT_CTL_SRV
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_plat_light_ctl_srv_restore()

meshx_err_t meshx_plat_light_ctl_srv_restore ( meshx_ptr_t p_model,
uint16_t delta_uv,
uint16_t lightness,
uint16_t temperature,
uint16_t temp_range_max,
uint16_t temp_range_min )

Restore the state of the Light CTL Server.

This function restores the state of the Light CTL Server with the provided parameters.

Parameters
[in]p_modelPointer to the model instance.
[in]delta_uvDelta UV value.
[in]lightnessLightness value.
[in]temperatureTemperature value.
[in]temp_range_maxMaximum temperature range.
[in]temp_range_minMinimum temperature range.
Returns
  • MESHX_SUCCESS on success.
  • Appropriate error code on failure.

Definition at line 398 of file esp_light_srv_model.c.

404{
406 p_model,
407 delta_uv,
408 lightness,
409 temperature,
410 temp_range_max,
411 temp_range_min
412 );
413}
meshx_err_t meshx_plat_set_light_ctl_srv_state(meshx_ptr_t p_model, uint16_t delta_uv, uint16_t lightness, uint16_t temperature, uint16_t temp_range_max, uint16_t temp_range_min)
Set the state of the Light CTL Server.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_plat_light_srv_delete()

meshx_err_t meshx_plat_light_srv_delete ( meshx_ptr_t * p_pub,
meshx_ptr_t * p_ctl_srv )

Delete a Light CTL Server instance.

This function releases resources associated with a Light CTL Server model.

Parameters
[in,out]p_pubPointer to the publication context to be deleted.
[in,out]p_ctl_srvPointer to the Light CTL Server instance to be deleted.
Returns
  • MESHX_SUCCESS on success.
  • Appropriate error code on failure.

Definition at line 277 of file esp_light_srv_model.c.

278{
279 if (p_ctl_srv)
280 {
281 if(*p_ctl_srv && ((MESHX_LIGHT_CTL_SRV *)*p_ctl_srv)->state)
282 {
283 MESHX_FREE(((MESHX_LIGHT_CTL_SRV *)*p_ctl_srv)->state);
284 ((MESHX_LIGHT_CTL_SRV *)*p_ctl_srv)->state = NULL;
285 }
286 MESHX_FREE(*p_ctl_srv);
287 *p_ctl_srv = NULL;
288 }
289
290 return meshx_plat_del_model_pub(p_pub);
291}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_plat_light_srv_init()

meshx_err_t meshx_plat_light_srv_init ( void )

Initialize the platform-specific Light Server.

This function sets up the necessary resources for the Light Server.

Returns
  • MESHX_SUCCESS on success.
  • Appropriate error code on failure.

Definition at line 263 of file esp_light_srv_model.c.

264{
265 /* Register callback for enabling Sending of Model Msg From MeshX to BLE Layer */
267 /* Register the ESP Generic Server callback */
268 esp_err_t esp_err = esp_ble_mesh_register_lighting_server_callback(
270 );
271 if (esp_err != ESP_OK)
272 err = MESHX_ERR_PLAT;
273
274 return err;
275}
static void meshx_ble_lightness_server_cb(MESHX_LIGHT_SRV_CB_EVT event, MESHX_LIGHT_SRV_CB_PARAM *param)
Callback function for BLE Mesh Lightness Server events.
#define MESHX_LIGHT_SRV_CB
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_plat_set_light_ctl_srv_state()

meshx_err_t meshx_plat_set_light_ctl_srv_state ( meshx_ptr_t p_model,
uint16_t delta_uv,
uint16_t lightness,
uint16_t temperature,
uint16_t temp_range_max,
uint16_t temp_range_min )

Set the state of the Light CTL Server.

This function updates the state of the Light CTL Server with the provided parameters.

Parameters
[in]p_modelPointer to the model instance.
[in]delta_uvDelta UV value.
[in]lightnessLightness value.
[in]temperatureTemperature value.
[in]temp_range_maxMaximum temperature range.
[in]temp_range_minMinimum temperature range.
Returns
  • MESHX_SUCCESS on success.
  • Appropriate error code on failure.

Definition at line 377 of file esp_light_srv_model.c.

384{
385 if (!p_model)
386 return MESHX_INVALID_ARG;
387
388 MESHX_MODEL *model = (MESHX_MODEL *)p_model;
389 MESHX_LIGHT_CTL_SRV *srv = (MESHX_LIGHT_CTL_SRV *)model->user_data;
390 srv->state->delta_uv = delta_uv;
391 srv->state->lightness = lightness;
392 srv->state->temperature = temperature;
393 srv->state->temperature_range_min = temp_range_min;
394 srv->state->temperature_range_max = temp_range_max;
395
396 return MESHX_SUCCESS;
397}
Here is the caller graph for this function: