esp-rs / esp-idf-svc

Type-Safe Rust Wrappers for various ESP-IDF services (WiFi, Network, Httpd, Logging, etc.)
https://docs.esp-rs.org/esp-idf-svc/
Apache License 2.0
303 stars 172 forks source link

wifi connection is complete, the ping fails #317

Closed MrDustZero closed 10 months ago

MrDustZero commented 10 months ago

code `

let mut esp_wifi = EspWifi::new(modem, sysloop.clone(), None)?;

let mut wifi = BlockingWifi::wrap(&mut esp_wifi, sysloop)?;

wifi.set_configuration(&Configuration::Client(ClientConfiguration::default()))?;

info!("Starting wifi...");

wifi.start()?;

info!("Scanning...");

let ap_infos = wifi.scan()?;

let ours = ap_infos.into_iter().find(|a| a.ssid == ssid);

let channel = if let Some(ours) = ours {
    info!(
        "Found configured access point {} on channel {}",
        ssid, ours.channel
    );
    Some(ours.channel)
} else {
    info!(
        "Configured access point {} not found during scanning, will go with unknown channel",
        ssid
    );
    None
};

wifi.set_configuration(&Configuration::Mixed(
    ClientConfiguration {
        ssid: ssid.into(),
        password: pass.into(),
        channel,
        auth_method,
        ..Default::default()
    }
    ,
    AccessPointConfiguration {
        ssid: "aptest".into(),
        channel: channel.unwrap_or(1),
        ..Default::default()
    },
))?;

info!("Connecting wifi...");

wifi.connect()?;

info!("Waiting for DHCP lease...");

wifi.wait_netif_up()?;

let ip_info = wifi.wifi().sta_netif().get_ip_info()?;

info!("Wifi DHCP info: {:?}", ip_info);

log::info!("About to do some pings for {:?}", std::net::Ipv4Addr::new(114,114,114,114));

let ping_summary = esp_idf_svc::ping::EspPing::default().ping(std::net::Ipv4Addr::new(114,114,114,114), &Default::default())?;
if ping_summary.transmitted != ping_summary.received {
    bail!("Pinging IP {} resulted in timeouts", std::net::Ipv4Addr::new(114,114,114,114));
}

log::info!("Pinging done");

`

console

