how to assign value to wifi structure ?

frankiPL
Posts: 9
Joined: Thu Nov 16, 2017 8:59 am

how to assign value to wifi structure ?

Postby frankiPL » Mon Dec 11, 2017 10:35 am

Hi,

I have an structure that I don't understand:

Code: Select all

typedef struct {
    uint8_t ssid[32];      /**< SSID of target AP*/
    uint8_t password[64];  /**< password of target AP*/
    wifi_scan_method_t scan_method;    /**< do all channel scan or fast scan */
    bool bssid_set;        /**< whether set MAC address of target AP or not. Generally, station_config.bssid_set needs to be 0; and it needs to be 1 only when users need to check the MAC address of the AP.*/
    uint8_t bssid[6];     /**< MAC address of target AP*/
    uint8_t channel;       /**< channel of target AP. Set to 1~13 to scan starting from the specified channel before connecting to AP. If the channel of AP is unknown, set it to 0.*/
    wifi_sort_method_t sort_method;    /**< sort the connect AP in the list by rssi or security mode */
    wifi_fast_scan_threshold_t  threshold;     /**< When scan_method is set to WIFI_FAST_SCAN, only APs which have an auth mode that is more secure than the selected auth mode and a signal stronger than the minimum RSSI will be used. */
} wifi_sta_config_t;
it is initualized by assigning "#defined" values:

Code: Select all

wifi_config_t wifi_config = {
    .sta = {
        .ssid = WIFI_AP_NAME,
        .password = WIFI_AP_PASS,
         bssid_set = 0
    },
};
where WIFI_AP_NAME and WIFI_AP_PASS is defined like this:

Code: Select all

#define WIFI_AP_NAME CONFIG_WIFI_SSID
#define CONFIG_WIFI_SSID "myssid"
Now, I have:

Code: Select all

char *wifi_ssid=mynvs_read(WIFI_SSID_TYPE);
char *wifi_pass=mynvs_read(WIFI_PASS_TYPE);
and I need to assign these values to .ssid and .password in wifi_config structure.

How to do that, because simple assigment throws an error:

Code: Select all

wifi_config_t wifi_config = {
        .sta = {
            .ssid = wifi_ssid,
            .password = wifi_pass,
            .bssid_set = 0
        },
    };
    error: missing braces around initializer [-Werror=missing-braces]
when I try to strcpy values, I got:

Code: Select all

error: pointer targets in passing argument 1 of 'strcpy' differ in signedness [-Werror=pointer-sign]
         strcpy(wifi_config.sta.password,wifi_pass);
Best Regards
Marek

User avatar
martinayotte
Posts: 141
Joined: Fri Nov 13, 2015 4:27 pm

Re: how to assign value to wifi structure ?

Postby martinayotte » Sat Dec 16, 2017 9:19 pm

Since ssid/password of the struct are arrays, you can't assign them pointers, you need to copy contain of your pointers into those arrays using strcpy()

frankiPL
Posts: 9
Joined: Thu Nov 16, 2017 8:59 am

Re: how to assign value to wifi structure ?

Postby frankiPL » Mon Dec 18, 2017 5:18 pm

Yes I have tried strcpy,
I assume I need to convert char* to unit8_t array, maybe something like this:
strcpy((unsigned char)wifi_config.sta.ssid,(unsigned char)mynvs_wifi_ssid);

User avatar
martinayotte
Posts: 141
Joined: Fri Nov 13, 2015 4:27 pm

Re: how to assign value to wifi structure ?

Postby martinayotte » Fri Dec 22, 2017 10:40 pm

If you fix the missing * typo and remove the unsigned, yes !

Code: Select all

strcpy((char *)wifi_config.sta.ssid,(char *)mynvs_wifi_ssid);

Who is online

Users browsing this forum: No registered users and 269 guests