Read file on SD Card by line

First my apologize for my bad anglish. I'm a noob to arduino and programming, may be somebody can help me to solved my problem.
I have a TXT on SD Card, i want to read the file line by line and send it using ethernet shield. I have Mega 2560 and official ethernet shield with micro SD slot.
Here is my skecth...

#include <TinyGPS.h>
#include <SD.h>
#include <stdlib.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xD2, 0xC2 };
IPAddress ip(192,168,0,3);
IPAddress gateway(192,168,0,1);
IPAddress subnet(255,255,255,0);
IPAddress server(192,168,0,5);
EthernetClient client;
boolean SDavailable;
char inChar;
int connectLoop;

char netBuffer[60];
byte myTest[5];

void setup() {
  Serial.begin(9600);
  // disable w5100
  pinMode(10,OUTPUT);
  pinMode(4, OUTPUT);
  
  digitalWrite(10, LOW); //ethernet on
  digitalWrite(4, HIGH); //SD card off
  Ethernet.begin(mac, ip, gateway);
  
  Serial.print("Starting SD...");
  digitalWrite(10, HIGH);
  digitalWrite(4, LOW);
  
  if(!SD.begin(4)) {
  Serial.println("failed");
  SDavailable = false;
  }
  else {
    SDavailable = true;
    Serial.println("ok");
  }
}


void loop() {
  digitalWrite(10, LOW);
  digitalWrite(4, HIGH);
  if(client.connect(server, 80))
  {  
    
    //Serial.println("connected...");
    //Serial.println("ARDUINO: forming HTTP request message");
    client.print("GET /arduino/insert2.php?netBuffer=");
    client.print(netBuffer);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    client.println("Connection: close\r\n");

    // read server response    
    while(client.connected())
    {
      while(client.available())
      {
        inChar = client.read();
        Serial.write(inChar);
        // set connectLoop to zero if a packet arrives
        connectLoop = 0;
      }

      //connectLoop++;

      // if more than 10000 milliseconds since the last packet
      if(connectLoop > 10000)
      {
        // then close the connection from this end.
        Serial.println();
        Serial.println(F("Timeout"));
        client.stop();
      }
      // this is a delay for the connectLoop timing
      delay(1);
    }

    Serial.println();
    Serial.println(F("disconnecting."));
    // close client end

    client.stop();
    //client.flush(); 
  }
  else
  {
    Serial.println("connection failure");
  }
  //String dataString = "";
  //dataString = netBuffer;
  //Serial.println(dataString);
  //LineNo++;
  
  
  if(SDavailable != false) {
  digitalWrite(4, LOW);
  digitalWrite(10, HIGH);
  
  File fh = SD.open("log.txt",FILE_READ);
  int chPos = 0;
  int lineNo = 0;
  
  if(!fh)
  {
    Serial.println("SD open fail");
    return;    
  }

  while(fh.available())
  {
    char ch = fh.read();
    if(ch == '\n') {
      chPos = 0;

       sscanf(netBuffer,"%u","%u","%u","%u","%u","%u",&myTest[0],&myTest[1],&myTest[2],&myTest[3],&myTest[4],&myTest[5]);  

      Serial.println(netBuffer);

      
      lineNo++;
    }
    else if(ch == '\r') {
      // do nothing
    }
    else if(chPos < 59) {
      netBuffer[chPos] = ch;
       chPos++;
      netBuffer[chPos] = 0;
    }
  }
  fh.close();
  
  
  }
  
}

this is the file content
CRM001,20130527094818,-6.88125,107.58240,0.43,305.50
CRM001,20130527094819,-6.88125,107.58240,0.91,185.26
CRM001,20130527094821,-6.88126,107.58240,1.50,184.12
CRM001,20130527094822,-6.88127,107.58239,1.56,192.71
CRM001,20130527094824,-6.88128,107.58239,0.94,200.54
CRM001,20130527094826,-6.88127,107.58239,0.61,324.25