I (42) boot: ESP-IDF v5.1-beta1-378-gea5e0ff298-dirt 2nd stage bootloader I (42) boot: compile time Jun 7 2023 08:02:08 I (43) boot: chip revision: v0.0 I (47) boot.esp32c6: SPI Speed : 40MHz I (52) boot.esp32c6: SPI Mode : DIO I (57) boot.esp32c6: SPI Flash Size : 8MB I (61) boot: Enabling RNG early entropy source... I (67) boot: Partition Table: I (70) boot: ## Label Usage Type ST Offset Length I (78) boot: 0 nvs WiFi data 01 02 00009000 00006000 I (85) boot: 1 phy_init RF data 01 01 0000f000 00001000 I (92) boot: 2 factory factory app 00 00 00010000 007f0000 I (100) boot: End of partition table I (104) esp_image: segment 0: paddr=00010020 vaddr=42000020 size=bf018h (782360) map I (272) esp_image: segment 1: paddr=000cf040 vaddr=40800000 size=00fd8h ( 4056) load I (273) esp_image: segment 2: paddr=000d0020 vaddr=420c0020 size=39790h (235408) map I (325) esp_image: segment 3: paddr=001097b8 vaddr=40800fd8 size=0efc4h ( 61380) load I (340) esp_image: segment 4: paddr=00118784 vaddr=4080ffa0 size=03258h ( 12888) load I (348) boot: Loaded app from partition at offset 0x10000 I (348) boot: Disabling RNG early entropy source... I (360) cpu_start: Unicore app I (361) cpu_start: Pro cpu up. W (369) clk: esp_perip_clk_init() has not been implemented yet I (376) cpu_start: Pro cpu start user code I (376) cpu_start: cpu freq: 160000000 Hz I (376) cpu_start: Application information: I (379) cpu_start: Project name: libespidf I (384) cpu_start: App version: 1 I (389) cpu_start: Compile time: Nov 14 2023 10:19:45 I (395) cpu_start: ELF file SHA256: 0000000000000000... I (401) cpu_start: ESP-IDF: v5.1.1-dirty I (406) cpu_start: Min chip rev: v0.0 I (411) cpu_start: Max chip rev: v0.99 I (416) cpu_start: Chip rev: v0.0 I (420) heap_init: Initializing. RAM available for dynamic allocation: I (428) heap_init: At 40817D30 len 000648E0 (402 KiB): D/IRAM I (434) heap_init: At 4087C610 len 00002F54 (11 KiB): STACK/DIRAM I (441) heap_init: At 50000000 len 00003FE8 (15 KiB): RTCRAM I (448) spi_flash: detected chip: generic I (452) spi_flash: flash io: dio W (456) timer_group: legacy driver is deprecated, please migrate to driver/gptimer.h I (464) sleep: Configure to isolate all GPIO pins in sleep state I (471) sleep: Enable automatic switching of GPIO sleep configuration I (478) coexist: coex firmware version: 80b0d89 I (484) coexist: coexist rom version 5b8dcfa I (489) app_start: Starting scheduler on CPU0 I (493) main_task: Started on CPU0 I (493) main_task: Calling app_main() I (493) pp: pp rom version: 5b8dcfa I (503) net80211: net80211 rom version: 5b8dcfa I (513) wifi:wifi driver task: 4087eba0, prio:23, stack:6656, core=0 I (513) wifi:wifi firmware version: ce9244d I (513) wifi:wifi certification version: v7.0 I (523) wifi:config NVS flash: disabled I (523) wifi:config nano formating: disabled I (523) wifi:mac_version:HAL_MAC_ESP32AX_761,ut_version:N I (533) wifi:Init data frame dynamic rx buffer num: 32 I (533) wifi:Init management frame dynamic rx buffer num: 32 I (543) wifi:Init management short buffer num: 32 I (543) wifi:Init dynamic tx buffer num: 32 I (553) wifi:Init static tx FG buffer num: 2 I (553) wifi:Init static rx buffer size: 1700 I (563) wifi:Init static rx buffer num: 10 I (563) wifi:Init dynamic rx buffer num: 32 I (563) wifi_init: rx ba win: 6 I (573) wifi_init: tcpip mbox: 32 I (573) wifi_init: udp mbox: 6 I (583) wifi_init: tcp mbox: 6 I (583) wifi_init: tcp tx win: 5744 I (583) wifi_init: tcp rx win: 5744 I (593) wifi_init: tcp mss: 1440 I (593) wifi_init: WiFi IRAM OP enabled I (603) wifi_init: WiFi RX IRAM OP enabled I (603) wifi: Starting wifi... I (603) phy_init: phy_version 202,b4b3263,May 17 2023,20:14:14 E (613) phy_init: esp_phy_load_cal_data_from_nvs: NVS has not been initialized. Call nvs_flash_init before starting WiFi/BT. W (623) phy_init: failed to load RF calibration data (0x1101), falling back to full calibration W (673) wifi:(bf)761:0x600a7cac:0x01b4b4b0 0x600a7cac - PCR at ??:?? 0x01b4b4b0 - at ??:?? W (673) wifi:(agc)0x600a7128:0xd21c0800, min.avgNF:0xce->0xd2(dB), RCalCount:0x1c0, min.RRssi:0x800(-128.00) 0x600a7128 - PCR at ??:?? 0xd21c0800 - LP_ANA_PERI at ??:?? W (673) wifi:(TB)WDEV_PWR_TB_MCS0:19 W (673) wifi:(TB)WDEV_PWR_TB_MCS1:19 W (683) wifi:(TB)WDEV_PWR_TB_MCS2:19 W (683) wifi:(TB)WDEV_PWR_TB_MCS3:19 W (683) wifi:(TB)WDEV_PWR_TB_MCS4:19 W (693) wifi:(TB)WDEV_PWR_TB_MCS5:19 W (693) wifi:(TB)WDEV_PWR_TB_MCS6:18 W (693) wifi:(TB)WDEV_PWR_TB_MCS7:18 W (703) wifi:(TB)WDEV_PWR_TB_MCS8:17 W (703) wifi:(TB)WDEV_PWR_TB_MCS9:15 W (703) wifi:(TB)WDEV_PWR_TB_MCS10:15 W (713) wifi:(TB)WDEV_PWR_TB_MCS11:15 I (713) wifi:11ax coex: WDEVAX_PTI0(0x55777555), WDEVAX_PTI1(0x00003377). 0x55777555 - _rtc_reserved_end at ??:?? 0x00003377 - at ??:??

