<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>DevAcademy Lesson 5, HTTP over Wi-Fi (Exercise 2), does not build with nrf7002dk_nrf5340_cpuapp when CONFIG_WPA_SUPP_CRYPTO_PSA=y is enabled</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/116133/devacademy-lesson-5-http-over-wi-fi-exercise-2-does-not-build-with-nrf7002dk_nrf5340_cpuapp-when-config_wpa_supp_crypto_psa-y-is-enabled</link><description>Hi, 
 I am following DevAcademy Lesson 5, HTTP over Wi-Fi (Exercise 2), which involves adding TLS to an HTTP connection. 
 When I remove CONFIG_WPA_SUPP_CRYPTO_PSA=y , I am able to successfully build the code for nrf7002dk_nrf5340_cpuapp . 
 Will removing</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 02 Dec 2024 15:59:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/116133/devacademy-lesson-5-http-over-wi-fi-exercise-2-does-not-build-with-nrf7002dk_nrf5340_cpuapp-when-config_wpa_supp_crypto_psa-y-is-enabled" /><item><title>RE: DevAcademy Lesson 5, HTTP over Wi-Fi (Exercise 2), does not build with nrf7002dk_nrf5340_cpuapp when CONFIG_WPA_SUPP_CRYPTO_PSA=y is enabled</title><link>https://devzone.nordicsemi.com/thread/513036?ContentTypeID=1</link><pubDate>Mon, 02 Dec 2024 15:59:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8564a119-51d6-4dcd-8cc0-a36cbd0b9980</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Please create a new support case for the latest issue which is away from the original scope.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DevAcademy Lesson 5, HTTP over Wi-Fi (Exercise 2), does not build with nrf7002dk_nrf5340_cpuapp when CONFIG_WPA_SUPP_CRYPTO_PSA=y is enabled</title><link>https://devzone.nordicsemi.com/thread/512029?ContentTypeID=1</link><pubDate>Tue, 26 Nov 2024 05:19:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1e177894-ea35-46bc-b6c3-61bf61b012e6</guid><dc:creator>ChiragBhavsar</dc:creator><description>&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;I was able to connect to the HTTP host, but I encountered issues when trying to connect to the WebSocket host.&lt;/p&gt;
