29 #define TCP_SERVER_PORT 7
32 #define TCP_SERVER_MAX_CLIENTS 1
38 #define NETWORK_SSID "\"<YOUR NETWORK NAME HERE>\""
42 #define NETWORK_PASSWORD "\"<YOUR NETWORK PASSWORD HERE>\""
54 #include "target_config.h"
56 #include "Wiconnect.h"
70 static uint8_t clientRxBuffer[256], clientTxBuffer[256];
73 static Serial consoleSerial(STDIO_UART_TX, STDIO_UART_RX);
85 SerialConfig serialConfig(WICONNECT_RX_PIN, WICONNECT_TX_PIN, 256, NULL);
89 Wiconnect wiconnectIfc(serialConfig, 256, NULL, WICONNECT_RESET_PIN);
98 int main(
int argc,
char **argv)
103 WiconnectSocket clientSocket(
sizeof(clientRxBuffer), clientRxBuffer,
sizeof(clientTxBuffer), clientTxBuffer);
105 consoleSerial.baud(115200);
112 printf(
"Initializing WiConnect Library...\r\n");
117 printf(
"Failed to initialize communication with WiFi module: %s\r\n"
118 "Make sure the wires are connected correctly\r\n", Wiconnect::getWiconnectResultStr(result));
126 printf(
"Joining WiFi network: %s\r\n", NETWORK_SSID);
131 printf(
"Failed to join network: %s\r\n", Wiconnect::getWiconnectResultStr(result));
140 printf(
"Starting TCP server, listening on: %s:%d\r\n", wiconnectIfc.
getIpAddress(), TCP_SERVER_PORT);
144 printf(
"Failed to start TCP server: %s\r\n", Wiconnect::getWiconnectResultStr(result));
155 printf(
"Waiting for a client to connect...\r\n");
159 printf(
"Failed to accept client: %s\r\n", Wiconnect::getWiconnectResultStr(result));
162 printf(
"Client connected: %s:%d\r\n", clientSocket.getHost(), clientSocket.getRemotePort());
172 printf(
"Failed to read data from client: %s\r\n", Wiconnect::getWiconnectResultStr(result));
173 clientSocket.close();
177 printf(
"From client: %s\r\n", dataPtr);
186 printf(
"Failed to send data to client: %s\r\n", Wiconnect::getWiconnectResultStr(result));
187 clientSocket.close();
195 clientSocket.close();
const char * getIpAddress(char *buffer ALLOW_NULL_STRING_BUFFER)
Return the current IP address of the module if possible, else return 0.0.0.0.
WiconnectResult
API Result code.
WiconnectResult tcpListen(uint16_t listeningPort, int maxClients=0 GPIO_IRQ_ARG_NC)
Start internal TCP server and listen on specified port.
Host<->Wiconnect Module serial configuration.
WiconnectResult init(bool bringNetworkUp=false)
Initialize library and communication link with WiConnect WiFi module.
WiconnectResult tcpAccept(WiconnectSocket &socket, uint32_t timeoutMs=WICONNECT_WAIT_FOREVER)
Wait for next client to connect to TCP server.
Connection object to remote server.
The root WiConnect library class. This class inheriets all WiConnect functionality.
#define WICONNECT_FAILED(result, func)
Populates result with return value from func, returns TRUE if return value contains error...
WiconnectResult join(const char *ssid=NULL, const char *password=NULL, const Callback &completeHandler=Callback())
Join a WiFi network.