I (723) wifi:mode : sta (40:4c:ca:46:11:54) I (723) wifi:enable tsf I (733) wifi: Scanning... I (5833) wifi: Found configured access point JJF3 on channel 11 I (5833) wifi:mode : sta (40:4c:ca:46:11:54) + softAP (40:4c:ca:46:11:55) I (5833) wifi:Total power save buffer number: 16 I (5833) wifi:Init max length of beacon: 752/752 I (5843) wifi:Init max length of beacon: 752/752 I (5843) esp_netif_lwip: DHCP server started on interface WIFI_AP_DEF with IP: 192.168.71.1 W (5853) wifi:Affected by the ESP-NOW encrypt num, set the max connection num to 10 I (5863) wifi:Total power save buffer number: 16 I (5863) esp_netif_lwip: DHCP server started on interface WIFI_AP_DEF with IP: 192.168.71.1 I (5873) wifi: Connecting wifi... I (5893) wifi:(mac)omc_ul_mu_data_disable_rx:1 I (5893) wifi:(phy)ppe_thresholds_present:0, nominal_packet_padding:2 I (5893) wifi:(phy)dcm tx(constellation:1, nss:0), dcm rx(constellation:1, nss:0) I (5893) wifi:(phy)rx_mcs_map:0xfffa(for_1_ss:2), tx_mcs_map:0xfffa, stbc_tx:1, bfmer(su:1, mu:1), ldpc:1 I (5903) wifi:(opr)len:7, TWT Required:0, VHT Operation Present:0, 6GHz Info Present:0, Co-Hosted BSS:0, Basic MCS and NSS:0xfffc I (5923) wifi:(opr)len:7, Default PE Duration:4, TXOP RTS Threshold:1022(32704 us), ER-SU-Disable:0 I (5923) wifi:(opr)len:7, BSS Color:7, disabled:0, Partial BSS Color:0 I (5933) wifi:(spr)len:3, ctrl:0x5, PSR Disallowed:1, Non-SRG OBSS PD SR Disallowed:0 I (5943) wifi:(spr)len:3, ctrl:0x5, Non-SRG Offset Present:1, SRG Info Present:0 I (5943) wifi:(spr)Non-SRG OBSS PD Max Offset:0, PD:-82(dB) I (5953) wifi:(uora)len:2, EOCWMin:2, EOCWMax:5 I (8703) wifi:new:<11,2>, old:<11,2>, ap:<11,2>, sta:<11,0>, prof:11 I (8703) wifi:(connect)dot11_authmode:0x3, pairwise_cipher:0x3, group_cipher:0x3 I (9423) wifi:state: init -> auth (b0) I (9423) wifi:state: auth -> assoc (0) I (9443) wifi:Extended Capabilities length:8, subtype:0x10, 42:6e:b9:c4:57:e1, Operating mode notification Support I (9443) wifi:(mac)omc_ul_mu_data_disable_rx:1 I (9443) wifi:(phy)ppe_thresholds_present:0, nominal_packet_padding:2 I (9453) wifi:(phy)dcm tx(constellation:1, nss:0), dcm rx(constellation:1, nss:0) I (9463) wifi:state: assoc -> run (10) I (9463) wifi:(he)ppe_thresholds_present:0, nominal_packet_padding(rx:2, cfg:2) I (9473) wifi:(trc)phytype:CBW20-SGI, snr:51, maxRate:86, highestRateIdx:0 I (9473) wifi:(trc)rate(S-MCS7, schedIdx:0), ampdu(rate:S-MCS7, schedIdx(0, stop:8)), snr:51, ampduState:wait operational I (9483) wifi:ifidx:0, rssi:-42, nf:-93, phytype(0x3, CBW20-SGI), phymode(0x5, 11ax), max_rate:860, he:1 I (9493) wifi:max ampdu length exponent:3(65535 bytes), mmss:0(no restriction) I (9513) wifi:(extcap)mbssid:0, enhanced_mbssid_advertise:0, complete_nontxbssid_profiles:0 I (9513) wifi:connected with JJF3, aid = 11, channel 11, BW20, bssid = 42:6e:b9:c4:57:e1 I (9523) wifi:cipher(pairwise:0x3, group:0x3), pmf:0, security:WPA2-PSK, phy:11ax, rssi:-42 I (9523) wifi:pm start, type: 1, itwt_start:0

