zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
9.98k stars 6.15k forks source link

CONFIG_WIFI_ESP32=y causes Kconfig warning on wemos ESP32-S2 Lolin Mini related to MBEDTLS #74417

Open leriksen137 opened 1 week ago

leriksen137 commented 1 week ago

CONFIG_WIFI_ESP32=y causes Kconfig warning on wemos ESP32-S2 Lolin Mini related to MBEDTLS

Bug

Can't build simple wifi application for the Wemos ESP32-S2 Lolin Mini board due to KConfig error. There seems to be an error where KConfig finds MBEDTLS defined in zephyr/soc/nxp/ instead of zephyr/soc/espressif.

Reproduction steps

Code for reproduction can be found here: https://github.com/leriksen137/config_wifi_esp32_does_not_build.git This project has the same topology as the zephyr example application.

Follow Zephyr getting started.

git clone https://github.com/leriksen137/config_wifi_esp32_does_not_build.git
cd config_wifi_esp32_does_not_build
west init -l --mf west.yml manifest
west update
west blobs fetch hal_espressif
west build -b esp32s2_lolin_mini app

See ESP32-S2 Lolin Mini why west blobs fetch hal_espressif is run.

Expected behavior

App should build without warnings.

Actual behavior

Example console output:

west build -b esp32s2_lolin_mini app --pristine
-- west build: making build dir path\to\repo\config_wifi_esp32_does_not_build\build pristine
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: path/to/repo/config_wifi_esp32_does_not_build/app
-- CMake version: 3.27.9
-- Found Python3: C:/Python311/python.exe (found suitable version "3.11.9", minimum required is "3.8") found components: Interpreter
-- Cache files will be written to: path/to/repo/config_wifi_esp32_does_not_build/zephyr/.cache
-- Zephyr version: 3.7.0-rc1 (path/to/repo/config_wifi_esp32_does_not_build/zephyr)
-- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
-- Board: esp32s2_lolin_mini, qualifiers: esp32s2
-- Found host-tools: zephyr 0.16.1 (~/zephyr-sdk-0.16.1)
-- Found toolchain: zephyr 0.16.1 (~/zephyr-sdk-0.16.1)
-- Found Dtc: C:/ProgramData/chocolatey/bin/dtc.exe (found suitable version "1.5.0", minimum required is "1.4.6")
-- Found BOARD.dts: path/to/repo/config_wifi_esp32_does_not_build/zephyr/boards/wemos/esp32s2_lolin_mini/esp32s2_lolin_mini.dts
-- Found devicetree overlay: path/to/repo/config_wifi_esp32_does_not_build/app/boards/esp32s2_lolin_mini.overlay
-- Generated zephyr.dts: path/to/repo/config_wifi_esp32_does_not_build/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: path/to/repo/config_wifi_esp32_does_not_build/build/zephyr/include/generated/zephyr/devicetree_generated.h
-- Including generated dts.cmake file: path/to/repo/config_wifi_esp32_does_not_build/build/zephyr/dts.cmake

warning: MBEDTLS (defined at path/to/repo/config_wifi_esp32_does_not_build/zephyr/soc/nxp/imxrt\imxrt5xx\Kconfig.defconfig:24, path/to/repo/config_wifi_esp32_does_not_build/zephyr/soc/nxp/imxrt\imxrt6xx\Kconfig.defconfig:81, path/to/repo/config_wifi_esp32_does_not_build/zephyr/soc/nxp/imxrt/Kconfig.defconfig:99, modules\mbedtls\Kconfig:18) has direct dependencies (ENTROPY_GENERATOR && SOC_MIMXRT595S_CM33 && SOC_FAMILY_NXP_IMXRT) || (ENTROPY_GENERATOR && SOC_MIMXRT685S_CM33 && SOC_FAMILY_NXP_IMXRT) || (ENTROPY_GENERATOR && (SOC_SERIES_IMXRT10XX || SOC_SERIES_IMXRT11XX) && SOC_FAMILY_NXP_IMXRT) || 0 with value n, but is currently being y-selected by the following symbols:
 - WIFI_ESP32 (defined at drivers/wifi/esp32/Kconfig.esp32:3), with value y, direct dependencies DT_HAS_ESPRESSIF_ESP32_WIFI_ENABLED && !SMP && WIFI (value: y), and select condition DT_HAS_ESPRESSIF_ESP32_WIFI_ENABLED && !SMP && WIFI (value: y)Parsing path/to/repo/config_wifi_esp32_does_not_build/zephyr/Kconfig
