diff --git a/samples/net/sockets/echo/Kconfig b/samples/net/sockets/echo/Kconfig new file mode 100644 index 00000000000000..548476af915145 --- /dev/null +++ b/samples/net/sockets/echo/Kconfig @@ -0,0 +1,16 @@ +# Copyright (c) 2024 Steve Boylan +# SPDX-License-Identifier: Apache-2.0 + +mainmenu "Sample app Configuration" + +if WIFI +config NET_SAMPLE_WIFI_SSID + string "WIFI SSID - Network name" + default "my_network" + +config NET_SAMPLE_WIFI_PSK + string "WIFI PSK - Network password key" + default "secret_passwd" +endif + +source "Kconfig.zephyr" diff --git a/samples/net/sockets/echo/README.rst b/samples/net/sockets/echo/README.rst index 1867c46657731b..60e408a9b733b7 100644 --- a/samples/net/sockets/echo/README.rst +++ b/samples/net/sockets/echo/README.rst @@ -83,3 +83,16 @@ the IP address will be printed to the console upon running this echo application. Proceed to test as above. + +Running on Raspberry Pi Pico W +============================== + +Edit boards/rpi_pico_rp2040_w.conf to add the Access Point SSID and password +at the end: + +.. code-block:: cfg + + CONFIG_NET_SAMPLE_WIFI_SSID="MyWifi" + CONFIG_NET_SAMPLE_WIFI_PSK="SuperSecret" + +Build and test as above. diff --git a/samples/net/sockets/echo/boards/rpi_pico_rp2040_w.conf b/samples/net/sockets/echo/boards/rpi_pico_rp2040_w.conf new file mode 100644 index 00000000000000..7ecf3903300bf5 --- /dev/null +++ b/samples/net/sockets/echo/boards/rpi_pico_rp2040_w.conf @@ -0,0 +1,49 @@ +CONFIG_EARLY_CONSOLE=y + +CONFIG_MAIN_STACK_SIZE=5200 +CONFIG_SHELL_STACK_SIZE=5200 +CONFIG_NET_TX_STACK_SIZE=2048 +CONFIG_NET_RX_STACK_SIZE=2048 +CONFIG_HEAP_MEM_POOL_SIZE=16384 +CONFIG_SHELL_STACK_SIZE=2560 + +CONFIG_WIFI=y +CONFIG_WIFI_LOG_LEVEL_ERR=y +CONFIG_NET_L2_WIFI_SHELL=y +# printing of scan results puts pressure on queues in new locking +# design in net_mgmt. So, use a higher timeout for a crowded +# environment. +CONFIG_NET_MGMT_EVENT_QUEUE_TIMEOUT=5000 +CONFIG_NET_MGMT_EVENT_QUEUE_SIZE=16 + +CONFIG_NETWORKING=y +CONFIG_NET_L2_ETHERNET=y + +CONFIG_NET_IPV6=n +CONFIG_NET_IPV4=y +CONFIG_NET_DHCPV4=y +CONFIG_NET_CONFIG_MY_IPV4_ADDR="" +CONFIG_NET_CONFIG_PEER_IPV4_ADDR="" + +CONFIG_NET_LOG=y +CONFIG_INIT_STACKS=y + +CONFIG_NET_SHELL=y + +CONFIG_NET_STATISTICS=y +CONFIG_NET_STATISTICS_PERIODIC_OUTPUT=n + +CONFIG_COMPILER_SAVE_TEMPS=y + +CONFIG_LOG=y +CONFIG_LOG_MODE_IMMEDIATE=y +CONFIG_LOG_BACKEND_SHOW_COLOR=n + +CONFIG_NET_SOCKETS_LOG_LEVEL_DBG=y +CONFIG_NET_CONN_LOG_LEVEL_DBG=y +CONFIG_NET_CONTEXT_LOG_LEVEL_DBG=y + +CONFIG_NET_TCP_LOG_LEVEL_DBG=y + +CONFIG_NET_SAMPLE_WIFI_SSID="" +CONFIG_NET_SAMPLE_WIFI_PSK="" diff --git a/samples/net/sockets/echo/src/socket_echo.c b/samples/net/sockets/echo/src/socket_echo.c index c8aad2bb068138..50105ba673f052 100644 --- a/samples/net/sockets/echo/src/socket_echo.c +++ b/samples/net/sockets/echo/src/socket_echo.c @@ -19,6 +19,14 @@ #include #include +#include + +#ifdef CONFIG_NET_L2_WIFI_MGMT +#include +#endif /* CONFIG_NET_L2_WIFI_MGMT */ + +#include +LOG_MODULE_REGISTER(socket_echo); #endif @@ -36,6 +44,34 @@ int main(void) }; static int counter; +#if defined(CONFIG_WIFI) + int nr_tries = 10; + struct net_if *iface = net_if_get_default(); + static struct wifi_connect_req_params cnx_params = { + .ssid = CONFIG_NET_SAMPLE_WIFI_SSID, + .ssid_length = 0, + .psk = CONFIG_NET_SAMPLE_WIFI_PSK, + .psk_length = 0, + .channel = 0, + .security = WIFI_SECURITY_TYPE_PSK, + }; + + cnx_params.ssid_length = strlen(CONFIG_NET_SAMPLE_WIFI_SSID); + cnx_params.psk_length = strlen(CONFIG_NET_SAMPLE_WIFI_PSK); + + /* Let's wait few seconds to allow wifi device be on-line */ + while (nr_tries-- > 0) { + ret = net_mgmt(NET_REQUEST_WIFI_CONNECT, iface, &cnx_params, + sizeof(struct wifi_connect_req_params)); + if (ret == 0) { + break; + } + + LOG_INF("Connect request failed %d. Waiting iface be up...", ret); + k_msleep(500); + } +#endif + serv = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); if (serv < 0) { printf("error: socket: %d\n", errno);