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));
121 printf(
"The WiFi firmware is not supported. Run the ota example to update the firmware:\r\n");
122 printf(
"https://developer.mbed.org/teams/ACKme/code/wiconnect-ota_example");
131 printf(
"Joining WiFi network: %s\r\n", NETWORK_SSID);
136 printf(
"Failed to join network: %s\r\n", Wiconnect::getWiconnectResultStr(result));
145 printf(
"Starting TCP server, listening on: %s:%d\r\n", wiconnectIfc.
getIpAddress(), TCP_SERVER_PORT);
149 printf(
"Failed to start TCP server: %s\r\n", Wiconnect::getWiconnectResultStr(result));
160 printf(
"Waiting for a client to connect...\r\n");
164 printf(
"Failed to accept client: %s\r\n", Wiconnect::getWiconnectResultStr(result));
167 printf(
"Client connected: %s:%d\r\n", clientSocket.getHost(), clientSocket.getRemotePort());
177 printf(
"Failed to read data from client: %s\r\n", Wiconnect::getWiconnectResultStr(result));
178 clientSocket.close();
182 printf(
"From client: %s\r\n", dataPtr);
191 printf(
"Failed to send data to client: %s\r\n", Wiconnect::getWiconnectResultStr(result));
192 clientSocket.close();
200 clientSocket.close();
WiconnectResult
API Result code.
Host<->Wiconnect Module serial configuration.
WiconnectResult tcpListen(uint16_t listeningPort, int maxClients=0)
Start internal TCP server and listen on specified port.
The WiFi module's firmware is out-dated. See updateFirmware() to update the firmware.
const char * getIpAddress(char *buffer=NULL)
Return the current IP address of the module if possible, else return 0.0.0.0.
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.