Loaded configuration 'path/to/repo/config_wifi_esp32_does_not_build/zephyr/boards/wemos/esp32s2_lolin_mini/esp32s2_lolin_mini_defconfig'
Merged configuration 'path/to/repo/config_wifi_esp32_does_not_build/app/prj.conf'

error: Aborting due to Kconfig warnings

CMake Error at path/to/repo/config_wifi_esp32_does_not_build/zephyr/cmake/modules/kconfig.cmake:389 (message):
  command failed with return code: 1
Call Stack (most recent call first):
  path/to/repo/config_wifi_esp32_does_not_build/zephyr/cmake/modules/zephyr_default.cmake:132 (include)
  path/to/repo/smart-pump-iot-adapter/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
  path/to/repo/smart-pump-iot-adapter/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
  CMakeLists.txt:5 (find_package)

-- Configuring incomplete, errors occurred!

Note the reference to zephyr/soc/nxp in the warning message.

Troubleshooting

I confirmed the output file in "path/to/repo/config_wifi_esp32_does_not_build/build/zephyr/zephyr.dts" contains:

    wifi: wifi {
        compatible = "espressif,esp32-wifi";
        status = "okay";
    };

In an attempt to help Zephyr correctly resolve the definition of MBEDTLS I removed the zephyr/soc/nxp directory. This causes a different error:

warning: MBEDTLS (defined at modules\mbedtls\Kconfig:18) has direct dependencies 0 with value n, but is currently being y-selected by the following symbols:
 - WIFI_ESP32 (defined at drivers/wifi/esp32/Kconfig.esp32:3), with value y, direct dependencies DT_HAS_ESPRESSIF_ESP32_WIFI_ENABLED && !SMP && WIFI (value: y), and select condition DT_HAS_ESPRESSIF_ESP32_WIFI_ENABLED && !SMP && WIFI (value: y)Parsing path/to/repo/config_wifi_esp32_does_not_build/zephyr/Kconfig
Loaded configuration 'path/to/repo/config_wifi_esp32_does_not_build/zephyr/boards/wemos/esp32s2_lolin_mini/esp32s2_lolin_mini_defconfig'
Merged configuration 'path/to/repo/config_wifi_esp32_does_not_build/app/prj.conf'

Trying to add CONFIG_0=y does not work.

Severity

Severe. The project I'm working on can't be finished while this is unresolved.

github-actions[bot] commented 1 week ago

Hi @leriksen137! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙

sylvioalves commented 1 week ago

@leriksen137 Can you try rebasing to latest main?

sylvioalves commented 1 week ago

btw, I have just tested you branch in here. It builds properly, but requires prf.conf changes as suggested below:

CONFIG_WIFI=y
CONFIG_NET_L2_WIFI_MGMT=y
CONFIG_NET_L2_ETHERNET=y
CONFIG_NETWORKING=y
CONFIG_NET_DHCPV4=y
CONFIG_NET_IPV4=y
CONFIG_NET_TCP=y
leriksen137 commented 1 week ago

@leriksen137 Can you try rebasing to latest main?

I ran west update and it now points to commit 83958eb937d. Is that what you meant?

leriksen137 commented 1 week ago

btw, I have just tested you branch in here. It builds properly, but requires prf.conf changes as suggested below:

CONFIG_WIFI=y
CONFIG_NET_L2_WIFI_MGMT=y
CONFIG_NET_L2_ETHERNET=y
CONFIG_NETWORKING=y
CONFIG_NET_DHCPV4=y
CONFIG_NET_IPV4=y
CONFIG_NET_TCP=y

