Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esp_wifi_set_country() called late #2689

Open
liclac opened this issue Dec 5, 2024 · 0 comments
Open

esp_wifi_set_country() called late #2689

liclac opened this issue Dec 5, 2024 · 0 comments
Labels
bug Something isn't working package:esp-wifi Issues related to the esp-wifi package

Comments

@liclac
Copy link

liclac commented Dec 5, 2024

Bug description

If you construct a configuration which is not world-safe (allowed in the default country code of O1) - for instance, an access point on Channel 13 with ESP_WIFI_COUNTRY_CODE = "DE" (or another country which allows the use of this channel):

wifi::AccessPointConfiguration { channel: 13, ..Default::default() }

You can't pass this to wifi::new_with_config(), or WifiController::set_configuration() without first calling WifiController::start(), or you get a runtime error:

WARN - esp_wifi_set_config(wifi_interface_t_WIFI_IF_AP, &mut cfg) returned an error: 258


====================== PANIC ======================
panicked at src/bin/downlink2/main.rs:62:10:
couldn't configure WiFi: InternalError(EspErrInvalidArg)

This is because esp_wifi_set_country() is not called until wifi::wifi_start(), after wifi::new_with_config() or WifiController::set_configuration() would call esp_wifi_set_config():

let country = wifi_country_t {
cc: core::mem::transmute::<[u8; 3], [i8; 3]>(cntry_code), // [u8] -> [i8] conversion
schan: 1,
nchan: 13,
max_tx_power: 20,
policy: wifi_country_policy_t_WIFI_COUNTRY_POLICY_MANUAL,
};
esp_wifi_result!(esp_wifi_set_country(&country))?;

To Reproduce

    static WIFI_INIT: StaticCell<EspWifiController> = StaticCell::new();
    let timer1 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0);
    let wifi_init: &'static mut _ = WIFI_INIT.init(
        esp_wifi::init(
            timer1.timer0,
            esp_hal::rng::Rng::new(peripherals.RNG),
            peripherals.RADIO_CLK,
        )
        .unwrap(),
    );
 
    let (wifi_dev, mut wifi_ctrl) =
        wifi::new_with_mode(wifi_init, peripherals.WIFI, wifi::WifiApDevice)
            .expect("couldn't create WiFi dev/ctrl");

    // -- it works if you move this section below `wifi_ctrl.start()` -- //
    wifi_ctrl
        .set_configuration(&wifi::Configuration::AccessPoint(
            wifi::AccessPointConfiguration {
                channel: 13,
                ..Default::default()
            },
        ))
        .expect("couldn't configure WiFi");
    // ----------------------------------------------------------------- //

    wifi_ctrl
        .start()
        .expect("couldn't start WiFi controller");

Expected behavior

I would expect my access point to run on channel 13, not panic.

Environment

  • Target device: ESP32
  • Crate name and version: esp-wifi 0.11.0
@liclac liclac added bug Something isn't working status:needs-attention This should be prioritized labels Dec 5, 2024
@github-project-automation github-project-automation bot moved this to Todo in esp-rs Dec 5, 2024
@jessebraham jessebraham added package:esp-wifi Issues related to the esp-wifi package and removed status:needs-attention This should be prioritized labels Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working package:esp-wifi Issues related to the esp-wifi package
Projects
Status: Todo
Development

No branches or pull requests

2 participants