nanoframework / Home

:house: The landing page for .NET nanoFramework repositories.
https://www.nanoframework.net
MIT License
861 stars 78 forks source link

Exception with WiFi `ScanAsync` #1166

Closed thombrink closed 1 year ago

thombrink commented 2 years ago

Library/API/IoT binding

System.Device.Wifi

Visual Studio version

No response

.NET nanoFramework extension version

No response

Target name(s)

No response

Firmware version

No response

Device capabilities

No response

Description

When running ESP32_OLIMEX the 'ScanAsync' method throws an InvalidOperationException exception:

    ++++ Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (1) ++++
    ++++ Message: 
    ++++ System.Device.Wifi.WifiAdapter::NativeScanAsync [IP: 0000] ++++
    ++++ System.Device.Wifi.WifiAdapter::ScanAsync [IP: 000d] ++++

951 does not solve the problem after implementing the 'CheckWifiInterface' interface from discord and using the latest nugets and firmware.

How to reproduce

No response

Expected behaviour

No response

Screenshots

No response

Sample project or code

No response

Aditional information

No response

josesimoes commented 2 years ago

OLIMEX does have Wifi support, otherwise you wouldn't even been able to deploy the application on it. Please check the WiFi sample about using scan.

You're better asking this in our Discord channel then here. We're using github issues to track work and give visibility to confirmed issues. Not to provide support or answer questions. 😉

thombrink commented 2 years ago

Sure!

Created a thread here: https://discord.com/channels/478725473862549535/481782754674212867/1027966089117847552

Feiko commented 2 years ago

I'm experiencing the same issue with the M5Stack Atom Lite (ESP32-PICO platform). Tried the default WiFi sample and played around with the network configuration settings in the VS extension. However, I get the same exception when using the ScanAsync method.

JORGEGO commented 2 years ago

Same error!!! 3 weeks stopper not connect

Ellerbach commented 2 years ago

I've started some investigation and regarding the dates and what is impacted, it seems possible that this PR has adjusted something: https://github.com/nanoframework/nf-interpreter/pull/2365 More precisely, looking at the changes, it can come from here: https://github.com/nanoframework/nf-interpreter/pull/2365/files#diff-97ea37fc6cd18b4e9204849a7619d0def3ee8c616f04d63714af8208c0de9a12

@AdrianSoundy would you have an idea of the problem? Can this be linked to this change you've been doing?

josesimoes commented 2 years ago

Confirmed with ScanWifi sample running on ATOM. Not working with latest fw and nugets. Working with fw 1.8.0.534 and Sys.Dev.Wifi 1.5.8.

AdrianSoundy commented 2 years ago

I'll have a look to see what's going on.

JORGEGO commented 2 years ago

Thanks @AdrianSoundy it is important for us.

zamby commented 2 years ago

I have same problem with ESP32 WEMOS.

Il thread '' (0x2) è terminato con il codice 0 (0x0). starting Wifi scan ++++ Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (1) ++++ ++++ Message: ++++ System.Device.Wifi.WifiAdapter::NativeScanAsync [IP: 0000] ++++ ++++ System.Device.Wifi.WifiAdapter::ScanAsync [IP: 0010] ++++ Eccezione generata: 'System.InvalidOperationException' in System.Device.Wifi.dll message:Exception was thrown: System.InvalidOperationException stack:System.Device.Wifi.WifiAdapter::NativeScanAsync System.Device.Wifi.WifiAdapter::ScanAsync

AdrianSoundy commented 2 years ago

The issue is being caused by an out of native memory when it tries to init the Wifi stack. Reducing amount of memory used for managed heap by 10K resolves problem but that's probably not the root cause. Something else has changed. Will investigate further.

AdrianSoundy commented 2 years ago

For PICO builds problem caused by adding SPIRAM to the Pico builds. As rev1 chip reduces native heap by at least 10K when it adds alternative C library with spiram fixes. So 1.8.0.594 last good build ( Builds 611 & 629 broken) 642 has spiram enabled.

alberk8 commented 2 years ago

For PICO builds problem caused by adding SPIRAM to the Pico builds. As rev1 chip reduces native heap by at least 10K when it adds alternative C library with spiram fixes. So 1.8.0.594 last good build ( Builds 611 & 629 broken) 642 has spiram enabled.

We should just disable SPIRAM for pico. The M5Stack Atom series does not have psram and this will be the most used ESP32-PICO devices.

josesimoes commented 2 years ago

Or, because we can, let's leave PSRAM enabled for this build and compensate those 10k. Doesn't seem much loss anyway...

AdrianSoundy commented 2 years ago

Ok i'll remove 10K from managed heap which works for Olimex and Pico boards I checked that the Pico rev 1 can have SPI ram.

josesimoes commented 2 years ago

Yes please!

JORGEGO commented 2 years ago

Excellent as soon as will be ready the version I will test. Thanks for your great effort

