请教一下WIFI 连接的若干问题

gallex
Posts: 4
Joined: Mon Dec 18, 2023 2:17 am

请教一下WIFI 连接的若干问题

Postby gallex » Mon Dec 18, 2023 2:30 am

我购买了一个现成的模块,连接WIFI时存在如下问题:

1) 同一个路由器,连接时间不一,有时长,有时短。
2) 有时甚至不能正常连接,必须重启(开关电源)才能连接。按Reset或软件重启都不行。
3)连接成功(以获得IP为标志)后,也有一定的概率,实际网络不通,或时延很长(ping 超过1000ms), 重启(开关电源,Reset不行)恢复正常。有时重启不行,还得多次重启,只到网络联通。

请问是什么原因呢?有碰到的网友吗?是软件需要更精细的流程控制,还是硬件需要修改(但是我的模块是买的现成的)

gallex
Posts: 4
Joined: Mon Dec 18, 2023 2:17 am

Re: 请教一下WIFI 连接的若干问题

Postby gallex » Mon Dec 18, 2023 4:30 am

在不能连接时,我把最详细的日志打印出来了。

D (833755) esp-tls: [sock=54] Connecting to server. HOST: 192.168.1.100, Port: 1883
E (843775) esp-tls: [sock=54] select() timeout
E (843775) transport_base: Failed to open a new connection: 32774
E (843775) mqtt_client: Error transport connect
D (843775) event: running post MQTT_EVENTS:0 with handler 0x400d958c and context 0x3ffcfc48 on loop 0x3ffc3fb8
0x400d958c: mqtt_event_handler(void*, char const*, long, void*) at /home/lg/esp/ambox/build/../main/mqtt.cpp:114

D (843785) mqtt_event_handler: Event dispatched from event loop base=MQTT_EVENTS, event_id=0
I (843795) mqtt_event_handler: MQTT_EVENT_ERROR
E (843805) log_error_if_nonzero: Last error reported from esp-tls: 0x8006
I (843805) mqtt_event_handler: Last errno string (Success)
D (843815) event: running post MQTT_EVENTS:2 with handler 0x400d958c and context 0x3ffcfc48 on loop 0x3ffc3fb8
0x400d958c: mqtt_event_handler(void*, char const*, long, void*) at /home/lg/esp/ambox/build/../main/mqtt.cpp:114

D (843825) mqtt_event_handler: Event dispatched from event loop base=MQTT_EVENTS, event_id=2
I (843835) mqtt_event_handler: MQTT_EVENT_DISCONNECTED
D (853835) event: running post MQTT_EVENTS:7 with handler 0x400d958c and context 0x3ffcfc48 on loop 0x3ffc3fb8
0x400d958c: mqtt_event_handler(void*, char const*, long, void*) at /home/lg/esp/ambox/build/../main/mqtt.cpp:114

D (853835) mqtt_event_handler: Event dispatched from event loop base=MQTT_EVENTS, event_id=7
I (853835) mqtt_event_handler: Other event id:7
D (853845) esp-tls: host:192.168.1.100: strlen 13
D (853845) esp-tls: [sock=54] Resolved IPv4 address: 192.168.1.100
D (853855) esp-tls: [sock=54] Connecting to server. HOST: 192.168.1.100, Port: 1883

ESP_MacChu
Posts: 47
Joined: Tue Nov 21, 2023 7:53 am

Re: 请教一下WIFI 连接的若干问题

Postby ESP_MacChu » Wed Dec 20, 2023 11:43 am

gallex wrote:
Mon Dec 18, 2023 4:30 am
在不能连接时,我把最详细的日志打印出来了。

D (833755) esp-tls: [sock=54] Connecting to server. HOST: 192.168.1.100, Port: 1883
E (843775) esp-tls: [sock=54] select() timeout
E (843775) transport_base: Failed to open a new connection: 32774
E (843775) mqtt_client: Error transport connect
D (843775) event: running post MQTT_EVENTS:0 with handler 0x400d958c and context 0x3ffcfc48 on loop 0x3ffc3fb8
0x400d958c: mqtt_event_handler(void*, char const*, long, void*) at /home/lg/esp/ambox/build/../main/mqtt.cpp:114