&lt;p&gt;i disable the http portion from the code and try to connect with&amp;nbsp;&lt;span&gt;WebSocket host&amp;nbsp;but i am not able to connect with it.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Could you please review my code and provide feedback to help me resolve the WebSocket connection issue?&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/HTTP_5F00_web.zip"&gt;devzone.nordicsemi.com/.../HTTP_5F00_web.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DevAcademy Lesson 5, HTTP over Wi-Fi (Exercise 2), does not build with nrf7002dk_nrf5340_cpuapp when CONFIG_WPA_SUPP_CRYPTO_PSA=y is enabled</title><link>https://devzone.nordicsemi.com/thread/510169?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2024 16:17:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d0b99ba-5f7e-4310-b2fb-b67603522f93</guid><dc:creator>Amanda Hsieh</dc:creator><description>[quote user="ChiragBhavsar"]&lt;p&gt;Built the project with &lt;code&gt;nrf7002dk_nrf5340_cpuapp_ns&lt;/code&gt; and initially encountered the same error. After changing &lt;code&gt;IPPROTO_TCP&lt;/code&gt; to &lt;code&gt;IPPROTO_TLS_1_2 able to build successfully,&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) to sock = socket(AF_INET, SOCK_STREAM,&lt;/span&gt;&lt;span&gt;IPPROTO_TLS_1_2&lt;/span&gt;);&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;
&lt;p&gt;I am currently working with &lt;code&gt;nrf7002dk_nrf5340_cpuapp&lt;/code&gt; and made some changes to the &lt;code&gt;prj.conf&lt;/code&gt; file. After these adjustments, I was able to build the project and get the expected output.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;[/quote]
&lt;p&gt;Good to hear about the success.&amp;nbsp;&lt;/p&gt;
[quote user="ChiragBhavsar"]Could you please provide feedback on the code below? (I&amp;#39;m using &lt;code&gt;nrf7002dk_nrf5340_cpuapp&lt;/code&gt;).[/quote]
&lt;p&gt;I don&amp;#39;t see the issue from that.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DevAcademy Lesson 5, HTTP over Wi-Fi (Exercise 2), does not build with nrf7002dk_nrf5340_cpuapp when CONFIG_WPA_SUPP_CRYPTO_PSA=y is enabled</title><link>https://devzone.nordicsemi.com/thread/510058?ContentTypeID=1</link><pubDate>Tue, 12 Nov 2024 09:45:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5cf62a71-ccaf-4357-ad83-5c4ec4fe05e4</guid><dc:creator>ChiragBhavsar</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;i used SDK v2.6.1,&lt;/p&gt;
&lt;p&gt;Built the project with &lt;code&gt;nrf7002dk_nrf5340_cpuapp_ns&lt;/code&gt; and initially encountered the same error. After changing &lt;code&gt;IPPROTO_TCP&lt;/code&gt; to &lt;code&gt;IPPROTO_TLS_1_2 able to build successfully,&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) to sock = socket(AF_INET, SOCK_STREAM,&lt;/span&gt;&lt;span&gt;IPPROTO_TLS_1_2&lt;/span&gt;);&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;
&lt;p&gt;I am currently working with &lt;code&gt;nrf7002dk_nrf5340_cpuapp&lt;/code&gt; and made some changes to the &lt;code&gt;prj.conf&lt;/code&gt; file. After these adjustments, I was able to build the project and get the expected output.&lt;/p&gt;
&lt;p&gt;Could you please provide feedback on the code below? (I&amp;#39;m using &lt;code&gt;nrf7002dk_nrf5340_cpuapp&lt;/code&gt;).&lt;/p&gt;
&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2023 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

#include &amp;lt;errno.h&amp;gt;
#include &amp;lt;stddef.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/types.h&amp;gt;
#include &amp;lt;zephyr/logging/log.h&amp;gt;

#include &amp;lt;dk_buttons_and_leds.h&amp;gt;

/* STEP 3 - Include the necessary header files */
#include &amp;lt;zephyr/net/wifi.h&amp;gt;
#include &amp;lt;zephyr/net/wifi_mgmt.h&amp;gt;
#include &amp;lt;zephyr/net/net_mgmt.h&amp;gt;
#include &amp;lt;net/wifi_mgmt_ext.h&amp;gt;

/* STEP 12.4 - Include the header file for the Wi-FI credentials library */
#include &amp;lt;net/wifi_credentials.h&amp;gt;
#include &amp;lt;zephyr/net/socket.h&amp;gt;

#include &amp;lt;zephyr/net/net_if.h&amp;gt;
#include &amp;lt;zephyr/sys/printk.h&amp;gt;

// #define SERVER_IP_ADDR &amp;quot;192.168.1.10&amp;quot; // Replace with your server&amp;#39;s IP
// #define SERVER_PORT 8080

// LOG_MODULE_REGISTER(Lesson2_Exercise2, LOG_LEVEL_INF);

/* STEP 4 - Define a macro for the relevant network events */
// #define EVENT_MASK (NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED)

/* STEP 1.2 - Include the header file of the HTTP client library */
#include &amp;lt;zephyr/net/http/client.h&amp;gt;
/* STEP 1.4 - Include the header file for the TLS credentials library */
#include &amp;lt;zephyr/net/tls_credentials.h&amp;gt;

/* STEP 2.3 - Include the certificate */
static const char ca_certificate[] = {
#include &amp;quot;certificate.h&amp;quot;
};

LOG_MODULE_REGISTER(Lesson5_Exercise1);

#define EVENT_MASK (NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED)

/* STEP 5 - Declare the callback structure for Wi-Fi events */
static struct net_mgmt_event_callback mgmt_cb;

/* STEP 6.1 - Define the boolean connected and the semaphore run_app */
static bool connected = 0;
static bool firsttime = 1;
static K_SEM_DEFINE(run_app, 0, 1);

/* STEP 4.1 - Define a macro for the credential security tag */
#define HTTP_TLS_SEC_TAG 1

/* STEP 2 - Define the macros for the HTTP server hostname and port */
#define HTTP_HOSTNAME &amp;quot;echo.thingy.rocks&amp;quot; //staging.api.nexkey.com
#define HTTP_PORT     443

/* STEP 3 - Declare the necessary buffers for receiving messages */
#define RECV_BUF_SIZE  2048
#define CLIENT_ID_SIZE 36

static char recv_buf[RECV_BUF_SIZE];
static char client_id_buf[CLIENT_ID_SIZE + 2];

/* STEP 4 - Define the variable for the counter as 0 */
static int counter = 0;

static int sock;
static struct sockaddr_storage server;

//static struct net_mgmt_event_callback mgmt_cb;
//static bool connected;
//static K_SEM_DEFINE(run_app, 0, 1);



static int server_resolve(void)
{
	int err;
	struct addrinfo *result;
	struct addrinfo hints = {.ai_family = AF_INET, .ai_socktype = SOCK_STREAM};

	err = getaddrinfo(HTTP_HOSTNAME, STRINGIFY(HTTP_PORT), &amp;amp;hints, &amp;amp;result);
	if (err != 0) {
		LOG_ERR(&amp;quot;getaddrinfo failed, err: %d, %s&amp;quot;, err, gai_strerror(err));
		return -EIO;
	}

	if (result == NULL) {
		LOG_ERR(&amp;quot;Error, address not found&amp;quot;);
		return -ENOENT;
	}

	struct sockaddr_in *server4 = ((struct sockaddr_in *)&amp;amp;server);
	server4-&amp;gt;sin_addr.s_addr = ((struct sockaddr_in *)result-&amp;gt;ai_addr)-&amp;gt;sin_addr.s_addr;
	server4-&amp;gt;sin_family = AF_INET;
	server4-&amp;gt;sin_port = ((struct sockaddr_in *)result-&amp;gt;ai_addr)-&amp;gt;sin_port;

	char ipv4_addr[NET_IPV4_ADDR_LEN];
	inet_ntop(AF_INET, &amp;amp;server4-&amp;gt;sin_addr.s_addr, ipv4_addr, sizeof(ipv4_addr));
	LOG_INF(&amp;quot;IPv4 address of HTTP server found %s&amp;quot;, ipv4_addr);

	freeaddrinfo(result);

	return 0;
}

static int setup_credentials(void)
{
	
	/* STEP 4.2 - Add the credential to the device */
	int err = tls_credential_add(HTTP_TLS_SEC_TAG, TLS_CREDENTIAL_CA_CERTIFICATE, ca_certificate,
				 sizeof(ca_certificate));
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to add TLS credentials, err: %d&amp;quot;, err);
		return err;
	}

	return 0;
}

static int server_connect(void)
{
	int err;
	sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TLS_1_2);
	if (sock &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to create socket, err: %d, %s&amp;quot;, errno, strerror(errno));
		return -errno;
	}

	/* STEP 5.1 - Configure the socket with the security tag for the certificate */
	sec_tag_t sec_tag_opt[] = {
		HTTP_TLS_SEC_TAG,
	};
	err = setsockopt(sock, SOL_TLS, TLS_SEC_TAG_LIST, sec_tag_opt, sizeof(sec_tag_opt));
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to set TLS security TAG list, err: %d&amp;quot;, errno);
		(void)close(sock);
		return -errno;
	}
	/* STEP 5.2 - Configure the socket with the hostname of the HTTP server */
	err = setsockopt(sock, SOL_TLS, TLS_HOSTNAME, HTTP_HOSTNAME, sizeof(HTTP_HOSTNAME));
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to set TLS_HOSTNAME option. Err: %d&amp;quot;, errno);
		(void)close(sock);
		return -errno;
	}

	err = connect(sock, (struct sockaddr *)&amp;amp;server, sizeof(struct sockaddr_in));
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;Connecting to server failed, err: %d, %s&amp;quot;, errno, strerror(errno));
		return -errno;
	}

	LOG_INF(&amp;quot;Connected to server&amp;quot;);
	return 0;
}

static void response_cb(struct http_response *rsp, enum http_final_call final_data, void *user_data)
{
	/* STEP 9 - Define the callback function to print the body */
	LOG_INF(&amp;quot;Response status: %s&amp;quot;, rsp-&amp;gt;http_status);

	if (rsp-&amp;gt;body_frag_len &amp;gt; 0) {
		char body_buf[rsp-&amp;gt;body_frag_len];
		strncpy(body_buf, rsp-&amp;gt;body_frag_start, rsp-&amp;gt;body_frag_len);
		body_buf[rsp-&amp;gt;body_frag_len] = &amp;#39;\0&amp;#39;;
		LOG_INF(&amp;quot;Received: %s&amp;quot;, body_buf);
	}

	LOG_INF(&amp;quot;Closing socket: %d&amp;quot;, sock);
	close(sock);
}

