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 File Reference

This file contains the API definitions for the MeshX application. More...

Go to the source code of this file.

Data Structures

struct  meshx_api_relay_server_evt
 Structure defines the payload for MESHX_ELEMENT_TYPE_RELAY_SERVER. More...
struct  meshx_api_light_cwww_server_evt
 Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_CWWW_SERVER. More...
struct  meshx_api_light_hsl_server_evt
 Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_HSL_SERVER. More...
struct  meshx_api_sensor_server_evt
 Structure defines the payload for MESHX_ELEMENT_TYPE_SENSOR_SERVER. More...
struct  meshx_api_relay_client_state
 Structure defines the payload for MESHX_ELEMENT_TYPE_RELAY_CLIENT. More...
struct  meshx_api_light_cwww_client_evt
 Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_CWWW_CLIENT. More...
union  meshx_data_payload
 Structure for the BLE Mesh application control message. More...
union  meshx_ctrl_payload
 Structure defines the payload for meshx_ctrl_payload. More...
struct  meshx_app_element_msg_header
 Structure for the BLE Mesh application element message header. More...
struct  meshx_ctrl_msg_header
 Structure for the BLE Mesh application control message header. More...
struct  meshx_app_api_msg
 Structure for the BLE Mesh application API message. More...

Macros

#define MESHX_APP_API_MSG_MAX_SIZE   sizeof(meshx_data_payload_t)
#define MESHX_ELEMENT_FUNC_ID_RELAY_SERVER_ONN_OFF   0x00
#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_SERVER_ONN_OFF   0x00
#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_SERVER_CTL   0x01
#define MESHX_ELEMENT_FUNC_ID_LIGHT_HSL_SERVER_ONN_OFF   0x00
#define MESHX_ELEMENT_FUNC_ID_LIGHT_HSL_SERVER_HSL   0x01
#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_CLIENT_ONN_OFF   0x00
#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_CLIENT_CTL   0x01
#define MESHX_ELEMENT_FUNC_ID_SENSOR_SERVER_DATA   0x00

Typedefs

typedef enum meshx_api_type meshx_api_type_t
 Enumeration of BLE Mesh application API message types.
typedef struct meshx_api_relay_server_evt meshx_api_relay_server_evt_t
 Structure defines the payload for MESHX_ELEMENT_TYPE_RELAY_SERVER.
typedef 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.
typedef 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.
typedef struct meshx_api_sensor_server_evt meshx_api_sensor_server_evt_t
 Structure defines the payload for MESHX_ELEMENT_TYPE_SENSOR_SERVER.
typedef struct meshx_api_relay_client_state meshx_api_relay_client_evt_t
 Structure defines the payload for MESHX_ELEMENT_TYPE_RELAY_CLIENT.
typedef 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.
typedef union meshx_data_payload meshx_data_payload_t
 Structure for the BLE Mesh application control message.
typedef union meshx_ctrl_payload meshx_ctrl_payload_t
 Structure defines the payload for meshx_ctrl_payload.
typedef struct meshx_app_element_msg_header meshx_app_element_msg_header_t
 Structure for the BLE Mesh application element message header.
typedef struct meshx_ctrl_msg_header meshx_ctrl_msg_header_t
 Structure for the BLE Mesh application control message header.
typedef struct meshx_app_api_msg meshx_app_api_msg_t
 Structure for the BLE Mesh application API message.
typedef 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.
typedef 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.

Enumerations

enum  meshx_api_type {
  MESHX_API_TYPE_DATA = CONTROL_TASK_MSG_EVT_DATA ,
  MESHX_API_TYPE_CTRL = CONTROL_TASK_MSG_EVT_CTRL
}
 Enumeration of BLE Mesh application API message types. More...

Functions

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.
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.
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.
meshx_err_t meshx_app_reg_element_callback (meshx_app_data_cb_t cb)
 Registers the BLE Mesh application callback.
meshx_err_t meshx_app_reg_system_events_callback (meshx_app_ctrl_cb_t cb)
 Registers the BLE Mesh application control callback.
uint16_t meshx_get_net_key_id (void)
 Get the network key identifier.

Detailed Description

This file contains the API definitions for the MeshX application.

Copyright © 2024 - 2025 MeshX

The MeshX API provides functions and structures to interact with the BLE Mesh application. It includes message types, payload structures, and callback function definitions.

Author
Pranjal Chanda

Macro Definition Documentation

◆ MESHX_APP_API_MSG_MAX_SIZE

#define MESHX_APP_API_MSG_MAX_SIZE   sizeof(meshx_data_payload_t)

◆ MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_CLIENT_CTL

#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_CLIENT_CTL   0x01