The sketch above give me the correct output in Serial monitor but when i send it to my gateway (php) on my local server, it only send the last line from the txt file. My plan is to log gps data to sd card for every 10 second (i already have a working sketch for this) and create a new file for every certain period i.e a day, week or month. When a client is connected i want to read the file on sd card line by line send it to my gateway application which will store the data to mysql database. When there's no client connected then i only want to log the data to sd card and remember the last sent record so if the client connect again it will continue sent from the last record.
What is the best way to do this plan since the logger will be used for years.

Any advice will be much appreciated.

Thank you

The sketch above give me the correct output in Serial monitor

Because you print the data in netBuffer to the serial port every time a \n is found in the file. But, where do you send netBuffer to the server?

Only one place, and even then you don't check to see that netBuffer contains anything.

I send the data to server using client.print(netBuffer). I can see there's a data in nefbufer using serial monitor but it always the last line. I#m just started to learn arduino and programming.

Any advice how can i send the data to server line by line?

I send the data to server using client.print(netBuffer).

But, you only send it once (after the whole file has been read) (or at the beginning before the file has been read at all). You need to connect to the server, and make a GET request, each time the \n is located.

Create a function called newLineFound(). Call that function when this statement evaluates to true:

    if(ch == '\n') {

Put this code in the function:

      chPos = 0;

       sscanf(netBuffer,"%u","%u","%u","%u","%u","%u",&myTest[0],&myTest[1],&myTest[2],&myTest[3],&myTest[4],&myTest[5]);  

      Serial.println(netBuffer);

      
      lineNo++;

(without all the useless whitespace).

Then, look through the rest of the code in loop(), and see what else (lots) of stuff should happen in that function, too.

First my apologize, i try to understand what you advise me but seems like i can't fully understand what you mean. i'm still always get the same line.

#include <TinyGPS.h>
#include <SD.h>
#include <stdlib.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 
  0x90, 0xA2, 0xDA, 0x0D, 0xD2, 0xC2 };
IPAddress ip(192,168,0,3);
IPAddress gateway(192,168,0,1);
IPAddress subnet(255,255,255,0);
IPAddress server(192,168,0,5);
EthernetClient client;
boolean SDavailable;
char inChar;
int connectLoop;

char netBuffer[60];
byte myTest[5];
int chPos = 0;
int lineNo = 0;

void setup() {
  Serial.begin(9600);
  // disable w5100
  pinMode(10,OUTPUT);
  pinMode(4, OUTPUT);

  digitalWrite(10, LOW); //ethernet on
  digitalWrite(4, HIGH); //SD card off
  Ethernet.begin(mac, ip, gateway);

  Serial.print("Starting SD...");
  digitalWrite(10, HIGH);
  digitalWrite(4, LOW);

  if(!SD.begin(4)) {
    Serial.println("failed");
    SDavailable = false;
  }
  else {
    SDavailable = true;
    Serial.println("ok");
  }
}

void newLineFound() {
  chPos = 0;
  sscanf(netBuffer,"%u","%u","%u","%u","%u","%u",&myTest[0],&myTest[1],&myTest[2],&myTest[3],&myTest[4],&myTest[5]);  
  //Serial.println(netBuffer);
  lineNo++;
}

void loop() {
  digitalWrite(10, LOW);
  digitalWrite(4, HIGH);
  if(client.connect(server, 80))
  {  
    client.print("GET /arduino/insert2.php?netBuffer=");
    client.print(netBuffer);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    client.println("Connection: close\r\n");

    // read server response    
    while(client.connected())
    {
      while(client.available())
      {
        inChar = client.read();
        Serial.write(inChar);
        // set connectLoop to zero if a packet arrives
        connectLoop = 0;
      }
      connectLoop++;
      // if more than 10000 milliseconds since the last packet
      if(connectLoop > 10000)
      {
        // then close the connection from this end.
        Serial.println();
        Serial.println(F("Timeout"));
        client.stop();
      }
      // this is a delay for the connectLoop timing
      delay(1);
    }
    Serial.println();
    Serial.println(F("disconnecting."));
    // close client end
    client.stop();
    //client.flush(); 
  }
  else
  {
    Serial.println("connection failure");
  }

  if(SDavailable != false) {
    digitalWrite(4, LOW);
    digitalWrite(10, HIGH);

    File fh = SD.open("test.txt",FILE_READ);
    if(!fh)
    {
      Serial.println("SD open fail");
      return;    
    }
    while(fh.available())
    {
      char ch = fh.read();
      if(ch == '\n') {
        newLineFound();
      }
      else if(ch == '\r') {
        // do nothing
      }
      else if(chPos < 59) {
        netBuffer[chPos] = ch;
        chPos++;
        netBuffer[chPos] = 0;
      }
    }
    fh.close();
  }  
}

