TCPEchoServer for Murata Type-YD WiFi module

Dependencies:   PowerControl SNICInterface mbed-rtos mbed

Fork of TCPEchoServer by Toyomasa Watarai

mbed 上で動作する TCPEchoServer です(ムラタ製 TypeYDモジュール使用)。

ターミナルを接続して実行すると、割り当てられたIPアドレスが表示されます。 対向機から実行する Python スクリプトは、こちら です(IPアドレスを書き換えて使用して下さい)。

Revision:
7:27b297e209a6
Parent:
3:36fd3cfad85a
Child:
8:6e121d9ce02b
--- a/main.cpp	Tue Jun 04 16:07:06 2013 +0100
+++ b/main.cpp	Fri Jan 23 10:15:33 2015 +0000
@@ -1,22 +1,55 @@
 #include "mbed.h"
-#include "EthernetInterface.h"
+#include "SNIC_WifiInterface.h"
+#include "TCPSocketServer.h"
+
+#if defined(TARGET_LPC1768)
+#include "PowerControl/EthernetPowerControl.h"
+#endif
 
 #define ECHO_SERVER_PORT   7
 
+#define DEMO_AP_SSID                  "SSID"
+#define DEMO_AP_SECURITY_TYPE         e_SEC_WPA2_AES
+#define DEMO_AP_SECUTIRY_KEY          "PASSWORD"
+
+C_SNIC_WifiInterface     wifi( p9, p10, NC, NC, p30 );
+
 int main (void) {
-    EthernetInterface eth;
-    eth.init(); //Use DHCP
-    eth.connect();
-    printf("IP Address is %s\n", eth.getIPAddress());
+#if defined(TARGET_LPC1768)
+    PHY_PowerDown();
+#endif
+
+    wifi.init(); //Use DHCP
+
+    wait(0.5);
+    int s = wifi.disconnect();
+    if( s != 0 )
+    {
+        return -1;
+    }    
+    
+    wait(0.3);
+    // Connect AP
+    wifi.connect( DEMO_AP_SSID
+                        , strlen(DEMO_AP_SSID)
+                        , DEMO_AP_SECURITY_TYPE
+                        , DEMO_AP_SECUTIRY_KEY
+                        , strlen(DEMO_AP_SECUTIRY_KEY) );
+    wait(0.5);
+    
+    wifi.setIPConfig( true );    
+    wait(0.5);
+    
+    printf("IP Address is %s\n", wifi.getIPAddress());
     
     TCPSocketServer server;
     server.bind(ECHO_SERVER_PORT);
-    server.listen();
-    
+    server.listen();    
+
     while (true) {
         printf("\nWait for new connection...\n");
         TCPSocketConnection client;
-        server.accept(client);
+        server.accept(&client);
         client.set_blocking(false, 1500); // Timeout after (1.5)s
         
         printf("Connection from: %s\n", client.get_address());