Arduino Ethernet-Shield Server und Client gleichzeitig

Hallo,

ich habe in einem anderen Post schon mal eine ähnliche Frage gestellt, aber ich denke die Frage müsste in einem eigenen Thread behandelt werden.

In meinem Projekt will ich Daten mit einem Arduino auf einer SD-Karte sammeln und diese via Ethernet (FTP-Server FileZilla) vom Arduino an den Computer senden.
Auf der anderen Seite will ich via LabVIEW über Ethernet Strings zu meinem Arduino senden und so mit dem Controller kommunizieren.

Ich habe das Beispiel meines FTP Servers und das Beispiel wie ich Strings verschicke versucht in ein Programm zusammenzuführen, dann bekamm ich diese Fehlermeldung.

SD_und_ETH:79:22: error: conflicting declaration 'EthernetServer server'

 EthernetServer server(3363);

                      ^

T:\XXX.ino:ino:75:11: note: previous declaration as 'IPAddress server'

 IPAddress server( 169, 254, 155, 167 );

           ^

T:\XXX.ino: In function 'void setup()':

SD_und_ETH:169:10: error: 'class IPAddress' has no member named 'begin'

   server.begin();

          ^

T:\XXX.ino: In function 'void loop()':

SD_und_ETH:218:34: error: 'class IPAddress' has no member named 'available'

   EthernetClient client = server.available();

                                  ^

Mehrere Bibliotheken wurden für "DS3231.h" gefunden
 Benutzt: C:\Users\XXX\Documents\Arduino\libraries\DS3231
 Nicht benutzt: C:\Users\XXX\Documents\Arduino\libraries\DS3231-master
exit status 1
conflicting declaration 'EthernetServer server'

Problem ist kla.

Ich versuche auf der einen Seite das Arduino als Client und einmal als Server zu betreiben. Das geht nicht so einfach. Hat jemand eine Idee wie ich die beiden Dienste miteinander kombienieren kann?

Code mit der LabVIEW Kommunikation:

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0x59, 0x67}; //adresse mac de la carte
IPAddress ip( 169, 254, 155, 2 );
IPAddress gateway( 169, 254, 155, 1 );
IPAddress subnet( 255, 255, 255, 0 );
String msg="";
char thisChar;
const int led_rot = 8;
EthernetServer server(3363);

void setup() {
  // initialize the ethernet device
  pinMode(led_rot, OUTPUT);
  Ethernet.begin(mac, ip);
  // start listening for clients
  server.begin();
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    //; // wait for serial port to connect. Needed for Leonardo only
    digitalWrite(led_rot, LOW);
  }

  Serial.print("Chat server address:");
  Serial.println(Ethernet.localIP());
}

void loop() {
  // wait for a new client:
  EthernetClient client = server.available();

  // when the client sends the first byte, say hello:
  if (client.connected()) {
    if (client) {
      while (client.available() != 0) {
        thisChar = client.read();
        msg += String(thisChar);
      }
      //msg ;
      Serial.println(msg);

      if (msg == "49") {
        digitalWrite(led_rot, HIGH);
        delay(1000);
      }
      else
      {
        digitalWrite(led_rot, LOW);
      }
      msg="";
    }
  }
}

Und der Code des FTP-Servers

/*
   FTP passive client for IDE v1.0.1 and w5100/w5200
   Posted October 2012 by SurferTim
   Modified 6 June 2015 by SurferTim
*/

#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>
// comment out next line to write to SD from FTP server
#define FTPWRITE

// this must be unique
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x67 };

// change to your network settings
IPAddress ip( 169, 254, 155, 2 );
IPAddress gateway( 192, 168, 155, 1 );
IPAddress subnet( 255, 255, 255, 0 );

// change to your server
IPAddress server( 169, 254, 155, 167 );

EthernetClient client;
EthernetClient dclient;

char outBuf[128];
char outCount;

// change fileName to your file (8.3 format!)
String fileName = " ";

void setup()
{
  Serial.begin(9600);

  digitalWrite(10, HIGH);

  if (!SD.begin(4))
  {
    Serial.println(F("SD init fail"));
  }

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  digitalWrite(10, HIGH);
  delay(2000);
  Serial.println(F("Bitte Textateiname eingeben eingeben: (z.b. 20190428.txt)"));
}

void loop()
{

  while (Serial.available()) {
    fileName = Serial.readString();
    fileName.remove(12);
    Serial.println(fileName);
  }

  if (fileName != " ")
  {
    if (doFTP()) Serial.println(F("FTP OK"));
    else Serial.println(F("FTP FAIL"));
    fileName = " ";
  }

  //  if(inChar == 'r')
  //  {
  //    readSD();
  //  }

}

File fh;