server response

HTTP/1.1 200 OK
Date: Tue, 28 May 2013 14:35:00 GMT
Server: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i mod_autoindex_color PHP/5.2.8
X-Powered-By: PHP/5.2.8
Content-Length: 270
Connection: close
Content-Type: text/html

array(1) {
  ["netBuffer"]=>
  string(52) "CRM001,20130527094010,-6.88123,107.58243,0.11,321.77"
}
'CRM001','20130527094010','-6.88123','107.58243','0.11','321.77'Array
(
    [netBuffer] => CRM001,20130527094010,-6.88123,107.58243,0.11,321.77
)
Successfully insert to DB
disconnecting.

Anybody can help me in this case?

  if(client.connect(server, 80))
  {  
    client.print("GET /arduino/insert2.php?netBuffer=");
    client.print(netBuffer);
    client.println(" HTTP/1.1");

Don't you want to do this when you find a new line, not at some random time in loop()?

I know i have to send get request each time new line is found. But i don't know how to write the code, i'll try it since i got the code from the forum and i have a very poor acknowledge in programming. But i'll try to get it working.

Thanks

The client.connect() call is what connects to the server. That entire if block needs to be moved into the function that you wrote that gets called when the \n is found.

Thanks Pauls...

Now i can send the the data to the sd card but the problem is its loop forever. once the last line is send, its restart and resend from the first line again. How can i detect the end of file / last line and then stop sending to the server and recheck if there's new line, send it.

#include <TinyGPS.h>
#include <SD.h>
#include <stdlib.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 
  0x90, 0xA2, 0xDA, 0x0D, 0xD2, 0xC2 };
IPAddress ip(192,168,0,3);
IPAddress gateway(192,168,0,1);
IPAddress subnet(255,255,255,0);
IPAddress server(192,168,0,5);
EthernetClient client;
boolean SDavailable;
char inChar;
int connectLoop;

char netBuffer[54];
byte myTest[2];

void setup() {
  Serial.begin(9600);
  // disable w5100
  pinMode(10,OUTPUT);
  pinMode(4, OUTPUT);

  digitalWrite(10, LOW); //ethernet on
  digitalWrite(4, HIGH); //SD card off
  Ethernet.begin(mac, ip, gateway);

  Serial.print("Starting SD...");
  digitalWrite(10, HIGH);
  digitalWrite(4, LOW);

  if(!SD.begin(4)) {
    Serial.println("failed");
    SDavailable = false;
  }
  else {
    SDavailable = true;
    Serial.println("ok");
  }
}

void loop() {
  if(SDavailable != false) {
    digitalWrite(4, LOW);
    digitalWrite(10, HIGH);  
    File fh = SD.open("test.txt",FILE_READ);
    int chPos = 0;
    int lineNo = 0; 
    if(!fh)
    {
      Serial.println("SD open fail");
      return;    
    }
    while(fh.available())
    {
      char ch = fh.read();
      if(ch == '\n') {
        chPos = 0;
        sscanf(netBuffer,"%u","%u","%u","%u","%u","%u",&myTest[0],&myTest[1],&myTest[2],&myTest[3],&myTest[4],&myTest[5]);  
        //Serial.println(netBuffer);
        lineNo++;


        digitalWrite(10, LOW);
        digitalWrite(4, HIGH);
        if(client.connect(server, 80))
        {  
          client.print("GET /arduino/insert2.php?netBuffer=");
          client.print(netBuffer);
          client.println(" HTTP/1.1");
          client.print("Host: ");
          client.println(server);
          client.println("Connection: close\r\n");

          // read server response    
          while(client.connected())
          {
            while(client.available())
            {
              inChar = client.read();
              Serial.write(inChar);
              // set connectLoop to zero if a packet arrives
              connectLoop = 0;
            }
            connectLoop++;

            // if more than 10000 milliseconds since the last packet
            if(connectLoop > 10000)
            {
              // then close the connection from this end.
              Serial.println();
              Serial.println(F("Timeout"));
              client.stop();
            }
            // this is a delay for the connectLoop timing
            delay(1);
          }
          Serial.println();
          Serial.println(F("disconnecting."));
          // close client end
          client.stop();
          //client.flush(); 
        }
        else
        {
          Serial.println("connection failure");
        }
      }
      else if(ch == '\r') {
        //do nothing
      }
      else if(chPos < 52) {
        netBuffer[chPos] = ch;
        chPos++;
        netBuffer[chPos] = 0;
      }
    }
    fh.close();
  }
}

