bug in esp_mesh_send sending to ROOT

leenowell
Posts: 92
Joined: Tue Jan 15, 2019 1:50 pm

bug in esp_mesh_send sending to ROOT

Postby leenowell » Sat Feb 09, 2019 2:44 pm

Hi all,

I am having some trouble with esp_mesh_send. The following code runs on 2 x ESP32s and seems to work fine if the node is ROOT but if it is not ROOT I get the following errors

Code: Select all

[0;32mI (1065587) HomeIoT: DoStuff: leaf node[0m

[0;32mI (1065587) HomeIoT: DoStuff: About to send message [Hello from HomeIOT] size [19] layer[2] numb nodes[1][0m

[0;32mI (1065587) mesh_node: MeshNodeSendData:  message size [19] message [Hello from HomeIOT][0m

[0;32mI (1065597) mesh_node: Destination is NULL so off to ROOT[0m

[0;31mE (1065597) mesh_node: MeshNodeSendData: Failed to send Mesh data Error[16392 = ESP_ERR_MESH_ARGUMENT] - message size [19] parent [ 3c:71:bf:96:e6:41 ] [0m

[0;31mE (1065617) HomeIoT: DoStuff: Failed to send Mesh data to ROOT Error[16392 = ESP_ERR_MESH_ARGUMENT] - Message [Hello from HomeIOT][0m

This is the function that sends the mesh data

Code: Select all

esp_err_t mesh_node_send_data(mesh_addr_t *dest_addr, mesh_data_t *data)
{
    esp_err_t err = ESP_OK;

    char *sMessage = (char*)data->data;
	ESP_LOGI(MESH_TAG,"MeshNodeSendData:  message size [%d] message [%s]", data->size, sMessage );
	
	err = esp_mesh_send(dest_addr, data, MESH_DATA_P2P, NULL, 0);

    if (mesh_parent_addr.addr == NULL)
    {
    	ESP_LOGE(MESH_TAG, "MeshNodeSendData: parent address is NULL");
    	return ESP_FAIL;
    }

    if (err != ESP_OK)
    	ESP_LOGE(MESH_TAG,"MeshNodeSendData: Failed to send Mesh data Error[%d = %s] - message size [%d] parent [ "MACSTR" ] ", err, esp_err_to_name(err), data->size, MAC2STR(mesh_parent_addr.addr) );
	else
    	ESP_LOGI(MESH_TAG,"MeshNodeSendData: Sent Mesh message -  message size [%d] parent ["MACSTR"] ", data->size, MAC2STR(mesh_parent_addr.addr) );

    return err;
}

and this is the calling code

Code: Select all

void DoStuff()
{
	char sMessage[40] = "";
	esp_err_t err;

	mesh_addr_t routeTable[100];
	int nRouteTableSize = 0;
	int nLayer = 0;

	bool bIsRoot = false;

	sprintf(sMessage, "Hello from HomeIOT");

	mesh_data_t data;
	data.data = (void*) sMessage;
	data.size = strlen((char*) data.data)+1;
	data.proto = MESH_PROTO_BIN;
    data.tos = MESH_TOS_DEF;

	while (1)
	{
		bIsRoot = esp_mesh_is_root();
		if (bIsRoot)
			ESP_LOGI(HOMEIOT_TAG, "DoStuff: I AM ROOT");
		else
			ESP_LOGI(HOMEIOT_TAG, "DoStuff: leaf node");

		// Only gives table of this node and those below
		err = esp_mesh_get_routing_table( (mesh_addr_t*) &routeTable, 100*6, &nRouteTableSize);
		nLayer =  esp_mesh_get_layer();

		ESP_LOGI(HOMEIOT_TAG, "DoStuff: About to send message [%s] size [%d] layer[%d] numb nodes[%d]", (char*) data.data, data.size, nLayer, nRouteTableSize);

		err = mesh_node_send_data( NULL ,  &data);

		if (err !=ESP_OK)
			ESP_LOGE(HOMEIOT_TAG, "DoStuff: Failed to send Mesh data to ROOT Error[%d = %s] - Message [%s]", err ,esp_err_to_name(err), (char *) data.data);


		vTaskDelay(5 * 1000 / portTICK_RATE_MS);
	}
}
This seems like a bug to me but anyone have any ideas?

thanks

Lee.
Last edited by leenowell on Sun Feb 10, 2019 2:11 pm, edited 2 times in total.

leenowell
Posts: 92
Joined: Tue Jan 15, 2019 1:50 pm

update bug in esp_mesh_send sending to ROOT

Postby leenowell » Sun Feb 10, 2019 1:34 pm

Hi All,

UPDATED after further testing - sorry

So after a lot of debugging and trying all sorts of things, I *think* I may have found something - initially I thought this was the culprit but after more testing looks like it is not. Having said this, the internal_communication one does seem to still be the case but making the changes in my code still has the invalid argument error - so back to the drawing board :(

The data I am sending is a struct. If I create an instance of it within my send function and set the "mesh_data_t.data" element to point to it I get the error. If I just move the instance of the struct to be a global variable it works fine.

This code (simplified to highlight the issue) gives the error

Code: Select all

MySendFunction()
{
	mesh_data_t dataToRoot;
	homeiot_message_t homeiotSendMessage;

	homeiotSendMessage.event = NODE_DATA;
	dataToRoot.data 	= (void*) &homeiotSendMessage;
	dataToRoot.size 	= sizeof(homeiotSendMessage);

	err = mesh_node_send_data( NULL ,  &dataToRoot);
Where as this code works fine

Code: Select all

homeiot_message_t homeiotSendMessage;

MySendFunction()
{
	mesh_data_t dataToRoot;

	homeiotSendMessage.event = NODE_DATA;
	dataToRoot.data 	= (void*) &homeiotSendMessage;
	dataToRoot.size 	= sizeof(homeiotSendMessage);

	err = mesh_node_send_data( NULL ,  &dataToRoot);

The internal_communication example behaves similarly however the error is different. Instead of "ESP_ERR_MESH_ARGUMENT" it returns "ROOT-2-UNICAST".

I assume this is a bug in the mesh send function as not sure why it rejects (or indeed knows) when the data it points to is on the stack. Using a global variable will potentially cause concurrency issues. Would be interested in your thoughts.

thanks

Lee.

leenowell
Posts: 92
Joined: Tue Jan 15, 2019 1:50 pm

Re: bug in esp_mesh_send sending to ROOT

Postby leenowell » Sun Feb 10, 2019 5:00 pm

Sorry please disregard the previous post as I can now reproduce the error even with the data variable being global. Only other update to give is that even with logging set to "verbose" I get no log output during the call to esp_mesh_send. I log immediately before and after it and that's all I get.

thanks

Lee.

leenowell
Posts: 92
Joined: Tue Jan 15, 2019 1:50 pm

Re: bug in esp_mesh_send sending to ROOT

Postby leenowell » Tue Feb 12, 2019 7:49 am

Hi

Any thoughts on this? Even if you could tell me what the error means eg which argument or what sort of checks it does maybe I could dig in a bit further ?

Thanks

Lee.

leenowell
Posts: 92
Joined: Tue Jan 15, 2019 1:50 pm

Re: bug in esp_mesh_send sending to ROOT

Postby leenowell » Thu Feb 14, 2019 12:11 pm

Hi all

Any thoughts in this? Happy to run any further tests to help identify the issue.

Thanks

Lee.

User avatar
hassan789
Posts: 156
Joined: Thu Jun 29, 2017 2:15 am

Re: bug in esp_mesh_send sending to ROOT

Postby hassan789 » Sun Jul 21, 2019 1:52 am

having the same problem from time to time... must be a bug in the MDF/IDF layer...

Who is online

Users browsing this forum: Bing [Bot] and 395 guests