Empfang einer UDP-Message über Ethercard Library möglich?

How has an understandable description of the ethercard library?

I tried www.aelius.com, but is completely not understandable for a beginner. Most of the examples are far away from practical requirements.

I am planning the follwing application:

A simple webpage which configures a hardware circuit with an ardnuino nano. I use the ethernet shield ENC28J60 wth the library ethercard. I like to enter integer values on a browser which must be read by the arduino.

How knows a very simple code, not a science dissertation.

Thanks Tom

Tom09:
How knows a very simple code, not a science dissertation.

Probably best found with a WIZ5100 or the like.

Tom09:
I tried www.aelius.com, but is completely not understandable for a beginner. Most of the examples are far away from practical requirements.

It's not clear to me whether you're talking about some examples on that website or not. If you haven't already, take a look at the example sketches that come with the EtherCard library. You'll find them in the Arduino IDE under File > Examples > EtherCard after you install the library.

There's also some documentation here:

Hallo,
ich sende über die Ethercard Library UDP-Daten an einen LINUX-Server. Die Daten werden auf dem Server auch korrekt empfangen. Der Server sendet bei jedem empfangenen Telegramm ein Rücktelegramm.
Leider habe ich bisher weder ein funktionsfähiges Beispiel gefunden, mit welchen Befehlen man empfangene UDP-Programme von einem Webserver auslesen kann, noch eine aussagefähige Dokumenation von der Ethercard Library.

Falls jemand bereits ein derartiges Programm schon einmal geschrieben hat, dass auch wirklich funktioniert, würde ich mich über eine Rückmeldung freuen. Nach diversen Recherchen habe ich gesehen, dass dies anscheinend mit "ether.packetLoop(ether.packetReceive())" funktionieren soll.

Ethernet_Client.ino (1.93 KB)

Setze Deinen Code bitte direkt ins Forum. Benutze dazu Codetags (</>-Button oben links im Forumseditor oder [code] davor und [/code] dahinter ohne *). So ist er auch auf portablen Geräten lesbar.
Das kannst Du auch noch nachträglich ändern.

Warum benutzt Du nicht die EthernetUdp?
Dort ist für Dich intertessant (ungetestet):

char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
// im Setup 
EthernetUDP.begin(localPort); 

// im loop
  int packetSize = Udp.parsePacket();
  if(packetSize)
  {
     Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
  }

Gruß Tommy

Genau. Nichts einfacheres als Udp Telegramme erhalten und auswerten.

Hier mal ein Auszug aus einem umfangreicheren Sketch zur Anregung