once the last line is send, its restart and resend from the first line again.

Because you are telling it to. Why is the code to read the SD card in loop(), where it will run over and over again, rather than in setup() where it will run once?

My apologize...
If i put the code in setup, can i get and send a new value when a new line is added to the file on SD card? since setup function will only run once after each powerup or reset of the Arduino board.

Thank you

If i put the code in setup, can i get and send a new value when a new line is added to the file on SD card? since setup function will only run once after each powerup or reset of the Arduino board.

I think that you need to reconsider what you are doing.

How is the data being added to the SD card? Certainly, the Arduino knows when that happens, and could send the data to the server at that time.

Sending all the data in the file on the SD card every time the Arduino resets doesn't really seem necessary. Either the client or the server should keep track of which record was last sent to the server, and the Arduino should only send newer records to the server.

Of course, it would be helpful if you explained what you were trying to accomplish instead of how you think you should do it.

Here is what i'm trying to accomplish :

  1. Log data to Sd Card (test.txt) every 10 second. This loop forever because i use sd card data as a backup.
  2. Once client is available, open test.txt read and send the data line by line to gateway application on server. I use a simple php script for this.
  3. If client not available, stop sending data and remember the last line sent to server.
  4. Once the client available open the test.txt and continue send the data start from the line after the last sent record.

I want to create a new file for every week. since the file stored in sd card will be more than one i need to rename the file after all its content is sent to server. If a new file is created and there's still any data that hasn't been sent to the server on the previous file, then once a client is available find the file and the last line sent and continue sending the data. I'm thinking about this idea because the ethernet connection is not alway available, it will only available a few hours in a day.

Here is my code so far :

#include <TinyGPS.h>
#include <SD.h>
#include <stdlib.h>
#include <SPI.h>
#include <Ethernet.h>

TinyGPS gps;
static char dtostrfbuffer[20];
int CS = 4;
int ETH = 10;
int LED = 13;

byte mac[] = { 
  0x90, 0xA2, 0xDA, 0x0D, 0xD2, 0xC2 };
IPAddress ip(192,168,0,3);
IPAddress gateway(192,168,0,1);
IPAddress subnet(255,255,255,0);
IPAddress server(192,168,0,5);
EthernetClient client;
boolean SDavailable;

//Define String
String SD_date_time = "invalid";
String DB_date_time = "invalid";
String SD_lat = "invalid";
String SD_lon = "invalid";
String SD_speed = "invalid";
String SD_heading = "invalid";
char inChar;
int connectLoop;
char netBuffer[54];
byte data[2];

static void gpsdump(TinyGPS &gps);
static bool feedgps();
static void print_float(float val, float invalid, int len, int prec, int SD_val);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_dbdate(TinyGPS &gps);
static void print_str(const char *str, int len);


int freeRam() {
  extern int __heap_start,*__brkval;
  int v;
  return (int)&v - (__brkval == 0 ? (int)&__heap_start : (int) __brkval);  
}

