Mega 2560 Ethernet Probleme

Hallo Gemeinde,

Ich habe mir vor kurzem eine Arduino Mega 2560 mit einem W5100 Ether Shield zugelegt.

Ziel ist es dort mehrere Sensoren anzuschließen und anschließend über FHEM abzufragen.

Zu diesem Zweck soll dann ConfigurableFirmata auf dem mega laufen, aber leider Funktioniert das nicht.

Um mich mit dem Mega vertraut zu machen habe ich erst einmal ein paar von den kleineren Beispielen ausprobiert, das hat auch alles geklappt.

Dann habe ich den WebServer getestet. Hat auch alles geklappt, sowohl über den Seriellen Monitor, als auch über den Browser meines Rechners.

Dann habe ich das ConfigurableFirmata aufgespielt aber dies lässt sich über den Browser nicht abrufen.

Über die firmata_test.exe bekomme ich alle Pins angezeigt und kann diese auch ansteuern.

Ein Ping von meinem PC aus gab mir nur "Zielhost nicht erreicht" aus.

Ich habe verschiedene Einstellungen versucht, aber ohne Erfolg.

Dann habe ich einmal den WebClient Beispiel Sketch geladen und da habe ich dann auch das selbe Problem, kann das Board über den Browser nicht erreichen und beim Ping kommt wieder die Meldung "Zielhost nicht erreicht"

Da das Bord mit dem WebServer Sketch funktioniert, gehe ich mal davon aus das es in Ordnung ist.

Aber was kann es sein das ich das Bord als Client nicht an Pingen oder im Browser ansprechen kann?