◆ MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_CLIENT_ONN_OFF

#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_CLIENT_ONN_OFF   0x00

◆ MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_SERVER_CTL

#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_SERVER_CTL   0x01

◆ MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_SERVER_ONN_OFF

#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_SERVER_ONN_OFF   0x00

◆ MESHX_ELEMENT_FUNC_ID_LIGHT_HSL_SERVER_HSL

#define MESHX_ELEMENT_FUNC_ID_LIGHT_HSL_SERVER_HSL   0x01

◆ MESHX_ELEMENT_FUNC_ID_LIGHT_HSL_SERVER_ONN_OFF

#define MESHX_ELEMENT_FUNC_ID_LIGHT_HSL_SERVER_ONN_OFF   0x00

◆ MESHX_ELEMENT_FUNC_ID_RELAY_SERVER_ONN_OFF

#define MESHX_ELEMENT_FUNC_ID_RELAY_SERVER_ONN_OFF   0x00

◆ MESHX_ELEMENT_FUNC_ID_SENSOR_SERVER_DATA

#define MESHX_ELEMENT_FUNC_ID_SENSOR_SERVER_DATA   0x00

Typedef Documentation

◆ meshx_api_light_cwww_client_evt_t

Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_CWWW_CLIENT.

◆ meshx_api_light_cwww_server_evt_t

Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_CWWW_SERVER.

◆ meshx_api_light_hsl_server_evt_t

Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_HSL_SERVER.

◆ meshx_api_relay_client_evt_t

Structure defines the payload for MESHX_ELEMENT_TYPE_RELAY_CLIENT.

◆ meshx_api_relay_server_evt_t

Structure defines the payload for MESHX_ELEMENT_TYPE_RELAY_SERVER.

◆ meshx_api_sensor_server_evt_t

Structure defines the payload for MESHX_ELEMENT_TYPE_SENSOR_SERVER.

◆ meshx_api_type_t

Enumeration of BLE Mesh application API message types.

◆ meshx_app_api_msg_t

Structure for the BLE Mesh application API message.

This structure defines the BLE Mesh application API message.

◆ meshx_app_ctrl_cb_t

typedef 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.

This function is the BLE Mesh application control callback function.

Parameters
[in]msg_hdrPointer to the BLE Mesh application control message header.
[in]msgPointer to the message.
Returns
MESHX_SUCCESS on success, error code otherwise.

◆ meshx_app_data_cb_t

typedef 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.

This function is the BLE Mesh application callback function.

Parameters
[in]msg_hdrPointer to the BLE Mesh application message header.
[in]msgPointer to the message.
Returns
MESHX_SUCCESS on success, error code otherwise.

◆ meshx_app_element_msg_header_t

Structure for the BLE Mesh application element message header.

◆ meshx_ctrl_msg_header_t

Structure for the BLE Mesh application control message header.

This structure defines the header for BLE Mesh application control messages.

◆ meshx_ctrl_payload_t

Structure defines the payload for meshx_ctrl_payload.

◆ meshx_data_payload_t

Structure for the BLE Mesh application control message.

This structure defines the BLE Mesh application control payloads.

Enumeration Type Documentation

◆ meshx_api_type

Enumeration of BLE Mesh application API message types.

Enumerator
MESHX_API_TYPE_DATA CONTROL_TASK_MSG_EVT_DATA 

Data message : All msg rekated to BLE mesh elements

MESHX_API_TYPE_CTRL CONTROL_TASK_MSG_EVT_CTRL 

Control message : All msg related to System control

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 */
@ 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.
CONTROL_TASK_MSG_EVT_CTRL
Definition meshx_control_task.h:89
CONTROL_TASK_MSG_EVT_DATA
Definition meshx_control_task.h:88

Function Documentation

◆ meshx_app_reg_element_callback()

meshx_err_t meshx_app_reg_element_callback ( meshx_app_data_cb_t cb)

Registers the BLE Mesh application callback.

This function registers the BLE Mesh application data path callback.

