NNN40_WiFi_Demo

Dependencies:   WIFI_API_32kRAM mbed

Fork of NNN40_WiFi by Delta

Revision:
10:fff1a8a4b003
Parent:
7:c497e792660d
Child:
11:0d4c4bc2274a
--- a/main.cpp	Tue Jun 09 06:06:23 2015 +0000
+++ b/main.cpp	Thu Jul 02 03:10:05 2015 +0000
@@ -4,29 +4,85 @@
 
 WIFIDevice wifi;
 
-const char* PC_SERVER_ADDRESS = "192.168.1.234";
+const char* PC_SERVER_ADDRESS_1 = "10.0.1.2";
+const char* PC_SERVER_ADDRESS_2 = "10.0.1.3";
 uint16_t PC_PORT = 5222;
-DigitalOut LED01(LED1);
-DigitalOut LED02(LED2);
+
+DigitalOut LED01(p13);
+DigitalOut LED02(p7);
+
 
 int main(void)
 {   
+
     EthernetInterface eth;
     eth.init(); //Use DHCP
     wait(1);
+    DPRINT(N_ERR, "Hello World, NNN40_WiFi\n");
     // set given SSID and PW as the highest priority  
-    wifi.setNetwork("HTC820", "11111111", 0);
+    //wifi.setNetwork("KORYO-Guest", "koryo123", 0);
+    wifi.setNetwork("Gordon Airport Network", "password", 0);
     wait(1);
-    LED01 = 1;
+   
     eth.connect(40000);
+    DPRINT(N_ERR, "****IP Address:%s\n",eth.getIPAddress());
+    DPRINT(N_ERR, "****MAC Address:%s\n",eth.getMACAddress());
 
-    LED02 = 1;
-    TCPSocketConnection socket;     
-    socket.connect(PC_SERVER_ADDRESS,PC_PORT); 
+    LED01 = 1;
+    TCPSocketConnection socket1;     
+    if(0 == socket1.connect(PC_SERVER_ADDRESS_1,PC_PORT))
+    {
+         
+         DPRINT(N_ERR, "****socket1 connect ok!!!\n");
+    }
+    else
+    {
+        DPRINT(N_ERR, "****socket connect1 failed !!\n");
+    }
+   
+    TCPSocketConnection socket2;     
+    if(0 == socket2.connect(PC_SERVER_ADDRESS_2,PC_PORT))
+    {
+         
+         LED02 = 1;
+         DPRINT(N_ERR, "****socket2 connect ok!!!\n");
+    }
+    else
+    {
+        DPRINT(N_ERR, "****socke2 connect failed !!\n");
+    }
+   
     char msg[] = "Hello World";
-    socket.send(msg, sizeof(msg));
+    char buf[1024];
+    //socket.send(msg, sizeof(msg));
 
-    socket.close();
+    /*
+    if(socket.receive(rx, sizeof(msg)) != -1)
+    {
+         DPRINT(N_ERR, "****RX data :%s\n",&rx[0]);
+    }
+    else
+    {
+         DPRINT(N_ERR, "****RX error\n");
+    }
+    */
+    int i = 1;
+    while(1)
+    {
+        wait(1);
+        int j = sprintf(buf, "Hello World : %d\n",i);
+        DPRINT(N_ERR, "******************Send Message : %d \n", i++);
+        //socket.send(msg, sizeof(msg));   
+        socket1.send(buf, j);    
+        socket2.send(buf, j);   
+        
+        if(i%2 == 0 )  LED02 = 1;
+        else LED02 = 0; 
+    }
+    DPRINT(N_ERR, "****socket close \n");
+    socket1.close();
+    //socket2.close();
     eth.disconnect();
     wifi.sleep();
+
 }