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
esp_cfg_srv_model.c
Go to the documentation of this file.
1
15
17
18/* Global variable for Configuration Server parameters */
20 /* 3 transmissions with 20ms interval */
21 .net_transmit = ESP_BLE_MESH_TRANSMIT(2, 20),
22 .relay = ESP_BLE_MESH_RELAY_ENABLED,
23 .relay_retransmit = ESP_BLE_MESH_TRANSMIT(2, 20),
24 .beacon = ESP_BLE_MESH_BEACON_ENABLED,
25#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
26 .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_ENABLED,
27#else
28 .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_NOT_SUPPORTED,
29#endif
30#if defined(CONFIG_BLE_MESH_FRIEND)
31 .friend_state = ESP_BLE_MESH_FRIEND_ENABLED,
32#else
33 .friend_state = ESP_BLE_MESH_FRIEND_NOT_SUPPORTED,
34#endif
35 .default_ttl = 7,
36};
37
39 .model_id = MESHX_MODEL_ID_CONFIG_SRV,
40 .user_data = &meshx_config_server_instance,
41 .keys = ESP_BLE_MESH_MODEL_KEYS_UNUSED,
42 .groups = ESP_BLE_MESH_MODEL_GROUPS_UNASSIGNED,
43};
44
54static void meshx_ble_mesh_config_server_cb(esp_ble_mesh_cfg_server_cb_event_t event,
55 const esp_ble_mesh_cfg_server_cb_param_t *param)
56{
57 if (event != ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT)
58 return;
59
61 {
62 .ctx =
63 {
64 .net_idx = param->ctx.net_idx,
65 .app_idx = param->ctx.app_idx,
66 .dst_addr = param->ctx.recv_dst,
67 .src_addr = param->ctx.addr,
68 .opcode = param->ctx.recv_op,
69 .p_ctx = (meshx_ptr_t) &param->ctx
70 },
71 .model =
72 {
73 .model_id = param->model->model_id,
74 .el_id = param->model->element_idx,
75 .p_model = param->model
76 }
77 };
78 MESHX_LOGD(MODULE_ID_MODEL_SERVER, "ele: %d", pub_param.model.el_id);
79 /* Copy all the status msg from the BLE layer */
80 memcpy(&pub_param.state_change,
81 &param->value.state_change,
83
87 &pub_param,
88 sizeof(pub_param));
89 if (err)
90 {
91 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Error publishing control task msg (Err: 0x%x)", err);
92 }
93}
94
96{
97 esp_err_t err = esp_ble_mesh_register_config_server_callback(
98 (esp_ble_mesh_cfg_server_cb_t)&meshx_ble_mesh_config_server_cb);
99 if (err)
100 {
101 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Error plat registering config server (Err: 0x%x)", err);
102 return MESHX_ERR_PLAT;
103 }
104 return MESHX_SUCCESS;
105}
106
108{
109 if (p_conf_srv == NULL)
110 {
111 return MESHX_INVALID_ARG;
112 }
113 /* Return the pointer to the configuration server instance */
114 *p_conf_srv = &meshx_config_server_instance;
115
116 return MESHX_SUCCESS;
117}
118
120{
121 if (p_model == NULL)
122 {
123 return MESHX_INVALID_ARG;
124 }
125 /* Return the pointer to the configuration server model */
126 memcpy(p_model, &meshx_config_server_model, sizeof(meshx_config_server_model));
127 return MESHX_SUCCESS;
128}
static MESHX_CFG_SRV meshx_config_server_instance
static MESHX_MODEL meshx_config_server_model
meshx_err_t meshx_plat_config_srv_init(void)
Initializes the MeshX platform configuration server.
meshx_err_t meshx_plat_get_config_srv_instance(meshx_ptr_t *p_conf_srv)
Retrieve the instance of the BLE Mesh configuration server.
static void meshx_ble_mesh_config_server_cb(esp_ble_mesh_cfg_server_cb_event_t event, const esp_ble_mesh_cfg_server_cb_param_t *param)
BLE Mesh Configuration Server callback function.
meshx_err_t meshx_plat_get_config_srv_model(meshx_ptr_t p_model)
Retrieves the configuration server model for the BLE Mesh.
void * meshx_ptr_t
#define MESHX_MODEL_ID_CONFIG_SRV
BLE Mesh models related Model ID and Opcode definitions.
Header file for MeshX BLE Mesh Configuration Server.
struct meshx_config_srv_cb_param meshx_config_srv_cb_param_t
@ CONTROL_TASK_MSG_CODE_FRM_BLE
meshx_err_t control_task_msg_publish(control_task_msg_code_t msg_code, control_task_msg_evt_t msg_evt, const void *msg_evt_params, size_t sizeof_msg_evt_params)
Publish a control task message.
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
#define MESHX_MODEL
#define MESHX_CFG_SRV
@ MODULE_ID_MODEL_SERVER
Definition module_id.h:30
meshx_cfg_srv_state_change_t state_change
Configuration Server model state change value union.