Hello,
I just bought an Arduino UNO Rev3, and this W5500 ethernet module to go with it. I used the diagram from the Ethernet library to connect the ethernet module and the Arduino. I'm also using the "WebServer" example, provided by the IDE, to configure the Arduino as a web server. I haven't done any modifications to the code, except changing the IP address and adding a few print statements for debugging.
When I upload the code, I can successfully ping the Arduino from my computer, so IP stack is good:
$ ping -c3 10.200.40.199
PING 10.200.40.199 (10.200.40.199) 56(84) bytes of data.
64 bytes from 10.200.40.199: icmp_seq=1 ttl=128 time=0.241 ms
64 bytes from 10.200.40.199: icmp_seq=2 ttl=128 time=0.242 ms
64 bytes from 10.200.40.199: icmp_seq=3 ttl=128 time=0.241 ms
--- 10.200.40.199 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2062ms
rtt min/avg/max/mdev = 0.241/0.241/0.242/0.000 ms
However, when I try a TCP connection to port 80, the connection is refused by Arduino:
$ nc -vw2 10.200.40.199 80
nc: connect to 10.200.40.199 port 80 (tcp) failed: Connection refused
I'm using the latest version of the Ethernet library (v2.0.2). After some troubleshooting, I noticed that the server.begin() function fails, but I haven't been able to find any details on why. The function doesn't return anything, so I'm kind of stuck and would appreciate some help.
Here's the truncated version of the "WebServer" example and what I'm uploading to the Arduino:
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino WIZnet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
modified 02 Sept 2015
by Arturo Guadalupi
*/
#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(10, 200, 40, 199);
EthernetServer server(80);
void setup() {
Ethernet.init(10); // Most Arduino shields
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.");
}
if(Ethernet.hardwareStatus() == EthernetW5500) {
Serial.println("Hardware is W5500");
}
if(Ethernet.linkStatus() == LinkON) {
Serial.println("Link is ON");
}
// start the server
server.begin();
if(!server) {
Serial.println("Server is NOT listening...");
}
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");
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
Here's the serial output:
Ethernet WebServer Example
Hardware is W5500
Link is ON
Server is NOT listening...
server is at 10.200.40.199
What am I doing wrong here?