Page 1 of 1

ble_mesh_model发布消息的问题

Posted: Mon Apr 14, 2025 2:34 am
by whj3900829
大家好:
我是新手小白,请教一个BLE_MESH周期性发布的一个问题。以标准on_off_cli模型为例,我想让on_off_sever模型通过发布的消息实现周期性的开关,可以通过模型设置发布的周期和地址,但是有个问题发布的消息无法回调更新(on_off状态和tid)。标准模型没有ESP_BLE_MESH_MODEL_PUBLISH_UPDATE_EVT这个事件,只有自定义模型才有。那如果我想用标准模型来实现发布自动更新消息该怎么做?如果需要手动周期性更新消息,那设置周期发布有什么用?我直接手动周期发布就可以了。请各路大神赐教,谢谢!

typedef struct {
/** Pointer to the model to which the context belongs. Initialized by the stack. */
esp_ble_mesh_model_t *model;

uint16_t publish_addr; /*!< Publish Address. */
uint16_t app_idx:12, /*!< Publish AppKey Index. */
cred:1, /*!< Friendship Credentials Flag. */
send_rel:1; /*!< Force reliable sending (segment acks) */

uint8_t ttl; /*!< Publish Time to Live. */
uint8_t retransmit; /*!< Retransmit Count & Interval Steps. */

uint8_t period; /*!< Publish Period. */
uint8_t period_div:4, /*!< Divisor for the Period. */
fast_period:1, /*!< Use FastPeriodDivisor */
count:3; /*!< Retransmissions left. */

uint32_t period_start; /*!< Start of the current period. */

/** @brief Publication buffer, containing the publication message.
*
* This will get correctly created when the publication context
* has been defined using the ESP_BLE_MESH_MODEL_PUB_DEFINE macro.
*
* ESP_BLE_MESH_MODEL_PUB_DEFINE(name, size);
*/
struct net_buf_simple *msg;

/** Callback used to update publish message. Initialized by the stack. */
esp_ble_mesh_cb_t update;//这个似乎用于更新的,但是不知道怎么用

/** Publish Period Timer. Initialized by the stack. */
struct k_delayed_work timer;

/** Role of the device that is going to publish messages */
uint8_t dev_role;
} esp_ble_mesh_model_pub_t;//模型的发布参数


/** This enum value is the event of Generic Client Model */
typedef enum {
ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT,
ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT,
ESP_BLE_MESH_GENERIC_CLIENT_PUBLISH_EVT,//发布完成的事件,不是发布之前
ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT,
ESP_BLE_MESH_GENERIC_CLIENT_EVT_MAX,
} esp_ble_mesh_generic_client_cb_event_t;//标准模型

typedef enum {
ESP_BLE_MESH_MODEL_OPERATION_EVT, /*!< User-defined models receive messages from peer devices (e.g. get, set, status, etc) event */
ESP_BLE_MESH_MODEL_SEND_COMP_EVT, /*!< User-defined models send messages completion event */
ESP_BLE_MESH_MODEL_PUBLISH_COMP_EVT, /*!< User-defined models publish messages completion event */
ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT, /*!< User-defined client models receive publish messages event */
ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT, /*!< Timeout event for the user-defined client models that failed to receive response from peer server models */
ESP_BLE_MESH_MODEL_PUBLISH_UPDATE_EVT, /*!< When a model is configured to publish messages periodically, this event will occur during every publish period */
ESP_BLE_MESH_SERVER_MODEL_UPDATE_STATE_COMP_EVT, /*!< Server models update state value completion event */
ESP_BLE_MESH_MODEL_EVT_MAX,
} esp_ble_mesh_model_cb_event_t;//自定义模型