Header file for WiFi module. This file contains the function prototypes and data structures for the WiFi module. The module provides a TCP server that can be initialized and started using the functions wifi_tcp_server_begin_init() and wifi_tcp_server_begin(). The TCP server uses lwIP library for network communication and has a buffer size of 2048 bytes.
More...
#include <stdio.h>
#include "lwip/pbuf.h"
#include "lwip/tcp.h"
Go to the source code of this file.
|
#define | DEBUG_PRINT(...) printf(__VA_ARGS__) |
| Macro for printing debug messages. More...
|
|
#define | WIFI_BUFFER_SIZE 2048 |
| Buffer size for messages sent out via wifi.
|
|
#define | WIFI_MAX_MESSAGE_LENGTH 1024 |
| Maximum length of a received message.
|
|
#define | WIFI_POLL_TIME_S 20 |
| Poll time in seconds.
|
|
#define | WIFI_TCP_PORT 4242 |
| Port to listen on.
|
|
|
void | wifi_run_tcp_server_test (void) |
| Runs a TCP server and opens it. Then, it enters a loop to check for Wi-Fi driver or lwIP work that needs to be done. If using pico_cyw43_arch_poll, it polls periodically from the main loop to check for work. Otherwise, it sleeps for 1000ms. More...
|
|
void | wifi_tcp_server_begin (void) |
| Begins a TCP server by connecting to Wi-Fi with the given SSID and password.
|
|
void | wifi_tcp_server_begin_init (void) |
| Initializes the TCP server by initializing standard input/output, initializing the CYW43 architecture, and enabling station mode.
|
|
err_t | wifi_tcp_server_recv (void *p_arg, __unused struct tcp_pcb *p_tpcb, struct pbuf *p_buf, __unused err_t err) |
| This function is called by lwIP when data is received from a TCP client. It receives the data and checks if a complete message has been received (e.g., terminated by a newline character). If a complete message has been received, it null-terminates the received data, prints it to the console, and resets the receive buffer. More...
|
|
err_t | wifi_tcp_server_send_data (void *p_arg, struct tcp_pcb *p_tpcb) |
| This function is a callback from lwIP, so cyw43_arch_lwip_begin is not required. However, you can use this method to cause an assertion in debug mode if this method is called when cyw43_arch_lwip_begin IS needed. More...
|
|
Header file for WiFi module. This file contains the function prototypes and data structures for the WiFi module. The module provides a TCP server that can be initialized and started using the functions wifi_tcp_server_begin_init() and wifi_tcp_server_begin(). The TCP server uses lwIP library for network communication and has a buffer size of 2048 bytes.
- Author
- Jurgen Tan
- Version
- 0.1
- Date
- 2023-11-28
- Copyright
- Copyright (c) 2023
◆ DEBUG_PRINT
#define DEBUG_PRINT |
( |
|
... | ) |
printf(__VA_ARGS__) |
Macro for printing debug messages.
- Parameters
-
... | Variable number of arguments to be printed. |
◆ wifi_tcp_server_t
Struct representing a TCP server connection.
- Note
- The struct contains information about a TCP server connection, including the server and client PCBs, flags indicating whether the connection is complete, buffers for sent and received data, and various counters for tracking the state of the connection.
◆ wifi_run_tcp_server_test()
void wifi_run_tcp_server_test |
( |
void |
| ) |
|
Runs a TCP server and opens it. Then, it enters a loop to check for Wi-Fi driver or lwIP work that needs to be done. If using pico_cyw43_arch_poll, it polls periodically from the main loop to check for work. Otherwise, it sleeps for 1000ms.
- Note
- The code contains a note that assumes certain conditions have been met before the function can be executed. These conditions include the inclusion of necessary libraries and header files, definition of macros, structs and functions, allocation of memory, setup of hardware and network configurations, granting of permissions, opening of necessary ports, implementation of error handling, and cleanup.
References wifi_tcp_server::is_complete.
◆ wifi_tcp_server_recv()
err_t wifi_tcp_server_recv |
( |
void * |
p_arg, |
|
|
__unused struct tcp_pcb * |
p_tpcb, |
|
|
struct pbuf * |
p_buf, |
|
|
__unused err_t |
err |
|
) |
| |
This function is called by lwIP when data is received from a TCP client. It receives the data and checks if a complete message has been received (e.g., terminated by a newline character). If a complete message has been received, it null-terminates the received data, prints it to the console, and resets the receive buffer.
- Parameters
-
[in] | p_arg | Pointer to the TCP server state structure. |
[in] | p_tpcb | Pointer to the TCP protocol control block (Unused). |
[in] | p_buf | Pointer to the received data buffer. |
[in] | err | Error code (Unused). |
- Returns
- err_t Error code.
References wifi_tcp_server::buffer_recv, wifi_tcp_server::p_client_pcb, wifi_tcp_server::recv_len, WIFI_BUFFER_SIZE, and wifi_tcp_server_send_data().
◆ wifi_tcp_server_send_data()
err_t wifi_tcp_server_send_data |
( |
void * |
p_arg, |
|
|
struct tcp_pcb * |
p_tpcb |
|
) |
| |
This function is a callback from lwIP, so cyw43_arch_lwip_begin is not required. However, you can use this method to cause an assertion in debug mode if this method is called when cyw43_arch_lwip_begin IS needed.
- Parameters
-
[in] | p_arg | A void pointer to the wifi_tcp_server_t struct. |
[in] | p_tpcb | A pointer to the tcp_pcb struct. |
- Returns
- err_t value indicating success or failure.
References wifi_tcp_server::buffer_sent, DEBUG_PRINT, wifi_tcp_server::sent_len, and WIFI_BUFFER_SIZE.