This does not contain CONFIG_WIFI_ESP32. According to the documentation, it seems to me that I need to enable this. Not doing this caused some other issues in trying to get wifi running on the board I mentioned.

sylvioalves commented 1 week ago

btw, I have just tested you branch in here. It builds properly, but requires prf.conf changes as suggested below:

CONFIG_WIFI=y
CONFIG_NET_L2_WIFI_MGMT=y
CONFIG_NET_L2_ETHERNET=y
CONFIG_NETWORKING=y
CONFIG_NET_DHCPV4=y
CONFIG_NET_IPV4=y
CONFIG_NET_TCP=y

This does not contain CONFIG_WIFI_ESP32. According to the documentation, it seems to me that I need to enable this. Not doing this caused some other issues in trying to get wifi running on the board I mentioned.

You can add that, however, it is not needed. You have already enabled wifi in dts .overlay file. Then, Kconfig automatically adds that into build:

menuconfig WIFI_ESP32
    bool "ESP32 SoC WiFi support"
    default y
    depends on DT_HAS_ESPRESSIF_ESP32_WIFI_ENABLED

Anyway, with the suggested prj.conf above, I was able to build the application.

sylvioalves commented 1 week ago
~/espressif/config_wifi_esp32_does_not_build (main) $ rm -rf build; west build -p -b esp32s2_lolin_mini app
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: /home/sylvio/espressif/config_wifi_esp32_does_not_build/app
-- CMake version: 3.28.1
-- Found Python3: /usr/bin/python3 (found suitable version "3.10.12", minimum required is "3.8") found components: Interpreter 
-- Cache files will be written to: /home/sylvio/.cache/zephyr
-- Zephyr version: 3.6.99 (/home/sylvio/espressif/zephyr/zephyr)
-- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
-- Board: esp32s2_lolin_mini, qualifiers: esp32s2
-- Found host-tools: zephyr 0.16.8 (/home/sylvio/zephyr-sdk-0.16.8)
-- Found toolchain: zephyr 0.16.8 (/home/sylvio/zephyr-sdk-0.16.8)
-- Found Dtc: /home/sylvio/zephyr-sdk-0.16.8/sysroots/x86_64-pokysdk-linux/usr/bin/dtc (found suitable version "1.6.0", minimum required is "1.4.6") 
-- Found BOARD.dts: /home/sylvio/espressif/zephyr/zephyr/boards/wemos/esp32s2_lolin_mini/esp32s2_lolin_mini.dts
-- Found devicetree overlay: /home/sylvio/espressif/config_wifi_esp32_does_not_build/app/boards/esp32s2_lolin_mini.overlay
-- Generated zephyr.dts: /home/sylvio/espressif/config_wifi_esp32_does_not_build/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: /home/sylvio/espressif/config_wifi_esp32_does_not_build/build/zephyr/include/generated/zephyr/devicetree_generated.h
-- Including generated dts.cmake file: /home/sylvio/espressif/config_wifi_esp32_does_not_build/build/zephyr/dts.cmake
Parsing /home/sylvio/espressif/zephyr/zephyr/Kconfig
Loaded configuration '/home/sylvio/espressif/zephyr/zephyr/boards/wemos/esp32s2_lolin_mini/esp32s2_lolin_mini_defconfig'
Merged configuration '/home/sylvio/espressif/config_wifi_esp32_does_not_build/app/prj.conf'
Configuration saved to '/home/sylvio/espressif/config_wifi_esp32_does_not_build/build/zephyr/.config'
Kconfig header saved to '/home/sylvio/espressif/config_wifi_esp32_does_not_build/build/zephyr/include/generated/zephyr/autoconf.h'
-- Found GnuLd: /home/sylvio/zephyr-sdk-0.16.8/xtensa-espressif_esp32s2_zephyr-elf/xtensa-espressif_esp32s2_zephyr-elf/bin/ld.bfd (found version "2.38") 
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /home/sylvio/zephyr-sdk-0.16.8/xtensa-espressif_esp32s2_zephyr-elf/bin/xtensa-espressif_esp32s2_zephyr-elf-gcc
ESP-IDF path: /home/sylvio/espressif/zephyr/modules/hal/espressif
esptool path: /home/sylvio/espressif/zephyr/modules/hal/espressif/tools/esptool_py/esptool.py
-- Using ccache: /usr/bin/ccache
-- Configuring done (2.9s)
-- Generating done (0.1s)
-- Build files have been written to: /home/sylvio/espressif/config_wifi_esp32_does_not_build/build
-- west build: building application
[1/438] Preparing syscall dependency handling