Parameters
[in]cbPointer to the application callback.
Returns
MESHX_SUCCESS on success, error code otherwise.
207{
209
214 if (err)
215 {
216 MESHX_LOGE(MODULE_ID_COMMON, "Failed to register control task callback: (%d)", err);
217 return err;
218 }
219
220 meshx_api_ctrl.app_data_cb = cb;
221
222 return err;
223}
static meshx_err_t meshx_api_control_task_handler(const dev_struct_t *pdev, control_task_msg_evt_t evt, const void *params)
Control task handler for BLE Mesh application messages.
Definition meshx_api.c:33
static struct @023200254140264171361220101366151270341050312256 meshx_api_ctrl
meshx_err_t(* control_task_msg_handle_t)(dev_struct_t *pdev, control_task_msg_evt_t evt, void *params)
Function pointer type for control task message handler.
Definition meshx_control_task.h:188
@ CONTROL_TASK_MSG_CODE_TO_APP
Definition meshx_control_task.h:72
meshx_err_t control_task_msg_subscribe(control_task_msg_code_t msg_code, control_task_msg_evt_t evt_bmap, control_task_msg_handle_t callback)
Subscribe to a control task message.
Definition meshx_control_task.c:142
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:114
**This function is called by the parent element when a state change request *is received It validates the request and returns a result to the element not the model layer **return * MESHX_SUCCESS
Definition meshx_model_level.cpp:385
@ MODULE_ID_COMMON
Definition module_id.h:36

◆ meshx_app_reg_system_events_callback()

meshx_err_t meshx_app_reg_system_events_callback ( meshx_app_ctrl_cb_t cb)

Registers the BLE Mesh application control callback.

This function registers the BLE Mesh application control callback.

Parameters
[in]cbPointer to the control callback.
Returns
MESHX_SUCCESS on success, error code otherwise.
235{
237
242 if (err)
243 {
244 MESHX_LOGE(MODULE_ID_COMMON, "Failed to register control task callback: (%d)", err);
245 return err;
246 }
247
248 meshx_api_ctrl.app_ctrl_cb = cb;
249
250 return err;
251}

◆ meshx_get_net_key_id()

uint16_t meshx_get_net_key_id ( void )

Get the network key identifier.

Returns
uint16_t The network key identifier.
317{
318 return g_dev.meshx_store.net_key_id;
319}
static dev_struct_t g_dev
Definition meshx.c:33

◆ meshx_send_ctrl_msg_to_app()

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.

This function sends a control message to the BLE Mesh application.

Parameters
[in]evtThe event ID.
[in]msg_lenThe message length.
[in]msgPointer to the message.
Returns
MESHX_SUCCESS on success, error code otherwise.
155{
157
158 err = meshx_prepare_ctrl_message(evt, msg_len, msg);
159 if(err)
160 MESHX_LOGE(MODULE_ID_COMMON, "Failed to create ctrl message: (0x%x)", err);
161
163 if(err)
164 MESHX_LOGE(MODULE_ID_COMMON, "Failed to send ctrl message to app: (0x%x)", err);
165
166 return err;
167}
static meshx_err_t meshx_prepare_ctrl_message(meshx_ctrl_evt_t evt, uint16_t msg_len, const void *msg)
Prepares a control message to be sent to the BLE Mesh application.
Definition meshx_api.c:97
struct meshx_app_api_msg meshx_app_api_msg_t
Structure for the BLE Mesh application API message.
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.
Definition meshx_control_task.c:84

◆ meshx_send_msg_to_app()

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.

This function sends a message to the BLE Mesh application.

Parameters
[in]element_idThe element ID.
[in]element_typeThe element type.
[in]func_idThe function ID.
[in]msg_lenThe message length.
[in]msgPointer to the message.
Returns
MESHX_SUCCESS on success, error code otherwise.
129{
131
132 err = meshx_prepare_data_message(element_id, element_type, func_id, msg_len,msg);
133 if(err)
134 MESHX_LOGE(MODULE_ID_COMMON, "Failed to create message: (0x%x)", err);
135
137 if(err)
138 MESHX_LOGE(MODULE_ID_COMMON, "Failed to send message to app: (0x%x)", err);
139
140 return err;
141}
static meshx_err_t meshx_prepare_data_message(uint16_t element_id, uint16_t element_type, uint16_t func_id, uint16_t msg_len, const void *msg)
Prepares a message to be sent to the BLE Mesh application.
Definition meshx_api.c:66

◆ meshx_send_msg_to_element()

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.

This function sends a message to the element from BLE mesh Application

Parameters
[in]element_idThe element ID.
[in]element_typeThe element type.
[in]func_idThe function ID.
[in]msg_lenThe message length.
[in]msgPointer to the message.
Returns
MESHX_SUCCESS on success, error code otherwise.
183{
185
186 err = meshx_prepare_data_message(element_id, element_type, func_id, msg_len,msg);
187 if(err)
188 MESHX_LOGE(MODULE_ID_COMMON, "Failed to create message: (0x%x)", err);
189
191 if(err)
192 MESHX_LOGE(MODULE_ID_COMMON, "Failed to send message to app: (0x%x)", err);
193
194 return err;
195}
@ CONTROL_TASK_MSG_CODE_TO_MESHX
Definition meshx_control_task.h:73