Page 1 of 1

Platformio issue

Posted: Sun Feb 19, 2017 8:17 pm
by Async_Awayt
Not being really happy with Eclipse programming the ESP32 I gave Platformio a shot (on a mac running Sierra).
I really like that autocomplete works on platformio making programming much easier (never got that working on eclipse even though I tried it on Windows, Ubuntu as well as on the mac.)

Anyway, the first app worked well (blinking the builtin LED on a DOIT board). However, when trying the esp-idf-template wifi example I ran out of luck.
Firstly, I get a couple of errors during the build:
- C99 designator 'ssid' outside aggregate initializer at line ...
- C99 designator 'password' outside aggregate initializer at line ...
It seemed to compile nicely in spite of that.
Second odd thing happened when trying to upload the app...it seemed to hang up for a moment at:
-Compressed 487056 bytes to 248151...
Eventually the upload would get successfully uploaded though.
Problem is that it seems to stop at the line:
- ESP_ERROR_CHECK( esp_wifi_init(&cfg) );

Not a lot of support on ESP32 programming with Platformio out there...any of you guys know how to fix the issue?

Re: Platformio issue

Posted: Fri Mar 24, 2017 12:37 pm
by f.h-f.s.
I've seen that error
C99 designator 'ssid' outside aggregate initializer at line ...
When I try to compile the c code in a cpp file.

You can't initialize a struct in c++ like this:

Code: Select all

    wifi_config_t wifi_config = {
        .sta = {
            .ssid = EXAMPLE_WIFI_SSID,
        },
};
It should generate an error.

Are you not getting any build errors(try to build verbose?)? Are you using cpp or c sources?

Re: Platformio issue

Posted: Sat Mar 25, 2017 11:22 pm
by CTRL_CAIN
f.h-f.s. wrote:I've seen that error
C99 designator 'ssid' outside aggregate initializer at line ...
When I try to compile the c code in a cpp file.

You can't initialize a struct in c++ like this:

Code: Select all

    wifi_config_t wifi_config = {
        .sta = {
            .ssid = EXAMPLE_WIFI_SSID,
        },
};
It should generate an error.

Are you not getting any build errors(try to build verbose?)? Are you using cpp or c sources?
Im also using platform IO and getting the same error when trying to configure a SOFTAP. Any clue whats going on with this or any work around?

Re: Platformio issue

Posted: Sat Mar 25, 2017 11:24 pm
by CTRL_CAIN
Im getting the same error when configuring wifi for SOFTAP. Any clue whats going on or a work around. c source. Thanks.

Re: Platformio issue

Posted: Mon Mar 27, 2017 12:58 am
by ESP_Angus
Please see this post about rewriting struct "designated initializers" of this kind, for use from C++ code:
https://esp32.com/viewtopic.php?f=13&t= ... izer#p5942

Angus

Re: Platformio issue

Posted: Thu Nov 29, 2018 8:59 am
by DimaRU
Just small magic in C++:

Code: Select all

    wifi_config_t wifi_config = {
        .sta = {
            {.ssid = EXAMPLE_WIFI_SSID},
            {.password = EXAMPLE_WIFI_PASS}
        },
    };

Re: Platformio issue

Posted: Thu Sep 19, 2019 2:47 am
by azz-zza
DimaRU wrote:
Thu Nov 29, 2018 8:59 am
Just small magic in C++:

Code: Select all

    wifi_config_t wifi_config = {
        .sta = {
            {.ssid = EXAMPLE_WIFI_SSID},
            {.password = EXAMPLE_WIFI_PASS}
        },
    };
Unfortunately, magic is not working:

Code: Select all

   wifi_config_t wifi_config = {
        .ap = {
            {.ssid = EXAMPLE_ESP_WIFI_SSID},
            {.ssid_len = 6 },
            // {.ssid_len = strlen(EXAMPLE_ESP_WIFI_SSID)},
            {.password = EXAMPLE_ESP_WIFI_PASS},
            {.max_connection = EXAMPLE_MAX_STA_CONN},
            {.authmode = WIFI_AUTH_WPA_WPA2_PSK}
        },
    };

Compiling .pio/build/esp32doit-devkit-v1/src/main.o
src/main.cpp: In function 'void wifi_init_softap()':
src/main.cpp:75:5: error: name 'ssid_len' used in a GNU-style designated initializer for an array
     };
     ^
src/main.cpp:75:5: error: braces around scalar initializer for type 'uint8_t {aka unsigned char}'
Compiling .pio/build/esp32doit-devkit-v1/bootloader/bootloader_support/src/bootloader_sha.o
Compiling .pio/build/esp32doit-devkit-v1/bootloader/bootloader_support/src/bootloader_utility.o
*** [.pio/build/esp32doit-devkit-v1/src/main.o] Error 1
Compiling .pio/build/esp32doit-devkit-v1/bootloader/bootloader_support/src/efuse.o


Re: Platformio issue

Posted: Wed Nov 03, 2021 10:09 am
by mark.jeronimus
azz-zza wrote:
Thu Sep 19, 2019 2:47 am
Unfortunately, magic is not working:

Code: Select all

   wifi_config_t wifi_config = {
        .ap = {
            {.ssid = EXAMPLE_ESP_WIFI_SSID},
            {.ssid_len = 6 },
            // {.ssid_len = strlen(EXAMPLE_ESP_WIFI_SSID)},
            {.password = EXAMPLE_ESP_WIFI_PASS},
            {.max_connection = EXAMPLE_MAX_STA_CONN},
            {.authmode = WIFI_AUTH_WPA_WPA2_PSK}
        },
    };
Only wrap the `char[]` fields in curly brackets.

When it compiles, you still get a bunch of warnings about uninitialized members.

My suggestion below, is to turn everything into proper initializer lists rather than sticking to aggregate initializers. (This is for stations instead of access points, as that's what I happen to be working on, but the idea should be clear)

Code: Select all

 
    wifi_config_t wifi_config = { .sta =  {
        /* ssid            */ EXAMPLE_ESP_WIFI_SSID,
        /* password        */ EXAMPLE_ESP_WIFI_PASS,
        /* scan_method     */ {},
        /* bssid_set       */ {},
        /* bssid           */ {},
        /* channel         */ {},
        /* listen_interval */ {},
        /* sort_method     */ {},
        /* threshold       */ {
            /* rssi            */ {},
            /* authmode        */ WIFI_AUTH_WPA2_PSK},
        /* pmf_cfg         */ {
            /* capable         */ true,
            /* required        */ false},
        /* rm_enabled      */ {},
        /* btm_enabled     */ {},
//      /* mbo_enabled     */ {}, // For IDF 4.4 and higher
        /* reserved        */ {}
    }};
Of course, as expected, this becomes very sensitive to changes to the underlying struct, as seen by the difference between IDF 4.3 and 4.4.

Once C++20 becomes mainstream, which supports brings back C99 designators, these issues will all become naught, as the original C example will work out of the box.