Chat Server - No response back from Serial saying "We have a new client"

I'm doing the Ethernet Chat Server example. I'm curious if the needed mac address is found on the sticker on back of Ethernet board or is it found by typing "ipconfig /all" and using the physical address for Ethernet Adapter Local Area Network? I'm also using the IPv4 address in the example, which was found using "ipconfig" in command prompt.

I ask because I'm not getting feedback in the serial monitor by use of statement Serial.println("We have a new client"); I believe the cause to be no value in "client" for

 // wait for a new client:
  EthernetClient client = server.available();

What am I doing wrong? =(

I'm curious if the needed mac address is found on the sticker on back of Ethernet board or is it found by typing "ipconfig /all" and using the physical address for Ethernet Adapter Local Area Network?

Are you expecting the Arduino to respond to "ipconfig 'all"? Are you typing it using the Arduino's keyboard?

I'm also using the IPv4 address in the example, which was found using "ipconfig" in command prompt.

Really? The Arduino responded to the ipconfig command? That's incredibly hard to believe.

What am I doing wrong?

How is the Arduino with Ethernet shield connected to the network?

ok I see that using "ipconfig /all" is going to give me my laptop's IP and mac address. I'm connecting the Arduino + Ethernet shield to my laptop using a Ethernet cable. It is my understanding to use the mac address found on the sticker of the Ethernet shield. How can I find out the Arduino's IP, Subnet, and Gateway once connected? :fearful:

While at Control Panel\All Control Panel Items\Network and Sharing Center I see my Local Area Connect has no network access, but my Wireless Network Connection has internet access.

I'm connecting the Arduino + Ethernet shield to my laptop using a Ethernet cable.

Why? Why are you not connecting it to your router?

It is my understanding to use the mac address found on the sticker of the Ethernet shield.

Oh, good. Subtlety wasn't lost on you.

How can I find out the Arduino's IP, Subnet, and Gateway once connected?

Read them from the source code where you assign them. (Based on the IP you have your router reserve for the Arduino.)

While at Control Panel\All Control Panel Items\Network and Sharing Center I see my Local Area Connect has no network access, but my Wireless Network Connection has internet access.

And? The Arduino with Ethernet shield is not giving your laptop access to the internet.

I'm now connecting my ethernet shield to my router. how do I see the IP my router reserved for the Arduino? I really don't know where to go with

Read them from the source code where you assign them. (Based on the IP you have your router reserve for the Arduino.)

Please provide further direction. Thank YOu.

encryptor:

Read them from the source code where you assign them. (Based on the IP you have your router reserve for the Arduino.)

Please provide further direction. Thank YOu.

You program it into your Arduino's code.

Post all of your code.

I'm trying to set the values of IP, subnet, and gateway correctly. I'm not sure how to find out these values after plugging in the ethernet shield to the router.

/*
 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
 * Analog inputs attached to pins A0 through A5 (optional)
 
 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 (found on sticker of Ethernet Shield)
// and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x97, 0x39 };
IPAddress ip(192,168,1,100);
IPAddress gateway(192,168,1, 1);
IPAddress subnet(255, 255, 255, 0);


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

void setup()
{
  // initialize the ethernet device
  Ethernet.begin(mac, ip, gateway, subnet);
  // start listening for clients
  server.begin();
 // Open serial communications and wait for port to open:
  Serial.begin(9600);


  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)
    {
      // clead 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);
    }
  }
}

You need to look up how to configure your router. Usually, it's as simple as pointing your browser to 198.162.0.1.

The router will assign one of a block of IP addresses to any device that connects, including the Arduino.

That is not what you generally want it to do, if it is to be a server. So, you need to tell the router to assign a specific address to the Arduino every time it connects.

That, then, is the address you put in the code.

The default values for gateway and subnet are usually good. You can simply ignore them.

The router will assign one of a block of IP addresses to any device that connects, including the Arduino.

That is not what you generally want it to do, if it is to be a server. So, you need to tell the router to assign a specific address to the Arduino every time it connects.

I'm in the router's administration tool. Are telling me to change an IP for Static DNS 1? How can I insert a screen shot in this forum so you can see what I see? This isn't as easy as inserting a work document with pic.

Here is what you do:

Go into a computer on your network and do the IP config to get your computer's IP address, gateway and subnet mask. Set the Arduino's Subnet mask and gateway to the same. Pick a number close to the computer's IP address. Ping it to make sure no other computer on the network has it. If they don't, use that as the Arduino's IP address.

Ok I'm using the subnet and gateway that resulted from ipconfig. I 1st pinged my router's IP and got a response. I then pinged an IP that is +1 difference from my router's IP. The host was unreachable and hence not currently in use. Do I add this created IP in the router's administration tools under Static DNS 2? I say Static DNS 2 because Static DNS 1 has my router's IP. I'm not getting the print in the serial monitor saying "We have a client". How can I post a screen shot here?

COMMAND PROMPT:

Wireless LAN adapter Wireless Network Connection:

IPv4 Address. . . . . . . . . . . : 192.168.1.100
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1

Arduino SKETCH:

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


C:\Users\encryptor>ping 192.168.1.100

Pinging 192.168.1.100 with 32 bytes of data:
Reply from 192.168.1.100: bytes=32 time<1ms TTL=128
Reply from 192.168.1.100: bytes=32 time<1ms TTL=128
Reply from 192.168.1.100: bytes=32 time<1ms TTL=128
Reply from 192.168.1.100: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.1.100:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

C:\Users\encryptor>ping 192.168.1.101

Pinging 192.168.1.101 with 32 bytes of data:
Reply from 192.168.1.100: Destination host unreachable.
Reply from 192.168.1.100: Destination host unreachable.
Reply from 192.168.1.100: Destination host unreachable.
Reply from 192.168.1.100: Destination host unreachable.

Ping statistics for 192.168.1.101:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

I'm in the router's administration tool.

Look at the lan IP address of the router (normally 192.168.1.1 or 192.168.0.1). That is what you use for the gateway, and use the first three numbers for the basis of the arduino IP address. Below is some test code that will show the router assigned IP address in the serial monitor.

//zoomkat 2-13-12
//DNS and DHCP-based web client test code
//for use with IDE 1.0
//open serial monitor and send an e to test
//and to see test result
//for use with W5100 based ethernet shields
//browser equivelant URL: 
// http://web.comporium.net/~shb/arduino.txt
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605 

#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
char serverName[] = "web.comporium.net"; // zoomkat's test web page server
EthernetClient client;

//////////////////////

void setup(){
  Serial.begin(9600); 
  Serial.println("DNS and DHCP-based web client test 2/13/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }
  // print your local IP address:
  Serial.print("Arduino IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print("."); 
  }
  Serial.println();
  Serial.println();
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

encryptor:
Ok I'm using the subnet and gateway that resulted from ipconfig. I 1st pinged my router's IP and got a response. I then pinged an IP that is +1 difference from my router's IP. The host was unreachable and hence not currently in use. Do I add this created IP in the router's administration tools under Static DNS 2? I say Static DNS 2 because Static DNS 1 has my router's IP. I'm not getting the print in the serial monitor saying "We have a client". How can I post a screen shot here?

You don't have to do anything with the router unless you plan on accessing the Arduino from outside of the local network. Did you update the Arduino's code with the new IP address? Are you trying to connect through a computer that is on the local network? What telnet client are you using? What does the telnet client say?

You can post a screenshot either by uploading it to an image hosting site and surrounding the picture's link in [ IMG ] tags, or you can click additional options and upload it directly to the site.

Arrch:

encryptor:
Ok I'm using the subnet and gateway that resulted from ipconfig. I 1st pinged my router's IP and got a response. I then pinged an IP that is +1 difference from my router's IP. The host was unreachable and hence not currently in use. Do I add this created IP in the router's administration tools under Static DNS 2? I say Static DNS 2 because Static DNS 1 has my router's IP. I'm not getting the print in the serial monitor saying "We have a client". How can I post a screen shot here?

You don't have to do anything with the router unless you plan on accessing the Arduino from outside of the local network. Did you update the Arduino's code with the new IP address? Are you trying to connect through a computer that is on the local network? What telnet client are you using? What does the telnet client say?

You can post a screenshot either by uploading it to an image hosting site and surrounding the picture's link in [ IMG ] tags, or you can click additional options and upload it directly to the site.

I tried the example given. Thank You! It did provide me with my arduino's IP. Yes I updated arduino code with the new IP. I use ipconfig in the command prompt to figure out the gateway and subnet IPs of my wireless router. I plug my arduino + ethernet shield with Cat5 cable into the first ethernet port on my wireless router. What do you mean by what telnet client am I using?? I'm using telnet port 23 in the code. What I'm going by is the serial monitor and I'm expecting to see "We have a new client!" printed there, which I'm still not getting.

encryptor:
What do you mean by what telnet client am I using?? I'm using telnet port 23 in the code. What I'm going by is the serial monitor and I'm expecting to see "We have a new client!" printed there, which I'm still not getting.

So you are just opening up the Serial monitor and expecting it to let you know someone has connected? You have to actually connect using a telnet client for that message to appear....

lol! That is what I'm doing. I really don't know much about telnet other than it a communication protocol that allows text to be sent across the line. I haven't connected using a telnet client for that message to appear. How can I do that? Thanks. :disappointed_relieved:

The below code is the example chatserver code. Upload it. Open the arduino serial monitor. Then go windows start > all programs > accessorys, and open "command prompt". Type in telnet 192.168.1.177 and hit the enter key. You should get a black screen with a blinking cursor. start typing and see what appears in the serial monitor.

/*
 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
 * Analog inputs attached to pins A0 through A5 (optional)
 
 created 18 Dec 2009
 by David A. Mellis
 modified 12 March 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 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() {
  // initialize the ethernet device
  Ethernet.begin(mac, ip, gateway, subnet);
  // start listening for clients
  server.begin();
  // open the serial port
  Serial.begin(9600);
  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) {
      // clead 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);
    }
  }
}

For some reason I'm not able to connect to my arduino device using Telnet. Why isn't this working? My ethernet cable is connected between router and arduino device. I've tried a few different approaches:
My devices IP is 192.168.1.118

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\encryptor>telnet 192.168.1.118
Connecting To 192.168.1.118...Could not open connection to the host, on port 23:
Connect failed

Welcome to Microsoft Telnet Client

Escape Character is 'CTRL+]'

Microsoft Telnet> open 192.168.1.118
Connecting To 192.168.1.118...Could not open connection to the host, on port 23:
Connect failed =(

My arduino device is showing to be connected.

C:\Users\encryptor>ping 192.168.1.118

Pinging 192.168.1.118 with 32 bytes of data:
Reply from 192.168.1.118: bytes=32 time=1ms TTL=128
Reply from 192.168.1.118: bytes=32 time=1ms TTL=128
Reply from 192.168.1.118: bytes=32 time<1ms TTL=128
Reply from 192.168.1.118: bytes=32 time=1ms TTL=128

Ping statistics for 192.168.1.118:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms

encryptor:
For some reason I'm not able to connect to my arduino device using Telnet. Why isn't this working?

Telnet will attempt to connect to the TCP port reserved for the telnet protocol (23) by default. The output you posted indicates that there is nothing at IP 192.168.1.118 accepting connections on TCP port 23. Either you have the address wrong, or your sketch is not listening on that port. Perhaps it's listening on a different port. If so, you can direct the Telnet client to connect to that other port by adding it to the command line. For example, this command would try to connect to the standard HTTP port (80):

telnet 192.168.1.118 80