mdf的router加websocket协议问题

yeqinggui
Posts: 5
Joined: Wed May 18, 2022 8:52 am

mdf的router加websocket协议问题

Postby yeqinggui » Thu Jun 09, 2022 8:07 am

esp-mdf\examples\function_demo\mwifi\router组网没问题,esp-mdf\esp-idf\examples\protocols\websocket测试也没问题后,把websocket里边几个函数移植到router,在router的void tcp_client_read_task(void *arg)把socket_tcp_client_create屏蔽,增加websocket_app_start,结果连不上服务器,报错如下:



I (9436) [WEBSOCKET, 344]: Root obtains the IP address. It is posted by LwIP stack automatically
I (9446) [WEBSOCKET, 206]: TCP client read task is running
I (9452) WEBSOCKET: Connecting to ws://106.122.194.252.9999...
E (9482) TRANS_TCP: DNS lookup failed err=202 res=0x0
E (9483) TRANSPORT_WS: Error connecting to host 106.122.194.252.9999:80
E (9485) WEBSOCKET_CLIENT: Error transport connect


不知道哪里没配置好,还是修改函数没修改对,只是修改下边这个函数
void tcp_client_read_task(void *arg)
{
mdf_err_t ret = MDF_OK;
char *data = MDF_MALLOC(MWIFI_PAYLOAD_LEN);
size_t size = MWIFI_PAYLOAD_LEN;
uint8_t dest_addr[MWIFI_ADDR_LEN] = {0x0};
mwifi_data_type_t data_type = {0x0};
cJSON *json_root = NULL;
cJSON *json_addr = NULL;
cJSON *json_group = NULL;
cJSON *json_data = NULL;
cJSON *json_dest_addr = NULL;

MDF_LOGI("TCP client read task is running");

while (mwifi_is_connected()) {
if (g_sockfd == -1) {
// g_sockfd = socket_tcp_client_create(CONFIG_SERVER_IP, CONFIG_SERVER_PORT);//屏蔽掉,改为下边
websocket_app_start(); //新增加

if (g_sockfd == -1) {
vTaskDelay(500 / portTICK_RATE_MS);
continue;
}
}

memset(data, 0, MWIFI_PAYLOAD_LEN);
ret = read(g_sockfd, data, size);
MDF_LOGD("TCP read, %d, size: %d, data: %s", g_sockfd, size, data);

if (ret <= 0) {
MDF_LOGW("<%s> TCP read", strerror(errno));
close(g_sockfd);
g_sockfd = -1;
continue;
}

json_root = cJSON_Parse(data);
MDF_ERROR_CONTINUE(!json_root, "cJSON_Parse, data format error");

/**
* @brief Check if it is a group address. If it is a group address, data_type.group = true.
*/
json_addr = cJSON_GetObjectItem(json_root, "dest_addr");
json_group = cJSON_GetObjectItem(json_root, "group");

if (json_addr) {
data_type.group = false;
json_dest_addr = json_addr;
} else if (json_group) {
data_type.group = true;
json_dest_addr = json_group;
} else {
MDF_LOGW("Address not found");
cJSON_Delete(json_root);
continue;
}

/**
* @brief Convert mac from string format to binary
*/
do {
uint32_t mac_data[MWIFI_ADDR_LEN] = {0};
sscanf(json_dest_addr->valuestring, MACSTR,
mac_data, mac_data + 1, mac_data + 2,
mac_data + 3, mac_data + 4, mac_data + 5);

for (int i = 0; i < MWIFI_ADDR_LEN; i++) {
dest_addr = mac_data;
}
} while (0);

json_data = cJSON_GetObjectItem(json_root, "data");
char *send_data = cJSON_PrintUnformatted(json_data);

ret = mwifi_write(dest_addr, &data_type, send_data, strlen(send_data), true);
MDF_ERROR_GOTO(ret != MDF_OK, FREE_MEM, "<%s> mwifi_root_write", mdf_err_to_name(ret));

FREE_MEM:
MDF_FREE(send_data);
cJSON_Delete(json_root);
}

MDF_LOGI("TCP client read task is exit");

close(g_sockfd);
g_sockfd = -1;
MDF_FREE(data);
vTaskDelete(NULL);
}

wangzekun
Posts: 6
Joined: Mon May 22, 2023 2:23 am

Re: mdf的router加websocket协议问题

Postby wangzekun » Mon May 22, 2023 6:43 am

我也遇到了类似问题 root 节点无法访问esp32 ap 的tcp server.


(9979) [mqtt_examples, 422]: Root obtains the IP address. It is posted by LwIP stack automatically
W (9989) mqtt_examples: tcp_client_task run
lwip_socket(PF_INET, SOCK_STREAM, 0) = 54
I (9997) mqtt_examples: Socket created, connecting to 192.168.4.1:8989
lwip_connect(54, addr=192.168.4.1 port=8989)
tcp_connect to port 8989
tcp_pcb_purge
tcp_pcb_purge: data left on ->unacked
lwip_connect(54) failed, err=-14
E (10018) mqtt_examples: Socket unable to connect: errno 104
tcp_slowtmr: no active pcbs

ESP_Eavo
Posts: 186
Joined: Tue Jun 08, 2021 6:23 am

Re: mdf的router加websocket协议问题

Postby ESP_Eavo » Tue Jun 06, 2023 8:35 am

探索更轻量级的 Wi-Fi Mesh 组网方案 - ESP-Mesh-Lite。作为 ESP-Wi-Fi-Mesh 的理想替代方案,ESP-Mesh-Lite 提供了一种更简化、更高效的解决方案。它不仅支持节点直连服务器,还可供其他标准 Wi-Fi 设备轻松接入,而且无需依赖网关。这种全新的 Mesh 网络结构通过优化设计和更高效的资源利用,为您带来了更大的灵活性、可扩展性和简易实现的优势。立即升级到 ESP-Mesh-Lite,开启全新的连接可能性,并让您的项目从中受益。

ESP-Mesh Lite 的 资源如下:
代码仓库:https://github.com/espressif/esp-mesh-lite
包管理器:https://components.espressif.com/compon ... mesh_lite/

Who is online

Users browsing this forum: No registered users and 8 guests