esp-idf-svc icon indicating copy to clipboard operation
esp-idf-svc copied to clipboard

Feature request: implement esp_wifi_set_country

Open leelists opened this issue 2 years ago • 2 comments

Hi!

First of, Thank you all for the awesome set of esp related crates :)

I'm porting a little c app from esp-idf to rust and search a simple way to call

    const wifi_country_t cc = {
            .cc = "fr",
            .schan = 1,
            .nchan = 14,
            .max_tx_power = 255,
    };
    ESP_ERROR_CHECK(esp_wifi_set_country(&cc));

from rust, but i'm a bit stuck

Any clues are welcomed

leelists avatar May 28 '22 10:05 leelists

We don't have safe wrappers to do this yet, but in general you can always call esp-idf C functions with the esp_idf_sys crate.

E.g, a rough pseudo-ish code example:

use esp_idf_sys::*;

let cc = wifi_country_t {
  cc: "fr",
  schan: 1,
  nchan: 14,
  max_tx_power: 255,
  ..Default::default()
};

let res = esp!(unsafe {
  esp_wifi_set_country(&cc)
});

If this works for you, and you feel like contributing back, adding a safe wrapper around this to esp-idf-svc would be a helpful contribution :).

MabezDev avatar May 30 '22 10:05 MabezDev

Many thanks, I will see if i'am able to do that

leelists avatar Jun 02 '22 10:06 leelists