Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easymesh agent to retry when init_dml fails on access_not_allowed error #126

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/agent/em_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#include "em_orch_agent.h"
#include "util.h"

#define MAX_RETRY 20
#define RETRY_SLEEP_INTERVAL_IN_MS 1000

em_agent_t g_agent;
const char *global_netid = "OneWifiMesh";

Expand Down Expand Up @@ -401,6 +404,8 @@ void em_agent_t::input_listener()
wifi_bus_desc_t *desc;
dm_easy_mesh_t dm;
raw_data_t data;
int num_retry = 0;
bus_error_t bus_error_val;

bus_init(&m_bus_hdl);

Expand All @@ -417,12 +422,25 @@ void em_agent_t::input_listener()

memset(&data, 0, sizeof(raw_data_t));

if (desc->bus_data_get_fn(&m_bus_hdl, WIFI_WEBCONFIG_INIT_DML_DATA, &data) != 0) {
printf("%s:%d bus get failed\n", __func__, __LINE__);
return;
} else {
printf("%s:%d recv data:\r\n%s\r\n", __func__, __LINE__, (char *)data.raw_data.bytes);
while (((bus_error_val = desc->bus_data_get_fn(&m_bus_hdl, WIFI_WEBCONFIG_INIT_DML_DATA, &data)) != bus_error_success)
&& num_retry < MAX_RETRY) {
printf("%s:%d bus get failed, error:%d, ", __func__, __LINE__, bus_error_val);
if (bus_error_val == bus_error_access_not_allowed) {
// This error can come when backhaul STA is not yet connected, thus retry after some amount of sleep
usleep(RETRY_SLEEP_INTERVAL_IN_MS * 1000);
num_retry++;
printf("retry %d of %d\n", num_retry, MAX_RETRY);
} else {
printf("no retries, returning..\n");
return;
}
}

if (num_retry == MAX_RETRY) {
printf("no further retries, returning..\n");
return;
}
printf("%s:%d recv data:\r\n%s\r\n", __func__, __LINE__, (char *)data.raw_data.bytes);

g_agent.io_process(em_bus_event_type_dev_init, (unsigned char *)data.raw_data.bytes, data.raw_data_len);

Expand Down
Loading