MeshX 0.4
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_api.h
Go to the documentation of this file.
1/**
2 * Copyright © 2024 - 2025 MeshX
3 *
4 * @file meshx_api.h
5 * @brief This file contains the API definitions for the MeshX application.
6 *
7 * The MeshX API provides functions and structures to interact with the BLE Mesh application.
8 * It includes message types, payload structures, and callback function definitions.
9 *
10 * @author Pranjal Chanda
11 */
12
13#ifndef __MESHX_API_H__
14#define __MESHX_API_H__
15
16#include "unit_test.h"
17#include <meshx_common.h>
18#include <meshx_control_task.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#define MESHX_APP_API_MSG_MAX_SIZE sizeof(meshx_data_payload_t)
26
27/* MeshX Function ID Relay Server */
28#define MESHX_ELEMENT_FUNC_ID_RELAY_SERVER_ONN_OFF 0x00
29
30/* MeshX Function ID Light CWWW Server */
31#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_SERVER_ONN_OFF 0x00
32#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_SERVER_CTL 0x01
33
34/* MeshX Function ID Light HSL Server */
35#define MESHX_ELEMENT_FUNC_ID_LIGHT_HSL_SERVER_ONN_OFF 0x00
36#define MESHX_ELEMENT_FUNC_ID_LIGHT_HSL_SERVER_HSL 0x01
37
38/* MeshX Function ID Light CWWW Client */
39#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_CLIENT_ONN_OFF 0x00
40#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_CLIENT_CTL 0x01
41
42/* MeshX Function ID Sensor Server */
43#define MESHX_ELEMENT_FUNC_ID_SENSOR_SERVER_DATA 0x00
44
45/**
46 * @brief Enumeration of BLE Mesh application API message types.
47 */
48typedef enum meshx_api_type
49{
50 MESHX_API_TYPE_DATA = CONTROL_TASK_MSG_EVT_DATA, /**< Data message : All msg rekated to BLE mesh elements */
51 MESHX_API_TYPE_CTRL = CONTROL_TASK_MSG_EVT_CTRL, /**< Control message : All msg related to System control */
53
54
55/**
56 * @brief Structure defines the payload for MESHX_ELEMENT_TYPE_RELAY_SERVER
57 */
62
63/**
64 * @brief Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_CWWW_SERVER
65 */
67{
68 union
69 {
70 struct
71 {
72 uint8_t state;
74 struct
75 {
76 uint16_t lightness;
77 uint16_t temperature;
78 uint16_t delta_uv;
84
85/**
86 * @brief Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_HSL_SERVER
87 */
89{
90 union
91 {
92 struct
93 {
94 uint8_t state;
96 struct
97 {
98 uint16_t lightness;
99 uint16_t hue;
100 uint16_t saturation;
104
105/**
106 * @brief Structure defines the payload for MESHX_ELEMENT_TYPE_SENSOR_SERVER
107 */
114
115/**
116 * @brief Structure defines the payload for MESHX_ELEMENT_TYPE_RELAY_CLIENT
117 */
123
124/**
125 * @brief Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_CWWW_CLIENT
126 */
128{
129 uint8_t err_code;
130 union
131 {
132 struct
133 {
134 uint8_t state;
136 struct
137 {
138 uint16_t lightness;
139 uint16_t temperature;
140 uint16_t delta_uv;
146/**
147 * @brief Structure for the BLE Mesh application control message.
148 *
149 * This structure defines the BLE Mesh application control payloads.
150 *
151 */
161
162/**
163 * @brief Structure defines the payload for meshx_ctrl_payload
164 */
166{
167 struct {
168 uint16_t net_idx;
169 uint16_t addr;
170 uint8_t device_uuid[16];
172 struct {
173 uint8_t reason;
175 uint32_t reserved;
177
178
179/**
180 * @brief Structure for the BLE Mesh application element message header.
181 */
183{
184 uint16_t element_id; /* Element ID */
185 uint16_t element_type; /* meshx_element_type_t */
186 uint16_t func_id; /* Functionality number */
187 uint16_t msg_len; /* Length of the message */
189
190/**
191 * @brief Structure for the BLE Mesh application control message header.
192 *
193 * This structure defines the header for BLE Mesh application control messages.
194 *
195 */
197{
198 uint16_t evt_id; /* Event */
199 uint16_t reserved; /* Reserved */
201
202/**
203 * @brief Structure for the BLE Mesh application API message.
204 *
205 * This structure defines the BLE Mesh application API message.
206 *
207 */
218
219/**
220 * @brief BLE Mesh application callback function.
221 *
222 * This function is the BLE Mesh application callback function.
223 *
224 * @param[in] msg_hdr Pointer to the BLE Mesh application message header.
225 * @param[in] msg Pointer to the message.
226 *
227 * @return MESHX_SUCCESS on success, error code otherwise.
228 */
230
231/**
232 * @brief BLE Mesh application control callback function.
233 *
234 * This function is the BLE Mesh application control callback function.
235 *
236 * @param[in] msg_hdr Pointer to the BLE Mesh application control message header.
237 * @param[in] msg Pointer to the message.
238 *
239 * @return MESHX_SUCCESS on success, error code otherwise.
240 */
242
243/**
244 * @brief Sends a message to the BLE Mesh application.
245 *
246 * This function sends a message to the BLE Mesh application.
247 *
248 * @param[in] element_id The element ID.
249 * @param[in] element_type The element type.
250 * @param[in] func_id The function ID.
251 * @param[in] msg_len The message length.
252 * @param[in] msg Pointer to the message.
253 *
254 * @return MESHX_SUCCESS on success, error code otherwise.
255 */
256meshx_err_t meshx_send_msg_to_app(uint16_t element_id, uint16_t element_type, uint16_t func_id, uint16_t msg_len, const void *msg);
257
258/**
259 * @brief Sends a control message to the BLE Mesh application.
260 *
261 * This function sends a control message to the BLE Mesh application.
262 *
263 * @param[in] evt The event ID.
264 * @param[in] msg_len The message length.
265 * @param[in] msg Pointer to the message.
266 *
267 * @return MESHX_SUCCESS on success, error code otherwise.
268 */
269meshx_err_t meshx_send_ctrl_msg_to_app(meshx_ctrl_evt_t evt, uint16_t msg_len, const void *msg);
270
271/**
272 * @brief Sends a message to the element
273 *
274 * This function sends a message to the element from BLE mesh Application
275 *
276 * @param[in] element_id The element ID.
277 * @param[in] element_type The element type.
278 * @param[in] func_id The function ID.
279 * @param[in] msg_len The message length.
280 * @param[in] msg Pointer to the message.
281 *
282 * @return MESHX_SUCCESS on success, error code otherwise.
283 */
284meshx_err_t meshx_send_msg_to_element(uint16_t element_id, uint16_t element_type, uint16_t func_id, uint16_t msg_len, const void *msg);
285
286/**
287 * @brief Registers the BLE Mesh application callback.
288 *
289 * This function registers the BLE Mesh application data path callback.
290 *
291 * @param[in] cb Pointer to the application callback.
292 *
293 * @return MESHX_SUCCESS on success, error code otherwise.
294 */
296
297/**
298 * @brief Registers the BLE Mesh application control callback.
299 *
300 * This function registers the BLE Mesh application control callback.
301 *
302 * @param[in] cb Pointer to the control callback.
303 *
304 * @return MESHX_SUCCESS on success, error code otherwise.
305 */
307
308/**
309 * @brief Get the network key identifier.
310 * @return uint16_t The network key identifier.
311 */
312uint16_t meshx_get_net_key_id(void);
313
314#ifdef __cplusplus
315} /* extern "C" */
316#endif
317
318#endif /* __MESHX_API_H__ */
union meshx_data_payload meshx_data_payload_t
Structure for the BLE Mesh application control message.
struct meshx_api_sensor_server_evt meshx_api_sensor_server_evt_t
Structure defines the payload for MESHX_ELEMENT_TYPE_SENSOR_SERVER.
union meshx_ctrl_payload meshx_ctrl_payload_t
Structure defines the payload for meshx_ctrl_payload.
meshx_err_t(* meshx_app_data_cb_t)(const meshx_app_element_msg_header_t *msg_hdr, const meshx_data_payload_t *msg)
BLE Mesh application callback function.
Definition meshx_api.h:229
struct meshx_ctrl_msg_header meshx_ctrl_msg_header_t
Structure for the BLE Mesh application control message header.
struct meshx_app_element_msg_header meshx_app_element_msg_header_t
Structure for the BLE Mesh application element message header.
meshx_api_type
Enumeration of BLE Mesh application API message types.
Definition meshx_api.h:49
@ MESHX_API_TYPE_DATA
Definition meshx_api.h:50
@ MESHX_API_TYPE_CTRL
Definition meshx_api.h:51
enum meshx_api_type meshx_api_type_t
Enumeration of BLE Mesh application API message types.
meshx_err_t meshx_send_msg_to_app(uint16_t element_id, uint16_t element_type, uint16_t func_id, uint16_t msg_len, const void *msg)
Sends a message to the BLE Mesh application.
Definition meshx_api.c:128
struct meshx_api_relay_client_state meshx_api_relay_client_evt_t
Structure defines the payload for MESHX_ELEMENT_TYPE_RELAY_CLIENT.
struct meshx_api_relay_server_evt meshx_api_relay_server_evt_t
Structure defines the payload for MESHX_ELEMENT_TYPE_RELAY_SERVER.
meshx_err_t(* meshx_app_ctrl_cb_t)(const meshx_ctrl_msg_header_t *msg_hdr, const meshx_ctrl_payload_t *msg)
BLE Mesh application control callback function.
Definition meshx_api.h:241
struct meshx_app_api_msg meshx_app_api_msg_t
Structure for the BLE Mesh application API message.
meshx_err_t meshx_send_msg_to_element(uint16_t element_id, uint16_t element_type, uint16_t func_id, uint16_t msg_len, const void *msg)
Sends a message to the element.
Definition meshx_api.c:182
meshx_err_t meshx_app_reg_element_callback(meshx_app_data_cb_t cb)
Registers the BLE Mesh application callback.
Definition meshx_api.c:206
meshx_err_t meshx_send_ctrl_msg_to_app(meshx_ctrl_evt_t evt, uint16_t msg_len, const void *msg)
Sends a control message to the BLE Mesh application.
Definition meshx_api.c:154
struct meshx_api_light_hsl_server_evt meshx_api_light_hsl_server_evt_t
Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_HSL_SERVER.
struct meshx_api_light_cwww_server_evt meshx_api_light_cwww_server_evt_t
Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_CWWW_SERVER.
struct meshx_api_light_cwww_client_evt meshx_api_light_cwww_client_evt_t
Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_CWWW_CLIENT.
uint16_t meshx_get_net_key_id(void)
Get the network key identifier.
Definition meshx.c:316
meshx_err_t meshx_app_reg_system_events_callback(meshx_app_ctrl_cb_t cb)
Registers the BLE Mesh application control callback.
Definition meshx_api.c:234
#define MESHX_APP_API_MSG_MAX_SIZE
Definition meshx_api.h:25
Header file for the MeshX BLE Mesh Sensor Server module.
Common application definitions and includes for BLE Mesh Node.
meshx_ctrl_evt_t
Enumeration for the BLE Mesh application control event.
Definition meshx_common.h:31
Header file for the control task in the BLE mesh node application.
CONTROL_TASK_MSG_EVT_CTRL
Definition meshx_control_task.h:89
CONTROL_TASK_MSG_EVT_DATA
Definition meshx_control_task.h:88
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_CWWW_CLIENT.
Definition meshx_api.h:128
uint8_t err_code
Definition meshx_api.h:129
uint16_t delta_uv
Definition meshx_api.h:140
uint16_t temperature
Definition meshx_api.h:139
union meshx_api_light_cwww_client_evt::@010331215225145076254176237210306046131140170171 state_change
uint16_t temp_range_min
Definition meshx_api.h:141
uint16_t temp_range_max
Definition meshx_api.h:142
struct meshx_api_light_cwww_client_evt::@010331215225145076254176237210306046131140170171::@074174003215102134322053141270100354144151177356 on_off
struct meshx_api_light_cwww_client_evt::@010331215225145076254176237210306046131140170171::@376020317200137254005016072103236264206161124021 ctl
uint16_t lightness
Definition meshx_api.h:138
uint8_t state
Definition meshx_api.h:134
Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_CWWW_SERVER.
Definition meshx_api.h:67
uint16_t lightness
Definition meshx_api.h:76
union meshx_api_light_cwww_server_evt::@257165005032013366004013204037032016036030275264 state_change
uint16_t delta_uv
Definition meshx_api.h:78
struct meshx_api_light_cwww_server_evt::@257165005032013366004013204037032016036030275264::@375004001161356005102054253202024137247030164222 on_off
uint16_t temp_range_min
Definition meshx_api.h:79
uint16_t temp_range_max
Definition meshx_api.h:80
struct meshx_api_light_cwww_server_evt::@257165005032013366004013204037032016036030275264::@245341060156102221224175046143367317210200103050 ctl
uint16_t temperature
Definition meshx_api.h:77
uint8_t state
Definition meshx_api.h:72
Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_HSL_SERVER.
Definition meshx_api.h:89
uint16_t lightness
Definition meshx_api.h:98
union meshx_api_light_hsl_server_evt::@347235105244230326232000270243372246073133053316 state_change
uint8_t state
Definition meshx_api.h:94
struct meshx_api_light_hsl_server_evt::@347235105244230326232000270243372246073133053316::@202375373323027037070222212050326072162342057303 on_off
uint16_t saturation
Definition meshx_api.h:100
uint16_t hue
Definition meshx_api.h:99
struct meshx_api_light_hsl_server_evt::@347235105244230326232000270243372246073133053316::@153162234125000074275266213156212277206313354032 hsl
Structure defines the payload for MESHX_ELEMENT_TYPE_RELAY_CLIENT.
Definition meshx_api.h:119
uint8_t err_code
Definition meshx_api.h:120
uint8_t on_off
Definition meshx_api.h:121
Structure defines the payload for MESHX_ELEMENT_TYPE_RELAY_SERVER.
Definition meshx_api.h:59
uint8_t on_off
Definition meshx_api.h:60
Structure defines the payload for MESHX_ELEMENT_TYPE_SENSOR_SERVER.
Definition meshx_api.h:109
union meshx_api_sensor_server_evt::@336376344215041027113126022265212173363045212317 state_change
meshx_sensor_srv_status_t sensor_status
Definition meshx_api.h:111
Structure for the BLE Mesh application API message.
Definition meshx_api.h:209
uint8_t data[sizeof(meshx_data_payload_t)]
Definition meshx_api.h:216
union meshx_app_api_msg::@072073010055105213156102377164134137032042011011 msg_type_u
meshx_app_element_msg_header_t element_msg
Definition meshx_api.h:213
meshx_ctrl_msg_header_t ctrl_msg
Definition meshx_api.h:212
Structure for the BLE Mesh application element message header.
Definition meshx_api.h:183
uint16_t element_id
Definition meshx_api.h:184
uint16_t func_id
Definition meshx_api.h:186
uint16_t msg_len
Definition meshx_api.h:187
uint16_t element_type
Definition meshx_api.h:185
Structure for the BLE Mesh application control message header.
Definition meshx_api.h:197
uint16_t evt_id
Definition meshx_api.h:198
uint16_t reserved
Definition meshx_api.h:199
Definition meshx_ble_mesh_sensor_srv.h:25
Structure defines the payload for meshx_ctrl_payload.
Definition meshx_api.h:166
uint16_t addr
Definition meshx_api.h:169
uint16_t net_idx
Definition meshx_api.h:168
struct meshx_ctrl_payload::@203371072015171176147201027223133225232162040063 prov_comp
struct meshx_ctrl_payload::@366007045022113102213126135336116375135121027025 prov_failed
uint8_t device_uuid[16]
Definition meshx_api.h:170
uint32_t reserved
Definition meshx_api.h:175
uint8_t reason
Definition meshx_api.h:173
Structure for the BLE Mesh application control message.
Definition meshx_api.h:153
meshx_api_sensor_server_evt_t sensor_server_evt
Definition meshx_api.h:159
meshx_api_relay_server_evt_t relay_server_evt
Definition meshx_api.h:155
meshx_api_relay_client_evt_t relay_client_evt
Definition meshx_api.h:154
meshx_api_light_cwww_client_evt_t light_cwww_client_evt
Definition meshx_api.h:156
meshx_api_light_hsl_server_evt_t light_hsl_server_evt
Definition meshx_api.h:158
meshx_api_light_cwww_server_evt_t light_cwww_server_evt
Definition meshx_api.h:157
Header file for the production console unit test functionality.