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
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. ![]()
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 ![]()
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 ![]()