Arduino + Ethernet Shield | dude about if is possible

Hi to all!

I do some test with ard uno + ethernet shield. And im trying do that but dont know if that is posibble:

example: ip arduino 192.168.1.144 ip server 192.168.1.4

a daemon or cron access to: 192.168.1.144/led4=status

arduino give to server: 192.168.1.4/givestatus.php?led=4

My question is whether it is possible to client-server simultaneously. When I try to configure the server ip and client ip gives me error. Thank you!

Are you saying that you want the same ethernet port to be operating on 2 IP addresses?

If so,... I've never heard of any hardware that does this (let alone Arduino shields)

No, maybe explain me wrong. I mean if it's possible to put the request in the example:

web server accesses a web server ethernet arduino. Arduino send a client.print ("POST / blbla.php blblbla");

An ethernet shield can be a client and server in the same sketch, but on the same ip using different ports.

So there is no solution or alternative to do what I've described? 

I was trying the following but does not work:

  [quote]   
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);
.
.
.
 if (client.available()) {
        char c = client.read();
        Serial.write(c); 
        if (c == '\n' && currentLineIsBlank) {:
          client.println("HTTP/1.1 200 OK"); // Enviar un encabezado de respuesta HTTP estándar
          client.println("Content-Type: text/html");
          client.println();
          client.println("<!DOCTYPE HTML>"); // Tipo de documento.
          client.println("<html>"); // Etiqueta html inicio del documento. 
          client.print("Arduino!! - ");
           client.println("</html>"); // Etiqueta html fin del documento.
          client.print("POST http://192.168.1.4/test.php?hum=222 HTTP/1.0"); 
          client.println("User-Agent: Arduino 1.0");
          client.println();
        }

Thanks again.

You need two instances of EthernetClient. One for the web server, and a separate instance for the client.

       IPAddress server(192,168,1,4);
      EthernetClient client2;
      if(client2.connect(server,80)) {
          client2.println("GET /test.php?hum=222 HTTP/1.0"); 
          client2.println("User-Agent: Arduino 1.0");
          client2.println();
      }

edit: Corrected the syntax errors in the example.

Thanks again. But when i start to program and use:

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

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

void setup() {

That give error.

sketch_jun13a:7: error: conflicting declaration 'EthernetServer server'
sketch_jun13a:6: error: 'server' has a previous declaration as 'IPAddress server'

Then delete the instance of the local variable "server" in the code.

edit: ...or use server2 like the client example I gave you if you need two instances.

Yeah i do work that, but now i have a new problem, full code:

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


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

EthernetServer server(80);

void setup() {
  Serial.begin(9600);
  while (!Serial) {
  }
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  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 (c == '\n' && currentLineIsBlank) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("</html>");
          send();
        }
      }
    }
    delay(1);
    client.stop();
    Serial.println("client disonnected");
  }
}

void send(){
  IPAddress server(192,168,1,4);
  EthernetClient client2;
  if(client2.connect(server,80)) {
    client2.println("GET /phpuser/dht.php?dht=1&temp=11&hum=432"); 
    client2.println(" HTTP/1.0");
    client2.println("User-Agent: Arduino 1.0");
    client2.println(); 
    Serial.println("Connect ok");
  }
  else
  {
    Serial.println("connect fail");
  }
  if (client2.connected()) {
  }
  else {
    Serial.println("logout");
  }
  client2.stop();
  client2.flush();
}

When i access to: http://192.168.1.177/

that add verys date to database and i only want one for visit:

see:

Thanks!

Finally that work:

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


byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);
String readString=String(30);
EthernetServer server(80);

void setup() {
  Serial.begin(9600);
  while (!Serial) {
  }
  Ethernet.begin(mac, ip);
  server.begin();
}


void loop()
{
  EthernetClient cliente = server.available();
  
  if(cliente)
  {
    boolean lineaenblanco=true;
    while(cliente.connected())//Cliente conectado
    {
      if(cliente.available())
      {
        char c=cliente.read();
        if(readString.length()<30)
        {
          readString.concat(c); 
        }
        if(c=='\n' && lineaenblanco)
        {
          int DHT = readString.indexOf("DHT=");
          if(readString.substring(DHT,DHT+5)=="DHT=1")
          {
            send();
          }
          
          
          cliente.println("HTTP/1.1 200 OK");      
          cliente.stop();//Cierro conexión con el cliente
          readString="";
        }
      }
    }
  }
}

void send(){
  IPAddress server(192,168,1,4);
  EthernetClient client2;
  if(client2.connect(server,80)) {
    client2.println("GET /phpuser/dht.php?dht=1&temp=11&hum=432"); 
    client2.println(" HTTP/1.0");
    client2.println("User-Agent: Arduino 1.0");
    client2.println(); 
    //Serial.println("Connect ok");
  }
  client2.stop();
  client2.flush();
}