problem with simple esp_mesh_send command

cgfoed
Posts: 10
Joined: Thu Jul 18, 2019 6:40 am

problem with simple esp_mesh_send command

Postby cgfoed » Thu Jul 18, 2019 8:02 am

I'm using the current ESP-IDF on eclipse 4.12, trying to modify the internal_communication_example.

My goal in the end is to aggregate sensor data across the Mesh which shall be send to the Router which is also an ESP32 with softAP.
The basic setup seems to work for now. I've observed my small network electing a root, meshing together and connecting to the "router-ESP".
So far so good.
Now I'm trying to send data from a leaf or a node to the router-ESP.

I created a new task but I can't figure out why I'm getting this error:

Code: Select all

incompatible types when assigning to type 'ip4_addr_t' {aka 'struct ip4_addr'} from type 'u32_t' {aka 'unsigned int'}	mesh_main.c	/internal_communication_example/main	line 398	C/C++ Problem

Code: Select all

void sensor_test(void *arg)
{
	u32_t greetings = 123456; 
    mesh_data_t data;
    data.data = &greetings; //todo
    data.size = sizeof(greetings); //todo
    data.proto = MESH_PROTO_BIN;
    data.tos = MESH_TOS_P2P;
    is_running = true;


    while (is_running) {
        /* non-root do nothing but print */
        if (!esp_mesh_is_root()) {
            vTaskDelay(10 * 1000 / portTICK_RATE_MS);
            continue;
        }


         mip_t broker_addr;
         broker_addr.ip4 = ipaddr_addr("192.168.2.2");
		 broker_addr.port = 1883;
         esp_mesh_send(&broker_addr, &data, MESH_DATA_TODS, NULL, 0);
         
    }
    vTaskDelete(NULL);
}
   

I do understand the nature of the error, but I don't understand why it occurs, since;

Code: Select all

u32_t ipaddr_addr(const char *cp);
<<returns a u32_t

and "mip_t" comes down to a u32_t as well:

Code: Select all

typedef union {
    uint8_t addr[6];    /**< mac address */
    mip_t mip;          /**< mip address */
} mesh_addr_t;
looking for "mip_t" shows:

Code: Select all

typedef struct {
    ip4_addr_t ip4;    /**< IP address */
    uint16_t port;     /**< port */
} __attribute__((packed)) mip_t;
looking for "ip4_addr_t" shows:

Code: Select all

typedef struct ip4_addr ip4_addr_t;
looking for "ip4_addr " reveals:

Code: Select all

struct ip4_addr {
  u32_t addr;
};


What exactly is my problem here?

And btw; it would be highly appreciated to have more code examples for all the functions and workings of the mesh.
Thanks!

ESP_Bond
Posts: 51
Joined: Mon Apr 15, 2019 1:37 pm

Re: problem with simple esp_mesh_send command

Postby ESP_Bond » Thu Jul 18, 2019 10:33 am

The reason for the error is due to the parameter type mismatch, and your usage is also wrong.
We recommend that you develop on ESP-MDF, and there are rich examples on ESP-MDF.
https://github.com/espressif/esp-mdf

Image

cgfoed
Posts: 10
Joined: Thu Jul 18, 2019 6:40 am

Re: problem with simple esp_mesh_send command

Postby cgfoed » Thu Jul 18, 2019 1:25 pm

Well, thanks for that advice...



Is there any additional help somebody can offer?

ESP_yudong
Posts: 68
Joined: Wed May 16, 2018 12:31 pm

Re: problem with simple esp_mesh_send command

Postby ESP_yudong » Thu Jul 18, 2019 1:49 pm

Is this the line 398 in mesh_main.c ?

Code: Select all

broker_addr.ip4 = ipaddr_addr("192.168.2.2");
The type of broker_addr.ip4.addr is u32_t, but broker_addr.ip4 is not.

cgfoed
Posts: 10
Joined: Thu Jul 18, 2019 6:40 am

Re: problem with simple esp_mesh_send command

Postby cgfoed » Fri Jul 19, 2019 6:19 am

is there a code snippet for sending data to an mesh-external IP anywhere?

To answer your question:
Yes, this is line 398 - i'm aware that the error is located at that line.

cgfoed
Posts: 10
Joined: Thu Jul 18, 2019 6:40 am

Re: problem with simple esp_mesh_send command

Postby cgfoed » Fri Jul 19, 2019 12:50 pm

if somebody else comes across this problem; I'm using this workaround, written by ugallu now:

https://github.com/espressif/esp-idf/issues/2028

JL1946
Posts: 11
Joined: Mon Feb 25, 2019 3:46 pm

Re: problem with simple esp_mesh_send command

Postby JL1946 » Sun Dec 31, 2023 8:02 pm

Hello:
I know that I'm late to the party but I had the same problem and solved it this way:
1. I have set the server ip as 10.0.0.1
2. since ESP32 is little-endian, I had to reverse the array

Code: Select all

    mip_t SOURCE_IPV4_PORT = {0};
    
    uint8_t temp_ip[4] = {1, 0, 0, 10};					// Host Server ip actually is 10.0.0.1 entered in reverse order
    esp_ip4_addr_t *ip_addr;
    memcpy(&ip_addr, (uint32_t *)temp_ip, 4);			// the cast reverses the array (little-endian)

    memcpy (&SOURCE_IPV4_PORT.ip4, &ip_addr, 4);
    SOURCE_IPV4_PORT.port = 9000;
of course the above code could be shortened, but I chose to code it as shown...
I hope this helps...

Who is online

Users browsing this forum: No registered users and 22 guests