GainSpan Wi-Fi library see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/

Fork of GSwifi_old by gs fan

GainSpan Wi-Fi library

The GS1011 is an ultra low power 802.11b wireless module from GainSpan.

see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/

Information

Please change the baud rate in advance.

  • ATB=115200
  • AT&W0

It may be better and sometimes faster.
GSwifi gs(p13, p14, baud);

Heavily modified new library: http://mbed.org/users/gsfan/code/GSwifi

ゲインスパン Wi-Fi モジュール ライブラリ

ゲインスパン社の低電力 Wi-Fiモジュール(無線LAN) GS1011 シリーズ用のライブラリです。

解説: http://mbed.org/users/gsfan/notebook/gainspan_wifi/

Information

モジュールはあらかじめ次のコマンドでボーレートを変更しておく。

  • ATB=115200
  • AT&W0

場合によってはもっと高速の方がいいかもしれない。クラス宣言時にレート設定をする。
GSwifi gs(p13, p14, baud);

大幅に更新された新しいライブラリ: http://mbed.org/users/gsfan/code/GSwifi

Revision:
24:5c350ae2e703
Parent:
23:a783c62c36d0
--- a/GSwifi.cpp	Mon Jan 21 05:58:28 2013 +0000
+++ b/GSwifi.cpp	Wed Jan 23 07:41:23 2013 +0000
@@ -22,6 +22,9 @@
     _escape = 0;
     _response = GSRES_NONE;
     _gs_mode = GSMODE_COMMAND;
+    _ssid = NULL;
+    _reconnect = 0;
+    _reconnect_count = 0;
 
     _gs.baud(baud);
     _gs.attach(this, &GSwifi::isr_recv, Serial::RxIrq);
@@ -34,6 +37,9 @@
     _escape = 0;
     _response = GSRES_NONE;
     _gs_mode = GSMODE_COMMAND;
+    _ssid = NULL;
+    _reconnect = 0;
+    _reconnect_count = 0;
 
     _gs.baud(baud);
     _gs.attach(this, &GSwifi::isr_recv, Serial::RxIrq);
@@ -141,7 +147,6 @@
                 _buf_cmd.put(dat);
                 if (dat == '\n') {
                     _gs_enter ++;
-                    DBG("* %d %d *", _response, _connect);
                     if (_response == GSRES_NONE && _connect) {
                         DBG("poll_cmd\r\n");
                         poll_cmd();
@@ -390,7 +395,7 @@
             }
             break;
         case GSRES_CONNECT:
-            if (strncmp(buf, "CONNECT", 7) == 0) {
+            if (strncmp(buf, "CONNECT ", 8) == 0) {
                 _cid = x2i(buf[8]);
                 flg = 1;
             }
@@ -476,7 +481,7 @@
     }
 }
 
-int GSwifi::connect (GSSECURITY sec, const char *ssid, const char *pass, int dhcp) {
+int GSwifi::connect (GSSECURITY sec, const char *ssid, const char *pass, int dhcp, int reconnect) {
     int r;
     char cmd[GS_CMD_SIZE];
     
@@ -556,7 +561,13 @@
         command(cmd, GSRES_NORMAL);
     }
 
-    if (r == 0) _connect = true;
+    if (r == 0) {
+        _connect = true;
+        _reconnect = reconnect;
+        _reconnect_count = 0;
+        if (!_ssid) _ssid = new char[sizeof(ssid) + 1];
+        strcpy(_ssid, ssid);
+    }
     return r;
 }
 
@@ -989,6 +1000,20 @@
             }
         }
     }
+    
+    if (!_connect && _reconnect_count < _reconnect && _ssid) {
+        // re-connrct
+        int r;
+        char cmd[GS_CMD_SIZE];
+        _reconnect_count ++;
+        DBG("re-connect %d\r\n", _reconnect_count);
+        sprintf(cmd, "AT+WA=%s", _ssid);
+        r = command(cmd, GSRES_DHCP, GS_TIMEOUT2);
+        if (r == 0) {
+            _connect = true;
+            _reconnect_count = 0;
+        }
+    }
 }
 
 void GSwifi::newSock (int cid, GSTYPE type, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive) {