Arduino Wifi ChatServer Failure

First of all apologies, I'm fairly new to all this but have managed to, so far install the IDE and follow the site based examples up to WifiChatServer. Whereupon I'm stumped.

The problem is.... I have installed the software (changed the WPA login details to my own) and have established a wireless connection. It's confirmed an IP address and sits waiting for a connection to be made.

I've opened telnet, pinged the IP and had a response. But when I ssh the IP all I get is...

ssh: connect to host 192.168.1.7 port 22: Connection refused

[Process completed]

I've also tried scanning the ports available on the address, but all it does is come back saying "Port Scan complete' but no further details.

Now I suspect that my Wireless Airport Extreme to be the issue (but I'm not sure). I've tried switching off my firewall but this seems to make no difference. Do I have to enable the communication/port manually? Is there any other way of checking theAarduino is connected? I've tried iStumbler but it doesn't seem to show. Not sure if it should, or is an indication of the problem

Any help in pointing me in the right direction greatly appreciated, as I've spent a fortnight trying things and scratching my head? If I'm being a numpty, happy for someone to show me the error of my ways!

Thanks

Hi Doc, I haven't played with any of the ethernet shields yet but I am not completely inexperienced at networking and looking at your post makes me want to ask a couple of questions:

Which ethernet shield are you playing with? (not sure it will make a lot of difference to me but might entice other posters to reply if more info like this...)

What does your sketch look like right now?

Why do you think it should be capable of SSH? (Is there something mentioning SSH regarding the shield? Does part of the sketch you have uploaded claim to be an openssh-server implentation?)

Try the below client test code without making changes to your router’s normal setup.

//zoomkat 9-22-12
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields
//remove SD card if inserted

#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(){

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600); 
  Serial.println("Better client test 9/22/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
}

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.1"); //download text
    client.println("Host: web.comporium.net");
    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

}

Apologies, I didn’t make myself clear. I’m using an Arduino Wifi Shield (R3 I think - I’m away form home currently and can’t check)

The sketch I’m using is the one shown on Arduino’s website - http://arduino.cc/en/Tutorial/WiFiChatServer copied below. The use of telnet is mentioned in the preamble:

/*
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.

This example is written for a network using WPA encryption. For
WEP or WPA, change the Wifi.begin() call accordingly.

Circuit:

  • WiFi shield attached

created 18 Dec 2009
by David A. Mellis
modified 31 May 2012
by Tom Igoe

*/

#include <SPI.h>
#include <WiFi.h>

char ssid = “yourNetwork”; // your network SSID (name)
char pass = “secretPassword”; // your network password (use for WPA, or use as key for WEP)

int keyIndex = 0; // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

WiFiServer server(23);

boolean alreadyConnected = false; // whether or not the client was connected previously

void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println(“WiFi shield not present”);
// don’t continue:
while(true);
}

// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);

// wait 10 seconds for connection:
delay(10000);
}
// start the server:
server.begin();
// you’re connected now, so print out the status:
printWifiStatus();
}

void loop() {
// wait for a new client:
WiFiClient 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);
}
}
}

void printWifiStatus() {
// print the SSID of the network you’re attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print your WiFi shield’s IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print(“signal strength (RSSI):”);
Serial.print(rssi);
Serial.println(" dBm");
}

DocHoliday:
I’ve opened telnet, pinged the IP and had a response. But when I ssh the IP all I get is…

ssh: connect to host 192.168.1.7 port 22: Connection refused

[Process completed]

It sounds like you are getting confused by the terminology.

The window you type commands like ping into, is a shell. Sometimes called a command prompt, sometimes a command line. On the Windows OS you can Open a shell by clicking an icon labelled MSDos Prompt or similar. On OSX and Linux you access the shell by clicking a Terminal icon, usually.

Telnet is a simple TCP network protocol and also the name of the client application used to connect to a Telnet server. Typically a Telnet server listens for Telnet clients on TCP Port 23.

SSH is a much more complicated TCP protocol. Typically a SSH server listens for SSH clients on TCP Port 22. SSH is similar to telnet but the data is encrypted.

To connect to the Chat Server, you will need to start a Telnet client (not an SSH client).

Windows ships with a Telnet client but it needs to be installed from Programs and Features on versions after XP.
Linux and OSX have a client installed by default.