[4/438] Generating include/generated/zephyr/version.h
-- Zephyr version: 3.6.99 (/home/sylvio/espressif/zephyr/zephyr), build: v3.6.0-6455-gf33d2c1251d8
[438/438] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:      535178 B    4194048 B     12.76%
     iram0_0_seg:       62528 B     224000 B     27.91%
     dram0_0_seg:      156184 B     224000 B     69.72%
     irom0_0_seg:      273034 B      7680 KB      3.47%
     drom0_0_seg:         64 KB         4 MB      1.56%
    rtc_iram_seg:          0 GB         8 KB      0.00%
    rtc_slow_seg:          0 GB         8 KB      0.00%
    rtc_data_seg:          0 GB         8 KB      0.00%
rtc_reserved_seg:          0 GB         0 GB
        IDT_LIST:          0 GB         8 KB      0.00%
Generating files from /home/sylvio/espressif/config_wifi_esp32_does_not_build/build/zephyr/zephyr.elf for board: esp32s2_lolin_mini
esptool.py v4.7.0
Creating esp32s2 image...
Image has only RAM segments visible. ROM segments are hidden and SHA256 digest is not appended.
Info: inserting 4 bytes padding between net_buf_pool_area and net_if_area
Merged 15 ELF sections
Successfully created esp32s2 image.
leriksen137 commented 1 week ago
~/espressif/config_wifi_esp32_does_not_build (main) $ rm -rf build; west build -p -b esp32s2_lolin_mini app
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: /home/sylvio/espressif/config_wifi_esp32_does_not_build/app
-- CMake version: 3.28.1
-- Found Python3: /usr/bin/python3 (found suitable version "3.10.12", minimum required is "3.8") found components: Interpreter 
-- Cache files will be written to: /home/sylvio/.cache/zephyr
-- Zephyr version: 3.6.99 (/home/sylvio/espressif/zephyr/zephyr)
-- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
-- Board: esp32s2_lolin_mini, qualifiers: esp32s2
-- Found host-tools: zephyr 0.16.8 (/home/sylvio/zephyr-sdk-0.16.8)
-- Found toolchain: zephyr 0.16.8 (/home/sylvio/zephyr-sdk-0.16.8)
-- Found Dtc: /home/sylvio/zephyr-sdk-0.16.8/sysroots/x86_64-pokysdk-linux/usr/bin/dtc (found suitable version "1.6.0", minimum required is "1.4.6") 
-- Found BOARD.dts: /home/sylvio/espressif/zephyr/zephyr/boards/wemos/esp32s2_lolin_mini/esp32s2_lolin_mini.dts
-- Found devicetree overlay: /home/sylvio/espressif/config_wifi_esp32_does_not_build/app/boards/esp32s2_lolin_mini.overlay
-- Generated zephyr.dts: /home/sylvio/espressif/config_wifi_esp32_does_not_build/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: /home/sylvio/espressif/config_wifi_esp32_does_not_build/build/zephyr/include/generated/zephyr/devicetree_generated.h
-- Including generated dts.cmake file: /home/sylvio/espressif/config_wifi_esp32_does_not_build/build/zephyr/dts.cmake
Parsing /home/sylvio/espressif/zephyr/zephyr/Kconfig
Loaded configuration '/home/sylvio/espressif/zephyr/zephyr/boards/wemos/esp32s2_lolin_mini/esp32s2_lolin_mini_defconfig'
Merged configuration '/home/sylvio/espressif/config_wifi_esp32_does_not_build/app/prj.conf'
Configuration saved to '/home/sylvio/espressif/config_wifi_esp32_does_not_build/build/zephyr/.config'
Kconfig header saved to '/home/sylvio/espressif/config_wifi_esp32_does_not_build/build/zephyr/include/generated/zephyr/autoconf.h'
-- Found GnuLd: /home/sylvio/zephyr-sdk-0.16.8/xtensa-espressif_esp32s2_zephyr-elf/xtensa-espressif_esp32s2_zephyr-elf/bin/ld.bfd (found version "2.38") 
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /home/sylvio/zephyr-sdk-0.16.8/xtensa-espressif_esp32s2_zephyr-elf/bin/xtensa-espressif_esp32s2_zephyr-elf-gcc
ESP-IDF path: /home/sylvio/espressif/zephyr/modules/hal/espressif
esptool path: /home/sylvio/espressif/zephyr/modules/hal/espressif/tools/esptool_py/esptool.py
-- Using ccache: /usr/bin/ccache
-- Configuring done (2.9s)
-- Generating done (0.1s)
-- Build files have been written to: /home/sylvio/espressif/config_wifi_esp32_does_not_build/build
-- west build: building application
[1/438] Preparing syscall dependency handling

