Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NetworkSocketAPI WizFi310Interface mbed
Fork of WizFi310_TCP_Echo_Server_Example by
Diff: main.cpp
- Revision:
- 0:50932ef4b276
- Child:
- 1:5981ba4a8323
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Apr 17 06:45:17 2017 +0000
@@ -0,0 +1,81 @@
+/* NetworkSocketAPI Example Program
+ * Copyright (c) 2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "mbed.h"
+#include "TCPSocket.h"
+#include "mbed.h"
+#include "WizFi310Interface.h"
+#include "TCPSocket.h"
+#include "TCPServer.h"
+
+#define TARGET_NUCLEO_F411RE
+
+
+#if defined(TARGET_NUCLEO_F411RE)
+Serial pc(USBTX, USBRX);
+//WizFi310Internet wifi(PA_11, PA_12, D6, D7, D3, NC, 115200);
+WizFi310Interface wifi(D8, D2, D7, D6, D9, NC, 115200);
+#endif
+
+#if defined(TARGET_WIZwiki_W7500)
+Serial pc(USBTX, USBRX);
+WizFi310Interface wifi(D1, D0, D7, D6, D8, NC, 115200);
+#endif
+
+#define AP_SSID "DIR-815_Wiznet"
+#define AP_PASSWORD "12345678"
+#define AP_SECURITY NSAPI_SECURITY_WPA2
+
+int main()
+{
+ pc.baud(115200);
+ printf("WizFi310 NetworkSocketAPI TCP Client Example\r\n");
+
+ wifi.connect(AP_SSID, AP_PASSWORD, AP_SECURITY);
+
+ const char *ip = wifi.get_ip_address();
+ const char *mac = wifi.get_mac_address();
+ printf("IP address is: %s\r\n", ip ? ip : "No IP");
+ printf("MAC address is: %s\r\n", mac ? mac : "No MAC");
+
+ TCPServer srv;
+ TCPSocket clt_sock;
+ SocketAddress clt_addr;
+
+ srv.open(&wifi);
+ srv.set_blocking(true);
+ srv.bind(80);
+ srv.listen();
+ srv.accept(&clt_sock);
+
+ char buffer[512];
+
+ 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);
+ }
+ }
+}
