NightFox’s Lib
Macros | Functions | Variables
Basic WiFi helpers

Basic functions to initialize WiFi, setup a UDP socket, and send and receive data. More...

Macros

#define NF_MAX_INCOMMING_PENDING   1
 Maxmimum number of connection requests in the queue.
 
#define NF_WIFI_BUFFER_SIZE   256
 Size of communications buffer.
 

Functions

bool NF_WiFiConnectDefaultAp (void)
 Try to connect to the default access point in the DS user configuration. More...
 
void NF_WiFiDisconnectAp (void)
 Disconnect from the access point and shutdown WiFi.
 
bool NF_WIFI_CreateUdpSender (const char *address, u16 port)
 Creates a socket in client mode using UDP. More...
 
bool NF_WIFI_CreateUdpListener (u16 port)
 Creates a socket in server mode using UDP. More...
 
bool NF_WIFI_UdpSend (const char *data)
 Sends a text string over the currenty open UDP socket. More...
 
s32 NF_WIFI_UdpListen (u32 timeout)
 Listens to data from the currently open socket. More...
 

Variables

struct in_addr NF_IP
 Current IP address.
 
struct in_addr NF_GATEWAY
 Current gateway.
 
struct in_addr NF_MASK
 Current netmask.
 
struct in_addr NF_DNS1
 Current DNS 1.
 
struct in_addr NF_DNS2
 Current DNS 2.
 
s32 NF_SOCKET
 Server socket ID.
 
s32 NF_CONNECTED
 Connection result.
 
int NF_SINSIZE
 Size of struct .SIN.
 
s32 NF_BYTES_RECIEVED
 Received bytes.
 
struct sockaddr_in NF_SA_SERVER
 Server socket address.
 
struct sockaddr_in NF_SA_CLIENT
 Client socket address.
 
char NF_SEND_BUFFER [NF_WIFI_BUFFER_SIZE]
 Send buffer.
 
char NF_RECV_BUFFER [NF_WIFI_BUFFER_SIZE]
 Reception buffer.
 
bool NF_WIFI_IS_SERVER
 This is set to true if this console is in server mode, false in client mode.
 
s32 NF_MAXFD
 Maximum number of sockets to examine by select().
 
fd_set NF_READFDS
 Struct to save data used by select() sockets.
 
struct timeval NF_TIMEOUT
 Current timeout in microseconds.
 

Detailed Description

Basic functions to initialize WiFi, setup a UDP socket, and send and receive data.

Function Documentation

◆ NF_WIFI_CreateUdpListener()

bool NF_WIFI_CreateUdpListener ( u16  port)

Creates a socket in server mode using UDP.

It accepts data from any UP address.

Example:

// Create a UDP socket at port 12345
bool NF_WIFI_CreateUdpListener(u16 port)
Creates a socket in server mode using UDP.
Definition: nf_wifi.c:94
Parameters
portPort.
Returns
True if it has been created successfully

◆ NF_WIFI_CreateUdpSender()

bool NF_WIFI_CreateUdpSender ( const char *  address,
u16  port 
)

Creates a socket in client mode using UDP.

Example:

// Create a UDP socket with address 192.168.1.201 and port 12345
NF_WIFI_CreateUdpSender("192.168.1.201", 12345);
bool NF_WIFI_CreateUdpSender(const char *address, u16 port)
Creates a socket in client mode using UDP.
Definition: nf_wifi.c:62
Parameters
addressIP address.
portPort.
Returns
True if it has been created successfully

◆ NF_WIFI_UdpListen()

s32 NF_WIFI_UdpListen ( u32  timeout)

Listens to data from the currently open socket.

If any data is received it is saved in the global variable NF_RECV_BUFFER. It saves the number of received bytes in NF_BYTES_RECIEVED.

The function returns a positive value if any data is received. If there is a timeout (specified in microseconds), it returns a negative value.

Example:

// Listen for data for with a timeout of 300000 microseconds (300 ms)
s32 NF_WIFI_UdpListen(u32 timeout)
Listens to data from the currently open socket.
Definition: nf_wifi.c:153
Parameters
timeout
Returns
Positive number on success, negative number on error.

◆ NF_WIFI_UdpSend()

bool NF_WIFI_UdpSend ( const char *  data)

Sends a text string over the currenty open UDP socket.

A socket must have been opened by NF_WIFI_CreateUdpSender(), which will be used by this function.

Sent data is saved in NF_SEND_BUFFER as well so that you can run a checksum function on it, for example.

Example:

// Sends string "This is a test" over the currently open socket
NF_WIFI_UdpSend("This is a test");
bool NF_WIFI_UdpSend(const char *data)
Sends a text string over the currenty open UDP socket.
Definition: nf_wifi.c:128
Parameters
dataText string to be sent.
Returns
True on success.

◆ NF_WiFiConnectDefaultAp()

bool NF_WiFiConnectDefaultAp ( void  )

Try to connect to the default access point in the DS user configuration.

Returns
True if the connection has succeeded.