I have been playing around with an arduino ethernet shield, trying to get basic examples to work, to no avail. Here is my setup:
The Arduino Mega 2560 is connected to the computer via usb and the ethernet shield is stacked upon it. I have tried many variations of the examples that come with the arduino software, and none seemed to work properly.After lots of debugging with wireshark, I figured that:
I can't use DHCP, because it just hangs at the
Ethernet.begin(mac)
call.When I try with a static ip, the
Ethernet.localIP()
function returns 0.0.0.0. However, I can ping my device from my computer using the ip I have set and the device seems to receive and send packets properly.The problem now is that for some reason it drops the tcp connections.E.g here is the code I run that comes the closest to working:#include <SPI.h> #include <Ethernet.h> byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192,168,2,27); IPAddress server(192,168,2,52); EthernetClient client; void setup() { // start the Ethernet connection: Ethernet.begin(mac, ip); // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } Serial.println("a"); delay(1000); Serial.println("connecting..."); if (client.connect(server, 23)) { Serial.println("connected"); } else { Serial.println("connection failed"); } Serial.println(Ethernet.localIP()); } void loop() { // if there are incoming bytes available // from the server, read them and print them: if (client.available()) { char c = client.read(); Serial.print(c); } // as long as there are bytes in the serial queue, // read them and send them out the socket if it's open: while (Serial.available() > 0) { char inChar = Serial.read(); if (client.connected()) { client.print(inChar); } } // if the server's disconnected, stop the client: if (!client.connected()) { Serial.println(); Serial.println("disconnecting."); client.stop(); // do nothing: while(true); } }
Its basically the Ethernet/TelnetClient example.
I have set up a telnet server on my computer. Now this is the arduino/computer exchange:
The arduino sends a RST packet, but my server goes on to send it the greeting and login prompt. I have tried the same with an arduino uno, and have also tried disconnecting the usb and using another power supply. So, what could be the issue?