no upgrade or change at this. move to new Library for WIZ550io, W5500 -> http://mbed.org/teams/EthernetInterfaceW5500-makers/code/W5500Interface/

Dependents:   LPC11U68_NTPClient_HelloWorld_WIZ550io

Fork of WIZ550ioInterface by ban4jp -

please get the new Library for WIZ550io, W5500 (WIZnet) http://mbed.org/teams/EthernetInterfaceW5500-makers/code/W5500Interface/

Import libraryW5500Interface

This is the Interface library for WIZnet W5500 chip which forked of EthernetInterfaceW5500, WIZnetInterface and WIZ550ioInterface. This library has simple name as "W5500Interface". and can be used for Wiz550io users also.

Files at this revision

API Documentation at this revision

Comitter:
samux
Date:
Sat Nov 24 16:59:36 2012 +0000
Parent:
1:fb4494783863
Child:
3:9aa05e19c62e
Commit message:
set dns server name (now able to use "open host port")

Changed in this revision

Wifly/Wifly.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Wifly/Wifly.cpp	Fri Aug 24 13:48:36 2012 +0000
+++ b/Wifly/Wifly.cpp	Sat Nov 24 16:59:36 2012 +0000
@@ -22,7 +22,7 @@
 #include <algorithm>
 
 //Debug is disabled by default
-#if (0 && defined(TARGET_LPC1768))
+#if (0 && !defined(TARGET_LPC11U24))
 #define DBG(x, ...) std::printf("[Wifly : DBG]"x"\r\n", ##__VA_ARGS__);
 #define WARN(x, ...) std::printf("[Wifly : WARN]"x"\r\n", ##__VA_ARGS__);
 #define ERR(x, ...) std::printf("[Wifly : ERR]"x"\r\n", ##__VA_ARGS__);
@@ -32,7 +32,7 @@
 #define ERR(x, ...)
 #endif
 
-#if TARGET_LPC1768
+#if !defined(TARGET_LPC11U24)
 #define INFO(x, ...) printf("[Wifly : INFO]"x"\r\n", ##__VA_ARGS__);
 #else
 #define INFO(x, ...)
@@ -70,6 +70,15 @@
     char cmd[20];
 
     for (int i= 0; i < MAX_TRY_JOIN; i++) {
+
+        // no auto join
+        if (!sendCommand("set w j 0\r", "AOK"))
+            continue;
+
+        //no echo
+        if (!sendCommand("set u m 1\r", "AOK"))
+            continue;
+
         // set time
         if (!sendCommand("set c t 20\r", "AOK"))
             continue;
@@ -93,13 +102,9 @@
         // tcp retry
         if (!sendCommand("set i f 0x7\r", "AOK"))
             continue;
-
-        //no echo
-        if (!sendCommand("set u m 1\r", "AOK"))
-            continue;
-
-        // no auto join
-        if (!sendCommand("set w j 0\r", "AOK"))
+            
+        // set dns server
+        if (!sendCommand("set d n rn.microchip.com\r", "AOK"))
             continue;
 
         //dhcp
@@ -145,16 +150,18 @@
                 continue;
         }
 
-        //join the network
-        sprintf(cmd, "join\r");
-        if (!sendCommand(cmd, "Associated", NULL, 3000))
-            continue;
-
+        //join the network (10s timeout)
         if (state.dhcp) {
-            if (!sendCommand("", "DHCP=ON", NULL, 3000))
+            if (!sendCommand("join\r", "DHCP=ON", NULL, 10000))
+                continue;
+        } else {
+            if (!sendCommand("join\r", "Associated", NULL, 10000))
                 continue;
         }
 
+        if (!sendCommand("save\r", "Stor"))
+            continue;
+
         exit();
 
         state.associated = true;
@@ -211,27 +218,23 @@
     char rcv[20];
     char cmd[20];
 
-    // get ip from host and set host
-    if (gethostbyname(host, rcv)) {
-        sprintf(cmd, "set i h %s\r", rcv);
-        if (!sendCommand(cmd, "AOK"))
-            return false;
-    } else {
-        return false;
+    // try to open
+    sprintf(cmd, "open %s %d\r", host, port);
+    if (sendCommand(cmd, "OPEN", NULL, 10000)) {
+        state.tcp = true;
+        state.cmd_mode = false;
+        return true;
     }
 
-    // set port
-    sprintf(cmd, "set i r %d\r", port);
-    if (!sendCommand(cmd, "AOK"))
-        return false;
-
-    // open
-    if (sendCommand("open\r", NULL, rcv)) {
+    // if failed, retry and parse the response
+    if (sendCommand(cmd, NULL, rcv, 5000)) {
         if (strstr(rcv, "OPEN") == NULL) {
             if (strstr(rcv, "Connected") != NULL) {
+                wait(0.25);
                 if (!sendCommand("close\r", "CLOS"))
                     return false;
-                if (!sendCommand("open\r", "OPEN"))
+                wait(0.25);
+                if (!sendCommand(cmd, "OPEN", NULL, 10000))
                     return false;
             } else {
                 return false;
@@ -240,7 +243,7 @@
     } else {
         return false;
     }
-    
+
     state.tcp = true;
     state.cmd_mode = false;
 
@@ -316,9 +319,10 @@
     // if already in cmd mode, return
     if (state.cmd_mode)
         return true;
-        
+
     if (send("$$$", 3, "CMD") == -1) {
         ERR("cannot enter in cmd mode\r\n");
+        exit();
         return false;
     }
     state.cmd_mode = true;
@@ -330,11 +334,11 @@
     // if already disconnected, return
     if (!state.associated)
         return true;
-        
+
     if (!sendCommand("leave\r", "DeAuth"))
         return false;
     exit();
-    
+
     state.associated = false;
     return true;
 
@@ -359,12 +363,12 @@
     // if not connected, return
     if (!state.tcp)
         return true;
-        
+
     wait(0.25);
     if (!sendCommand("close\r", "CLOS"))
         return false;
     exit();
-    
+
     state.tcp = false;
     return true;
 }