   return 0;
 }
 
-
-void loadData(void* data, int offset, int length) {
-    uint8_t* pos = (uint8_t*)data;
-    for(int i = 0; --length; ++i,++pos) {
-       *pos = EEPROM.read(i);
-    }
-}
-
-void saveData(const void* data, int start, int length) {
-  const uint8_t* pos = (const uint8_t*)data;
-  Serial.println(length);
-  int ln = length;
-  for(int i = start; --length; ++i,++pos) {
-      EEPROM.write(i, *pos);
-  }
-  #ifdef DEBUG
-      Serial.begin(9600);
-      Serial.println("debug :: config saved");
-   #endif
-}
+void loadConfig() {
+  int offset = 0;
+  _config.version = EEPROM.read(offset++);
+  _config.mode = EEPROM.read(offset++);
+  for(int i = 0, n = sizeof(_config.ssid);i < n; ++i)
+    _config.ssid[i] = EEPROM.read(offset++);
+    
+  for(int i = 0, n = sizeof(_config.pass);i < n; ++i)
+    _config.pass[i] = EEPROM.read(offset++);
+    
+  for(int i = 0, n = sizeof(_config.serverAddr);i < n; ++i)
+    _config.serverAddr[i] = EEPROM.read(offset++);
+    
+  _config.port =  ((short)EEPROM.read(offset++)) << 8;
+  _config.port  |=  EEPROM.read(offset++);
+  _config.tailVersion = EEPROM.read(offset);
+}
+
+
+void saveConfig() {
+  Serial.print("SSID SIZE : ");
+  Serial.println(sizeof(_config.ssid));
+  int offset = 0;
+  EEPROM.write(offset++, _config.version);
+  EEPROM.write(offset++, _config.mode);
+  for(int i = 0, n = sizeof(_config.ssid);i < n; ++i)
+    EEPROM.write(offset++, _config.ssid[i]);
+    
+  for(int i = 0, n = sizeof(_config.pass);i < n; ++i)
+    EEPROM.write(offset++, _config.serverAddr[i]);
+    
+  for(int i = 0, n = sizeof(_config.serverAddr);i < n; ++i)
+    EEPROM.write(offset++, _config.serverAddr[i]);   
+    
+  EEPROM.write(offset++, (byte)(_config.port >> 8));
+  EEPROM.write(offset++, (byte)_config.port);
+  EEPROM.write(offset++, _config.tailVersion);
+}
+
+/*typedef struct Config {
+  uint8_t version = VER;
+  uint8_t mode = MODE_BOOT;
+  char ssid[32] = "unknown";
+  char pass[32] = "unknown";
+  char serverAddr[64] = "unknown";
+  int port = 80;
+  uint8_t tailVersion = VER;   
+} CONFIG;*/
+
 
 bool checkConfig(CONFIG* config) {
   return config->tailVersion == VER && config->version == VER;

    printConfig(&_config);
  }
  #endif
 
}

void loop() {

  }
}

void intoSetupMode(bool force) {
  if(_config.mode == MODE_SETUP && !force) return;
  _config.mode = MODE_SETUP;
  saveConfig();
  sendATCmd("AT+RST\r\n", 2000);
  sendATCmd("AT+CWMODE=2\r\n");
  sendATCmd("AT+CIPMUX=1\r\n");
