“Messaging in ESP_BLE_MESH” 可以翻译为 “ESP_BLE_MESH 中的消息传递”。

huangapple go评论55阅读模式
英文:

Messaging in ESP_BLE_MESH

问题

I understand your request. Here is the translation of the provided content:

我想要为我的BLE Mesh项目寻求帮助。

我的任务是创建一个具有以下拓扑结构的Mesh网络:

  • 大约有15台设备,这些设备从某些传感器读取信息,然后每隔N秒发送数据(仅为0到300之间的数字)到主设备。这些设备应该消耗很少的电力。
  • 有一个主设备/网关,需要从网络中的所有其他设备接收数据,并将这些消息转发到我的Android应用程序。主设备还有无限电源供应。
  • 有一些中继设备,它们帮助将传感器设备的消息传递到主设备。这些设备位于固定位置并且具有无限电源供应。

我决定基于存储库https://github.com/espressif/esp-idf/tree/master/examples/bluetooth/esp_ble_mesh/ble_mesh_vendor_model上的供应商模型进行构建,因为它还区分了主设备 - 客户端和从设备 - 服务器,并且还允许自动进行配置过程。

问题在于供应商模型示例中的服务器只会在example_ble_mesh_custom_model_cb(esp_ble_mesh_model_cb_event_t event, esp_ble_mesh_model_cb_param_t *param)回调中对来自该主设备的消息做出响应时,才会发送消息给客户端:

static void example_ble_mesh_custom_model_cb(esp_ble_mesh_model_cb_event_t event,
                                             esp_ble_mesh_model_cb_param_t *param)
{
    switch (event) {
    case ESP_BLE_MESH_MODEL_OPERATION_EVT:
        if (param->model_operation.opcode == ESP_BLE_MESH_VND_MODEL_OP_SEND) {
            uint16_t tid = *(uint16_t *)param->model_operation.msg;
            ESP_LOGI(TAG, "Recv 0x%06" PRIx32 ", tid 0x%04x", param->model_operation.opcode, tid);
            esp_err_t err = esp_ble_mesh_server_model_send_msg(&vnd_models[0],
                    param->model_operation.ctx, ESP_BLE_MESH_VND_MODEL_OP_STATUS,
                    sizeof(tid), (uint8_t *)&tid);
            if (err) {
                ESP_LOGE(TAG, "Failed to send message 0x%06x", ESP_BLE_MESH_VND_MODEL_OP_STATUS);
            }
        }
        break;
    case ESP_BLE_MESH_MODEL_SEND_COMP_EVT:
        if (param->model_send_comp.err_code) {
            ESP_LOGE(TAG, "Failed to send message 0x%06" PRIx32, param->model_send_comp.opcode);
            break;
        }
        ESP_LOGI(TAG, "Send 0x%06" PRIx32, param->model_send_comp.opcode);
        break;
    default:
        break;
    }
}

而我需要服务器能够随时向客户端发送消息。

为此,我尝试将esp_ble_mesh_server_model_send_msg()移动到一个单独的函数中,该函数将每隔N秒调用一次:

static void send_pulse_data(void* arg) {
    // 创建消息
    esp_err_t err = esp_ble_mesh_server_model_send_msg(&vnd_models[0],
            param->model_operation.ctx, ESP_BLE_MESH_VND_MODEL_OP_STATUS,
            sizeof(message), (uint8_t *)&message);
    if (err) {
        ESP_LOGE(TAG, "Failed to send message 0x%06x", ESP_BLE_MESH_VND_MODEL_OP_STATUS);
    }
}

但我遇到了一个问题,为了向客户端发送消息,需要param->model_operation.ctx等参数,而我无法在example_ble_mesh_custom_model_cb回调之外获取这些参数。

我想请教如何选择适合我的需求的正确模型,如何从服务器发送消息到客户端,如何在客户端端接收消息以及使用哪些函数。任何关于实现的建议、代码片段或评论都对我非常有帮助。

我也会非常感谢如果您能回答我以下的问题:

  1. 如何让传感器设备消耗很少的电力?我是否需要明确执行某些操作,或者仅仅禁用中继并定期发送消息就足够了?
  2. 将ESP_BLE_MESH_RELAY_DISABLED更改为ESP_BLE_MESH_RELAY_ENABLED就足够启用中继吗?
  3. 在每次使用设备网络时是否需要进行配置?

请注意,我只提供翻译,不提供问题的答案。如果您需要答案,请重新提问。

英文:

I would like to ask for help with my BLE Mesh project.

My task is to create a Mesh network with the following topology:

  • There are about 15 devices that read information from some sensor and once every N seconds send data (just a number from 0 to 300) to the main device. These devices should consume little power.
  • There is ONE master device/gateway that needs to receive data from all other devices on the network and forward those messages to my android app. The master device also has an unlimited power supply.
  • There are Relay devices that help to deliver messages from devices with sensors to the main device. These devices are in fixed locations and have an unlimited power supply.

I decided to build on the Vendor Model from the repository https://github.com/espressif/esp-idf/tree/master/examples/bluetooth/esp_ble_mesh/ble_mesh_vendor_model, because it also distinguishes between the main device - Client and slave devices - Server, and also allows you to automate the provisioning process.

The problem is that the Servers in the Vendor Model example send messages to the Client only in response to a message from that very master inside the example_ble_mesh_custom_model_cb(esp_ble_mesh_model_cb_event_t event, esp_ble_mesh_model_cb_param_t *param) callback:

static void example_ble_mesh_custom_model_cb(esp_ble_mesh_model_cb_event_t event,
                                             esp_ble_mesh_model_cb_param_t *param)
{
    switch (event) {
    case ESP_BLE_MESH_MODEL_OPERATION_EVT:
        if (param->model_operation.opcode == ESP_BLE_MESH_VND_MODEL_OP_SEND) {
            uint16_t tid = *(uint16_t *)param->model_operation.msg;
            ESP_LOGI(TAG, "Recv 0x%06" PRIx32 ", tid 0x%04x", param->model_operation.opcode, tid);
            esp_err_t err = esp_ble_mesh_server_model_send_msg(&vnd_models[0],
                    param->model_operation.ctx, ESP_BLE_MESH_VND_MODEL_OP_STATUS,
                    sizeof(tid), (uint8_t *)&tid);
            if (err) {
                ESP_LOGE(TAG, "Failed to send message 0x%06x", ESP_BLE_MESH_VND_MODEL_OP_STATUS);
            }
        }
        break;
    case ESP_BLE_MESH_MODEL_SEND_COMP_EVT:
        if (param->model_send_comp.err_code) {
            ESP_LOGE(TAG, "Failed to send message 0x%06" PRIx32, param->model_send_comp.opcode);
            break;
        }
        ESP_LOGI(TAG, "Send 0x%06" PRIx32, param->model_send_comp.opcode);
        break;
    default:
        break;
    }
}

while I need Servers to be able to send messages to Client whenever they want.

To do this, I tried to move esp_ble_mesh_server_model_send_msg() into a separate function that would be called every N seconds:

static void send_pulse_data(void* arg) {
    // create message
    esp_err_t err = esp_ble_mesh_server_model_send_msg(&vnd_models[0],
            param->model_operation.ctx, ESP_BLE_MESH_VND_MODEL_OP_STATUS,
            sizeof(message), (uint8_t *)&message);
    if (err) {
        ESP_LOGE(TAG, "Failed to send message 0x%06x", ESP_BLE_MESH_VND_MODEL_OP_STATUS);
    }
}

, but I ran into the fact that in order to send a message to the Client, parameters such as param->model_operation.ctx are needed, which I can’t get anywhere except inside the example_ble_mesh_custom_model_cb callback.

I would like to ask for advice on choosing the right model, on how to send messages from the Servers to the Client for my requirements, on how to receive messages on the Client side and on what functions to use for this.
Basically any implementation tips, code snippets or comments would be very helpful to me.

I would also be very grateful if you could answer my questions below:

  1. How to make devices with sensors consume little power? Do I need to explicitly do something for this, or is it enough to disable Relay and send messages once in a limited amount of time?
  2. Is it enough to change ESP_BLE_MESH_RELAY_DISABLED to ESP_BLE_MESH_RELAY_ENABLED to enable Relay?
  3. Do I need to do provisioning every time I use the devices network?

答案1

得分: 2

Here are the translations of the code and responses:

  1. 如何让具有传感器的设备耗电量少?我是否需要明确地采取措施,或者仅禁用中继并定期发送消息就足够了?
    => 我认为这里最大的问题是ESP32的能耗。禁用中继或定期发送消息,而不使用ESP32的休眠功能可能没有什么用。

  2. 将ESP_BLE_MESH_RELAY_DISABLED更改为ESP_BLE_MESH_RELAY_ENABLED就足够启用中继吗?
    => 通常是的。您可以检查中继功能是否在nRF mesh应用程序中激活(如果您用它来配置您的节点)。

  3. 每次使用设备网络都需要进行配置吗?
    通常不需要,在menuconfig中,您可以找到ESP BLE mesh持久存储选项,以便您的设备可以无问题地重新连接到网络。

英文:

example to send btmesh message :

void send_to_dimmer(uint8_t payload)
{
printf("payload received by send_to_dimmer() 0x%02x", payload);
esp_ble_mesh_msg_ctx_t ctx = {0};
esp_err_t err = ESP_OK;

ctx.net_idx = 0x0000;
ctx.app_idx = 0x0000;
ctx.addr = 0x0003;   /* dimmer */
ctx.send_ttl = ESP_BLE_MESH_TTL_DEFAULT;
ctx.send_rel = true;

err = esp_ble_mesh_server_model_send_msg(&vnd_models[0],&ctx,
 ESP_BLE_MESH_VND_MODEL_OP_SEND, sizeof(payload), &payload);
if (err) {
    ESP_LOGI(TAG, "Send message to dimmer failed KO");
    return;
}
else {ESP_LOGI(TAG, "Message sent to dimmer OK");}

}

  1. How to make devices with sensors consume little power? Do I need to explicitly do something for this, or is it enough to disable Relay and send messages once in a limited amount of time?
    => I think the biggest problem here is the ESP32 energy consumption. Disabling relay or sending limited amount of message without using esp32 sleep capability might be useless.

  2. Is it enough to change ESP_BLE_MESH_RELAY_DISABLED to ESP_BLE_MESH_RELAY_ENABLED to enable Relay?
    => normally yes. You can check if relay feature is activated in nRF mesh app for instance (if you used it ot provision your nodes).

  3. Do I need to do provisioning every time I use the devices network?
    Normally no, in menuconfig, you can find ESP BLE mesh persistent storage option, so that you device will reconnect to network without problem.

huangapple
  • 本文由 发表于 2023年5月13日 20:15:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76242681.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定