void setup()
{
  //Serial interfaces
  Serial.begin(9600);
  Serial3.begin(4800);

  //set pinmode
  pinMode(ETH, OUTPUT);
  pinMode(CS, OUTPUT);

  //start ethernet
  digitalWrite(ETH, LOW); //ethernet on
  digitalWrite(CS, HIGH); //SD card off
  Ethernet.begin(mac, ip, gateway);

  //Connect to the SD Card
  Serial.println("Starting SD card...");
  digitalWrite(ETH, HIGH);
  digitalWrite(CS, LOW);
  if(!SD.begin(CS))
  {
    Serial.println("Card Failure");
    //return;
    SDavailable = false;
  }
  else
  {
    Serial.println("Card initialized"); 
    SDavailable = true;
  }
  Serial.print("Free SRAM= ");
  Serial.print(freeRam());
  
  //start read & send data
  if(SDavailable != false) {
    digitalWrite(4, LOW);
    digitalWrite(10, HIGH);  
    File fh = SD.open("test.txt",FILE_READ);
    int chPos = 0;
    int lineNo = 0; 
    if(!fh)
    {
      Serial.println("SD open fail");
      return;    
    }
    while(fh.available())
    {
      char ch = fh.read();
      if(ch == '\n') {
        chPos = 0;
        sscanf(netBuffer,"%u","%u","%u","%u","%u","%u",&data[0],&data[1],&data[2],&data[3],&data[4],&data[5]);  
        //Serial.println(netBuffer);
        lineNo++;
        Serial.println(lineNo);
        digitalWrite(10, LOW);
        digitalWrite(4, HIGH);
        if(client.connect(server, 80))
        {  
          client.print("GET /arduino/insert2.php?netBuffer=");
          client.print(netBuffer);
          client.println(" HTTP/1.1");
          client.print("Host: ");
          client.println(server);
          client.println("Connection: close\r\n");

          // read server response    
          while(client.connected())
          {
            while(client.available())
            {
              inChar = client.read();
              Serial.write(inChar);
              // set connectLoop to zero if a packet arrives
              connectLoop = 0;
            }
            connectLoop++;

            // if more than 10000 milliseconds since the last packet
            if(connectLoop > 10000)
            {
              // then close the connection from this end.
              Serial.println();
              Serial.println(F("Timeout"));
              client.stop();
            }
            // this is a delay for the connectLoop timing
            delay(1);
          }
          Serial.println();
          Serial.println(F("disconnecting."));
          // close client end
          client.stop();
          //client.flush(); 
        }
        else
        {
          Serial.println("connection failure");
        }
      }
      else if(ch == '\r') {
        //do nothing
      }
      else if(chPos < 59) {
       netBuffer[chPos] = ch;
      chPos++;
        netBuffer[chPos] = 0;
      }
    }
    fh.close();
  }
  //end read & send data  
}


void loop()
{
  String SDString ="";
  bool newdata = false;
  unsigned long start = millis();

  
  while (millis() - start < 10000)
  {
    if (feedgps())
      newdata = true;
  }

  gpsdump(gps);
  SDString = "CRM001," + SD_date_time + "," + SD_lat + "," + SD_lon + "," + SD_speed + "," + SD_heading; 
  //write data to sd card
  if (SDavailable !=false) {
    digitalWrite(CS, LOW);
    digitalWrite(ETH, HIGH);
    if(SD_date_time != "invalid")
      digitalWrite(LED, HIGH);
    else
      digitalWrite(LED, LOW);

    //open file log.txt
    File dataFile = SD.open("test.txt", FILE_WRITE); 
    if (dataFile)
    {
      dataFile.println(SDString);
      Serial.println(SDString);
    }
    else
    {
      Serial.println("\nCouldn't open the log file!");
    } 
    dataFile.close(); 
  }  
}

static void gpsdump(TinyGPS &gps)
{
  float flat, flon;
  unsigned long age, date, time, chars = 0;
  unsigned short sentences = 0, failed = 0;
  gps.f_get_position(&flat, &flon, &age); 
  print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE,3, 5, 1); //LATITUDE
  print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE,3, 5, 2); //LONGITUDE
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
  print_date(gps); //DATE AND TIME
  //print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 8, 2, 0);
  print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 3, 2, 4);
  print_float(gps.f_speed_kmph(), TinyGPS::GPS_INVALID_F_SPEED, 3, 2, 3);
}