D (843785) mqtt_event_handler: Event dispatched from event loop base=MQTT_EVENTS, event_id=0
I (843795) mqtt_event_handler: MQTT_EVENT_ERROR
E (843805) log_error_if_nonzero: Last error reported from esp-tls: 0x8006
I (843805) mqtt_event_handler: Last errno string (Success)
D (843815) event: running post MQTT_EVENTS:2 with handler 0x400d958c and context 0x3ffcfc48 on loop 0x3ffc3fb8
0x400d958c: mqtt_event_handler(void*, char const*, long, void*) at /home/lg/esp/ambox/build/../main/mqtt.cpp:114

D (843825) mqtt_event_handler: Event dispatched from event loop base=MQTT_EVENTS, event_id=2
I (843835) mqtt_event_handler: MQTT_EVENT_DISCONNECTED
D (853835) event: running post MQTT_EVENTS:7 with handler 0x400d958c and context 0x3ffcfc48 on loop 0x3ffc3fb8
0x400d958c: mqtt_event_handler(void*, char const*, long, void*) at /home/lg/esp/ambox/build/../main/mqtt.cpp:114

D (853835) mqtt_event_handler: Event dispatched from event loop base=MQTT_EVENTS, event_id=7
I (853835) mqtt_event_handler: Other event id:7
D (853845) esp-tls: host:192.168.1.100: strlen 13
D (853845) esp-tls: [sock=54] Resolved IPv4 address: 192.168.1.100
D (853855) esp-tls: [sock=54] Connecting to server. HOST: 192.168.1.100, Port: 1883
请问具体使用的是什么设备和程序呢?并且看问题描述,不是很确定是连接路由器还是连接服务器。

gallex
Posts: 4
Joined: Mon Dec 18, 2023 2:17 am

Re: 请教一下WIFI 连接的若干问题

Postby gallex » Fri Dec 22, 2023 1:21 am

ESP_MacChu wrote:
Wed Dec 20, 2023 11:43 am
gallex wrote:
Mon Dec 18, 2023 4:30 am
在不能连接时,我把最详细的日志打印出来了。

D (853835) event: running post MQTT_EVENTS:7 with handler 0x400d958c and context 0x3ffcfc48 on loop 0x3ffc3fb8
0x400d958c: mqtt_event_handler(void*, char const*, long, void*) at /home/lg/esp/ambox/build/../main/mqtt.cpp:114

D (853835) mqtt_event_handler: Event dispatched from event loop base=MQTT_EVENTS, event_id=7
I (853835) mqtt_event_handler: Other event id:7
D (853845) esp-tls: host:192.168.1.100: strlen 13
D (853845) esp-tls: [sock=54] Resolved IPv4 address: 192.168.1.100
D (853855) esp-tls: [sock=54] Connecting to server. HOST: 192.168.1.100, Port: 1883
请问具体使用的是什么设备和程序呢?并且看问题描述,不是很确定是连接路由器还是连接服务器。
连接路由器,然后再连接MQTT服务器。现在的问题是,连接路由器时间时长时短,有概率连不上。连接MQTT服务器,在路由器连接成功后,也可能联不上。重启后恢复,也可能要重启多次。

ESP_MacChu
Posts: 47
Joined: Tue Nov 21, 2023 7:53 am

Re: 请教一下WIFI 连接的若干问题

Postby ESP_MacChu » Tue Jan 02, 2024 11:27 am

因为所提供的信息不是很详细,无法直接确定问题。这里提供一些排查的思路:
1. 如果程序打出来 Wi-Fi 错误码,可以使用其进行失败原因的定位
2. 确定是路由器的问题还是 ESP32 的问题:
a. 排查路由器问题的步骤:
i. 确定路由器是否正处于断电重启阶段
ii. 查看是否能正常连上其他路由器
b. 排查 ESP32 问题的步骤:
i. 查看是否是特定的 ESP32 才会出现此问题
ii. 查看使用 ESP-IDF 里的 station 示例 (https://github.com/espressif/esp-idf/tr ... ed/station) 是否能正常连上 Wi-Fi,此处示例里默认存在重连机制,可以同步观察在几次重连后是否能正常连上 Wi-Fi。
iii. 确认所配置的 SSID 与密码是否正确
iiii. 查看在配置路由器为 OPEN 模式后是否能正常连上
iiiii. 查看在 Wi-Fi 连接前的代码逻辑里额外调用 API esp_wifi_set_ps(WIFI_PS_NONE) 后是否能正常连上 Wi-Fi。
3. 如进行上述所有步骤仍然没有定位到问题,建议进行 Wi-Fi 抓包来进一步分析,可参考 乐鑫 Wireshark 使用指南 (https://docs.espressif.com/projects/esp ... guide.html)

Who is online

Users browsing this forum: No registered users and 144 guests