JORGEGO commented 2 years ago

It seems still not work... Now in my case after upgrading the last firmware and the las version assemblies, exception it is not producing, but not detect any Wi-Fi network starting Wifi scan Wifi_AvailableNetworksChanged - get report starting Wifi scan Wifi_AvailableNetworksChanged - get report starting Wifi scan Wifi_AvailableNetworksChanged - get report starting Wifi scan Wifi_AvailableNetworksChanged - get report

JORGEGO commented 2 years ago

Nothing... with the new firmware and package starting to crash other assemblies The thread '' (0x2) has exited with code 0 (0x0). ++++ Exception System.Exception - CLR_E_FILE_IO (1) ++++ ++++ Message: ++++ Windows.Storage.FileIO::ReadTextNative [IP: 0000] ++++ ++++ Windows.Storage.FileIO::ReadText [IP: 0008] ++++ ++++ greenyng.device.nanoframework.atomlite.scale001.Persistence::LoadContext [IP: 000a] ++++ ++++ greenyng.device.nanoframework.atomlite.scale001.Program::Main [IP: 0030] ++++ Exception thrown: 'System.Exception' in Windows.Storage.dll ++++ Exception System.ArgumentException - 0xfd000000 (1) ++++ ++++ Message: ++++ System.IO.Ports.SerialPort::NativeInit [IP: 0000] ++++ ++++ System.IO.Ports.SerialPort::Open [IP: 000f] ++++ ++++ greenyng.device.nanoframework.atomlite.scale001.qr.QRUtilities::InitQRCode [IP: 001e] ++++ ++++ greenyng.device.nanoframework.atomlite.scale001.Navigation.Manufacturer::ReadIdDevice [IP: 0009] ++++ ++++ greenyng.device.nanoframework.atomlite.scale001.Program::Main [IP: 0030] ++++ Exception thrown: 'System.ArgumentException' in System.IO.Ports.dll An unhandled exception of type 'System.ArgumentException' occurred in System.IO.Ports.dll

JORGEGO commented 2 years ago

How could I get the 1.8.0.534 firmware?

JORGEGO commented 2 years ago

I could not lost more time...

JORGEGO commented 2 years ago

nanoff --target ESP32_PICO --fwversion 1.8.0.534 --update --serialport COM6

josesimoes commented 1 year ago

The "reporting" on the cause of the failure has been improved.

@thombrink most likely what the cause for the failure was that the scan operation was being attempted when the station was still in the process of connecting. This is one of the most common causes for scan to fail and our API wasn't reporting that conveniently.

josesimoes commented 1 year ago

Seems that there is a regression on this issue. ScanAsync is not working again.

zhulige commented 1 year ago

ESP32_LILYGO Same problem

zhulige commented 1 year ago

