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.
Note: I'm using only one ESP.
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.
It should send some message to an external server.
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
nc -l -k -p 8089If 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.
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.
Will there be official border router implementation?
@negativekelvin
```
"that's not included in mesh"
"normal router is able to establish a connection between mesh networks."
@ugallu did you get this working? I am finding esp_mesh_send is hanging when trying to send data to an external IP.
I made a workaround. I sent data from nodes to root via
esp_err_t err = esp_mesh_send(NULL, &data, 0, NULL, 0);
and on the root, I got the message with esp_mesh_recv.
Then I opened a standard socket to my server (or simply to netcat) and sent it with the socket's write method (this maybe can help, I called write(socket, message, messageLength), instead of read: https://github.com/espressif/ESP8266_RTOS_SDK/issues/46)
Please send a message if you get further.
@JerrysGarage @ugallu
You could refer to the examples in https://github.com/espressif/esp-mdf
The lastest esp-idf master is not fully tested on ESP-MESH.
You'd better use esp-mdf submodule before v3.1 release.
@ugallu Do you have an example you could share?
I am trying to send a JSON from a Leaf to a Server. At this point I do not have an intermediate node however I will in the final application.
Right now I am getting stuck just sending a JSON object from the Leaf to the Root.
On the Leaf I run the:
mesh_data_t data_out;
char buffer[50] = "{\"Hello\":\"World\"}";
data_out.data = (uint8_t*)buffer;
data_out.size = strlen(buffer);
data_out.proto = MESH_PROTO_JSON;
data_out.tos = MESH_TOS_P2P;
err = esp_mesh_send(NULL, &data_out, MESH_DATA_P2P, NULL , 0);
On the Root I run:
int flag = MESH_DATA_TODS;
for(int table_index = 1;table_index<route_table_size;table_index++)
{
mesh_data_t data_in;
data_in.data = malloc(RX_SIZE*sizeof(char));
memset(data_in.data, 0, RX_SIZE);
err = esp_mesh_recv(&route_table[table_index], &data_in, 10000, &flag, NULL, 0);
free(data_in.data)
}
After the leaf node freezes when esp_mesh_send is called. The root node calls esp_mesh_recv and polls until the timeout is up.
It seems like I am not using the esp_mesh_send. I am able to get the root node to send and receive a packet to itself, just not other nodes.
@dongdong004 I have looked at the examples in esp-mdf but havn't found an example that simply sends a JSON object from leaf->root->server. Do you know of one?
Thanks for help!
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)_
@JerrysGarage
Thank you both! What is the best way for a node to get the address dest_addr for Root?
Its NULL, if you need it just for sending message.
From the esp_mesh_send API: to: the address of the final destination of the packet (1)if the packet is to root, just set “to” to NULL and set flag to zero
NULL works for me when using esp_mesh_send however when using the mdf_wifi_mesh_send function, the first line is MDF_PARAM_CHECK(dest_addr); which prevents me from passing a NULL.
esp_mesh_recv_toDS , you needn't know the address of root, just set dest_addr as ip+port and set flag to MESH_DATA_TODS https://github.com/ugallu/esp-mesh-socket/blob/master/main/mesh_main.c#L112
MESH_EVENT_ROOT_ADDRESS, /**< the root address is obtained. It is posted by mesh stack automatically. */
@dongdong004 @ugallu Got it working, Thanks for all the help!
hi JerrysGarage
could you explain me how you did it? that what im looking for my project.
Regards
Daniel
hi @JerrysGarage
could you explain me how you did it? that what im looking for my project.
Regards
Daniel
@JerrysGarage
- root receive to DS: https://github.com/espressif/esp-mdf/blob/master/components/protocol_stacks/mdf_wifi_mesh/mdf_wifi_mesh.c#L376
- node send data: https://github.com/espressif/esp-mdf/blob/master/components/protocol_stacks/mdf_wifi_mesh/mdf_wifi_mesh.c#L210
- Use the esp-idf @ugallu said.
Hi @dongdong004 , could you please update the "node send data" example? (:
Hi @dongdong004 , could you please update the "node send data" example? (:
Hi @vcmorini,
Most helpful comment
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.
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)_