Page 1 of 1

wifi_config_t structrue ap and sta members are overriten

Posted: Thu Apr 19, 2018 3:53 pm
by Gasoile
Hi, I'm starting a project with ESP32 using esp-idf and I'm getting some wierd behaviors when using wifi_config_t structures.
If I initialize the structure like this:

Code: Select all

wifi_config_t wifi_cfg = {
  .ap = {
    .ssid = "TEST",
    .password = "TESTPASS",
    .ssid_len = 8,
    .channel = 1,
    .authmode = WIFI_AUTH_WPA2_PSK,
    .ssid_hidden = false,
    .max_connection = 1,
    .beacon_interval = 100
  },
  .sta = {
    .ssid = "SCANN",
    .password = "SCANNPASS",
    .bssid_set = false,
    .bssid[0] = 0,
    .bssid[1] = 1,
    .bssid[2] = 2,
    .bssid[3] = 3,
    .bssid[4] = 4,
    .bssid[5] = 5,
    .channel = 0,
    .sort_method = WIFI_CONNECT_AP_BY_SIGNAL,
    .threshold = {
      .rssi = -127,
      .authmode = WIFI_AUTH_OPEN
      }
  }
};
and then print:

Code: Select all

ESP_LOGD(HYPERION_WIFI_TAG,"WiFi Configuration:\n\tap:\n\t\tssid:%s\n\t\tpassword:%s\n\t\tssid_len:%u\n\t\tchannel:%u\n\t\tauthmode:%u\n\t\tssid_hidden:%u\n\t\tmax_connection:%u\n\t\tbeacon_interval:%u\n\tsta:\n\t\tssid:%s\n\t\tpassword:%s\n\t\tbssid_set:%u\n\t\tbssid:%2x:%2x:%2x:%2x:%2x:%2x\n\t\tchannel:%u\n\t\tsort_method:%u\n\t\tthreshold.rssi:%d\n\t\tthreshold.authmode:%u", wifi_cfg.ap.ssid,wifi_cfg.ap.password, wifi_cfg.ap.ssid_len, wifi_cfg.ap.channel, wifi_cfg.ap.authmode, wifi_cfg.ap.ssid_hidden, wifi_cfg.ap.max_connection, wifi_cfg.ap.beacon_interval, wifi_cfg.sta.ssid, wifi_cfg.sta.password, wifi_cfg.sta.bssid_set, wifi_cfg.sta.bssid[0], wifi_cfg.sta.bssid[1], wifi_cfg.sta.bssid[2], wifi_cfg.sta.bssid[3], wifi_cfg.sta.bssid[4], wifi_cfg.sta.bssid[5], wifi_cfg.sta.channel, wifi_cfg.sta.sort_method, wifi_cfg.sta.threshold.rssi, wifi_cfg.sta.threshold.authmode);
and the result I get is:

WiFi Configuration:
ap:
ssid:SCANN
password:SCANNPASS
ssid_len:0
channel:0
authmode:33619968
ssid_hidden:3
max_connection:4
beacon_interval:5
sta:
ssid:SCANN
password:SCANNPASS
bssid_set:0
bssid: 0: 1: 2: 3: 4: 5
channel:0
sort_method:0
threshold.rssi:-127
threshold.authmode:0

Note that the members from the member ap from wifi_config_t are affected by initializing the member sta. Does someone has similar problem? What am I missing?

Thanks a lot for any help.

Re: wifi_config_t structrue ap and sta members are overriten

Posted: Fri Apr 20, 2018 1:05 am
by ESP_Sprite
The .sta and .ap members are in an C union: they essentially map to the same bit of memory. This is because the ESP32 essentially has two virtual interfaces: one that can act as a station, one that can act as an access point. You can't configure one interface as both things, so the members can happily share the memory for the configuration options and save some memory.

Re: wifi_config_t structrue ap and sta members are overriten

Posted: Fri Apr 20, 2018 9:20 am
by Gasoile
Thanks a lot!
I had not realized it is union! It would be handy to have it as struct if you want to switch between modes or use APSTA mode. In my case I will not save some money because I need to keep track of both AP and STA configurations...
But now I can finally move one in peace :) .