0
votes

I am trying to create an interface with my arduino Uno and my apache localhost server using the arduino Ethernet Shield. I am trying to connect to the local host but failing. I have googled and edited the sample code from arduino documentation according to my needs.

My local host ip is 127.0.0.1, port 80. My code is as follow:

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


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,0,103 };
byte server[] = { 127,0,0,1};

EthernetClient client;

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

  delay(1000);

  Serial.println("connecting...");

  int res = client.connect(server, 80);

  Serial.println(res);

  if (res) {
    Serial.println("connected");
    client.println("GET /sampleArduinoEthernetMysql/");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.println("data:");
    Serial.println(c);
  }else{
    Serial.println("NA");
  }

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

  }
}

In the arduino serial monitor it is showing connection failed. This is due to the else case I have written in the code. I have googled about this problem but somehow the solutions are not working for me.

1

1 Answers

0
votes

Arduino only "talks" with a socket, point your code to an apache server does not work... you need to create a php page and create a socket server for the arduino be able to "talk".

you can read This or This

PS: Be sure that IP (192.168.0.103) of your arduino is right.