static void client_id_cb(struct http_response *rsp, enum http_final_call final_data,
			 void *user_data)
{
	/* STEP 6.1 - Log the HTTP response status */
	LOG_INF(&amp;quot;Response status: %s&amp;quot;, rsp-&amp;gt;http_status);

	/* STEP 6.2 - Retrieve and format the client ID */
	char client_id_buf_tmp[CLIENT_ID_SIZE + 1];
	strncpy(client_id_buf_tmp, rsp-&amp;gt;body_frag_start, CLIENT_ID_SIZE);
	client_id_buf_tmp[CLIENT_ID_SIZE] = &amp;#39;\0&amp;#39;;
	client_id_buf[0] = &amp;#39;/&amp;#39;;
	strcat(client_id_buf, client_id_buf_tmp);

	LOG_INF(&amp;quot;Successfully acquired client ID: %s&amp;quot;, client_id_buf);

	/* STEP 6.3 - Close the socket */
	LOG_INF(&amp;quot;Closing socket: %d&amp;quot;, sock);
	close(sock);
}

static int client_http_put(void)
{
	/* STEP 7 - Define the function to send a PUT request to the HTTP server */
	int err = 0;
	int bytes_written;
	const char *headers[] = {&amp;quot;Connection: close\r\n&amp;quot;, NULL};

	struct http_request req;
	memset(&amp;amp;req, 0, sizeof(req));

	char buffer[12] = {0};
	bytes_written = snprintf(buffer, 12, &amp;quot;%d&amp;quot;, counter);
	if (bytes_written &amp;lt; 0) {
		LOG_INF(&amp;quot;Unable to write to buffer, err: %d&amp;quot;, bytes_written);
		return bytes_written;
	}

	req.header_fields = headers;
	req.method = HTTP_PUT;
	req.url = client_id_buf;
	req.host = HTTP_HOSTNAME;
	req.protocol = &amp;quot;HTTP/1.1&amp;quot;;
	req.payload = buffer;
	req.payload_len = bytes_written;
	req.response = response_cb;
	req.recv_buf = recv_buf;
	req.recv_buf_len = sizeof(recv_buf);

	LOG_INF(&amp;quot;HTTP PUT request: %s&amp;quot;, buffer);
	err = http_client_req(sock, &amp;amp;req, 5000, NULL);
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to send HTTP PUT request %s, err: %d&amp;quot;, buffer, err);
	}

	return err;
}

static int client_http_get(void)
{
	/* STEP 8 - Define the function to send a GET request to the HTTP server */
	int err = 0;
	const char *headers[] = {&amp;quot;Connection: close\r\n&amp;quot;, NULL};
	
	struct http_request req;
	memset(&amp;amp;req, 0, sizeof(req));

	req.header_fields = headers;
	req.method = HTTP_GET;
	req.url = client_id_buf;
	req.host = HTTP_HOSTNAME;
	req.protocol = &amp;quot;HTTP/1.1&amp;quot;;
	req.response = response_cb;
	req.recv_buf = recv_buf;
	req.recv_buf_len = sizeof(recv_buf);

	LOG_INF(&amp;quot;HTTP GET request&amp;quot;);
	err = http_client_req(sock, &amp;amp;req, 5000, NULL);
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to send HTTP GET request, err: %d&amp;quot;, err);
	}

	return err;
}

static int client_get_new_id(void)
{
	int err = 0;

	/* STEP 5.1 - Define the structure http_request and fill the block of memory */
	struct http_request req;
	memset(&amp;amp;req, 0, sizeof(req));

	/* STEP 5.2 - Populate the http_request structure */
	const char *headers[] = {&amp;quot;Connection: close\r\n&amp;quot;, NULL};
	req.header_fields = headers;
	req.method = HTTP_POST;
	req.url = &amp;quot;/new&amp;quot;;
	req.host = HTTP_HOSTNAME;
	req.protocol = &amp;quot;HTTP/1.1&amp;quot;;
	req.response = client_id_cb;
	req.recv_buf = recv_buf;
	req.recv_buf_len = sizeof(recv_buf);

	/* STEP 5.3 - Send the request to the HTTP server */
	LOG_INF(&amp;quot;HTTP POST request&amp;quot;);
	err = http_client_req(sock, &amp;amp;req, 5000, NULL);
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to send HTTP POST request, err: %d&amp;quot;, err);
	}
	return err;
}

/* STEP 6.2 - Define the callback function for network events */
static void net_mgmt_event_handler(struct net_mgmt_event_callback *cb,
			  uint32_t mgmt_event, struct net_if *iface)
{
	if ((mgmt_event &amp;amp; EVENT_MASK) != mgmt_event) {
		return;
	}
	if (mgmt_event == NET_EVENT_L4_CONNECTED) {
		LOG_INF(&amp;quot;Network connected&amp;quot;);
		connected = true;
		dk_set_led_on(DK_LED1);
		//k_sem_give(&amp;amp;run_app);
		return;
	}
	if (mgmt_event == NET_EVENT_L4_DISCONNECTED) {
		if (connected == false) {
			LOG_INF(&amp;quot;Waiting for network to be connected&amp;quot;);
		} else {
			dk_set_led_off(DK_LED1);
			LOG_INF(&amp;quot;Network disconnected&amp;quot;);
			connected = false;
		}
		//k_sem_reset(&amp;amp;run_app);
		return;
	}
}

/* STEP 7 - Define the function to populate the Wi-Fi credential parameters */
//static int wifi_args_to_params(struct wifi_connect_req_params *params)
//{

	/* STEP 7.1 Populate the SSID and password */
	//params-&amp;gt;ssid = CONFIG_WIFI_CREDENTIALS_STATIC_SSID;
	//params-&amp;gt;ssid_length = strlen(params-&amp;gt;ssid);

	//params-&amp;gt;psk = CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD;
	//params-&amp;gt;psk_length = strlen(params-&amp;gt;psk);

	/* STEP 7.2 - Populate the rest of the relevant members */
	//params-&amp;gt;channel = WIFI_CHANNEL_ANY;
	//params-&amp;gt;security = WIFI_SECURITY_TYPE_PSK;
	//params-&amp;gt;mfp = WIFI_MFP_OPTIONAL;
	//params-&amp;gt;timeout = SYS_FOREVER_MS;
	//params-&amp;gt;band = WIFI_FREQ_BAND_UNKNOWN;
	//#if NCS_VERSION_NUMBER &amp;gt; 0x20600
	//memset(params-&amp;gt;bssid, 0, sizeof(params-&amp;gt;bssid));
	//#endif
	//return 0;