[4/438] Generating include/generated/zephyr/version.h
-- Zephyr version: 3.6.99 (/home/sylvio/espressif/zephyr/zephyr), build: v3.6.0-6455-gf33d2c1251d8
[438/438] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:      535178 B    4194048 B     12.76%
     iram0_0_seg:       62528 B     224000 B     27.91%
     dram0_0_seg:      156184 B     224000 B     69.72%
     irom0_0_seg:      273034 B      7680 KB      3.47%
     drom0_0_seg:         64 KB         4 MB      1.56%
    rtc_iram_seg:          0 GB         8 KB      0.00%
    rtc_slow_seg:          0 GB         8 KB      0.00%
    rtc_data_seg:          0 GB         8 KB      0.00%
rtc_reserved_seg:          0 GB         0 GB
        IDT_LIST:          0 GB         8 KB      0.00%
Generating files from /home/sylvio/espressif/config_wifi_esp32_does_not_build/build/zephyr/zephyr.elf for board: esp32s2_lolin_mini
esptool.py v4.7.0
Creating esp32s2 image...
Image has only RAM segments visible. ROM segments are hidden and SHA256 digest is not appended.
Info: inserting 4 bytes padding between net_buf_pool_area and net_if_area
Merged 15 ELF sections
Successfully created esp32s2 image.

Oh interesting. I found his warning while trying to make wifi work on this board. I guess my idea that it's related to CONFIG_WIFI_ESP32 not working was wrong then?

sylvioalves commented 1 week ago

Not, it is not related I think. Have you tried building again?

ZProgramZ commented 1 week ago

Hi Sylvio @sylvioalves

I am working on the same project with laurent, we got it running. The issue was that we do had not defined all modules needed in out mainfest yaml.

However it is building now but unforunately we stuck allready on the next problem.

I we run following code:

#include "wifi.h"

#include <zephyr/kernel.h>
#include <zephyr/net/net_event.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/wifi_mgmt.h>

#define WIFI_MGMT_EVENTS                                   \
  (NET_EVENT_WIFI_SCAN_RESULT | NET_EVENT_WIFI_SCAN_DONE | \
   NET_EVENT_WIFI_CONNECT_RESULT | NET_EVENT_WIFI_DISCONNECT_RESULT)

#define SSID "MyNetwork"
#define PSK "MyPassword"

static const uint8_t *pSsid = (uint8_t *)(SSID);
static const uint8_t *pPsk = (uint8_t *)(PSK);
static K_SEM_DEFINE(wifi_connected, 0, 1);
static K_SEM_DEFINE(ipv4_address_obtained, 0, 1);

static struct net_mgmt_event_callback wifi_cb;
static struct net_mgmt_event_callback ipv4_cb;

