-1

I have an Arduino Uno and a W5100 Ethernet Shield. I am trying to post some data from the Arduino board to the WAMP server running on my computer. I do not have a router so I have directly connected my Ethernet shield stacked onto the Arduino Uno to the laptop's Ethernet port via an Ethernet cable. I have also assigned the Ethernet connection a static IP address 192.168.0.1 and my localhost page opens when I put this address in my browser.

In my Arduino sketch I have assigned the Arduino shield an IP address 192.168.0.4, i.e. on the same IP segment. When I try to do client.connect to the server (192.168.0.1), i.e. localhost, I get "Connection failed".

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

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0x6F, 0xED }; 
IPAddress ip(192,168,0,4);
byte server[]={192,168,0,1};

int value=9;
EthernetClient client;

void setup() {
  // Serial.begin starts the serial connection between computer and Arduino
  Serial.begin(9600);
  // start the Ethernet connection
  Ethernet.begin(mac,ip);
}

void loop() {
  // Connect to the server (your computer or web page)  
  if (client.connect(server, 80)) {
    Serial.println("Connecting...");
    client.print("GET /Ethernet/getData.php?"); // This
    client.print("value="); // This
    client.print(value); // And this is what we did in the testing section above. We are making a GET request just like we would from our browser but now with live data from the sensor
    client.println(" HTTP/1.1"); // Part of the GET request
    client.println("Host: 192.168.0.1"); 
    client.println("Connection: close"); 
    client.println(); // Empty line
    client.println(); // Empty line
    client.stop();    // Closing connection to server
  }

  else {
    // If Arduino can't connect to the server (your computer or web page)
    Serial.println("--> connection failed\n");
  }
  delay(10000);
}

Now when I upload the sketch onto the board and run the serial monitor, I get this output:

Serial monitor output

My Ethernet connection detail screenshot is as follows:

Ethernet connection details

Please tell me any changes that I must make and also are there any WAMP settings which I should change to allow the connection to get established?

Please consider the fact that I don't have a router anywhere in this connection - just my laptop and Ethernet shield connection.

  • 1
    What state are the LEDs in on the ethernet board? Do they show a proper ethernet connection has been negotiated? If neither end is able to auto-negotiate uplink mode you may well need a special cross-over cable. – Majenko Jan 26 '16 at 16:15
  • 1. Are you running a firewall? 2. Have you checked if your server is actually listening on that interface? – IOB Toolkit Team Jan 26 '16 at 17:47
  • @Majenko all the LEDs i.e. the full duplex ,LINK, 100M,COLL are blinking. – Divye Jan 26 '16 at 18:29
  • @IOBToolkitTeam yes my mcAfee runs a firewall. How to check if my server is listening on that interface. when i enter 192.168.0.1 in browser i am able to view the WAMP server page. if that's what you mean – Divye Jan 26 '16 at 18:32
  • 1
    If you're running firewall, it probably blocks your Arduino. Since I'm not using windows since 1999, I can't help you with that. :) – IOB Toolkit Team Jan 26 '16 at 19:14
0

Well, the problem has been solved. The Ethernet shield was not properly stacked onto the Arduino board which caused connection to fail.

  • Could you edit and expand your answer on how it was not properly stacked...? Were some of the pins bent, or badly soldered, or was the shield just not seated correctly? Also, could you mark your answer as the accepted answer, in order to remove it from the Unanswered Questions list? Thx. – Greenonline Mar 1 '16 at 20:13
0

After uploading the sketch from your laptop you should disconnect your Arduino and Ethernet shield setup from your laptop and then use a switch.

Connect the same setup to the switch at one end and the other end of the switch must be connected to your laptop then you can try to access your web page using IP address you specified in Ethernet sketch.

  • 1
    Welcome to Arduino SE! As we here try to keep the quality of answers and questions high could you please fix any grammatical or spelling errors in your answer? – Avamander Feb 29 '16 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.