ChatServer Ethernet Example Not Working

Hello,

I am having some issues running the ChatServer example on the Adafruit Featherwing M0, with the Ethernet Featherwing shield.

I have uncommented Ethernet.init(10), but other than that, the code has not changed.

Windows 10 Firewall is off and disabled for every type of network. The error appears to deal with the EthernetClient client = server.available();. This is never true, which is a problem.

Here is the code:

/*
 Chat Server

 A simple server that distributes any incoming messages to all
 connected clients.  To use, telnet to your device's IP address and type.
 You can see the client's input in the serial monitor as well.
 Using an Arduino Wiznet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe

 */

#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.
// gateway and subnet are optional:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);
IPAddress myDns(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);


// telnet defaults to port 23
EthernetServer server(23);
boolean alreadyConnected = false; // whether or not the client was connected previously

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

  // initialize the ethernet device
  Ethernet.begin(mac, ip, myDns, gateway, subnet);

  // 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
  }

  // 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 listening for clients
  server.begin();

  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) {
    if (!alreadyConnected) {
      // clear out the input buffer:
      client.flush();
      Serial.println("We have a new client");
      client.println("Hello, client!");
      alreadyConnected = true;
    }

    if (client.available() > 0) {
      // read the bytes incoming from the client:
      char thisChar = client.read();
      // echo the bytes back to the client:
      server.write(thisChar);
      // echo the bytes to the server as well:
      Serial.write(thisChar);
    }
  }
}

Any help is appreciated. Thanks!

had similar problems with modern routers - see post #6
what output appears on the serial monitor?
open the command prompt and run ipconfig/all - what is displayed?

1 Like

That probably means that your Windows machine doesn't get a connection to the Feather which might be an Arduino problem but doesn't have to be so.

Start by telling us how your network is organized. As you don't use DHCP on the Feather I guess you use fixed IPs in the whole network. Is your Windows PC also connected by Ethernet cable? What's the output of ipconfig on that host?

ipconfig /all yields the following:

Windows IP Configuration

   Host Name . . . . . . . . . . . . : MEEM-3144-W
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : mtu.edu

Unknown adapter Local Area Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : TAP-Windows Adapter V9
   Physical Address. . . . . . . . . : 00-FF-F3-8F-FE-93
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

Wireless LAN adapter Local Area Connection* 12:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter #3
   Physical Address. . . . . . . . . : B8-08-CF-3A-39-B7
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

