TCP Echo Server Example using WizFi310
Dependencies: NetworkSocketAPI WizFi310Interface mbed
Prerequisite
This example shows that Wizwiki-W7500 and WizFi310 operates as a TCP server. When receiving data from a TCP client, it returns same data.
To implement this function, you need a Platform board and Wi-Fi board. Below are what we used.
- WIZwiki-W7500 from WIZnet (Platform board)
- WizFi310 from WIZnet (Wi-Fi board)
WIZwiki-W7500 Pin map

- D0 is for RXD, D1 is for TXD
- D6 is for CTS, D7 is for RTS
- D9 is for RESET
WizFi310 Pin map
- J1 is for RXD, J3 is for TXD
- SW6-1 is connected to D6 for RTS, SW6-2 is connected to D7 for CTS
- SW5-3 is connected to D9 for RESET
Software
Connect to Wi-Fi
wifi.connect(AP_SSID, AP_PASSWORD, AP_SECURITY);
Get information
const char *ip = wifi.get_ip_address(); const char *mac = wifi.get_mac_address();
Receive data and return to TCP client
while (true)
{
int n = clt_sock.recv(buffer, sizeof(buffer));
if( n < 0 )
{
clt_sock.close();
srv.close();
}
if( n > 0 )
{
buffer[n] = '\0';
printf("length : %d\r\n", n);
clt_sock.send(buffer, n);
}
}
Caution
TCP client and server should be in a same network.
Revision 1:5981ba4a8323, committed 2017-04-18
- Comitter:
- stkim92
- Date:
- Tue Apr 18 00:57:35 2017 +0000
- Parent:
- 0:50932ef4b276
- Commit message:
- revise Code description (TCP client -> server)
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Apr 17 06:45:17 2017 +0000
+++ b/main.cpp Tue Apr 18 00:57:35 2017 +0000
@@ -25,9 +25,9 @@
#if defined(TARGET_NUCLEO_F411RE)
-Serial pc(USBTX, USBRX);
+//Serial pc(USBTX, USBRX);
//WizFi310Internet wifi(PA_11, PA_12, D6, D7, D3, NC, 115200);
-WizFi310Interface wifi(D8, D2, D7, D6, D9, NC, 115200);
+//WizFi310Interface wifi(D8, D2, D7, D6, D9, NC, 115200);
#endif
#if defined(TARGET_WIZwiki_W7500)
@@ -35,14 +35,14 @@
WizFi310Interface wifi(D1, D0, D7, D6, D8, NC, 115200);
#endif
-#define AP_SSID "DIR-815_Wiznet"
-#define AP_PASSWORD "12345678"
+#define AP_SSID "wizms1"
+#define AP_PASSWORD "maker0701"
#define AP_SECURITY NSAPI_SECURITY_WPA2
int main()
{
pc.baud(115200);
- printf("WizFi310 NetworkSocketAPI TCP Client Example\r\n");
+ printf("WizFi310 NetworkSocketAPI TCP Server Example\r\n");
wifi.connect(AP_SSID, AP_PASSWORD, AP_SECURITY);