static void handle_wifi_connect_result(struct net_mgmt_event_callback *cb) {
  const struct wifi_status *status = (const struct wifi_status *)(cb->info);

  if (status->status) {
    printk("Connection request failed (%d)\n", status->status);
  } else {
    printk("Connected\n");
    k_sem_give(&wifi_connected);
  }
}

static void handle_wifi_disconnect_result(struct net_mgmt_event_callback *cb) {
  const struct wifi_status *status = (const struct wifi_status *)(cb->info);

  if (status->status) {
    printk("Info Length %i\n", cb->info_length);
    printk("Size of wifi_status struct %i\n", sizeof(struct wifi_status));
    printk("Connection Status %i\n", status->conn_status);
    printk("Dissconnection reason %i\n", status->disconn_reason);
    printk("AP Status %i\n", status->ap_status);
    printk("Disconnection request (%d)\n", status->status);
  } else {
    printk("Disconnected\n");
    k_sem_take(&wifi_connected, K_NO_WAIT);
  }
}

static void handle_ipv4_result(struct net_if *iface) {
  int i = 0;

  for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) {
    char buf[NET_IPV4_ADDR_LEN];

    if (iface->config.ip.ipv4->unicast[i].ipv4.addr_type != NET_ADDR_DHCP) {
      continue;
    }

    printk("IPv4 address: %s\n",
           net_addr_ntop(
               AF_INET, &iface->config.ip.ipv4->unicast[i].ipv4.address.in_addr,
               buf, sizeof(buf)));
    printk("Subnet: %s\n",
           net_addr_ntop(AF_INET, &iface->config.ip.ipv4->unicast[i].netmask,
                         buf, sizeof(buf)));
    printk("Router: %s\n", net_addr_ntop(AF_INET, &iface->config.ip.ipv4->gw,
                                         buf, sizeof(buf)));
  }

  k_sem_give(&ipv4_address_obtained);
}

static void wifi_mgmt_event_handler(struct net_mgmt_event_callback *cb,
                                    uint32_t mgmt_event, struct net_if *iface) {
  switch (mgmt_event) {
    case NET_EVENT_WIFI_CONNECT_RESULT:
      handle_wifi_connect_result(cb);
      break;

    case NET_EVENT_WIFI_SCAN_RESULT:
      printf("NET_EVENT_WIFI_SCAN_RESULT\n");
      break;

    case NET_EVENT_WIFI_DISCONNECT_RESULT:
      printf("NET_EVENT_WIFI_DISCONNECT_RESULT\n");
      printf("Device Name %s\n", iface->if_dev->dev->name);
      printf("Init Result %i\n", iface->if_dev->dev->state->init_res);
      printf("Initialized? %s\n",
             iface->if_dev->dev->state->initialized ? "YES" : "NO");
      handle_wifi_disconnect_result(cb);
      break;

    case NET_EVENT_IPV4_ADDR_ADD:
      handle_ipv4_result(iface);
      break;

    default:
      break;
  }
}

void wifi_connect(void) {
  // const char ifname[] = {"wifi"};
  // auto index = net_if_get_by_name(ifname);
  struct net_if *iface = net_if_get_default();

  if (iface == nullptr) {
    printf("No default interface\n");
  }

  printf("Device Name %s\n", iface->if_dev->dev->name);
  printf("Init Result %i\n", iface->if_dev->dev->state->init_res);

  struct wifi_connect_req_params wifi_params = {0};

  wifi_params.ssid = pSsid;
  wifi_params.psk = pPsk;
  wifi_params.ssid_length = strlen(SSID);
  wifi_params.psk_length = strlen(PSK);
  wifi_params.channel = WIFI_CHANNEL_ANY;
  wifi_params.security = WIFI_SECURITY_TYPE_PSK;
  wifi_params.band = WIFI_FREQ_BAND_2_4_GHZ;
  wifi_params.mfp = WIFI_MFP_OPTIONAL;
  wifi_params.bssid[0] = 0xAA;
  wifi_params.bssid[1] = 0xAA;
  wifi_params.bssid[2] = 0xAA;
  wifi_params.bssid[3] = 0xAA;
  wifi_params.bssid[4] = 0xAA;
  wifi_params.bssid[5] = 0xAA;
  wifi_params.timeout = SYS_FOREVER_MS;

  printk("Connecting to SSID: %s\n", wifi_params.ssid);
  printk("SSID Length: %d\n", wifi_params.ssid_length);
  printk("With password: %s\n", wifi_params.psk);
  printk("Password Length: %d\n", wifi_params.psk_length);

  if (net_mgmt(NET_REQUEST_WIFI_CONNECT, iface, &wifi_params,
               sizeof(struct wifi_connect_req_params))) {
    printk("WiFi Connection Request Failed\n");
  }
}

