pefect / Mbed 2 deprecated WizFi310_TCP_Echo_Server_Example

Dependencies:   NetworkSocketAPI WizFi310Interface mbed

Fork of WizFi310_TCP_Echo_Server_Example by WIZnet

Revision:
3:4b4eb90875bd
Parent:
2:8d119e9b8f5a
Child:
4:a602935de142
--- a/main.cpp	Mon Oct 02 20:48:08 2017 +0000
+++ b/main.cpp	Mon Oct 02 21:29:51 2017 +0000
@@ -23,30 +23,38 @@
 #include "push.h"
 #include "setting.h"
 
-Serial pc(USBTX, USBRX);
+#define TEST_MODE 0
+#define DEMO_MODE 1
+
+#define MODE TEST_MODE
+
 WizFi310Interface wifiInterface(D1, D0, D7, D6, D8, NC, 115200);
-char buf[MAX_BUF_SIZE] = "";
 
 int main()
 {
+    //Start Goout
+    Serial pc(USBTX, USBRX);
     pc.baud(115200);
     
+    //Wifi AP Mode Start
     wifiInterface.connectAP(AP_SSID, AP_PASSWORD, AP_SECURITY);
     
+    char buf[MAX_BUF_SIZE] = "";
     char id[MAX_ID_SIZE] = "";
     char pwd[MAX_PWD_SIZE] = "";
-    const char *ip = wifiInterface.get_ip_address();
-    const char *mac = wifiInterface.get_mac_address();
 
+    //Wifi AP Mode Server Start
     TCPServer srv;
     TCPSocket clt_sock;
     
+    //Wifi AP Mode Server init
     srv.open(&wifiInterface);
     srv.set_blocking(true);
     srv.bind(8080);
     srv.listen();
     srv.accept(&clt_sock);
 
+    //Wifi AP Mode Server recv Wifi config info
     while (true)
     {
         int n = clt_sock.recv(buf, MAX_BUF_SIZE);
@@ -63,28 +71,48 @@
         }
     }
     
-    /*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!).*/
-    
+    //Wifi AP Mode Server response Wifi config info
     sendMacResponse(wifiInterface, clt_sock);
     processWiFiJson(buf, pwd, id);
     
-    
+    //free wifi AP Server
     clt_sock.close();
     srv.close();
     
+#if MODE == DEMO_MODE
+    //Decoder Init
+    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!).
+#endif
+    
+    //Wifi Station(Client) Mode start
     wifiInterface.connect(buf, pwd, STA_SECURITY);
     TCPSocket *socket = new TCPSocket(&wifiInterface);
     
+#if MODE == DEMO_MODE
+    //detecting start
+    detecting(player, socket, buf, id)
+#endif
+
+#if MODE == TEST_MODE
+    //recv tts text
     recvInfo(socket, buf, id);
+    //recv tts data and play
     playTTS(socket, buf); 
+    //recv android app push notification
     requestNoti(socket, id, buf);
+#endif
     
+    //free wifi
     socket->close();
     wifiInterface.disconnect();
-    //player.sendCancel();
-    //player.stop();
+
+#if MODE == DEMO_MODE
+    //free decoder
+    player.sendCancel();
+    player.stop();
+#endif
     
     printf("D\n");
     delete socket;