//}

static struct wifi_credentials_personal wifi_cred;
void set_wifi_credentials_struct() 
{

	char *wifi_ssid = &amp;quot;realme&amp;quot;;
	char *wifi_password = &amp;quot;Chirag@1527&amp;quot;;

	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(&amp;amp;wifi_cred);

	if (ret != 0) {
		LOG_ERR(&amp;quot;Failed to set credentials, err: %d&amp;quot;, ret);
	}
}
static void button_handler(uint32_t button_state, uint32_t has_changed)
{
	/* STEP 10 - Define the button handler to send requests upon button triggers */
	if (has_changed &amp;amp; DK_BTN1_MSK &amp;amp;&amp;amp; button_state &amp;amp; DK_BTN1_MSK) {
		if (server_connect() &amp;gt;= 0) {
			client_http_put();
			counter++;
		}
	} else if (has_changed &amp;amp; DK_BTN2_MSK &amp;amp;&amp;amp; button_state &amp;amp; DK_BTN2_MSK) {
		if (server_connect() &amp;gt;= 0) {
			client_http_get();
		}
	}
}

int main(void)
{
	/* STEP 8.1 - Declare the variable for the network configuration parameters */
	//struct wifi_connect_req_params cnx_params;



	/* STEP 8.2 - Get the network interface */
	struct net_if *iface = net_if_get_first_wifi();
	if (iface == NULL) {
		LOG_ERR(&amp;quot;Returned network interface is NULL&amp;quot;);
		return -1;
	}

	if (dk_leds_init() != 0) {
		LOG_ERR(&amp;quot;Failed to initialize the LED library&amp;quot;);
	}

	/* Sleep to allow initialization of Wi-Fi driver */
	k_sleep(K_SECONDS(1));

	/* STEP 9 - Initialize and add the callback function for network events */
	net_mgmt_init_event_callback(&amp;amp;mgmt_cb, net_mgmt_event_handler, EVENT_MASK);
	net_mgmt_add_event_callback(&amp;amp;mgmt_cb);

	/* STEP 10 - Populate cnx_params with the network configuration */
	//wifi_args_to_params(&amp;amp;cnx_params);

    set_wifi_credentials_struct();
	/* STEP 11 - Call net_mgmt() to request the Wi-Fi connection */
	LOG_INF(&amp;quot;Connecting to Wi-Fi&amp;quot;);
	//printf(&amp;quot;try to connect with wifi&amp;quot;);
	//LOG_ERR(&amp;quot;buttons library&amp;quot;);
	//int err = net_mgmt(NET_REQUEST_WIFI_CONNECT_STORED, iface, &amp;amp;wifi_cred, sizeof(struct wifi_credentials_personal));
	//LOG_ERR(&amp;quot;buttons library&amp;quot;);
	// if (err) {
	// 	LOG_ERR(&amp;quot;Connecting to Wi-Fi failed, err: %d&amp;quot;, err);
	// 	//return ENOEXEC;
	// }

	//k_sem_take(&amp;amp;run_app, K_FOREVER);

	if (dk_buttons_init(button_handler) != 0) {
		LOG_ERR(&amp;quot;Failed to initialize the buttons library &amp;quot;);
	}
	while(1)
	{
		//LOG_ERR(&amp;quot;Failed to initialize the buttons library &amp;quot;);
		k_sleep(K_SECONDS(1));
		if(!connected)
		{
			int err = net_mgmt(NET_REQUEST_WIFI_CONNECT_STORED, iface, &amp;amp;wifi_cred, sizeof(struct wifi_credentials_personal));
		}
		if(connected &amp;amp;&amp;amp; firsttime == 1)
		{
			k_sleep(K_SECONDS(1));
			if (server_resolve() != 0) {
				LOG_ERR(&amp;quot;Failed to resolve server name&amp;quot;);
				return 0;
			}
			
			if (setup_credentials() != 0) {
		        LOG_ERR(&amp;quot;Setup credentials failed&amp;quot;);
	        }

			if (server_connect() != 0) {
				LOG_ERR(&amp;quot;Failed to initialize client&amp;quot;);
				return 0;
			}	

			/* STEP 11 - Retrieve the client ID upon connection */
			if (client_get_new_id() &amp;lt; 0) {
				LOG_ERR(&amp;quot;Failed to get client ID&amp;quot;);
				return 0;
			}
			firsttime = 0;
			LOG_ERR(&amp;quot;buttons library&amp;quot;);
		}
		//return 0;
	}

	

		
}&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;# Wi-Fi
CONFIG_WIFI=y
CONFIG_WIFI_NRF700X=y
CONFIG_WPA_SUPP=y
# CONFIG_WPA_SUPP_CRYPTO_PSA=y

# Wi-Fi Credentials
CONFIG_WIFI_CREDENTIALS=y
CONFIG_WIFI_CREDENTIALS_STATIC=n

# Networking Management API
CONFIG_NET_MGMT=y
CONFIG_NET_MGMT_EVENT=y
CONFIG_NET_MGMT_EVENT_INFO=y
CONFIG_NET_MGMT_EVENT_STACK_SIZE=4096
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_WIFI_MGMT_EXT=y

# Support for shell commands
# CONFIG_SHELL=y
# CONFIG_WIFI_CREDENTIALS_SHELL=y
# CONFIG_SHELL_STACK_SIZE=4400

# Logging
CONFIG_LOG=y

# DK library
CONFIG_DK_LIBRARY=y

# System settings
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_NANO=n

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_POSIX_MAX_FDS=16

CONFIG_NET_L2_ETHERNET=y
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=y
CONFIG_NET_TCP=y
CONFIG_NET_DHCPV4=y
CONFIG_DNS_RESOLVER=y

# TLS
# STEP 1.1 - Enable the TLS library and security relevant configurations
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
CONFIG_TLS_CREDENTIALS=y
CONFIG_MBEDTLS_RSA_C=y
CONFIG_MBEDTLS_DHM_C=y 

# STEP 1.2 - Enable support for server name indication (SNI)
CONFIG_MBEDTLS_SSL_SERVER_NAME_INDICATION=y

# Memory
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=153600

CONFIG_NET_TCP_WORKQ_STACK_SIZE=2048
CONFIG_NET_TX_STACK_SIZE=4096
CONFIG_NET_RX_STACK_SIZE=4096
CONFIG_NET_BUF_RX_COUNT=16
CONFIG_NET_BUF_TX_COUNT=16
CONFIG_NET_BUF_DATA_SIZE=256
CONFIG_NET_TC_TX_COUNT=0