I (9533) wifi:pm start, type:1, aid:0xb, trans-BSSID:42:6e:b9:c4:57:e1, BSSID[5]:0xe1, mbssid(max-indicator:0, index:0), he:1 I (9543) wifi:set rx beacon pti, rx_bcn_pti: 10, bcn_timeout: 25000, mt_pti: 10, mt_time: 10000 I (9553) wifi:[ADDBA]TX addba request, tid:0, dialogtoken:1, bufsize:32, A-MSDU:0(not supported), policy:1(IMR), ssn:0(0x0) I (9563) wifi:[ADDBA]TX addba request, tid:7, dialogtoken:2, bufsize:32, A-MSDU:0(not supported), policy:1(IMR), ssn:0(0x20) I (9573) wifi:[ADDBA]TX addba request, tid:5, dialogtoken:3, bufsize:32, A-MSDU:0(not supported), policy:1(IMR), ssn:0(0x0) I (9583) wifi:AP's beacon interval = 102400 us, DTIM period = 1 I (9593) wifi:(mac)omc_ul_mu_data_disable_rx:1 I (9593) wifi:(phy)ppe_thresholds_present:0, nominal_packet_padding:2 I (9603) wifi:(phy)dcm tx(constellation:1, nss:0), dcm rx(constellation:1, nss:0) I (9603) wifi:(spr)len:3, ctrl:0x15, PSR Disallowed:1, Non-SRG OBSS PD SR Disallowed:0 I (9613) wifi:(spr)len:3, ctrl:0x15, Non-SRG Offset Present:1, SRG Info Present:0 I (9623) wifi:(spr)Non-SRG OBSS PD Max Offset:0, PD:-82(dB) I (9623) wifi:[ADDBA]RX addba response, status:0, tid:0/tb:1(0xa1), bufsize:32, batimeout:0, txa_wnd:32 I (9633) wifi:[ADDBA]RX addba response, status:0, tid:7/tb:1(0xa1), bufsize:32, batimeout:0, txa_wnd:32 I (9643) wifi: Waiting for DHCP lease... I (9653) wifi:[ADDBA]RX addba response, status:0, tid:5/tb:1(0xa1), bufsize:32, batimeout:0, txa_wnd:32 I (9683) wifi:(spr)len:3, ctrl:0x5, PSR Disallowed:1, Non-SRG OBSS PD SR Disallowed:0 I (9683) wifi:(spr)len:3, ctrl:0x5, Non-SRG Offset Present:1, SRG Info Present:0 I (9683) wifi:(spr)Non-SRG OBSS PD Max Offset:0, PD:-82(dB) I (10643) esp_netif_handlers: sta ip: 192.168.3.71, mask: 255.255.255.0, gw: 192.168.3.1 I (10643) wifi: About to do some pings for IpInfo { ip: 192.168.3.71, subnet: Subnet { gateway: 192.168.3.1, mask: Mask(24) }, dns: Some(192.168.3.1), secondary_dns: Some(0.0.0.0) } I (10653) esp_idf_svc::ping: About to run a summary ping 114.114.114.114 with configuration Configuration { count: 5, interval: 1s, timeout: 1s, data_size: 56, tos: 0 } I (10673) esp_idf_svc::ping: Ping session established, got handle 0x40829d00 0x40829d00 - _heap_start at ??:?? I (10673) esp_idf_svc::ping: Ping session started I (10683) esp_idf_svc::ping: Waiting for the ping session to complete I (11673) esp_idf_svc::ping: Ping timeout callback invoked I (11673) esp_idf_svc::ping: From ??? icmp_seq=1 timeout W (12043) wifi:idx:0, ifx:0, tid:6, TAHI:0x100e157, TALO:0xc4b96e42, (ssn:1, win:64, cur_ssn:1), CONF:0xc0006005 0xc4b96e42 - LP_ANA_PERI at ??:?? 0xc0006005 - LP_ANA_PERI at ??:?? I (12673) esp_idf_svc::ping: Ping timeout callback invoked I (12673) esp_idf_svc::ping: From ??? icmp_seq=2 timeout I (13673) esp_idf_svc::ping: Ping timeout callback invoked I (13673) esp_idf_svc::ping: From ??? icmp_seq=3 timeout I (14673) esp_idf_svc::ping: Ping timeout callback invoked I (14673) esp_idf_svc::ping: From ??? icmp_seq=4 timeout I (15673) esp_idf_svc::ping: Ping timeout callback invoked I (15673) esp_idf_svc::ping: From ??? icmp_seq=5 timeout I (15673) esp_idf_svc::ping: Ping end callback invoked I (15673) esp_idf_svc::ping: 5 packets transmitted, 0 received, time 4983ms I (15683) esp_idf_svc::ping: Ping session stopped I (15693) esp_idf_svc::ping: Ping session 0x40829d00 removed 0x40829d00 - _heap_start at ??:?? I (15693) wifi:state: run -> init (0) I (15703) wifi:ifidx:0, rssi:-41, nf:-93, phytype(0x3, CBW20-SGI), phymode(0x5, 11ax), max_rate:860, he:1 I (15703) wifi:max ampdu length exponent:3(65535 bytes), mmss:0(no restriction) I (15713) wifi:pm stop, total sleep time: 0 us / 6172595 us

