   strcpy_P(buffer, (char*)pgm_read_word(&(string_table[2]))); //&type=data
   wifiSerial.print(buffer);
 
-  strcpy_P(buffer, (char*)pgm_read_word(&(string_table[3]))); //&header=datetime,lat,lng,light,temperature,humidity,rain
-  wifiSerial.print(buffer);
-
-  strcpy_P(buffer, (char*)pgm_read_word(&(string_table[4]))); //&load=
-  wifiSerial.print(buffer);
+  strcpy_P(buffer, (char*)pgm_read_word(&(string_table[3]))); //&header=datetime,lat,lng,
+  wifiSerial.print(buffer);
+
+  strcpy_P(buffer, (char*)pgm_read_word(&(string_table[4]))); //light,temperature,humidity,rain
+  wifiSerial.print(buffer);
+
+  strcpy_P(buffer, (char*)pgm_read_word(&(string_table[5]))); //&load=
+  wifiSerial.print(buffer);
+}
+
+void send_data() {
+#if DEBUG
+  print_debug(4);
+#endif
 
   //Send the whole file
   strcpy_P(buffer, (char*)pgm_read_word(&(string_table[0])));
   File data_file = SD.open(buffer);
-  char a;
+  String a;
+  int i = 0;
+
   while (data_file.available()) {
-    a = char(data_file.read());
-    wifiSerial.write(a);
-    delay(5);
+    start_message();
+    while (data_file.available()) {
+      i++;
+      a = data_file.readStringUntil('\n');
+      wifiSerial.print(a + "\n");
+      delay(5);
+      if (i > 20) {
+        wifiSerial.write(end_of_file);
+        start_message();
+      }
+    }
+    delay(DELAY_TIME);
+    if (!start_connection()){
+      break;
+    }
   }
   wifiSerial.write(end_of_file);
   data_file.close();

  Serial.begin(SERIAL_BAUD_RATE);
  wifiSerial.begin(WIFI_BAUD_RATE);
  gpsSerial.begin(GPS_BAUD_RATE);  // gps begins after wifi because it is used first
  //dht.begin();

  pinMode(10, OUTPUT);



#define SEPARATOR ","

#define DELAY_TIME 150

#define PIN_LIGHT A1
#define SD_CHIP_SELECT 10