void wifi_status(void) {
  struct net_if *iface = net_if_get_default();

  struct wifi_iface_status status = {0};

  if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &status,
               sizeof(struct wifi_iface_status))) {
    printk("WiFi Status Request Failed\n");
  }

  printk("\n");

  if (status.state >= WIFI_STATE_ASSOCIATED) {
    printk("SSID: %-32s\n", status.ssid);
    printk("Band: %s\n", wifi_band_txt(status.band));
    printk("Channel: %d\n", status.channel);
    printk("Security: %s\n", wifi_security_txt(status.security));
    printk("RSSI: %d\n", status.rssi);
  }
}

void wifi_disconnect(void) {
  struct net_if *iface = net_if_get_default();

  if (net_mgmt(NET_REQUEST_WIFI_DISCONNECT, iface, NULL, 0)) {
    printk("WiFi Disconnection Request Failed\n");
  }
}

void wifi_scan(void) {
  struct net_if *iface = net_if_get_default();

  if (net_mgmt(NET_REQUEST_WIFI_SCAN, iface, NULL, 0)) {
    printk("WiFi Scan Request Failed\n");
  }
}

void mainWifi(void) {
  int sock;

  printk("WiFi Example\n");

  net_mgmt_init_event_callback(
      &wifi_cb, wifi_mgmt_event_handler,
      NET_EVENT_WIFI_CONNECT_RESULT | NET_EVENT_WIFI_DISCONNECT_RESULT |
          NET_EVENT_WIFI_SCAN_RESULT | NET_EVENT_WIFI_SCAN_DONE);

  net_mgmt_init_event_callback(&ipv4_cb, wifi_mgmt_event_handler,
                               NET_EVENT_IPV4_ADDR_ADD);

  net_mgmt_add_event_callback(&wifi_cb);
  net_mgmt_add_event_callback(&ipv4_cb);

  wifi_connect();
  // wifi_scan();
  k_sem_take(&wifi_connected, K_FOREVER);
  wifi_status();
  k_sem_take(&ipv4_address_obtained, K_FOREVER);
  printk("Ready...\n\n");

  printk("Looking up IP addresses:\n");
  struct zsock_addrinfo *res;

  // Stay connected for 30 seconds, then disconnect.
  // k_sleep(K_SECONDS(30));
  // wifi_disconnect();
}

we got this output:

*** Booting Zephyr OS build v3.7.0-rc1-19-g02ad7ef1f9cd ***
[00:00:00.291,000] <inf> net_config: Initializing network
[00:00:00.291,000] <inf> net_config: Running dhcpv4 client...
WiFi Example
Connecting to SSID: MyNetwork
SSID Length: 9
With password: MyPassword
Password Length: 10
[00:00:01.292,000] <err> esp32_wifi: Failed to send packet
[00:00:02.293,000] <err> esp32_wifi: Failed to send packet
NET_EVENT_WIFI_DISCONNECT_RESULT
Device Name wifi
Init Result 0
Initialized? YES
Info Length 4
Size of wifi_status struct 4
Connection Status -1
Dissconnection reason -1
AP Status -1
Disconnection request (-1)
[00:00:09.292,000] <err> esp32_wifi: Failed to send packet

Any idea why all the status are -1? Why do we get the Dissconect_request callback on connecting request?

Many thanks for your help.

Regards Martin