esp-idf: [TW#23298] Esp_mesh_send doesn't sends message to external address (IDFGH-3215)

I’m not sure it is an issue, or its working properly and I’m doing something wrong. Esp_mesh_send doesn’t sends message to external address.

Environment

  • Development Kit: none
  • Core (if using chip or module): ESP-WROOM32
  • IDF version: 64b56be
  • Development Env: VSCode
  • Operating System: Ubuntu 16.04
  • Power Supply: USB

Note: I’m using only one ESP.

Problem Description

Esp_mesh_send doesn’t sends message to external address.

I’m using a modified version of the idf mesh example (https://github.com/espressif/esp-idf/tree/master/examples/mesh/internal_transceiver) to send a messsage to my server, without success. I checked the API’s esp_mesh_send part: http://esp-idf.readthedocs.io/en/latest/api-reference/mesh/esp_mesh.html#_CPPv213esp_mesh_sendPK11mesh_addr_tPK11mesh_data_tiA_K10mesh_opt_ti It says “if the packet is outgoing to external IP network such as an IP server address, translate IPv4:PORT known as “to”.” I tried to use MESH_PROTO_BIN, MESH_PROTO_JSON, MESH_PROTO_HTTP data types without any success.

Expected Behavior

It should send some message to an external server.

Actual Behavior

It doesn’t sends anything. I can ping the ESP32 and my port is open.

Current monitor log:

I (6193) mesh: [SCAN][ch:4]AP:1, otherID:0, idle:0, mAP:1, root:0, top mAP:0[Layer:0/1.ing]router found
I (6193) mesh: 916, [SCAN]init rc[30:ae:a4:1b:c4:55,-69], mine:0, voter:0
I (6203) mesh: [SCAN:13/13+extra+]rc[128][30:ae:a4:1b:c4:55,-69], self[30:ae:a4:1b:c4:54,-69,reason:0,votes:1,idle][mine:1,voter:1(1.00)percent:1.00][128,1,30:ae:a4:1b:c4:55]

I (6213) mesh: [DONE]connect to router:TP-LINK_7DFE, rssi:-69, 18:d6:c7:a7:7d:fe[layer:1], rc[30:ae:a4:1b:c4:55/-69]
I (12363) wifi: n:4 1, o:4 0, ap:4 1, sta:4 0, prof:4
I (13343) wifi: state: init -> auth (b0)
I (13353) wifi: state: auth -> assoc (0)
I (13363) wifi: state: assoc -> run (10)
I (13583) wifi: connected with TP-LINK_7DFE, channel 4
I (13593) wifi: pm start, type: 0

E (13593) event: invalid static ip
I (13593) mesh_main: <MESH_EVENT_PARENT_CONNECTED>layer:0-->1, parent:18:d6:c7:a7:7d:fe<ROOT>
I (13603) mesh_main: <MESH_EVENT_ROOT_ADDRESS>root address:30:ae:a4:1b:c4:55
E (13603) mesh_main: Routing table
W (13613) mesh_main: [#RX:1/1][L:1] parent:18:d6:c7:a7:7d:fe, receive from 30:ae:a4:1b:c4:54, size:1460, heap:187240, flag:0[err:0x0, proto:0, tos:0]
I (14573) mesh_main: <MESH_EVENT_ROOT_GOT_IP>sta ip: 192.168.0.217, mask: 255.255.255.0, gw: 192.168.0.1
I (14573) event: sta ip: 192.168.0.217, mask: 255.255.255.0, gw: 192.168.0.1
E (14623) mesh_main: Send to server

Steps to repropduce

  • set SSID and PASSWORD for your wifi in menuconfig
  • connect to the same network with your pc
  • get IP with ifconfig
  • start netcat in your PC nc -l -k -p 8089
  • Clone my repo: https://github.com/ugallu/esp-mesh-socket
  • Modify the IP number and port number at line 112,113.
  • Make and Flash the program to the esp
  • Check monitor and netcat. It should try to send a message when it got an IP.

Code to reproduce this issue

https://github.com/ugallu/esp-mesh-socket

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I think you use the receiving API a bit off. The first parameter needs a pointer, and the api will write the address of the sender to the allocated variable. Then you can process this address.

// the rx_buf is a static global array
mesh_data_t data;
int flag = 0;
data.data = rx_buf;
data.size = RX_SIZE;

is_running = true;
while (is_running) {
    data.size = RX_SIZE;
    err = esp_mesh_recv(&from, &data, portMAX_DELAY, &flag, NULL, 0);
    if (err != ESP_OK || !data.size) {
        ESP_LOGE(MESH_TAG, "err:0x%x, size:%d", err, data.size);
        continue;
    }        
    ESP_LOGW(MESH_TAG, "GOT MESSAGE FROM NODE "MACSTR" :%s", MAC2STR(from.addr), data.data);
}

I created a branch named send2Root in my repo for you with a working and tested (I have only one esp32 at home, so I sent from root to root, but I think it should work) example: https://github.com/ugallu/esp-mesh-socket/blob/send2Root/main/mesh_main.c

ps: I would use as few dynamic memory allocation as possible. And be sure you use the correct esp-idf, I currently use this: https://github.com/espressif/esp-idf/tree/a2556229aa6f55b16b171e3325ee9ab1943e8552 with upgraded submodules (git submodule update --init --recursive)

Will there be official border router implementation?

If you want to send a message to external address, socket shoud be created by yourself. And using esp_mesh_recv_toDS() to receive packets destined to external IP network.

  • Here’s the brief of esp_mesh_recv_toDS()
  * @brief     receive a packet targeted to external IP network
  *            root uses this API to receive packets destined to external IP network
  *            root forwards the received packets to the final destination via socket.
  *            if no socket connection is ready to send out the received packets and this esp_mesh_recv_toDS()
  *            hasn't been called by applications, packets from the whole mesh network will be pending in toDS queue.
  *            Use esp_mesh_get_rx_pending() to check the number of packets available in the queue waiting
  *            to be received by applications in case of running out of memory in root.
  *            Use esp_mesh_set_xon_qsize() could configure the RX queue size, default:72. If this size is too large,
  *            and esp_mesh_recv_toDS() isn't called in time, there is a risk that a great deal of memory is occupied
  *            by the pending packets. If this size is too small, it will impact the efficiency on upstream. How to
  *            decide this value depends on the specific application scenarios.