Once you have a Telnet client available. Open a Shell and type.

telnet <ip of the chat server>[pre]
E.g 
[pre]telnet 192.168.1.1

You will probably find it works.

MattS,

Apologies you are right, I have been sloppy with my explanation.

(I'm on a Mac btw). I've opened Terminal and obtained a command prompt and pinged (ping 192.168.1.x) another client. It shows a response including response time, which I take to mean that it has send and successfully communicated with that device i.e. if it hadn't, an error would have occurred.

I've then opened Terminal again, and selected the Remote Login (telnet) option. This brings up a command line, whereby I type telnet 192.168.1.x only to get the error message I previously mentioned.

I'm confused because this implies the device is there, but connection is denigned because of permissions. Only I don't know how to correct the permissions issue. Any ideas?

Have you upgraded the wifi shield firmware? I upgraded the shield firmware and it works ok with my server sketches.

DocHoliday:
(I’m on a Mac btw)…
I’ve then opened Terminal again, and selected the Remote Login (telnet) option.

For testing purposes, don’t bother with selecting Remote Login from the menu.

You just need to type the telnet command into a plain old terminal shell.

telnet <ip_address> <port>

You can test telnet is working by typing

telnet www.google.com 80

You should see some text saying you are connected to www,google.com and the escape sequence ‘^]’ the ^ indicates the Ctl key.
Type GET, then the return key. If all is well, you will see a bunch of HTML and be disconnected. If not you may need to check your Mac’s firewall settings. System Preferences / Security / Firewall.

To connect to the chat server demo sketch, you don’t need the 80 on the telnet command line. Telnet will default to connecting to port 23.

MattS-UK

Apologies for not responding sooner - life, it got in the way!

I’ve tried telneting Google and all is well. I can see the html text as you indicated. So thanks, at least I know I can get a connection.

However if I try telnet 192.168.1.7 80 to connect to the device (in a new telnet session as you suggest) I get the same Connection refused response

Any other suggestions?

MattS-UK:
To connect to the chat server demo sketch, you don’t need the 80 on the telnet command line. Telnet will default to connecting to port 23.

:slight_smile:

In your code is the line
WiFiServer server(23);
Which instructs the WiFiShield to accept connection requests made to port 23

Adding 80 to the end of the telnet command instructs telnet to attempt connection to port 80. You have not told your Arduino to accept connections to port 80, so the connection is not accepted and telnet informs you the connection attempt was refused.

What version IDE are you using? If IDE v1.0.5 or later (like v1.5.5) you need a shield firmware upgrade. The old firmware had connection problems. This short sketch should show you what version firmware you are using. If 1.0.0, you need to upgrade. If 1.1.0, it is current.

#include <SPI.h>
#include <WiFi.h>

char ssid[] = "yourNetwork"; //  your network SSID (name) 
char pass[] = "secretPassword";    // your network password (use for WPA, or use as key for WEP)

int keyIndex = 0;            // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600); 
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    // don't continue:
    while(true);
  } 
  
  // check wifi shield firmware version
  Serial.print(F("Firmware version: "));
  Serial.println(WiFi.firmwareVersion());

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:    
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  } 

  // you're connected now, so print out the status:
  printWifiStatus();
 }

void loop() {
}

FYI: It won’t be much of a chat server either. The server library for the wifi shield uses only one socket for server functions. That should be one client connection at a time, so you can only chat with yourself.

SurferTim:
The old firmware had connection problems.

True, but if DocHoliday puts this in his code
WiFiServer server(23);

And subsequently types this at the command line
telnet 192.168.1.7 80
It ain't gonna connect, whatever version of firmware he uses!

Best fix the problems he has and not the problems he has yet to run into, I feel.

Best fix the problems he has and not the problems he has yet to run into, I feel.

I agree. I was only adding to your response. If it is a connection issue, get the connection working first. Part of that may be the firmware. If the OP has the ports correct, and it still won’t connect, that is probably the firmware.

However, if the OP is expecting this to be a chat server, he/she should stop now. It won’t work as a chat server using only one socket. You will only be able to chat with yourself. With the wifi server library/firmware the way it is, a second connection attempt could cause corruption, wrong data, or a crash.