void checkUDP()
{
  int packetSize;
  char* pos;
  memset(packetBuffer, 0, sizeof(packetBuffer));

  // if there's data available, read a packet
  packetSize = Udp.parsePacket();   // nachschauen ob was angekommen ist
  if (packetSize)
  {
    // read the packet into packetBuffer
    Udp.read(packetBuffer, sizeof(packetBuffer) - 2 ); //
    packetBuffer[sizeof(packetBuffer) - 1 ] = 0;
/*
    Serial << "UDP erhalten: " << packetSize << " Zeichen  " ;
    for(int i=0; i<sizeof(packetBuffer);i++)
    {
      Serial << (char)(packetBuffer[i]);
    }
    Serial << " <--" << endl;
*/


    pos = strstr(packetBuffer, "#200M");  // 200
    float windAnalog;
    if (pos)
    {
      windAnalog  = atof(pos + 5);
      windSpeed = windAnalog * 0.02929 * 1024 / 971;
      //   Serial << F("udp Windspeed=") << pos << "m/s" << endl;

    }

    pos = strstr(packetBuffer, "#210M");
    if (pos)
    {
      salfumantKg  = atof(pos + 5);
      //  Serial << F("Salfumant: ") << _FLOAT(salfumantKg,3) << F(" KG") << endl;
    }

    pos = strstr(packetBuffer, "#211M");
    if (pos)
    {
      Ph  = atof(pos + 5);
      //   Serial << F("PH: ") << _FLOAT(Ph,2) << endl;
    }

    pos = strstr(packetBuffer, "#213M");
    if (pos)
    {
      PhActual  = atof(pos + 5);
      //    Serial << F("PhActual: ") << _FLOAT(Ph,2) << endl;
    }


    pos = strstr(packetBuffer, "#201M");
    if (pos)
    {
      dachsensor = atof(pos + 5);
      tempLuft = dachsensor;
      //     Serial << F("TempLuft=") << tempLuft << " C" << endl;
    }
    // bis hier ok
    /**/
    pos = strstr(packetBuffer, "#202M"); 
    if (pos)
    {
      tempSonneDach = atof(pos + 5);
      if (tempSonneDach > tempSonne) tempSonne = tempSonneDach;

    }

    pos = strstr(packetBuffer, "#203M");
    if (pos)
    {
      int fehler = atoi(pos + 5);
      if (fehler)  Serial << F("Beim ESP war eine Messung falsch, Fehler=") << fehler << endl;
    }


    if (!strncmp(packetBuffer, "#82M", 4)) {  // Daten vom Schiebereglerinstrument 82
    //  Serial << F("UDP erhalten: ") << (char) packetBuffer << endl;

      eepromdaten.minWasserStand = atoi(packetBuffer + 4);
    }

  //  if (!strncmp(packetBuffer, "#74M<", 5)) Serial << F("UDP erhalten: ") << packetBuffer << endl;




      if (!strncmp(packetBuffer, "#27M", 4)) {  // Daten vom Schiebereglerinstrument 27
        Serial << F("UDP erhalten: ") << atoi(packetBuffer + 4) << endl;
        eepromdaten.distanzSR04 = atoi(packetBuffer + 4);
      }
      Serial << F("Alles gespeichert!") << endl;
    }

    }


  }
  return;
}

Danke für die Hinweise,
leider bekomme ich bereits beim kompilieren der beiden Code-Beispiele zahlreiche Fehlermeldungen, wie
"die Klasse UDP wurde in Ethernet UDP umbenannt" oder dass irgenwelche Libraries fehlen.

Falls jemand einen vollständigen und wichtig f u n k t i o n i e r e n d e n Code hat, den man per Cut und Paste nutzen kann würde ich mich über ein Feedback freuen. Ich muss nur kurze UDP-Strings an einen Server mit einer festen IP-Adresse senden und der Server gibt mir ab und zu Steuermeldungen in Form von UDP-Strings.

Für eine derartige Anwendung hatte ich einen Raspery PI im Einsatz, wobei hierfür eine Socket-Verbindung entwickelt wurde, die sowohl auf dem Server als auch auf dem Rasperry lief. Der Raspery PI ist aber für diese Anwendung überdimensioniert. Ich hatte daher die Hoffnung diese Übertragung mit einem Microcontroller vom Typ ATMEL unter Verwendung eines Ethernet-Chips zu realisieren.

I am looking of a simple code example, which sends data via UDP to a server and the server sends me back UDP messages.

I developed this kind of connection with an Rasperry PI before, based on a socket link. But for this small application the Rasperry PI is oversized.

Warum muss das mit der Ethercard lib sein? Das ENC28J60 Modul habe ich wegen Unzuverlässigkeit pensioniert und gegen ein W5100 der gleichen Größe ersetzt.

Richtige Entscheidung. Das Ding sollte man nur entsorgen.

Gruß Tommy

crosspost
english: Empfang einer UDP-Message über Ethercard Library möglich? - Deutsch - Arduino Forum
german: https://forum.arduino.cc/index.php?topic=633018.0

crosspost
english: https://forum.arduino.cc/index.php?topic=601152.0
german: https://forum.arduino.cc/index.php?topic=633018.0

Schau dir mal die EthernetUIP Lib an. Die ist befehlskompatibel mit der Standard Lib. Das verbessert die Probleme mit der Hardware etwas, aber nicht ganz.

Thanks for pointing this out @noiasca!

@Tom09 I've merged your cross posts. Yes, this makes a huge mess of the thread in two languages, but that's what you get for cross posting.

Cross posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes writing a detailed answer on this thread, without knowing that someone else already did the same in the other thread.

Repeated cross posting will result in a suspension from the forum.

In the future, please take some time to pick the forum section that best suits the topic of your question and then only post once to that forum section. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum section. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.