Zusammenfassend: `
a WebServer Beispiel funktioniert
b Unbekannter Sketch - da nicht mit gepostet - funktioniert nicht
c WebClient Beispiel funktioniert nicht

korrekt?

Mach mal ein Bild von deinem LAN-Shield. Kein Link. Ein echtes.

OK ich hoffe Du kannst damit etwas anfangen.

ich habe versucht dein Problem mit einem Mega nachzustellen.
Ich verwende ein anderes Ethernet-Shield - eins das für POE vorbereitet ist, die sind um ein paar Dollar teurer funktionieren aber imho besser als jene mit dem Layout das deinem ähnelt. Stichwort Reset und so.

Anyway. Ich glaube es liegt nur an einem Anwenderfehler:

im Webserver Beispiel vergibst du im Sketch eine fixe IP, daher weist du auch genau was du pingen musst.

Das Webclient-Beispiel holt sich mit DHCP eine IP. Die ist in der Regel anders als deine Fixe.
Ergo muss grundsätzlich dein Router mal DHCP aktiviert haben und eine freie aus dem Range zuordnen können.

Du musst also erstmal rausfinden, welche IP dein Board nun bekommen hat. Der originale Sketch gibt die IP-Adresse NICHT aus.

Ich habe mit AngryIP Scanner gesucht, bzw. solltest du die IP auch in deinem Router finden. Der Ping mit der richtigen IP klappt definitiv auch mit dem webclient Beispiel.

Wenn du dennoch nicht weiterkommst, lade die Serial-Ausgabe des webclient-Beispiels in code-Tags hier hoch.

Also dieser Coder hier Funktioniert:

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 77);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10);  // Most Arduino shields
//Ethernet.init(5);   // MKR ETH shield
//Ethernet.init(0);   // Teensy 2.0
//Ethernet.init(20);  // Teensy++ 2.0
//Ethernet.init(15);  // ESP8266 with Adafruit Featherwing Ethernet
//Ethernet.init(33);  // ESP32 with Adafruit Featherwing Ethernet

// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
  ; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Ethernet WebServer Example");

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);

// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
  Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
  while (true) {
    delay(1); // do nothing, no point running without Ethernet hardware
  }
}
if (Ethernet.linkStatus() == LinkOFF) {
  Serial.println("Ethernet cable is not connected.");
}

// start the server
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}


void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
  Serial.println("new client");
  // an http request ends with a blank line
  boolean currentLineIsBlank = true;
  while (client.connected()) {
    if (client.available()) {
      char c = client.read();
      Serial.write(c);
      // if you've gotten to the end of the line (received a newline
      // character) and the line is blank, the http request has ended,
      // so you can send a reply
      if (c == '\n' && currentLineIsBlank) {
        // send a standard http response header
        client.println("HTTP/1.1 200 OK");
        client.println("Content-Type: text/html");
        client.println("Connection: close");  // the connection will be closed after completion of the response
        client.println("Refresh: 5");  // refresh the page automatically every 5 sec
        client.println();
        client.println("<!DOCTYPE HTML>");
        client.println("<html>");
        // output the value of each analog input pin
        for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
          int sensorReading = analogRead(analogChannel);
          client.print("analog input ");
          client.print(analogChannel);
          client.print(" is ");
          client.print(sensorReading);
          client.println("
");
        }
        client.println("</html>");
        break;
      }
      if (c == '\n') {
        // you're starting a new line
        currentLineIsBlank = true;
      } else if (c != '\r') {
        // you've gotten a character on the current line
        currentLineIsBlank = false;
      }
    }
  }
  // give the web browser time to receive the data
  delay(1);
  // close the connection:
  client.stop();
  Serial.println("client disconnected");
}
}

Und dieser hier nicht:

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "www.google.com";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 1, 77);
IPAddress myDns(192, 168, 1, 1);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

// Variables to measure the speed
unsigned long beginMicros, endMicros;
unsigned long byteCount = 0;
bool printWebData = true;  // set to false for better speed measurement

void setup() {
// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10);  // Most Arduino shields
//Ethernet.init(5);   // MKR ETH shield
//Ethernet.init(0);   // Teensy 2.0
//Ethernet.init(20);  // Teensy++ 2.0
//Ethernet.init(15);  // ESP8266 with Adafruit Featherwing Ethernet
//Ethernet.init(33);  // ESP32 with Adafruit Featherwing Ethernet

// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
  ; // wait for serial port to connect. Needed for native USB port only
}

// start the Ethernet connection:
Serial.println("Initialize Ethernet with DHCP:");
if (Ethernet.begin(mac) == 0) {
  Serial.println("Failed to configure Ethernet using DHCP");
  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }
  // try to congifure using IP address instead of DHCP:
  Ethernet.begin(mac, ip, myDns);
} else {
  Serial.print("  DHCP assigned IP ");
  Serial.println(Ethernet.localIP());
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.print("connecting to ");
Serial.print(server);
Serial.println("...");

// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
  Serial.print("connected to ");
  Serial.println(client.remoteIP());
  // Make a HTTP request:
  client.println("GET /search?q=arduino HTTP/1.1");
  client.println("Host: www.google.com");
  client.println("Connection: close");
  client.println();
} else {
  // if you didn't get a connection to the server:
  Serial.println("connection failed");
}
beginMicros = micros();
}

void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
int len = client.available();
if (len > 0) {
  byte buffer[80];
  if (len > 80) len = 80;
  client.read(buffer, len);
  if (printWebData) {
    Serial.write(buffer, len); // show in the serial monitor (slows some boards)
  }
  byteCount = byteCount + len;
}

// if the server's disconnected, stop the client:
if (!client.connected()) {
  endMicros = micros();
  Serial.println();
  Serial.println("disconnecting.");
  client.stop();
  Serial.print("Received ");
  Serial.print(byteCount);
  Serial.print(" bytes in ");
  float seconds = (float)(endMicros - beginMicros) / 1000000.0;
  Serial.print(seconds, 4);
  float rate = (float)byteCount / seconds / 1000.0;
  Serial.print(", rate = ");
  Serial.print(rate);
  Serial.print(" kbytes/second");
  Serial.println();

  // do nothing forevermore:
  while (true) {
    delay(1);
  }
}
}

Ich gehe auch mal davon aus das es nur eine Code Sache sein sollte.

Hab auch schon daran gedacht das es vielleicht an der Firewall liegt, aber am Router ist die Firewall nicht aktiv und am Rechner habe ich sie mal Test weise abgeschaltet.

Setze Deinen Code bitte in Codetags (</>-Button oben links im Forumseditor oder [code] davor und [/code] dahinter ohne *).
Dann ist er besonders für die User von mobilen Geräten besser Lesbar und Du bekommst wahrscheinlich mehr Hilfe.

Gruß Tommy

ich hab mir vorhin extra Zeit für dein Problem genommen. Also ersuche ich dich dass du mein Post auch aufmerksam liest.

Da steht unter anderem:

noiasca:
Wenn du dennoch nicht weiterkommst, lade die Serial-Ausgabe des webclient-Beispiels in code-Tags hier hoch.

Zu 75% steht da die Lösung drinnen (die anderen 24% stehen bereits in meinem Post).

@Tommy56, Danke für die Info, das mit dem Code einfügen hatte ich gesucht aber nicht gefunden, kenne mich hier in dem Forum noch nicht so aus, habs aber jetzt geändert.

@noisca

Du ich bin Dir unendlich Dankbar für Deine Hilfe, aber das mit der Seriellen Ausgabe ist mir glatt durchgegangen, Sorry.

Also zuerst gibt er das hier aus:

Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Set-Cookie: 1P_JAR=2018-11-13-21; expires=Thu, 13-Dec-2018 21:42:31 GMT; path=/; domain=.google.com
Set-Cookie: CGIC=; expires=Wed, 15-May-2019 12:37:07 GMT; path=/complete/search; domain=.google.com; HttpOnly
Set-Cookie: CGIC=; expires=Wed, 15-May-2019 12:37:07 GMT; path=/search; domain=.google.com; HttpOnly
Set-Cookie: NID=146=l79XlprCgZfbuW9HLNWyPT2IYHr-ZrVufsyJGbt5aAyUENYHx4IemeFurmCKstaY1LTRV9_qV0vQzSvQul7cNP92OAP2aBjJQyNHvKNSXbGtSULGct6ob2P1nfyLMK-lKOC1YVEBybaAbbylJ44WS7gpnsKUQKbyxaqL9jkbNQo; expires=Wed, 15-May-2019 21:42:31 GMT; path=/; domain=.google.com; HttpOnly
Accept-Ranges: none
Vary: Accept-Encoding
Connection: close

Und dann kommt dann gibt er einen unglaublich langen Fließtext aus, der ist aber hier fürs Forum zu lang.

das kann nicht der Beginn der Ausgabe sein. Da fehlt was.
Du siehst aber dass die Kommunikation nach außen funktioniert.
Ich bleib dabei. Du pingst die falsche Adresse.

Der Code holt sich erst eine DHCP Adresse, wenn das fehlschlägt geht er auf deine eingetragen. Schau dir mal ganz genau die Kommentare an.

So habs noch mal durchlaufen lassen, da scheint beim C&P was verloren gegangen zu sein.

Initialize Ethernet with DHCP:
  DHCP assigned IP 192.168.1.107
connecting to www.google.com...
connected to 172.217.20.68
HTTP/1.1 200 OK
Date: Tue, 13 Nov 2018 21:58:55 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Set-Cookie: 1P_JAR=2018-11-13-21; expires=Thu, 13-Dec-2018 21:58:55 GMT; path=/; domain=.google.com
Set-Cookie: CGIC=; expires=Wed, 15-May-2019 12:53:31 GMT; path=/complete/search; domain=.google.com; HttpOnly
Set-Cookie: CGIC=; expires=Wed, 15-May-2019 12:53:31 GMT; path=/search; domain=.google.com; HttpOnly
Set-Cookie: NID=146=UBNL8S9Uw1nlC9YMydYQzwKldtjMkvuBYlG47yw6ZCOV9GM1gH-1m5Y4QRFjxCO-s_T6LpNY67lfvkPN725JIXFymKHU9CdR9Y7a2rRlpGHfDZZa8k7M0QWA_0KoznJUmbk-JfmjZqla-aaoMH8D6ABeSZIXcHL1zwBxaYjJnnU; expires=Wed, 15-May-2019 21:58:55 GMT; path=/; domain=.google.com; HttpOnly
Accept-Ranges: none
Vary: Accept-Encoding
Connection: close

Sehe ich das richtig das das Bord die IP 192.168.1.107 hat? Das verstehe ich dann aber nicht, weil ich im Skript ja die IP 192, 168, 1, 77 vorgegeben hatte.

noiasca:
Der Code holt sich erst eine DHCP Adresse, wenn das fehlschlägt geht er auf deine eingetragen. Schau dir mal ganz genau die Kommentare an.

?

OK, habs verstanden den Code mal Testweise angepasst und es hat funktioniert :slight_smile:

  // start the Ethernet connection:
  Serial.println("Initialize Ethernet with static IP:");
  Ethernet.begin(mac, ip, myDns);
    Serial.print("IP = ");
    Serial.println(Ethernet.localIP());

Bis hier hin schon mal Vielen Dank für Deine Geduld und Hilfe.

Würdest Du mir denn auch bei meinem eigentlichen Problem Helfen, ConfigurableFirmata auf meinem Arduino ans laufen zu bekommen?

Ich denke mal da wird ein ähnlich kleiner Fehler vorliegen.

über die test_firmata.exe werden mir alle Pins angezeigt, somit gehe ich mal davon aus das Grundsätzlich Firmata läuft, aber halt wieder die Verbindung zum Netzwerk nicht, kann es da eventuell an dem Port 3030 liegen?

Den Code kann ich hier leider nicht einfügen, zu lang.

Sorry, mit "Firmata" hab ich nichts zu tun.

Wenn du glaubst dass dir jemand helfen kann - du kannst die ino auch als Anhang hochladen. Wenn es mehrere Tabs sind - zippen und hochladen.

Heureka ich habs hinbekommen, jetzt läuft bei mir auch das ConfigurableFirmata.

Das Problem war, ich hatte immer die Configuration für das "Ethernet Shield W5100" verwendet, zum Testen habe ich dann mal die Configuration für den Ship "WIZ5100" verwendet und schon lief alle.

Was mich eigentlich verwundert, da auf dem Ethernet Shield W5100 nämlich der WIZ5100 verbaut ist.

Daher gehe ich mal davon aus das der Code für das "Ethernet Shield" einen Fehler enthält.

Trotzdem waren Deine Tips und Hilfe für mich sehr Lehrreich.

Vielen vielen Dank für Deine Hilfe.