# HTTP
CONFIG_HTTP_CLIENT=y
# 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

# CONFIG_NET_L2_WIFI_SHELL=y

# General
CONFIG_POSIX_CLOCK=y

# Optimize Wi-Fi stack to save some memory

CONFIG_NRF700X_MAX_TX_AGGREGATION=4

# Wi-Fi


CONFIG_WIFI_NRF700X_LOG_LEVEL_ERR=y


# WPA supplicant

CONFIG_WPA_SUPP_LOG_LEVEL_ERR=y

# Zephyr NET Connection Manager connectivity layer
CONFIG_L2_WIFI_CONNECTIVITY=y
# CONFIG_L2_WIFI_CONNECTIVITY_AUTO_DOWN=n
# CONFIG_L2_WIFI_CONNECTIVITY_AUTO_CONNECT=n

# DNS

# CONFIG_NET_SOCKETS_DNS_TIMEOUT=30000

# NET sockets

CONFIG_NET_UDP=y
# CONFIG_NET_SOCKETS_OFFLOAD=n

# CONFIG_NET_CONTEXT_SNDTIMEO=y

# TLS networking
CONFIG_NET_SOCKETS_ENABLE_DTLS=n
CONFIG_NET_SOCKETS_TLS_MAX_CONTEXTS=2


# TLS credentials

# Here is the overlay I used for nrf7002dk_nrf5340_cpuapp

# CONFIG_TLS_CREDENTIALS_BACKEND_VOLATILE=y

# mbedTLS
CONFIG_NRF_SECURITY=y
CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=81920
CONFIG_PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY=y
CONFIG_PSA_WANT_RSA_KEY_SIZE_2048=y

CONFIG_MBEDTLS_TLS_LIBRARY=y

CONFIG_PM_SINGLE_IMAGE=y&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DevAcademy Lesson 5, HTTP over Wi-Fi (Exercise 2), does not build with nrf7002dk_nrf5340_cpuapp when CONFIG_WPA_SUPP_CRYPTO_PSA=y is enabled</title><link>https://devzone.nordicsemi.com/thread/509904?ContentTypeID=1</link><pubDate>Mon, 11 Nov 2024 13:48:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c4a59d4-fcd3-4942-9a59-4a110dda8607</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
[quote user="ChiragBhavsar"]I encountered the following errors when using HTTP with TLS &amp;amp; build this with nrf7002dk_nrf5340_cpuapp.[/quote]
&lt;p&gt;Please try to build for&amp;nbsp;&lt;span&gt;nrf7002dk_nrf5340_cpuapp_ns with&amp;nbsp;&lt;a title="nrf7002dk_nrf5340_cpuapp_ns.conf" href="https://github.com/NordicDeveloperAcademy/wifi-fund/blob/main/lesson5/wififund_less5_exer2_solution/boards/nrf7002dk_nrf5340_cpuapp_ns.conf"&gt;nrf7002dk_nrf5340_cpuapp_ns.conf&lt;/a&gt;.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;-Amanda H.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DevAcademy Lesson 5, HTTP over Wi-Fi (Exercise 2), does not build with nrf7002dk_nrf5340_cpuapp when CONFIG_WPA_SUPP_CRYPTO_PSA=y is enabled</title><link>https://devzone.nordicsemi.com/thread/509675?ContentTypeID=1</link><pubDate>Fri, 08 Nov 2024 12:38:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4de71346-aa98-4cab-956e-187c29ce86a0</guid><dc:creator>ChiragBhavsar</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I encountered the following errors when using HTTP with TLS &amp;amp; build this with nrf7002dk_nrf5340_cpuapp. Could you help me resolve them?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Failed to set TLS security TAG list, err: 109&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Failed to initialize client&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Below is my code. Please review it and provide your feedback.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2023 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

#include &amp;lt;errno.h&amp;gt;
#include &amp;lt;stddef.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/types.h&amp;gt;
#include &amp;lt;zephyr/logging/log.h&amp;gt;

#include &amp;lt;dk_buttons_and_leds.h&amp;gt;

/* STEP 3 - Include the necessary header files */
#include &amp;lt;zephyr/net/wifi.h&amp;gt;
#include &amp;lt;zephyr/net/wifi_mgmt.h&amp;gt;
#include &amp;lt;zephyr/net/net_mgmt.h&amp;gt;
#include &amp;lt;net/wifi_mgmt_ext.h&amp;gt;

/* STEP 12.4 - Include the header file for the Wi-FI credentials library */
#include &amp;lt;net/wifi_credentials.h&amp;gt;
#include &amp;lt;zephyr/net/socket.h&amp;gt;

#include &amp;lt;zephyr/net/net_if.h&amp;gt;
#include &amp;lt;zephyr/sys/printk.h&amp;gt;

// #define SERVER_IP_ADDR &amp;quot;192.168.1.10&amp;quot; // Replace with your server&amp;#39;s IP
// #define SERVER_PORT 8080

// LOG_MODULE_REGISTER(Lesson2_Exercise2, LOG_LEVEL_INF);

/* STEP 4 - Define a macro for the relevant network events */
// #define EVENT_MASK (NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED)

/* STEP 1.2 - Include the header file of the HTTP client library */
#include &amp;lt;zephyr/net/http/client.h&amp;gt;
/* STEP 1.4 - Include the header file for the TLS credentials library */
#include &amp;lt;zephyr/net/tls_credentials.h&amp;gt;

/* STEP 2.3 - Include the certificate */
static const char ca_certificate[] = {
#include &amp;quot;certificate.h&amp;quot;
};

LOG_MODULE_REGISTER(Lesson5_Exercise1);

#define EVENT_MASK (NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED)

/* STEP 5 - Declare the callback structure for Wi-Fi events */
static struct net_mgmt_event_callback mgmt_cb;

/* STEP 6.1 - Define the boolean connected and the semaphore run_app */
static bool connected = 0;
static bool firsttime = 1;
static K_SEM_DEFINE(run_app, 0, 1);

/* STEP 4.1 - Define a macro for the credential security tag */
#define HTTP_TLS_SEC_TAG 1

/* STEP 2 - Define the macros for the HTTP server hostname and port */
#define HTTP_HOSTNAME &amp;quot;echo.thingy.rocks&amp;quot; //staging.api.nexkey.com
#define HTTP_PORT     443

