esp_mesh_recv duplicated package

Sakulh
Posts: 1
Joined: Mon Aug 21, 2023 6:46 pm

esp_mesh_recv duplicated package

Postby Sakulh » Wed Aug 23, 2023 7:45 am

Hi,

When using wifi mesh i been having som issues with "esp_mesh_recv". After running for a hour or two I start to receive the same packets first twice and then more then twice. Right now im running 1 root + 9 child devices. After rebooting child that has the issue it goes away(But comes back later). From the fixed root node im sending a package to each device with 1 second delay between packages.

Here is the code for setting up child device:
void mesh_init(){
is_running = true;

// mesh initialization
ESP_ERROR_CHECK(esp_mesh_init());
ESP_ERROR_CHECK(esp_event_handler_register(MESH_EVENT, ESP_EVENT_ANY_ID, &mesh_event_handler, NULL));

/* set mesh topology */
ESP_ERROR_CHECK(esp_mesh_set_topology(MESH_TOPO_CHAIN));

/* set mesh max layer according to the topology */
ESP_ERROR_CHECK(esp_mesh_set_max_layer(CONFIG_MESH_MAX_LAYER));

ESP_ERROR_CHECK(esp_mesh_disable_ps());
ESP_ERROR_CHECK(esp_mesh_set_ap_assoc_expire(60));

ESP_ERROR_CHECK(esp_mesh_allow_root_conflicts(false));

/* Set mesh device type */
esp_mesh_set_type(MESH_IDLE);

/* Set fixed root in the mesh network */
esp_mesh_fix_root(1);

/* Create default mesh config */
mesh_cfg_t cfg = MESH_INIT_CONFIG_DEFAULT();

/* mesh ID */
memcpy((uint8_t *) &cfg.mesh_id, MESH_ID, 6);



/* router config */
/* NO ROUTER CONFIG */
cfg.channel = 0;

/* mesh softAP config */
ESP_ERROR_CHECK(esp_mesh_set_ap_authmode(CONFIG_MESH_AP_AUTHMODE));
cfg.mesh_ap.max_connection = CONFIG_MESH_AP_CONNECTIONS;

const char * pswd = "mypswd1234";
memcpy((uint8_t *) &cfg.mesh_ap.password, pswd, strlen(pswd));


ESP_ERROR_CHECK(esp_mesh_set_config(&cfg));

//esp_mesh_send_block_time(2000);

ESP_ERROR_CHECK(esp_mesh_set_xon_qsize(128));


/* mesh start */
ESP_ERROR_CHECK(esp_mesh_start());


if(mesh_rx_task_handle != NULL)
esp_restart();

mesh_rx_task_handle = xTaskCreateStatic(
mesh_rx_task,
"MESH_RX",
STACK_SIZE,
NULL,
5/*configMAX_PRIORITIES - 1*/,
task_stack,
&rx_task_buffer
);
}


And here is the task that receives
static void mesh_rx_task(void *arg)
{
esp_err_t err;
int flag = 0;
ADOPTED_DEVICE_t device;
mesh_data_t data;
data.data = (uint8_t*)&device;
mesh_addr_t from;

uint32_t rx_msg_count = 0;
TickType_t last_tick = 0;

uint8_t zero_tick_counter = 0;
uint8_t tick_ok_counter = 0;

while (is_running) {
data.size = sizeof(ADOPTED_DEVICE_t);

err = esp_mesh_recv(&from, &data, portMAX_DELAY, &flag, NULL, 0); // WAITING HERE 5 MINUTES

if (err != ESP_OK || !data.size) {
ESP_LOGE(MESH_TAG, "%s", esp_err_to_name(err));
ESP_LOGE(MESH_TAG, "err:0x%x, size:%d", err, data.size);
continue;
}

TickType_t tick_now = xTaskGetTickCount();
uint32_t tick_between_msg = (tick_now - last_tick);
last_tick = tick_now;
ESP_LOGI(MESH_TAG, "MSG_COUNT_LOCAL: %lu\tMSG_COUNT_REMOTE: %lu\tTicks between: %lu", ++rx_msg_count,
device.msg_count, tick_between_msg);

if(tick_between_msg < 10){
tick_ok_counter = 0;

if(++zero_tick_counter > 10){
eeprom_mesh_tick_bug();
reboot_module = 0x55;
}
}else
tick_ok_counter++;


if(tick_ok_counter > 20){
tick_ok_counter = 0;
zero_tick_counter = 0;
}


if(data.size == sizeof(ADOPTED_DEVICE_t)){
ClearError(); // This function will only clear a led thats connected
led_blink_once();
}
}

ESP_LOGE(MESH_TAG, "RX TASK SHUTDOWN");
vTaskDelete(NULL);
}

Who is online

Users browsing this forum: No registered users and 11 guests