ets Jul 29 2019 12:21:46[2023-03-06 04:54:47.547] [2023-03-06 04:54:47.547] rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)[2023-03-06 04:54:47.563] configsip: 0, SPIWP:0xee[2023-03-06 04:54:47.563] clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00[2023-03-06 04:54:47.563] mode:DIO, clock div:2[2023-03-06 04:54:47.563] load:0x3fff0030,len:5688[2023-03-06 04:54:47.563] load:0x40078000,len:14528[2023-03-06 04:54:47.563] load:0x40080400,len:3708[2023-03-06 04:54:47.563] entry 0x4008067c[2023-03-06 04:54:47.578] I (27) boot: .NET nanoFramework 2nd stage bootloader ESP-IDF v4.4.4[2023-03-06 04:54:47.578] I (27) boot: build Feb 27 2023 15:13:27[2023-03-06 04:54:47.594] I (29) boot: chip revision: v3.0[2023-03-06 04:54:47.594] I (32) boot_comm: chip revision: 3, min. bootloader chip revision: 0[2023-03-06 04:54:47.594] I (40) boot.esp32: SPI Speed : 40MHz[2023-03-06 04:54:47.610] I (44) boot.esp32: SPI Mode : DIO[2023-03-06 04:54:47.610] I (49) boot.esp32: SPI Flash Size : 4MB[2023-03-06 04:54:47.610] I (53) boot: Enabling RNG early entropy source...[2023-03-06 04:54:47.610] I (59) boot: Partition Table:[2023-03-06 04:54:47.626] I (62) boot: ## Label Usage Type ST Offset Length[2023-03-06 04:54:47.626] I (70) boot: 0 nvs WiFi data 01 02 00009000 00006000[2023-03-06 04:54:47.626] I (77) boot: 1 phy_init RF data 01 01 0000f000 00001000[2023-03-06 04:54:47.642] I (84) boot: 2 factory factory app 00 00 00010000 001a0000[2023-03-06 04:54:47.658] I (92) boot: 3 deploy Unknown data 01 84 001b0000 001f0000[2023-03-06 04:54:47.658] I (99) boot: 4 config Unknown data 01 82 003c0000 00040000[2023-03-06 04:54:47.658] I (107) boot: End of partition table[2023-03-06 04:54:47.673] I (111) boot_comm: chip revision: 3, min. application chip revision: 0[2023-03-06 04:54:47.673] I (118) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=2b1f8h (176632) map[2023-03-06 04:54:47.689] I (190) esp_image: segment 1: paddr=0003b220 vaddr=3ff80067 size=00008h ( 8) load[2023-03-06 04:54:47.753] I (191) esp_image: segment 2: paddr=0003b230 vaddr=3ffb0000 size=03574h ( 13684) load[2023-03-06 04:54:47.768] I (201) esp_image: segment 3: paddr=0003e7ac vaddr=40080000 size=0186ch ( 6252) load[2023-03-06 04:54:47.768] I (207) esp_image: segment 4: paddr=00040020 vaddr=400d0020 size=cd658h (841304) map[2023-03-06 04:54:47.779] I (514) esp_image: segment 5: paddr=0010d680 vaddr=4008186c size=1a968h (108904) load[2023-03-06 04:54:48.104] I (559) esp_image: segment 6: paddr=00127ff0 vaddr=400c0000 size=00068h ( 104) load[2023-03-06 04:54:48.123] I (573) boot: Loaded app from partition at offset 0x10000[2023-03-06 04:54:48.136] I (573) boot: Disabling RNG early entropy source...[2023-03-06 04:54:48.136] I (584) psram: This chip is ESP32-D0WD[2023-03-06 04:54:48.136] E (585) psram: PSRAM ID read error: 0xffffffff[2023-03-06 04:54:48.136] E (585) spiram: SPI RAM enabled but initialization failed. Bailing out.[2023-03-06 04:54:48.154] I (592) cpu_start: Failed to init external RAM; continuing without it.[2023-03-06 04:54:48.154] I (599) cpu_start: Pro cpu up.[2023-03-06 04:54:48.154] I (603) cpu_start: Starting app cpu, entry point is 0x40085e10[2023-03-06 04:54:48.167] I (0) cpu_start: App cpu up.[2023-03-06 04:54:48.167] I (625) cpu_start: Pro cpu start user code[2023-03-06 04:54:48.167] I (625) cpu_start: cpu freq: 240000000[2023-03-06 04:54:48.199] I (625) cpu_start: Application information:[2023-03-06 04:54:48.199] I (629) cpu_start: Project name: nanoCLR[2023-03-06 04:54:48.199] I (634) cpu_start: App version: 1.8.1.11[2023-03-06 04:54:48.199] I (639) cpu_start: Compile time: Feb 27 2023 15:12:59[2023-03-06 04:54:48.217] I (645) cpu_start: ELF file SHA256: 198409da2436be8c...[2023-03-06 04:54:48.217] I (651) cpu_start: ESP-IDF: v4.4.4[2023-03-06 04:54:48.217] I (657) heap_init: Initializing. RAM available for dynamic allocation:[2023-03-06 04:54:48.231] I (664) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM[2023-03-06 04:54:48.231] I (670) heap_init: At 3FFBC660 len 000239A0 (142 KiB): DRAM[2023-03-06 04:54:48.231] I (676) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM[2023-03-06 04:54:48.262] I (682) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM[2023-03-06 04:54:48.262] I (689) heap_init: At 4009C1D4 len 00003E2C (15 KiB): IRAM[2023-03-06 04:54:48.262] I (696) spi_flash: detected chip: generic[2023-03-06 04:54:48.262] I (700) spi_flash: flash io: dio[2023-03-06 04:54:48.262] I (715) cpu_start: Starting scheduler on PRO CPU.[2023-03-06 04:54:48.279] I (0) cpu_start:(D?D

zhulige commented 1 year ago

starting Wi-Fi scan ++++ Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (1) ++++ ++++ Message: ++++ System.Device.Wifi.WifiAdapter::NativeScanAsync [IP: 0000] ++++ ++++ System.Device.Wifi.WifiAdapter::ScanAsync [IP: 000d] ++++

alberk8 commented 1 year ago

@zhulige , Load a firmware without PSRAM or use nanoff --platform esp32 --update --serialport COM3 to load the firmware.

zhulige commented 1 year ago

@alberk8 Ethernet cannot be used。

alberk8 commented 1 year ago

Then you need to do a manual compile of the firmware if you want Ethernet with Wifi or get the exact same esp32 module that support both.

zhulige commented 1 year ago

@alberk8 Ethernet + Wifi Can I use it at the same time?

alberk8 commented 1 year ago

Have not tried, most likely you cannot.

MaUlBit commented 1 year ago

@zhulige , Load a firmware without PSRAM or use nanoff --platform esp32 --update --serialport COM3 to load the firmware.

This solved my issue on the Arduini huzzah! ESP32-WROOM-32E Thanks for the hint!