/* STEP 3 - Declare the necessary buffers for receiving messages */
#define RECV_BUF_SIZE  2048
#define CLIENT_ID_SIZE 36

static char recv_buf[RECV_BUF_SIZE];
static char client_id_buf[CLIENT_ID_SIZE + 2];

/* STEP 4 - Define the variable for the counter as 0 */
static int counter = 0;

static int sock;
static struct sockaddr_storage server;

//static struct net_mgmt_event_callback mgmt_cb;
//static bool connected;
//static K_SEM_DEFINE(run_app, 0, 1);



static int server_resolve(void)
{
	int err;
	struct addrinfo *result;
	struct addrinfo hints = {.ai_family = AF_INET, .ai_socktype = SOCK_STREAM};

	err = getaddrinfo(HTTP_HOSTNAME, STRINGIFY(HTTP_PORT), &amp;amp;hints, &amp;amp;result);
	if (err != 0) {
		LOG_ERR(&amp;quot;getaddrinfo failed, err: %d, %s&amp;quot;, err, gai_strerror(err));
		return -EIO;
	}

	if (result == NULL) {
		LOG_ERR(&amp;quot;Error, address not found&amp;quot;);
		return -ENOENT;
	}

	struct sockaddr_in *server4 = ((struct sockaddr_in *)&amp;amp;server);
	server4-&amp;gt;sin_addr.s_addr = ((struct sockaddr_in *)result-&amp;gt;ai_addr)-&amp;gt;sin_addr.s_addr;
	server4-&amp;gt;sin_family = AF_INET;
	server4-&amp;gt;sin_port = ((struct sockaddr_in *)result-&amp;gt;ai_addr)-&amp;gt;sin_port;

	char ipv4_addr[NET_IPV4_ADDR_LEN];
	inet_ntop(AF_INET, &amp;amp;server4-&amp;gt;sin_addr.s_addr, ipv4_addr, sizeof(ipv4_addr));
	LOG_INF(&amp;quot;IPv4 address of HTTP server found %s&amp;quot;, ipv4_addr);

	freeaddrinfo(result);

	return 0;
}

static int setup_credentials(void)
{
	
	/* STEP 4.2 - Add the credential to the device */
	int err = tls_credential_add(HTTP_TLS_SEC_TAG, TLS_CREDENTIAL_CA_CERTIFICATE, ca_certificate,
				 sizeof(ca_certificate));
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to add TLS credentials, err: %d&amp;quot;, err);
		return err;
	}

	return 0;
}

static int server_connect(void)
{
	int err;
	sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (sock &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to create socket, err: %d, %s&amp;quot;, errno, strerror(errno));
		return -errno;
	}

	/* STEP 5.1 - Configure the socket with the security tag for the certificate */
	sec_tag_t sec_tag_opt[] = {
		HTTP_TLS_SEC_TAG,
	};
	err = setsockopt(sock, SOL_TLS, TLS_SEC_TAG_LIST, sec_tag_opt, sizeof(sec_tag_opt));
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to set TLS security TAG list, err: %d&amp;quot;, errno);
		(void)close(sock);
		return -errno;
	}
	/* STEP 5.2 - Configure the socket with the hostname of the HTTP server */
	err = setsockopt(sock, SOL_TLS, TLS_HOSTNAME, HTTP_HOSTNAME, sizeof(HTTP_HOSTNAME));
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to set TLS_HOSTNAME option. Err: %d&amp;quot;, errno);
		(void)close(sock);
		return -errno;
	}

	err = connect(sock, (struct sockaddr *)&amp;amp;server, sizeof(struct sockaddr_in));
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;Connecting to server failed, err: %d, %s&amp;quot;, errno, strerror(errno));
		return -errno;
	}

	LOG_INF(&amp;quot;Connected to server&amp;quot;);
	return 0;
}

static void response_cb(struct http_response *rsp, enum http_final_call final_data, void *user_data)
{
	/* STEP 9 - Define the callback function to print the body */
	LOG_INF(&amp;quot;Response status: %s&amp;quot;, rsp-&amp;gt;http_status);

	if (rsp-&amp;gt;body_frag_len &amp;gt; 0) {
		char body_buf[rsp-&amp;gt;body_frag_len];
		strncpy(body_buf, rsp-&amp;gt;body_frag_start, rsp-&amp;gt;body_frag_len);
		body_buf[rsp-&amp;gt;body_frag_len] = &amp;#39;\0&amp;#39;;
		LOG_INF(&amp;quot;Received: %s&amp;quot;, body_buf);
	}

	LOG_INF(&amp;quot;Closing socket: %d&amp;quot;, sock);
	close(sock);
}

static void client_id_cb(struct http_response *rsp, enum http_final_call final_data,
			 void *user_data)
{
	/* STEP 6.1 - Log the HTTP response status */
	LOG_INF(&amp;quot;Response status: %s&amp;quot;, rsp-&amp;gt;http_status);

	/* STEP 6.2 - Retrieve and format the client ID */
	char client_id_buf_tmp[CLIENT_ID_SIZE + 1];
	strncpy(client_id_buf_tmp, rsp-&amp;gt;body_frag_start, CLIENT_ID_SIZE);
	client_id_buf_tmp[CLIENT_ID_SIZE] = &amp;#39;\0&amp;#39;;
	client_id_buf[0] = &amp;#39;/&amp;#39;;
	strcat(client_id_buf, client_id_buf_tmp);

	LOG_INF(&amp;quot;Successfully acquired client ID: %s&amp;quot;, client_id_buf);

	/* STEP 6.3 - Close the socket */
	LOG_INF(&amp;quot;Closing socket: %d&amp;quot;, sock);
	close(sock);
}

static int client_http_put(void)
{
	/* STEP 7 - Define the function to send a PUT request to the HTTP server */
	int err = 0;
	int bytes_written;
	const char *headers[] = {&amp;quot;Connection: close\r\n&amp;quot;, NULL};

	struct http_request req;
	memset(&amp;amp;req, 0, sizeof(req));

	char buffer[12] = {0};
	bytes_written = snprintf(buffer, 12, &amp;quot;%d&amp;quot;, counter);
	if (bytes_written &amp;lt; 0) {
		LOG_INF(&amp;quot;Unable to write to buffer, err: %d&amp;quot;, bytes_written);
		return bytes_written;
	}

	req.header_fields = headers;
	req.method = HTTP_PUT;
	req.url = client_id_buf;
	req.host = HTTP_HOSTNAME;
	req.protocol = &amp;quot;HTTP/1.1&amp;quot;;
	req.payload = buffer;
	req.payload_len = bytes_written;
	req.response = response_cb;
	req.recv_buf = recv_buf;
	req.recv_buf_len = sizeof(recv_buf);

	LOG_INF(&amp;quot;HTTP PUT request: %s&amp;quot;, buffer);
	err = http_client_req(sock, &amp;amp;req, 5000, NULL);
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to send HTTP PUT request %s, err: %d&amp;quot;, buffer, err);
	}

	return err;
}

