NRF7002 BSD Socket examples
Nordic Semiconductors, a key player in the development of Bluetooth Low Energy devices, has introduced their latest NRF7002, a WiFi companion chip. In this article we introduce our github public repository with source code examples for its development kit. So you can have BSD Socket examples for your NRF7002-DK as an starting point.
The source code examples can be found in our public github repository, on this link: https://github.com/abluethinginthecloud/nrf7002-bsd-sockets-example
This code example implements 4 threads, covering the BSD socket possibilities for WiFi connections. At the moment of writting this article, 21st April 2023, NRF7002 supports only the WiFi Station mode. So, in these examples, we need to establish a connection with a router to enable internet connectivity.
The status of the connection will be checked continuously, and, once the board is connected to the Wifi network, one of the LEDs of the board will blink. At this moment, the board create four kinds of connections:
TCP Client connection. Sends a message to a defined server by TCP.
TCP Server connection. Receives TCP messages from different clients and echoes them.
UDP Client communication. Sends a message to a defined server by UDP.
UDP Server communication. Receives UDP messages from different clients and echoes them.
Configuring the examples
To test the examples, the first thing to do is configuring the prj.conf file. This file contains a list of settings the board will implement, and some of them need to be changed depending on the WiFi network configuration, or the desired IPs of the board and the servers.
# WiFi Stationing modifiable configurations
# Server’s IPv4 Address CONFIG_NET_CONFIG_PEER_IPV4_ADDR=”x.x.x.x”
# Board’s IPv4 Address CONFIG_NET_DHCPV4=y
# CONFIG_NET_CONFIG_MY_IPV4_GW=”x.x.x.x” #====================================================================#
Following up a brief explanation
Security level configurations
Select the security level of the router (on the example above, WPA2) and comment the other options.
- CONFIG_STA_SAMPLE_SSID. Introduce the name of the WiFi network.
- CONFIG_STA_SAMPLE_PASSWORD. Introduces the password of the WiFi network.
Server IPv4 configurations
- CONFIG_NET_CONFIG_PEER_IPV4_ADDR. IPv4 Address of the servers the clients will connect to.
Board IPv4 configurations
- CONFIG_NET_DHCPV4. If ‘y’, enables the DHCP assignment. If this option is enabled, the IPv4 address assigned to the board will be shown while running it.
- Static IPv4 configuration. To assign a static IPv4 to the board, disable the CONFIG_NET_DHCPV4 option and uncomment the three following configurations, introducing the desired IP address, the netmask, and the gateway.
Then, build the example with the nrf7002dk configuration, and flash it. To test the working of the TCP/UDP connections, we created four sessions on Docklight Scripting, each one communicating with one of the sockets. Please feel free to contact us in case you need more information.