Go Down

Topic: Arduino.cc Wifi Shield Connection Refused (Read 2445 times) previous topic - next topic

pinMode

I'm using the example code and get a ping response from the IP it connects to, but serving from and telnet to a variety of ports always fails with Connection Refused on two different networks. Anyone have a clue?

Code: [Select]

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


char ssid[] = "ckp";      // your network SSID (name)
char pass[] = "password";   // your network password
int keyIndex = 0;                 // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

WiFiServer server(23);

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(2400);
  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);
  }
  server.begin();
  // you're connected now, so print out the status:
  printWifiStatus();
}


void loop() {
  // listen for incoming clients
  WiFiClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("<br />");       
          }
          client.println("</html>");
           break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
   
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}


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");
}


Serial output:

Code: [Select]

Attempting to connect to SSID: ckp
SSID: ckp
IP Address: 10.1.9.24
signal strength (RSSI):-65 dBm
?


Ping:

Code: [Select]

CK:arduino etw$ ping 10.1.9.24
PING 10.1.9.24 (10.1.9.24): 56 data bytes
64 bytes from 10.1.9.24: icmp_seq=0 ttl=255 time=46.712 ms
64 bytes from 10.1.9.24: icmp_seq=1 ttl=255 time=3.614 ms
64 bytes from 10.1.9.24: icmp_seq=2 ttl=255 time=3.679 ms


Telnet:

Code: [Select]

CK:arduino etw$ telnet 10.1.9.24 23
Trying 10.1.9.24...
telnet: connect to address 10.1.9.24: Connection refused
telnet: Unable to connect to remote host

pinMode

Also, no result from port scan:

Code: [Select]

CK:arduino etw$ /Applications/Utilities/Network\ Utility.app/Contents/Resources/stroke 10.1.9.24 0 1000
Port Scanning host: 10.1.9.24

I was having this problem with Arduino IDE 1.0.5. I noticed that going back to 1.0.3 works. Looks like something is bad between 1.0.5 and wifi shield.

MattS-UK

The signal level  at -65dbm is not great.


Check you do not have a firewall running on the host you are trying to connect from.
The error message indicates the connection attempt is being refused (actively), rather than timing out.



SurferTim

#4
Jun 15, 2013, 01:14 pm Last Edit: Jun 15, 2013, 01:55 pm by SurferTim Reason: 1
I don't agree with this. That isn't bad at all.
Quote
The signal level  at -65dbm is not great.


I do agree with this.
Quote
The error message indicates the connection attempt is being refused (actively), rather than timing out.

Are you sure there is not another device responding to the pings? That "connection refused" is a firewall response, and the w5100 has no firewall, (edit:) and I presume the wifi shield has no firewall either. Disconnect the Arduino from your localnet and try the ping again.

BTW, my routers do a similar check when assigning localnet ips with dhcp. They do a ping to the ip about to be assigned to a new client, and if a device responds within a half second, it marks that ip lease as "busy", and gets another free ip from the ip pool.

edit: I use PuTTY in RAW mode to test http connections.

Chr1s


I was having this problem with Arduino IDE 1.0.5. I noticed that going back to 1.0.3 works. Looks like something is bad between 1.0.5 and wifi shield.


THANK YOU! You just saved me.
Indeed, I confirm that the WiFi shield that refused to work corectly since I bought it last thursday (and I paid a hundred of Euros for it!) now works like a charm since I've downgraded the IDE from version 1.0.5 to 1.0.3.

Thank you @marcelrocks, you definitely rock!!! :)

Same problem here. Frustrating - I wasted many hours on trying to get the Wifi Shield working with 1.0.5. After going back to Arduino 1.0.3 it all worked fine. Thanks for posting a temporary fix to this problem!

Sagiv

Hello,
I have the same problem,
I have downgraded to 1.0.3 but still get the same error.
can someone help?
tnx,

SurferTim

Actually, I think the subject line should be "I refuse to do the wifi shield firmware upgrade, and now it doesn't work".

@Sagiv: Post the code you are trying, and also include the security type (open, WEP, WPA, WPA2) that your router uses. Don't include the password tho.


YusifNurizade

Hello,

I had the same problem. I did the firmware upgrade but was still having problems connecting. When I migrated to the 1.0.3 IDE, I was able to connect to the Arduino using Tera Term. Thank you very much for the fix!

While I am able to connect, however, I am having an issue with the echo. What I type in the terminal emulator appear in the IDE Serial Monitor but does not echo back. Has anyone had this problem? I could really use some advice.

Thanks again,
Yusif Nurizade


Go Up