static int client_http_get(void)
{
	/* STEP 8 - Define the function to send a GET request to the HTTP server */
	int err = 0;
	const char *headers[] = {&amp;quot;Connection: close\r\n&amp;quot;, NULL};
	
	struct http_request req;
	memset(&amp;amp;req, 0, sizeof(req));

	req.header_fields = headers;
	req.method = HTTP_GET;
	req.url = client_id_buf;
	req.host = HTTP_HOSTNAME;
	req.protocol = &amp;quot;HTTP/1.1&amp;quot;;
	req.response = response_cb;
	req.recv_buf = recv_buf;
	req.recv_buf_len = sizeof(recv_buf);

	LOG_INF(&amp;quot;HTTP GET request&amp;quot;);
	err = http_client_req(sock, &amp;amp;req, 5000, NULL);
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to send HTTP GET request, err: %d&amp;quot;, err);
	}

	return err;
}

static int client_get_new_id(void)
{
	int err = 0;

	/* STEP 5.1 - Define the structure http_request and fill the block of memory */
	struct http_request req;
	memset(&amp;amp;req, 0, sizeof(req));

	/* STEP 5.2 - Populate the http_request structure */
	const char *headers[] = {&amp;quot;Connection: close\r\n&amp;quot;, NULL};
	req.header_fields = headers;
	req.method = HTTP_POST;
	req.url = &amp;quot;/new&amp;quot;;
	req.host = HTTP_HOSTNAME;
	req.protocol = &amp;quot;HTTP/1.1&amp;quot;;
	req.response = client_id_cb;
	req.recv_buf = recv_buf;
	req.recv_buf_len = sizeof(recv_buf);

	/* STEP 5.3 - Send the request to the HTTP server */
	LOG_INF(&amp;quot;HTTP POST request&amp;quot;);
	err = http_client_req(sock, &amp;amp;req, 5000, NULL);
	if (err &amp;lt; 0) {
		LOG_ERR(&amp;quot;Failed to send HTTP POST request, err: %d&amp;quot;, err);
	}
	return err;
}

/* STEP 6.2 - Define the callback function for network events */
static void net_mgmt_event_handler(struct net_mgmt_event_callback *cb,
			  uint32_t mgmt_event, struct net_if *iface)
{
	if ((mgmt_event &amp;amp; EVENT_MASK) != mgmt_event) {
		return;
	}
	if (mgmt_event == NET_EVENT_L4_CONNECTED) {
		LOG_INF(&amp;quot;Network connected&amp;quot;);
		connected = true;
		dk_set_led_on(DK_LED1);
		//k_sem_give(&amp;amp;run_app);
		return;
	}
	if (mgmt_event == NET_EVENT_L4_DISCONNECTED) {
		if (connected == false) {
			LOG_INF(&amp;quot;Waiting for network to be connected&amp;quot;);
		} else {
			dk_set_led_off(DK_LED1);
			LOG_INF(&amp;quot;Network disconnected&amp;quot;);
			connected = false;
		}
		//k_sem_reset(&amp;amp;run_app);
		return;
	}
}

/* STEP 7 - Define the function to populate the Wi-Fi credential parameters */
//static int wifi_args_to_params(struct wifi_connect_req_params *params)
//{

	/* STEP 7.1 Populate the SSID and password */
	//params-&amp;gt;ssid = CONFIG_WIFI_CREDENTIALS_STATIC_SSID;
	//params-&amp;gt;ssid_length = strlen(params-&amp;gt;ssid);

	//params-&amp;gt;psk = CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD;
	//params-&amp;gt;psk_length = strlen(params-&amp;gt;psk);

	/* STEP 7.2 - Populate the rest of the relevant members */
	//params-&amp;gt;channel = WIFI_CHANNEL_ANY;
	//params-&amp;gt;security = WIFI_SECURITY_TYPE_PSK;
	//params-&amp;gt;mfp = WIFI_MFP_OPTIONAL;
	//params-&amp;gt;timeout = SYS_FOREVER_MS;
	//params-&amp;gt;band = WIFI_FREQ_BAND_UNKNOWN;
	//#if NCS_VERSION_NUMBER &amp;gt; 0x20600
	//memset(params-&amp;gt;bssid, 0, sizeof(params-&amp;gt;bssid));
	//#endif
	//return 0;
//}

static struct wifi_credentials_personal wifi_cred;
void set_wifi_credentials_struct() 
{

	char *wifi_ssid = &amp;quot;realme&amp;quot;;
	char *wifi_password = &amp;quot;Chirag@1527&amp;quot;;

	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(&amp;amp;wifi_cred);

	if (ret != 0) {
		LOG_ERR(&amp;quot;Failed to set credentials, err: %d&amp;quot;, ret);
	}
}
static void button_handler(uint32_t button_state, uint32_t has_changed)
{
	/* STEP 10 - Define the button handler to send requests upon button triggers */
	if (has_changed &amp;amp; DK_BTN1_MSK &amp;amp;&amp;amp; button_state &amp;amp; DK_BTN1_MSK) {
		if (server_connect() &amp;gt;= 0) {
			client_http_put();
			counter++;
		}
	} else if (has_changed &amp;amp; DK_BTN2_MSK &amp;amp;&amp;amp; button_state &amp;amp; DK_BTN2_MSK) {
		if (server_connect() &amp;gt;= 0) {
			client_http_get();
		}
	}
}