static void print_int(unsigned long val, unsigned long invalid, int len)
{
  char sz[32];
  if (val == invalid)
    strcpy(sz, "*******");
  else
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz[i] = ' ';
  if (len > 0) 
    sz[len-1] = ' ';
  //Serial.print(sz);
  feedgps();
}


static void print_float(float val, float invalid, int len, int prec, int SD_val)
{
  char sz[32];
  if (val == invalid)
  {
    strcpy(sz, "*******");
    sz[len] = 0;
    if (len > 0) 
      sz[len-1] =' ';
    for (int i=7; i<len; ++i)
      sz[i] = ' ';
    //Serial.print(sz);
    if(SD_val == 1) SD_lat = sz;
    else if(SD_val == 2) SD_lon = sz;
    else if(SD_val== 3) SD_speed = sz;
    else if(SD_val== 4) SD_heading = sz;
  }
  else
  {
    //Serial.print(val, prec);
    if (SD_val == 1) SD_lat = dtostrf(val,3,5,dtostrfbuffer);
    else if (SD_val == 2) SD_lon = dtostrf(val,3,5,dtostrfbuffer);
    else if (SD_val == 3) SD_speed = dtostrf(val,4,2,dtostrfbuffer);
    else if (SD_val == 4) SD_heading = dtostrf(val,4,2,dtostrfbuffer);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1);
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(" ");
  }
  feedgps();
}


static void print_date(TinyGPS &gps)
{
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned long age;
  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
  if (age == TinyGPS::GPS_INVALID_AGE)
  {
    //Serial.print("*******    *******    ");
    SD_date_time = "invalid";
  }
  else
  {
    char sz[32];
    sprintf(sz,"%02d%02d%02d%02d%02d%02d",
    year, month, day, hour, minute, second);
    //Serial.print(sz);
    SD_date_time = sz;
  }
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
  feedgps();
}



static void print_str(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    //Serial.print(i<slen ? str[i] : ' ');
    feedgps();
}

static bool feedgps()
{
  while (Serial3.available())
  {
    if (gps.encode(Serial3.read()))
      return true;
  }
  return false;
}

Any help and advice would be very appreciated

Thank you

  1. Once client is available, open test.txt read and send the data line by line to gateway application on server. I use a simple php script for this.

This has to be checked in loop. There will never be a client connected when the Arduino boots up and runs setup().

  1. If client not available, stop sending data and remember the last line sent to server.

This is the part that you are not now doing. Well, that and making sure that when sending you are only sending new records.

The code that you have been posting, though, does not agree at all with this description. The code that have been posting has the Arduino acting as a client, connecting to a server. This description supposes that the Arduino is a server, serving up data when a client requests it.

Please clarify.

If i check the client available in loop() then where should i put the code for reading sd card and send data? In my previous post code i put the code in loop but its send the data over and over again.

How can i check the last sent record and use it once the client available.?

My apologize my missunderstanding about client and server. The point is i need to send data from a file on sd card to mysql database on a computer.

If i check the client available in loop() then where should i put the code for reading sd card and send data?

First, you MUST define whether the Arduino is a server, responding to clients (if(client.available()) or a client (making GET requests to a server). Until then, we are wasting out time.

How can i check the last sent record and use it once the client available.?

Count the records that have been sent. Send only records with higher numbers. It is easier to do this if each record contains a linearly increasing number.

My apologize my missunderstanding about client and server. The point is i need to send data from a file on sd card to mysql database on a computer.

Then, the Arduino is going to need to be a client, and client.available() will never be true, because that is a server function.

You will, I guess, need to determine, on each pass through loop() whether server.available() is true. If so, open the file, get the new records, and make GET requests.

I really can't figure out how to type the code with my very poor knowledge. I know there are lot of sample included with arduino. But combining many sketch into one working sketch is a hard thing for me.

Then, the Arduino is going to need to be a client, and client.available() will never be true, because that is a server function.

Then my previous code is not agree with this quote?
Any sample sketch will be easier to learn for me.

Thank you very much