Daten(IP) von SD lesen

Lan-Police:
liest ja keine TXT Datei aus !?

Hab da meine Probleme das mit:
...
zu verbinden...!

Lernen, lernen, lernen!

Hier habe ich Dir mal das Auslesen einer Datei auf SD-Karte mittels SdFat-Library und das Splitten von Bytes aus dem gelesenen String in einzelne Zahlen kombiniert.

Durch Entfernen der Kommentarstriche bei nur einer einzigen Zeile kannst Du mit dem folgenden Code sogar die Datei auf der Karte mit der gewünschten IP-Nummer beschreiben, denn auch eine Schreibfunktion ist dabei.

#include <SdFat.h>
SdFat sd;
//------------------------------------------------------------------------------
// store error strings in flash memory
#define error(s) sd.errorHalt_P(PSTR(s))
//------------------------------------------------------------------------------
// filename for storing configuration data
#define CONFIGFILE "config.txt"
//------------------------------------------------------------------------------
// 16 is minimum buffer size to store 4 3-digit numbers, three dots and trailing \0 character
char ipNumBuf[16];  

//------------------------------------------------------------------------------
void readIpConfigFile (char *fn)
{
  SdFile rdfile(fn, O_READ); // open file for reading
  // check for error opening file
  if (!rdfile.isOpen()) error("readIPConfigFile");
  int bytesRead = rdfile.fgets(ipNumBuf, sizeof(ipNumBuf));;
  rdfile.close();
}

//------------------------------------------------------------------------------
void makeIpConfigFile() {
  SdFile wrfile(CONFIGFILE, O_WRITE | O_CREAT | O_TRUNC);   // create or open test file
  // check for error opening file
  if (!wrfile.isOpen()) error("MakeConfigFile");
  wrfile.write_P(PSTR("123.145.156.178\n"));
  wrfile.close();
}
//------------------------------------------------------------------------------

int getIntFromString (char *stringWithInt, byte num)
// input: pointer to a char array
// returns an integer number from the string (positive numbers only!)
// num=1, returns 1st number from the string
// num=2, returns 2nd number from the string, and so on
{
  char *tail; 
  while (num>0)
  {
    num--;
    // skip non-digits
    while ((!isdigit (*stringWithInt))&&(*stringWithInt!=0)) stringWithInt++;
    tail=stringWithInt;
    // find digits
    while ((isdigit(*tail))&&(*tail!=0)) tail++;
    if (num>0) stringWithInt=tail; // new search string is the string after that number
  }  
  return(strtol(stringWithInt, &tail, 0));
}  
//------------------------------------------------------------------------------


void setup(void) {
  Serial.begin(9600);
  // the next three lines are for Arduino UNO and Ethernet Shield
  pinMode(10, OUTPUT);  // set the SS pin as an output (necessary!)
  digitalWrite(10, HIGH);  // but turn off the W5100 chip!
  if (!sd.begin(4,SPI_HALF_SPEED)) sd.initErrorHalt();
  
// remove comment from the next line to create the config file
//  makeIpConfigFile();

  readIpConfigFile(CONFIGFILE);
  Serial.print("IP number: ");
  Serial.println(ipNumBuf);
  Serial.println();
  Serial.print("Die einzelnen Bytes der IP-Nummer: ");
  for (int i=0;i<4;i++)
  {
     Serial.print(getIntFromString(ipNumBuf, i+1));
     Serial.print("  ");
  }
  Serial.println();
}

void loop(void) {}