byte doFTP()
{

  Serial.println(F("doFTP"));
#ifdef FTPWRITE
  fh = SD.open(fileName, FILE_READ);
#else
  SD.remove(fileName);
  fh = SD.open(fileName, FILE_WRITE);
#endif

  if (!fh)
  {
    Serial.println(F("SD open fail"));
    return 0;
  }

#ifndef FTPWRITE
  if (!fh.seek(0))
  {
    Serial.println(F("Rewind fail"));
    fh.close();
    return 0;
  }
#endif

  Serial.println(F("SD opened"));

  if (client.connect(server, 21)) {
    Serial.println(F("Command connected"));
  }
  else {
    fh.close();
    Serial.println(F("Command connection failed"));
    return 0;
  }

  if (!eRcv()) return 0;

  client.println(F("USER myuser"));

  if (!eRcv()) return 0;

  client.println(F("PASS mypassword"));

  if (!eRcv()) return 0;

  client.println(F("SYST"));

  if (!eRcv()) return 0;

  client.println(F("Type I"));

  if (!eRcv()) return 0;

  client.println(F("PASV"));

  if (!eRcv()) return 0;

  char *tStr = strtok(outBuf, "(,");
  int array_pasv[6];
  for ( int i = 0; i < 6; i++) {
    tStr = strtok(NULL, "(,");
    array_pasv[i] = atoi(tStr);
    if (tStr == NULL)
    {
      Serial.println(F("Bad PASV Answer"));

    }
  }

  unsigned int hiPort, loPort;

  hiPort = array_pasv[4] << 8;
  loPort = array_pasv[5] & 255;

  Serial.print(F("Data port: "));
  hiPort = hiPort | loPort;
  Serial.println(hiPort);

  if (dclient.connect(server, hiPort)) {
    Serial.println(F("Data connected"));
  }
  else {
    Serial.println(F("Data connection failed"));
    client.stop();
    fh.close();
    return 0;
  }

#ifdef FTPWRITE
  client.print(F("STOR "));
  client.println(fileName);
#else
  client.print(F("RETR "));
  client.println(fileName);
#endif

  if (!eRcv())
  {
    dclient.stop();
    return 0;
  }

#ifdef FTPWRITE
  Serial.println(F("Writing"));

  byte clientBuf[64];
  int clientCount = 0;

  while (fh.available())
  {
    clientBuf[clientCount] = fh.read();
    clientCount++;

    if (clientCount > 63)
    {
      dclient.write(clientBuf, 64);
      clientCount = 0;
    }
  }

  if (clientCount > 0) dclient.write(clientBuf, clientCount);

#else
  while (dclient.connected())
  {
    while (dclient.available())
    {
      char c = dclient.read();
      fh.write(c);
      Serial.write(c);
    }
  }
#endif

  dclient.stop();
  Serial.println(F("Data disconnected"));

  if (!eRcv()) return 0;

  client.println(F("QUIT"));

  if (!eRcv()) return 0;

  client.stop();
  Serial.println(F("Command disconnected"));

  fh.close();
  Serial.println(F("SD closed"));
  return 1;
}

byte eRcv()
{

  Serial.println(F("eRcv"));
  byte respCode;
  byte thisByte;

  while (!client.available()) delay(1);

  respCode = client.peek();

  outCount = 0;

  while (client.available())
  {
    thisByte = client.read();
    Serial.write(thisByte);

    if (outCount < 127)
    {
      outBuf[outCount] = thisByte;
      outCount++;
      outBuf[outCount] = 0;
    }
  }

  if (respCode >= '4')
  {
    efail();
    return 0;
  }

  return 1;
}


void efail()
{

  Serial.println(F("efail"));
  byte thisByte = 0;

  client.println(F("QUIT"));

  while (!client.available()) delay(1);

  while (client.available())
  {
    thisByte = client.read();
    Serial.write(thisByte);
  }

  client.stop();
  Serial.println(F("Command disconnected"));
  fh.close();
  Serial.println(F("SD closed"));
}

void readSD()
{

  Serial.println(F("readSD"));
  fh = SD.open(fileName, FILE_READ);

  if (!fh)
  {
    Serial.println(F("SD open fail"));
    return;
  }

  while (fh.available())
  {
    Serial.write(fh.read());
  }

  fh.close();
}

Danke schon mal.

EthernetServer server
IPAddress server

Du definierst 2 mal server mit unterschiedlichen Typen.

Das knallt!

Verwende unterschiedliche Bezeichner.

combie:
Du definierst 2 mal server mit unterschiedlichen Typen.

Das knallt!

Verwende unterschiedliche Bezeichner.

Uhhhh ja das hat geknallt. Habe mal nen Eserver aus dem einen gemacht. Dann ging es. Besten Danke!