Array / data type problem on SD Card

Hello,

I have bought an Ethernet shield with a SD slot and now I want to read and write array of different data types and formats with a function which is small as possible.
So far I think it is a good plan :wink: but now I have the problem that I cant find any really helpful examples and I am out of ideas how to do this.
At the end I want to save two files on my SD card, one with connection info's for a server Connection which is really "read only":

Ethernet data
byte mac[] = {0x00,0xFF,0xCE,0x54,0xB0,0x6E};
byte ip[] = {192,168,178,100};
int port = 80;

Here specially my problem is that I don't know how to read an array of byte data. I found many examples how to read one int value or strings but not really how to read an array and the data type functions. :frowning:

The second file should include values from a sensor (always exactly 50 values) in one int array and should be readable AND writable.

Values array
int lastRange[] = {10,10,0,5,9,7,2, ... };

Here is the same problem that I don't know how to write an array (read i think should be the same like in the first file only without type cast or something similar ?!)

So if it is possible the first file should look like this:

File config.txt

mac = 0x00,0xFF,0xCE,0x54,0xB0,0x6E
ip = 192,168,178,100
port = 80

and the second one like this (with of cause 50 values I just shorted it here):

File values.txt

lastRange = 10,10,0,5,9,7,2, ...

My actual basic function from an older project is this one, which works fine for single int values but of cause not for arrays and this daat types:

void readFile(File fileName) {
  actualFile = SD.open(fileName);
  if (actualFile) {
    while (actualFile.available()) {
      readOneLine(actualFile);
    }
    actualFile.close();
    Serial.println("read done");
  } else {
  	Serial.println("read err");
  }
}

void readOneLine(File actualFile) {
  char linebuf[160];
  int counter = 0;
  
  memset(linebuf,0,sizeof(linebuf));
  while (actualFile.available()) {
    linebuf[counter]=actualFile.read();
    if (linebuf[counter]=='\n') break;
    if (counter < sizeof(linebuf) - 1) { counter++; } }
    if (strstr(linebuf,"ip")) { temp = linebuf; }
    else if (strstr(linebuf,"mac")) { temp = linebuf; }
    else if (strstr(linebuf,"port")) { port = atoi(linebuf); }
    else if (strstr(linebuf,"values")) { lastRange = atoi(linebuf); }
    else {
    Serial.print("empty line");
  }
}

I hope that someone can help me here and can give me one or two good hits to solve this problem, I would be really thankful :smiley:

Best regards
Steffen

PS. I really tried to format this post in a good readable way i hope this helps you to understand what i want to do :wink:

Do newlines cost money in your country ? :wink:
Writing a lot of code in a single line does not make it better to read.

I'm not sure that reading the file is okay. What happens when a '\r' is read ?

Do you want to read the file, and start the Ethernet with those settings ?
That is possible. However reading that file gonna take some coding, to check everything.

Which Arduino board are you using (I hope the Mega 2560), the Uno runs out of memory when using the Ethernet and SD and some sensors.

Must the file "values.txt" contain readable data ? Or is it possible to store binary values ?
When you use readable data, and the text is "10,5,1", you can not change that into "10,100,1", because the '5' is only one character and there is no way to get '100' in there.

You see, I have many questions because I don't yet understand your project.
You should to start with a test-sketch, for reading and writing files. When that is okay, you can combine it with the Ethernet.