Mqtt over wifi lesson 4 exercise 1 not able to build with nrf7002dk_nrf5340_cpuapp

Hi,

I am unable to build the MQTT over Wi-Fi lesson 4, exercise 1 using the nrf7002dk_nrf5340_cpuapp board configuration, but the same code builds successfully with nrf7002dk_nrf5340_cpuapp_ns.

How can I build it with nrf7002dk_nrf5340_cpuapp?

i got the below error,Also in wifi_credentials.c file all ready  wifi_credentials_internal.h available,

/home/chiragbhavsar/NRF_VS_CODE/v2.6.1/nrf/subsys/net/lib/wifi_credentials/wifi_credentials.c:331: undefined reference to `wifi_credentials_delete_entry'

  • Hi,

    The lesson only supports building with TF-M, that is, building for the _ns board variant.

    To get it to work without TF-M, you can add support for storing the network credentials in settings storage and use the wifi connect shell command to connect to the network instead.

    # For storing Wi-Fi credentials
    CONFIG_WIFI_CREDENTIALS_BACKEND_SETTINGS=y
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_FLASH_MAP=y
    CONFIG_NVS=y
    CONFIG_SETTINGS=y
    CONFIG_SETTINGS_NVS=y
    # Enable Wi-Fi shell
    CONFIG_NET_L2_WIFI_SHELL=y

    After the device has started up and you see the "Waiting to connect to Wi-Fi" log, use the following command to connect to the network:

    wifi connect -s <ssid> -k 1 -p <password>

    Make sure to replace <ssid> and <password> with the SSID and password of the network you want to connect to.

    Best regards,
    Marte

  • I use a static Wi-Fi SSID and password for the initial connection.

    After establishing the MQTT connection, the wifi custom mobile app provides a new SSID and password on mqtt. How can I change the SSID and password at runtime?

    Is the method below correct?

    uint8_t _CusSsid[] = "xxxxx";
    uint8_t _CusPasswod[] = "xxxxx";
    cnx_params.ssid = _CusSsid;
    cnx_params.ssid_length = strlen(cnx_params.ssid);
    cnx_params.psk = _CusPasswod;
    cnx_params.psk_length = strlen(cnx_params.psk);
  • Hi,

    You can set it in runtime using wifi_credentials_set_personal or wifi_credentials_set_personal_struct(), for example like this:

    static struct wifi_credentials_personal wifi_cred;
    
    void set_wifi_credentials_struct() 
    {
    
    	char *wifi_ssid = "Myssid";
    	char *wifi_password = "Mypassword";
    
    	wifi_cred.header.type = WIFI_SECURITY_TYPE_PSK;
    	memset(wifi_cred.header.bssid, 0, sizeof(wifi_cred.header.bssid));
    	wifi_cred.header.flags = 0;
    	wifi_cred.header.channel = WIFI_CHANNEL_ANY;
    	wifi_cred.header.timeout = 10;
    
    	wifi_cred.header.ssid_len = strlen(wifi_ssid);
    	memcpy(wifi_cred.header.ssid, wifi_ssid, wifi_cred.header.ssid_len);
    	
    	wifi_cred.password_len = strlen(wifi_password);
    	memcpy(wifi_cred.password, wifi_password, wifi_cred.password_len);
    
    	int ret = wifi_credentials_set_personal_struct(&wifi_cred);
    
    	if (ret != 0) {
    		LOG_ERR("Failed to set credentials, err: %d", ret);
    	}
    }

    Best regards,
    Marte

  • Hi,

    The following two parameters are not available in wifi_credentials_personal. Could this cause any issues?
    wifi_cred.header.channel = WIFI_CHANNEL_ANY;
    wifi_cred.header.timeout = 10;
    Also, I added the security configuration below. Could this cause any issues?
    wifi_cred.header.type = CONFIG_STA_KEY_MGMT_WPA2;
  • Hi,

    ChiragBhavsar said:
    The following two parameters are not available in wifi_credentials_personal. Could this cause any issues?

    No, this should not cause any issues. My code was based on v2.7.1, where these parameters are included, but in v2.6.1, you do not need them.

    ChiragBhavsar said:
    Also, I added the security configuration below. Could this cause any issues?

    The security type is a variable of type wifi_security_type, so you need to use one of the elements in that enum.

    /** @brief IEEE 802.11 security types. */
    enum wifi_security_type {
    	/** No security. */
    	WIFI_SECURITY_TYPE_NONE = 0,
    	/** WPA2-PSK security. */
    	WIFI_SECURITY_TYPE_PSK,
    	/** WPA2-PSK-SHA256 security. */
    	WIFI_SECURITY_TYPE_PSK_SHA256,
    	/** WPA3-SAE security. */
    	WIFI_SECURITY_TYPE_SAE,
    	/** GB 15629.11-2003 WAPI security. */
    	WIFI_SECURITY_TYPE_WAPI,
    	/** EAP security - Enterprise. */
    	WIFI_SECURITY_TYPE_EAP,
    	/** WEP security. */
    	WIFI_SECURITY_TYPE_WEP,
    	/** WPA-PSK security. */
    	WIFI_SECURITY_TYPE_WPA_PSK,
    	/** WPA/WPA2/WPA3 PSK security. */
    	WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL,
    
    /** @cond INTERNAL_HIDDEN */
    	__WIFI_SECURITY_TYPE_AFTER_LAST,
    	WIFI_SECURITY_TYPE_MAX = __WIFI_SECURITY_TYPE_AFTER_LAST - 1,
    	WIFI_SECURITY_TYPE_UNKNOWN
    /** @endcond */
    };

    For WPA2-PSK (CONFIG_STA_KEY_MGMT_WPA2), the correct value is WIFI_SECURITY_TYPE_PSK.

    Best regards,
    Marte

Related