pefect / Mbed 2 deprecated WizFi310_TCP_Echo_Server_Example

Dependencies:   NetworkSocketAPI WizFi310Interface mbed

Fork of WizFi310_TCP_Echo_Server_Example by WIZnet

Revision:
2:8d119e9b8f5a
Parent:
1:5981ba4a8323
Child:
3:4b4eb90875bd
diff -r 5981ba4a8323 -r 8d119e9b8f5a main.cpp
--- a/main.cpp	Tue Apr 18 00:57:35 2017 +0000
+++ b/main.cpp	Mon Oct 02 20:48:08 2017 +0000
@@ -14,58 +14,42 @@
  * limitations under the License.
  */
  
-#include "mbed.h"
-#include "TCPSocket.h"
+#include <stdio.h>
+#include <stdlib.h>
 #include "mbed.h"
-#include "WizFi310Interface.h"
-#include "TCPSocket.h"
-#include "TCPServer.h"
-
-#define TARGET_NUCLEO_F411RE
-
+#include "detect.h"
+#include "info.h"
+#include "tts.h"
+#include "push.h"
+#include "setting.h"
 
-#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 "wizms1"
-#define AP_PASSWORD "maker0701"
-#define AP_SECURITY NSAPI_SECURITY_WPA2
+WizFi310Interface wifiInterface(D1, D0, D7, D6, D8, NC, 115200);
+char buf[MAX_BUF_SIZE] = "";
 
 int main()
 {
     pc.baud(115200);
-    printf("WizFi310 NetworkSocketAPI TCP Server Example\r\n");
     
-    wifi.connect(AP_SSID, AP_PASSWORD, AP_SECURITY);
+    wifiInterface.connectAP(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");
+    char id[MAX_ID_SIZE] = "";
+    char pwd[MAX_PWD_SIZE] = "";
+    const char *ip = wifiInterface.get_ip_address();
+    const char *mac = wifiInterface.get_mac_address();
 
     TCPServer srv;
     TCPSocket clt_sock;
-    SocketAddress clt_addr;
     
-    srv.open(&wifi);
+    srv.open(&wifiInterface);
     srv.set_blocking(true);
-    srv.bind(80);
+    srv.bind(8080);
     srv.listen();
     srv.accept(&clt_sock);
 
-    char buffer[512];
-
     while (true)
     {
-        int n = clt_sock.recv(buffer, sizeof(buffer));
+        int n = clt_sock.recv(buf, MAX_BUF_SIZE);
         if( n < 0 )
         {
             clt_sock.close();
@@ -73,9 +57,35 @@
         }
         if( n > 0 )
         {
-            buffer[n] = '\0';
-            printf("length : %d\r\n", n);
-            clt_sock.send(buffer, n);
+            buf[n] = '\0';
+            clt_sock.send(buf, n);
+            break;
         }
     }
+    
+    /*VS1053 player(PA_08, PA_07, PA_06, PA_00, PA_05, PA_01, PA_02); // mosi, miso, sck, cs, bsync, dreq, rst
+    player.hardwareReset(); //Make a reset to the VS1053 board
+    player.modeSwitch();    //Patch the VS1054 board to play MP3 files (very important!).*/
+    
+    sendMacResponse(wifiInterface, clt_sock);
+    processWiFiJson(buf, pwd, id);
+    
+    
+    clt_sock.close();
+    srv.close();
+    
+    wifiInterface.connect(buf, pwd, STA_SECURITY);
+    TCPSocket *socket = new TCPSocket(&wifiInterface);
+    
+    recvInfo(socket, buf, id);
+    playTTS(socket, buf); 
+    requestNoti(socket, id, buf);
+    
+    socket->close();
+    wifiInterface.disconnect();
+    //player.sendCancel();
+    //player.stop();
+    
+    printf("D\n");
+    delete socket;
 }