int main(void)
{
	/* STEP 8.1 - Declare the variable for the network configuration parameters */
	//struct wifi_connect_req_params cnx_params;



	/* STEP 8.2 - Get the network interface */
	struct net_if *iface = net_if_get_first_wifi();
	if (iface == NULL) {
		LOG_ERR(&amp;quot;Returned network interface is NULL&amp;quot;);
		return -1;
	}

	if (dk_leds_init() != 0) {
		LOG_ERR(&amp;quot;Failed to initialize the LED library&amp;quot;);
	}

	/* Sleep to allow initialization of Wi-Fi driver */
	k_sleep(K_SECONDS(1));

	/* STEP 9 - Initialize and add the callback function for network events */
	net_mgmt_init_event_callback(&amp;amp;mgmt_cb, net_mgmt_event_handler, EVENT_MASK);
	net_mgmt_add_event_callback(&amp;amp;mgmt_cb);

	/* STEP 10 - Populate cnx_params with the network configuration */
	//wifi_args_to_params(&amp;amp;cnx_params);

    set_wifi_credentials_struct();
	/* STEP 11 - Call net_mgmt() to request the Wi-Fi connection */
	LOG_INF(&amp;quot;Connecting to Wi-Fi&amp;quot;);
	//printf(&amp;quot;try to connect with wifi&amp;quot;);
	//LOG_ERR(&amp;quot;buttons library&amp;quot;);
	//int err = net_mgmt(NET_REQUEST_WIFI_CONNECT_STORED, iface, &amp;amp;wifi_cred, sizeof(struct wifi_credentials_personal));
	//LOG_ERR(&amp;quot;buttons library&amp;quot;);
	// if (err) {
	// 	LOG_ERR(&amp;quot;Connecting to Wi-Fi failed, err: %d&amp;quot;, err);
	// 	//return ENOEXEC;
	// }

	//k_sem_take(&amp;amp;run_app, K_FOREVER);

	if (dk_buttons_init(button_handler) != 0) {
		LOG_ERR(&amp;quot;Failed to initialize the buttons library &amp;quot;);
	}
	while(1)
	{
		//LOG_ERR(&amp;quot;Failed to initialize the buttons library &amp;quot;);
		k_sleep(K_SECONDS(1));
		if(!connected)
		{
			int err = net_mgmt(NET_REQUEST_WIFI_CONNECT_STORED, iface, &amp;amp;wifi_cred, sizeof(struct wifi_credentials_personal));
		}
		if(connected &amp;amp;&amp;amp; firsttime == 1)
		{
			if (server_resolve() != 0) {
				LOG_ERR(&amp;quot;Failed to resolve server name&amp;quot;);
				return 0;
			}
			
			if (setup_credentials() != 0) {
		        LOG_ERR(&amp;quot;Setup credentials failed&amp;quot;);
	        }

			if (server_connect() != 0) {
				LOG_ERR(&amp;quot;Failed to initialize client&amp;quot;);
				return 0;
			}	

			/* STEP 11 - Retrieve the client ID upon connection */
			if (client_get_new_id() &amp;lt; 0) {
				LOG_ERR(&amp;quot;Failed to get client ID&amp;quot;);
				return 0;
			}
			firsttime = 0;
			LOG_ERR(&amp;quot;buttons library&amp;quot;);
		}
		//return 0;
	}

	

		
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#
# Copyright (c) 2022 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Wi-Fi
# STEP 1.1 - Enable the Wi-Fi relevant configurations
CONFIG_WIFI=y
CONFIG_WIFI_NRF700X=y
CONFIG_WPA_SUPP=y


# STEP 2 - Configure the Wi-Fi credentials
CONFIG_WIFI_CREDENTIALS=y
# STEP 12.1 - Diasble static Wi-Fi network configuration
CONFIG_WIFI_CREDENTIALS_STATIC=n
#CONFIG_WIFI_CREDENTIALS_STATIC_SSID=&amp;quot;&amp;lt;your_network_SSID&amp;gt;&amp;quot;
#CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD=&amp;quot;&amp;lt;your_network_password&amp;gt;&amp;quot;

# Networking Management API
# STEP 1.2 Enable the Network Management relevant configurations
CONFIG_NET_MGMT=y
CONFIG_NET_MGMT_EVENT=y
CONFIG_NET_MGMT_EVENT_INFO=y
CONFIG_NET_MGMT_EVENT_STACK_SIZE=4096
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_WIFI_MGMT_EXT=y

# STEP 13 Enable support for shell commands
# CONFIG_SHELL=y
# CONFIG_WIFI_CREDENTIALS_SHELL=y
# CONFIG_SHELL_STACK_SIZE=4400

# Logging
CONFIG_LOG=y

# DK library
CONFIG_DK_LIBRARY=y

# System settings
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_NANO=n

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_POSIX_MAX_FDS=16
CONFIG_NET_L2_ETHERNET=y
CONFIG_NET_IPV6=y
CONFIG_NET_IPV4=y
CONFIG_NET_DHCPV4=y
CONFIG_NET_TCP=y
CONFIG_DNS_RESOLVER=y

# Memory
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_HEAP_MEM_POOL_SIZE=153600

CONFIG_STA_KEY_MGMT_WPA2=y

CONFIG_NET_TCP_WORKQ_STACK_SIZE=2048
CONFIG_NET_TX_STACK_SIZE=4096
CONFIG_NET_RX_STACK_SIZE=4096
CONFIG_NET_BUF_RX_COUNT=16
CONFIG_NET_BUF_TX_COUNT=16
CONFIG_NET_BUF_DATA_SIZE=256
CONFIG_NET_TC_TX_COUNT=0

# HTTP
# STEP 1 -  Enable the HTTP client library
CONFIG_HTTP_CLIENT=y

# 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

# CONFIG_RTT_CONSOLE=y
# CONFIG_STDOUT_CONSOLE=y

CONFIG_MPU_ALLOW_FLASH_WRITE=y

CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS=y
CONFIG_FCB=y

CONFIG_SETTINGS_FCB=y

# TLS
# STEP 1.1 - Enable the TLS library and security relevant configurations
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
CONFIG_TLS_CREDENTIALS=y
CONFIG_MBEDTLS_RSA_C=y
CONFIG_MBEDTLS_DHM_C=y 

# STEP 1.2 - Enable support for server name indication (SNI)
CONFIG_MBEDTLS_SSL_SERVER_NAME_INDICATION=y
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DevAcademy Lesson 5, HTTP over Wi-Fi (Exercise 2), does not build with nrf7002dk_nrf5340_cpuapp when CONFIG_WPA_SUPP_CRYPTO_PSA=y is enabled</title><link>https://devzone.nordicsemi.com/thread/509277?ContentTypeID=1</link><pubDate>Wed, 06 Nov 2024 14:43:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4a77c9de-d3b7-481f-9cd9-81abf442599f</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;That sample/exercise is made for the non-secure board, ie. nrf7002dk_nrf5340_cpuapp_ns, and lacks handling of the connection if used without the TF-M part.&lt;/p&gt;
&lt;p&gt;I would recommend that you look at samples/net/https_client in v2.5.x to show how to connect to a website using the nrf7002dk_nrf5340_cpuapp board.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>