I (15723) wifi:idx:0, tid:6 I (15723) wifi:new:<11,0>, old:<11,2>, ap:<11,2>, sta:<11,0>, prof:11 I (15893) wifi:flush txq I (15893) wifi:stop sw txq I (15893) wifi:lmac stop hw txq I (15893) esp_idf_svc::wifi: EspWifi dropped I (15893) esp_idf_svc::netif: Dropped I (15893) esp_idf_svc::netif: Dropped I (15903) wifi:Deinit lldesc rx mblock:10 I (15913) esp_idf_svc::eventloop: System event loop dropped Error: Pinging IP 114.114.114.114 resulted in timeouts I (15913) main_task: Returned from app_main()

hi,esp-32-c6 After the wifi connection is complete, the ping fails,i need help thanks!

ivmarkov commented 10 months ago

Why are you assuming that 114.114.114.114 is pingable in principle?

MrDustZero commented 10 months ago

@ivmarkov sorry, but I can't ping anything else, including the gateway,And tried multiple wifi ,Do I need to configure anything

MrDustZero commented 10 months ago

I (16616) esp_idf_svc::ping: Ping timeout callback invoked I (16616) esp_idf_svc::ping: From ??? icmp_seq=1 timeout I think there's something wrong with that

ivmarkov commented 10 months ago

Let me ask real simple: can you ping 114.114.114.114 from your own PC? From the terminal? Forget about the ESP. Ping it from your PC first!

MrDustZero commented 10 months ago

ESP

I (11583) esp_netif_handlers: sta ip: 192.168.3.71, mask: 255.255.255.0, gw: 192.168.3.1 I (11583) wifi: Wifi DHCP info: IpInfo { ip: 192.168.3.71, subnet: Subnet { gateway: 192.168.3.1, mask: Mask(24) }, dns: Some(192.168.3.1), secondary_dns: Some(0.0.0.0) } I (11593) wifi: About to do some pings for 192.168.3.1 I (11603) esp_idf_svc::ping: About to run a summary ping 192.168.3.1 with configuration Configuration { count: 5, interval: 1s, timeout: 1s, data_size: 56, tos: 0 } I (11613) esp_idf_svc::ping: Ping session established, got handle 0x408285dc 0x408285dc - _heap_start at ??:?? I (11623) esp_idf_svc::ping: Ping session started I (11623) esp_idf_svc::ping: Waiting for the ping session to complete I (12623) esp_idf_svc::ping: Ping timeout callback invoked I (12623) esp_idf_svc::ping: From ??? icmp_seq=1 timeout I (13623) esp_idf_svc::ping: Ping timeout callback invoked I (13623) esp_idf_svc::ping: From ??? icmp_seq=2 timeout

PC

Pinging 192.168.3.1 with 32 bytes of data: Reply from 192.168.3.1: bytes=32 time=1ms TTL=64 Reply from 192.168.3.1: bytes=32 time=1ms TTL=64 Reply from 192.168.3.1: bytes=32 time=4ms TTL=64 Reply from 192.168.3.1: bytes=32 time=3ms TTL=64

Ping statistics for 192.168.3.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 1ms, Maximum = 4ms, Average = 2ms

@ivmarkov see this ,wifi connection complete,ping gateway

I really don't know what the problem is (ToT)

MrDustZero commented 10 months ago

idf and rust all uninstall are installed resolve