Dave
Dave

Reputation: 83

I need to be able to read a large CSV file to an Arduino Uno 600 bytes at a time

I have a project where I have built a sensor network based on the arduino uno. It is a temp sensor and light sensor and an air flow meter. I am taking readings 5 times a second and saving the data to a CSV file on an SD card.

After a period of time I need to stop sensing and send the data to a server using HTTP POST. As the CSV file is large I can only do this by reading the logfile 600 bytes at a time sending that data and then reading the next 600 bytes and so on.

I still cant figure out how to read the next 600 bytes of information from the files.

Do I need some kind of pointer to remember where in the file I stopped reading?

Upvotes: 1

Views: 996

Answers (1)

Nkosi
Nkosi

Reputation: 247423

Rough example of how to read file in chunks

File file = SD.open(filename, FILE_READ);
char buffer[600];
if(file) {  
    while(file.position() < file.size()) {
        int bytesRead = file.readBytes(buffer, sizeof(buffer));

        //Sudo code...
        // Post buffer 
    }
}

Upvotes: 1

Related Questions