Wireless LAN adapter Local Area Connection* 13:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter #4
   Physical Address. . . . . . . . . : BA-08-CF-3A-39-B6
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Intel(R) Ethernet Connection (2) I219-LM
   Physical Address. . . . . . . . . : 28-F1-0E-21-66-AB
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::c0ea:3762:6891:edd9%8(Preferred)
   Autoconfiguration IPv4 Address. . : 169.254.237.217(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . :
   DHCPv6 IAID . . . . . . . . . . . : 170455310
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-24-F0-2E-1E-28-F1-0E-21-66-AB
   DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                       fec0:0:0:ffff::2%1
                                       fec0:0:0:ffff::3%1
   NetBIOS over Tcpip. . . . . . . . : Enabled

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . : mtu.edu
   Description . . . . . . . . . . . : Intel(R) Dual Band Wireless-AC 8260
   Physical Address. . . . . . . . . : B8-08-CF-3A-39-B6
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::549f:cd2a:4936:3295%12(Preferred)
   IPv4 Address. . . . . . . . . . . : 141.219.207.145(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.252.0
   Lease Obtained. . . . . . . . . . : Friday, March 18, 2022 3:02:45 PM
   Lease Expires . . . . . . . . . . : Friday, March 18, 2022 3:32:45 PM
   Default Gateway . . . . . . . . . : 141.219.204.1
   DHCP Server . . . . . . . . . . . : 141.219.72.22
   DHCPv6 IAID . . . . . . . . . . . : 163055823
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-24-F0-2E-1E-28-F1-0E-21-66-AB
   DNS Servers . . . . . . . . . . . : 141.219.70.130
                                       141.219.100.30
   NetBIOS over Tcpip. . . . . . . . : Enabled

@horace I looked at #6 and attempted to implement the code you provided. It seems as though I cannot configure ethernet using DHCP.

**edit should I have Ethernet.init(10); present somewhere?

in post #1 your program defines

IPAddress ip(192, 168, 1, 177);
IPAddress myDns(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);

I just noticed the subnet should be 255.255.255.0

apart from that the ipconfig reports for the Ethernet adapter on the PC

 Autoconfiguration IPv4 Address. . : 169.254.237.217(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.0.0

which is a different subnet etc to that defined in your program

try changing your program to match the PC

IPAddress ip(169.254.237.100);
IPAddress subnet(255.255.0.0);

and change the ethernet initialise to

 // initialize the ethernet device
  Ethernet.begin(mac, ip);

does it then work? if not
can the PC then ping your IPaddress 169.254.237.100 ?
run wireshark to view traffic on the therenet adapter

Edit: the adafruit-wiz5500-wiznet-ethernet-featherwing.pdf decument reports the chip selsct uses the CS pin
Which is connected to pin #10 on Feather Teensy 3, 32u4, 328p, M4 and M0, pin #15
on ESP8266, and PB4 on WICED

So here is my new code and ipconfig /all:

/*
 Chat Server

 A simple server that distributes any incoming messages to all
 connected clients.  To use, telnet to your device's IP address and type.
 You can see the client's input in the serial monitor as well.
 Using an Arduino Wiznet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe

 */

#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.
// gateway and subnet are optional:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(169,254,237,100);
IPAddress subnet(255,255,0,0);


// telnet defaults to port 23
EthernetServer server(23);
boolean alreadyConnected = false; // whether or not the client was connected previously

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

  // initialize the ethernet device
  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 native USB port only
  }

  // 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 listening for clients
  server.begin();

  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) {
    if (!alreadyConnected) {
      // clear out the input buffer:
      client.flush();
      Serial.println("We have a new client");
      client.println("Hello, client!");
      alreadyConnected = true;
    }

    if (client.available() > 0) {
      // read the bytes incoming from the client:
      char thisChar = client.read();
      // echo the bytes back to the client:
      server.write(thisChar);
      // echo the bytes to the server as well:
      Serial.write(thisChar);
    }
  }
}
Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Intel(R) Ethernet Connection (2) I219-LM
   Physical Address. . . . . . . . . : 28-F1-0E-21-66-AB
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::c0ea:3762:6891:edd9%8(Preferred)
   Autoconfiguration IPv4 Address. . : 169.254.237.217(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . :
   DHCPv6 IAID . . . . . . . . . . . : 170455310
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-24-F0-2E-1E-28-F1-0E-21-66-AB
   DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                       fec0:0:0:ffff::2%1
                                       fec0:0:0:ffff::3%1
   NetBIOS over Tcpip. . . . . . . . : Enabled

It seemed as though your last post was a little conflicting in terms of the subnet. Could you please clarify? I think I got to the intended code, but am not sure.

Unfortunately, I have gotten no new results. It seems like the client is still nonexistent. I should also mention that the ping was successful.

OK! So I used your example in #6 and after realizing that I was using the wrong server address, it worked! I really like the Java implementation and will stick to that! Thank you so much @horace!

if your PC can ping the Featherwing M0 that is progress

what does the Arduino Serial Monitor report?

what program are you running on the PC ? what output does it give?
port 23 may have problems as it is the Telenet port
I tend to avoid all low numbered ports and use 10000 upwards
I seem to remember you have the windows firewall switched off or you would need to give inbound access to the server port

good to hear you got it working!
Java is very good for serious client/server work - in particular multithreaded servers which will run on low cost Raspberry PI systems as well as PCs

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.