Arduino Ethernet Shield works on home network not on University network

Hi,

I am relatively new to Arduino and know very little about networking. I heard getting the arduino connected was very easy with the wifi shield and sure enough on my home network it worked well.

I am using my arduino at uni to monitor environmental conditions and ideally wanted it to email me if things got to hot.

Plugged my ethernet shield onto my arduino uno and uploaded some of the example sketches from Arduino IDE 1.6.1. the code to get the IP address worked:

/*
  DHCP-based IP printer

 This sketch uses the DHCP extensions to the Ethernet library
 to get an IP address via DHCP and print the address obtained.
 using an Arduino Wiznet Ethernet shield.

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

 created 12 April 2011
 modified 9 Apr 2012
 by Tom Igoe

 */

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  // this check is only needed on the Leonardo:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // 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:
    for (;;)
      ;
  }
  // print your local IP address:
  Serial.print("My 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();
}

void loop() {

}

I then tried the webserver example:

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

 */

#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[] = {
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};
IPAddress ip(ip address);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

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


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  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");
    // 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("
");
          }
          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 disconnected");
  }
}

Apart from the serial monitor printing "server is at (ip address)" nothing happens.

I then tried:

#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
byte ip[] = { ip address };
byte server[] = { 64, 233, 187, 99 }; // Google

EthernetClient client;

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);

  delay(1000);
  int serverReading = client.connect (server, 80);
  //Serial.println (serverReading);
  Serial.println("connecting...");

  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");
  }

  //Serial.println (serverReading);
}

void loop()
{
  
  //Serial.println (serverReading);
  
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}

From the web page Ethernet - Arduino Reference

the sketch returns the value of client.connect, which in my case returned: a couple of "1" and many many "0".

Suggesting the connection is initially successful then completely disconnects.

Serial printing the value of client.available also shows that the arduino is not receiving data.

I am at a bit of a loss, ask me for more info if needed.

Cheers

Apart from the serial monitor printing "server is at (ip address)" nothing happens.

Well, it wouldn't until you try connecting to it with a browser. If you did that, you failed to mention having done so.

None of the code you posted is for the WiFi shield. Are you using a Wifi shield, as the post says, or an Ethernet shield, as the title says?

Apologies I meant ethernet shield. When you say connect to a browser I have tried the IP address on google and it just fails to get anything.

Also in the second code example if it connects properly it should display on the serial monitor "new client" from the loop after printing the IP address shouldn't it?

When you say connect to a browser I have tried the IP address on google and it just fails to get anything.

Where did I say "connect to a browser"? You can't connect ANYTHING to a browser.

If your ethernet shield works at home, but not at school, then why are you assuming that there is something wrong with the code or the shield?

The problem CLEARLY is that the school network requires authentication - not just any Tom, Dick, or Sally can use it - and you are NOT taking that into consideration.

PaulS:
The problem CLEARLY is that the school network requires authentication - not just any Tom, Dick, or Sally can use it - and you are NOT taking that into consideration.

I registered my device (its MAC address) with university and I was given a specific IP address for the shield so I was no longer a Tom, Dick or Sally. So I assumed that the system would now recognize the device.

PaulS:
If your ethernet shield works at home, but not at school, then why are you assuming that there is something wrong with the code or the shield?

I didn't say anything was wrong with the shield or code, I just wanted to know if there is a way of connecting the ethernet shield to a network at an institution. As I said I have little experience with networking so I am not even sure it's possible but wanted to see if I could get some help.

Thanks

I have read about the ethernet shield having problems if connected to certain brands of switches or routers, TP-Link in particular. Some D-Link routers have also created problems.

Are you supposed to use a static IP or dhcp on your institution's network? My routers can issue a static dhcp lease. That is different from a static IP.

This might help me and my mate had the same problem, u should try and disable all the firewall from windows because its like you are trying to communicate 2 pcs.
If yoy disable it you can then work it out

i’d suspect the school has mapped your mac to a specific ip...
You need to modify your code to match that static ip... dhcp is unlikely to guess/give you that assigned address.