HoYa's MBED (Nucleo-F401RE)
Dependencies: NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed
Revision 2:d7647babe160, committed 2017-07-20
- Comitter:
- HoYa
- Date:
- Thu Jul 20 08:24:24 2017 +0000
- Parent:
- 1:b2b7580e09d7
- Child:
- 3:ad353d5bf223
- Commit message:
- Unsecured TCP Testing
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Jul 20 07:50:49 2017 +0000
+++ b/main.cpp Thu Jul 20 08:24:24 2017 +0000
@@ -11,10 +11,10 @@
pc.printf("\r\n");
pc.printf("Start Application\r\n");
+ // Wi-Fi
pc.printf("\r\n");
pc.printf("Connecting to AP...\r\n");
if (spwf.connect("hRPi3-AP", "rlawjdgh", NSAPI_SECURITY_WPA2)) {
-// if (spwf.connect("RP_RND_A", "radio1106", NSAPI_SECURITY_WPA2)) {
pc.printf("=> Success.\r\n");
} else {
pc.printf("=> Failed to connect.\r\n");
@@ -25,11 +25,40 @@
const char* mac = spwf.get_mac_address();
pc.printf("=> MAC Address is: %s\r\n", (mac) ? mac : "No MAC");
+ // DNS
pc.printf("\r\n");
pc.printf("DNS Testing...\r\n");
SocketAddress addr(&spwf, "st.com");
pc.printf("<st.com> is resolved to: %s\r\n", addr.get_ip_address());
-
+
+ // Unsecured TCP
+ pc.printf("\r\n");
+ pc.printf("Unsecured TCP Testing...\r\n");
+ TCPSocket socket(&spwf);
+ pc.printf("Connecting to <4.ifcfg.me>...\r\n");
+ int err = socket.connect("4.ifcfg.me", 23);
+ if (err) {
+ pc.printf("=> Failed to connect. (%d)\r\n", err);
+ return -1;
+ } else {
+ pc.printf("=> Success.\r\n");
+ }
+ pc.printf("Receiving Data\r\n");
+ char buffer[100];
+ int count = socket.recv(buffer, sizeof buffer);
+ if (count > 0) {
+ buffer[count] = '\0';
+ printf("=> %s\r\n", buffer);
+ }
+ else {
+ pc.printf("=> Nothing to receive.\r\n");
+ }
+ pc.printf("Close TCP socket\r\n");
+ socket.close();
+
+ printf ("Disconnect from AP\r\n");
+ spwf.disconnect();
+
while (1) {
led = !led;
wait(0.5);