Hi guys,
I am attempting to modify the sensor-client/server model to create a mesh network of sensors that report to one client node. I am trying to use the esp_ble_mesh_model_publish method to publish a sensor's status to the client node once every few seconds. I am able to send messages using esp_ble_mesh_server_model_send_msg, but that will not work for me as my goal is to extend the range of the sparse network by propagating the message among servers until it reaches the client. Thus, I think I have to publish the message to a group address. I cannot figure out how to do this. For reference, I am using VSCode with ESP-IDF on Mac.
Here are my specific questions:
How and where do I create a publishing group?
How do I subscribe to this group on both the servers and the client?
How do I set the DST of the esp_ble_mesh_model_publish function and what should the parameters of that function be?
How do I handle the message on the client side?
As always, any help is greatly appreciated.
-rrwatt
Publishing Messages in Mesh Network
Re: Publishing Messages in Mesh Network
It is very simple, just compare both functions:
Publish just ignore context, and you have to setup publish parameters on the model with provisioner like nrf mesh or other, which is setting up publish address.
Code: Select all
esp_err_t esp_ble_mesh_server_model_send_msg(esp_ble_mesh_model_t *model,
esp_ble_mesh_msg_ctx_t *ctx,
uint32_t opcode,
uint16_t length, uint8_t *data)
{
if (model == NULL || ctx == NULL ||
ctx->net_idx == ESP_BLE_MESH_KEY_UNUSED ||
ctx->app_idx == ESP_BLE_MESH_KEY_UNUSED) {
return ESP_ERR_INVALID_ARG;
}
return ble_mesh_model_send_msg(model, ctx, opcode, BTC_BLE_MESH_ACT_SERVER_MODEL_SEND,
length, data, 0, false, ROLE_NODE);
}
Code: Select all
esp_err_t esp_ble_mesh_model_publish(esp_ble_mesh_model_t *model, uint32_t opcode,
uint16_t length, uint8_t *data,
esp_ble_mesh_dev_role_t device_role)
{
if (model == NULL || model->pub == NULL || model->pub->msg == NULL ||
model->pub->publish_addr == ESP_BLE_MESH_ADDR_UNASSIGNED) {
return ESP_ERR_INVALID_ARG;
}
return ble_mesh_model_send_msg(model, NULL, opcode, BTC_BLE_MESH_ACT_MODEL_PUBLISH,
length, data, 0, false, device_role);
}
Re: Publishing Messages in Mesh Network
Thanks for your quick response @chegewara. I am trying to send data from a sensor_server to all other nodes like this. Note that this code resides in the example_ble_mesh_send_sensor_status function.
This is the output.
First, I don't understand why Sensor Data doesn't match the Message field. Also, what is this warning message about outbound bearer? I thought that 0xFFFF refers to all nodes in the network, but when I try to handle the publish message in the client code, it acts like no message has been received and nothing happens. Any advice? Thanks in advance.
-rrwatt
Code: Select all
ESP_LOG_BUFFER_HEX("Sensor Data", status, length);
err = esp_ble_mesh_server_model_send_msg(param->model, ¶m->ctx,
ESP_BLE_MESH_MODEL_OP_SENSOR_STATUS, length, status);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to send Sensor Status");
}
param->model->pub->publish_addr = 0xFFFF;
err2 = esp_ble_mesh_model_publish(param->model, ESP_BLE_MESH_MODEL_PUBLISH_UPDATE_EVT, length, status, ROLE_NODE);
ESP_LOGI(TAG, "Model Publish Addr: %u", param->model->pub->publish_addr);
ESP_LOG_BUFFER_HEX("Message", param->model->pub->msg, length);
err3 = esp_ble_mesh_model_publish(param->model, ESP_BLE_MESH_SENSOR_CLIENT_PUBLISH_EVT, length, status, ROLE_NODE);
if(err2 != ESP_OK) {
ESP_LOGE(TAG, "Failed to update. Error Code: %d", err2);
}
if(err3 != ESP_OK) {
ESP_LOGE(TAG, "Failed to publish. Error Code: %d", err3);
}
Code: Select all
I (110122) Sensor Data: c0 0a 17 60 0b 28
I (110122) EXAMPLE: Model Publish Addr: 65535
I (110122) Message: 98 36 fc 3f 07 00
W (110142) BLE_MESH: No outbound bearer found, inbound bearer 1
W (110152) BLE_MESH: No outbound bearer found, inbound bearer 1
-rrwatt
Re: Publishing Messages in Mesh Network
1. you get different values, because you are checking 2 different buffersrrwatt wrote: ↑Fri Apr 05, 2024 9:37 pm
First, I don't understand why Sensor Data doesn't match the Message field. Also, what is this warning message about outbound bearer? I thought that 0xFFFF refers to all nodes in the network, but when I try to handle the publish message in the client code, it acts like no message has been received and nothing happens. Any advice? Thanks in advance.
-rrwatt
2. when you are sending to all nodes (0xffff) then it will be also send to all elements on the same node you are sending from, thats why you see this warning; consider its an info message
Re: Publishing Messages in Mesh Network
Oh, ok. I think I understand what you are saying. Also, to read the published message on the client node, can I just modify the function to handle a message inside the or do I need to write some new function to look for the published message? Right now no matter what I add inside the case it doesn't receive the message. Please let me know. Thanks.
-rrwatt
Code: Select all
example_ble_mesh_sensor_client_cb
Code: Select all
case ESP_BLE_MESH_SENSOR_CLIENT_PUBLISH_EVT
-rrwatt
Re: Publishing Messages in Mesh Network
Hi,
its not that i dont want to help you, but i believe it will be faster and with better results to you when you start from scratch.
- grab espressif example
- in custom callback (esp_ble_mesh_register_custom_model_callback) just print logs for event and opcode to see what you are receiving and to see what you have actually to pass in your own code
I will try to help you when you have more questions.
its not that i dont want to help you, but i believe it will be faster and with better results to you when you start from scratch.
- grab espressif example
- in custom callback (esp_ble_mesh_register_custom_model_callback) just print logs for event and opcode to see what you are receiving and to see what you have actually to pass in your own code
I will try to help you when you have more questions.
-
- Posts: 2
- Joined: Sat May 04, 2024 4:56 am
Re: Publishing Messages in Mesh Network
Hello, could you share the project code, if possible. at my place of work, they decided to purchase esp 32 modules and set almost the same task as yours.rrwatt wrote: create a mesh network of sensors that report to one client node.
Who is online
Users browsing this forum: Google [Bot] and 81 guests