ESP32 连接WIFI路由器时UDP通信异常 [WIFI-1710]

zhoujh
Posts: 3
Joined: Thu Jun 21, 2018 4:22 pm

ESP32 连接WIFI路由器时UDP通信异常 [WIFI-1710]

Postby zhoujh » Mon Feb 10, 2020 3:02 pm

ESP32模块使用WIFI连接路由器,在使用SOCKET进行UDP通信时,发现在某些路由器下发不出数据,在同一个地方,连接华为的路由器可以正常通信,连接带光猫的天翼路由器则发出的数据收不到,也不能接收客户端发过来的数据,造成产品的兼容性不好,不知道有没遇到类似的情况?测试代码如下:
recSocket = CreateUDPClient(NET_CFG_LISTEN_PORT);
ESP_LOGI(TAG,"Create Config listen socket!,socket:%d",recSocket);

if(recSocket<=0){
ESP_LOGE(TAG,"Create listen socket fail");
return;
}

rec_buffer = audio_malloc(NET_CFG_RECBUFF_SIZE*sizeof(char));
if(rec_buffer == NULL){
ESP_LOGE(TAG,"Memory exhaust!");
return;
}
struct sockaddr_in peerAddr;
socklen_t peerLen = sizeof(peerAddr);

while(1){
NetworkConfigSend(dest_ip_address,"Hello",5);
memset(rec_buffer,0,NET_CFG_RECBUFF_SIZE);
if(recSocket>0){
ESP_LOGE(TAG,"Read socket data!");
//bytes_read = read (recSocket, rec_buffer, NET_CFG_RECBUFF_SIZE);
bytes_read = recvfrom(recSocket,rec_buffer,NET_CFG_RECBUFF_SIZE,0,(struct sockaddr *)&peerAddr,&peerLen);
if(bytes_read>0){
ESP_LOGI(TAG,"Receive packet:%s,bytes:%d",rec_buffer,bytes_read);
ESP_LOGI(TAG,"peer address = %s:%d\n", inet_ntoa(peerAddr.sin_addr), ntohs(peerAddr.sin_port));
if(NetCommandProcess(rec_buffer)>0){
ESP_LOGI(TAG,"Command process OK");
}
dest_ip_address = peerAddr.sin_addr.s_addr;
}
if(bytes_read < 0){
ESP_LOGE(TAG,"UDP Receive had error!Reset socket..");
recSocket = 0;
}
else{
ESP_LOGE(TAG,"Rec timeout");
}
}else{
vTaskDelay(2000);
recSocket = CreateUDPClient(NET_CFG_LISTEN_PORT);
ESP_LOGI(TAG,"Create Config listen socket!,socket:%d",recSocket);
if(recSocket<=0){
ESP_LOGE(TAG,"UDP Create faile!");
break;
}
}
}

ESP_Alvin
Posts: 120
Joined: Thu May 17, 2018 2:26 am

Re: ESP32 连接WIFI路由器时UDP通信异常

Postby ESP_Alvin » Tue Feb 11, 2020 7:46 am

Hi zhoujh,

您好,能不能提供下光猫的天翼路由器的具体型号?谢谢。

liuzhifu
Posts: 34
Joined: Tue Dec 13, 2016 2:18 am

Re: ESP32 连接WIFI路由器时UDP通信异常

Postby liuzhifu » Tue Mar 24, 2020 12:17 pm

Hi @ zhoujh,

使用中国电信天冀网关 2.0,型号 HS8145C 进行测试,配置如下:
  • HS8145C 设置无线网络
  • PC 通过以太口连到 HS8145C,配置静态 IP 地址: 192.168.100.3
  • macbook 连接无线网络,拿到 IP 地址为 192.168.100.8。macbook 连上去之后,会弹出一个页面提示输入上网帐号与密码,这一步直接跳过。
  • ESP32 连接无线网络,拿到 IP 地址为 192.168.100.2
测试结果如下:
  • 测试一:PC 与 Macbook 之间 ping 不通,也无法收发 UDP 包
  • 测试二:PC 与 ESP32 之间 ping 不通,也无法收发 UDP 包
  • 测试三:Macbook 与 ESP32 之间能 ping 通,正常收发 UDP 包
目前不确定测试一/二是否与没有上网帐号相关,但 ESP32 与 macbook 行为一致。

请问,你是如何做测试的?

ESP_Alvin
Posts: 120
Joined: Thu May 17, 2018 2:26 am

Re: ESP32 连接WIFI路由器时UDP通信异常 [WIFI-1710]

Postby ESP_Alvin » Wed Mar 25, 2020 2:06 am

Moderator's note: edit the topic title for issue tracking, thanks.

liuzhifu
Posts: 34
Joined: Tue Dec 13, 2016 2:18 am

Re: ESP32 连接WIFI路由器时UDP通信异常 [WIFI-1710]

Postby liuzhifu » Tue Mar 31, 2020 5:50 am

Hi zhoujh,

Any update about this issue?

liuzhifu
Posts: 34
Joined: Tue Dec 13, 2016 2:18 am

Re: ESP32 连接WIFI路由器时UDP通信异常 [WIFI-1710]

Postby liuzhifu » Wed Apr 15, 2020 12:29 pm

HI @zhoujh, 这个问题有更新么?

ESP_Alvin
Posts: 120
Joined: Thu May 17, 2018 2:26 am

Re: ESP32 连接WIFI路由器时UDP通信异常 [WIFI-1710]

Postby ESP_Alvin » Thu Apr 16, 2020 1:20 am

Hi zhoujh,

该问题有更新么?能否提供下反馈?谢谢。

Any updates or feedback for this issue? Thanks.

Alvin

zhoujh
Posts: 3
Joined: Thu Jun 21, 2018 4:22 pm

Re: ESP32 连接WIFI路由器时UDP通信异常 [WIFI-1710]

Postby zhoujh » Thu May 28, 2020 4:48 pm

光猫的型号是ZXHN F650(GPON ONU),ESP32可以正常连接WIFI,通过UDP socket跟手机通信,数据接收不到

连接华为路由器WS832则可以正常收发数据

Who is online

Users browsing this forum: No registered users and 7 guests