Bloqueio de comunicação com servidor local

Olá pessoal,

tenho uma dúvida relativamente simples, há qualquer tipo de software que possa bloquear a comunicação via Ethernet do Arduíno com um servidor Apache local?

Recentemente eu montei um servidor bem simplório para testar a comunicação entre meu Arduíno com ele, quando eu direciono para um servidor qualquer (google.com, por exemplo) ele funciona sem qualquer complicação, entretanto, quando direciono ele para um servidor local, ele simplesmente não abre comunicação, tentei com 2 códigos (sketches) distintos e mesmo assim não funciona.

Ambos os códigos são códigos exemplares da biblioteca "Ethernet".

Versão atualizada

#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[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 17);
IPAddress myDns(192, 168, 0, 1);
IPAddress server (192,168,0,20);
// 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;

// Variables to measure the speed
unsigned long beginMicros, endMicros;
unsigned long byteCount = 0;
bool printWebData = false;  // set to false for better speed measurement

void setup() {
  
  
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // start the Ethernet connection:
  Serial.println("Initialize Ethernet with DHCP:");
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // Check for Ethernet hardware present
    if (Ethernet.hardwareStatus() == EthernetNoHardware) {
      Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
      while (true) {
        delay(1); // do nothing, no point running without Ethernet hardware
      }
    }
    if (Ethernet.linkStatus() == LinkOFF) {
      Serial.println("Ethernet cable is not connected.");
    }
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip, myDns);
  } else {
    Serial.print("  DHCP assigned IP ");
    Serial.println(Ethernet.localIP());
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.print("connecting to ");
  Serial.print(server);
  Serial.println("...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.print("connected to ");
    Serial.println(client.remoteIP());
    // Make a HTTP request:
    client.println("GET /arduino/webclient1.php"); //  Dentro da pasta htdocs tem esta pasta com
    client.println("Host: Localhost");                    //  o webserver dentro.. 
    client.println("Connection: close");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed AND I DON'T KNOW THE FUCKING WHYY!! GADMMITT!!!!");
  }
  beginMicros = micros();
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  int len = client.available();
  if (len > 0) {
    byte buffer[80];
    if (len > 80) len = 80;
    client.read(buffer, len);
    if (printWebData) {
      Serial.write(buffer, len); // show in the serial monitor (slows some boards)
    }
    byteCount = byteCount + len;
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    endMicros = micros();
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    Serial.print("Received ");
    Serial.print(byteCount);
    Serial.print(" bytes in ");
    float seconds = (float)(endMicros - beginMicros) / 1000000.0;
    Serial.print(seconds, 4);
    float rate = (float)byteCount / seconds / 1000.0;
    Serial.print(", rate = ");
    Serial.print(rate);
    Serial.print(" kbytes/second");
    Serial.println();

    // do nothing forevermore:
    while (true) {
      delay(1);
    }
  }
}

Versão desatualizada.

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server (192,168,0,20);

EthernetClient client;

void setup(){

  Serial.begin(9600);
  while (!Serial) {
      ;
  }

  if (Ethernet.begin(mac) == 0) {
      Serial.println("Failed to configure Ethernet using DHCP");
      for (;;)
        ;
  }


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

  if (client.connect(server, 80)) {
      Serial.print("connected to ");
      Serial.println(client.remoteIP());
      client.println("GET /arduino/webclient1.php"); // Dentro da pasta htdocs tem esta pasta com
      client.println();                                             // o servweb dentro dele.
  } else {

     Serial.println("connection failed");

  }
}

void loop(){

  int len = client.available();
    if (len){
      char c = client.read();
      Serial.print(c);
    }

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

Erro da versão atualizada:

Erro da versão anterior:

Já desativei meu firewall (o que é improvavel já que o servidor ta de pé.), já botei meu ip local como DMZ (sei que não faz sentido em uma rede local, masvai que...)

Em um computador na mesma rede, se você digitar o seguinte endereço em um navegador:

192.168.0.20/arduino/webclient1.php

e der Enter, o que acontece, aparece o que no navegador?

Explique melhor:

quando eu direciono para um servidor qualquer (google.com, por exemplo) ele funciona sem qualquer complicação

Como fez para testar, qual código usou?

giova014:
Em um computador na mesma rede, se você digitar o seguinte endereço em um navegador:

192.168.0.20/arduino/webclient1.php

e der Enter, o que acontece, aparece o que no navegador?

Está normal, consigo acessar a pagina web que criei (webclient1).

Explique melhor:Como fez para testar, qual código usou?

Eu utilizo este código aqui:

#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[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };


IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
//char server[] = "www.google.com";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 100);
IPAddress myDns(192, 168, 0, 1);


EthernetClient client;

// Variables to measure the speed
unsigned long beginMicros, endMicros;
unsigned long byteCount = 0;
bool printWebData = true; 

void setup() {
  
Serial.begin(9600);
while (!Serial) {
    ; 
  }

  
  Serial.println("Initialize Ethernet with DHCP:");
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // Check for Ethernet hardware present
    if (Ethernet.hardwareStatus() == EthernetNoHardware) {
      Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
      while (true) {
        delay(1); // do nothing, no point running without Ethernet hardware
      }
    }
    if (Ethernet.linkStatus() == LinkOFF) {
      Serial.println("Ethernet cable is not connected.");
    }
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip, myDns);
  } else {
    Serial.print("  DHCP assigned IP ");
    Serial.println(Ethernet.localIP());
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.print("connecting to ");
  Serial.print(server);
  Serial.println("...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.print("connected to ");
    Serial.println(client.remoteIP());
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.1");
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
  beginMicros = micros();
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  int len = client.available();
  if (len > 0) {
    byte buffer[80];
    if (len > 80) len = 80;
    client.read(buffer, len);
    if (printWebData) {
      Serial.write(buffer, len); // show in the serial monitor (slows some boards)
    }
    byteCount = byteCount + len;
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    endMicros = micros();
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    Serial.print("Received ");
    Serial.print(byteCount);
    Serial.print(" bytes in ");
    float seconds = (float)(endMicros - beginMicros) / 1000000.0;
    Serial.print(seconds, 4);
    float rate = (float)byteCount / seconds / 1000.0;
    Serial.print(", rate = ");
    Serial.print(rate);
    Serial.print(" kbytes/second");
    Serial.println();

    // do nothing forevermore:
    while (true) {
      delay(1);
    }
  }
}

Mas, mudar mesmo, só mudo o endereso IP e a pagina que ele vai buscar:

IPAddress server(74,125,232,128); // <- Este endereço é o do google.
//char server[] = "www.google.com";   Descarta esta linha.

IPAddress ip(192, 168, 0, 177);
IPAddress myDns(192, 168, 0, 1);

//##################################//

//Pagina que ele vai buscar.

 if (client.connect(server, 80)) {
    Serial.print("connected to ");
    Serial.println(client.remoteIP());
    client.println("GET /search?q=arduino HTTP/1.1"); // Requerimento HTTP
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println();

Estão realmente bem similares, então o que está causando o problema está nas linhas diferentes, que são:

  • IP atribuido para o Arduino
  • IP do servidor de destino
  • Endereço do GET
  • Valor do cabeçalho "Host"

O me chamou mais a atenção foi o cabeçalho "Host".

Tente mudar de:

client.println("GET /arduino/webclient1.php");
client.println("Host: Localhost");

para:

client.println("GET /arduino/webclient1.php");
client.println("Host: 192.168.0.20");

O que acontece?

giova014:
Estão realmente bem similares, então o que está causando o problema está nas linhas diferentes, que são:

  • IP atribuido para o Arduino
  • IP do servidor de destino
  • Endereço do GET
  • Valor do cabeçalho "Host"

O me chamou mais a atenção foi o cabeçalho "Host".

Tente mudar de:

client.println("GET /arduino/webclient1.php");

client.println("Host: Localhost");



para:


client.println("GET /arduino/webclient1.php");
client.println("Host: 192.168.0.20");




O que acontece?

Troquei para o codigo que disse, e...

    client.println("GET /arduino/webclient1.php");
    client.println("Host: 192.168.0.20");

Aconteceu isso aqui:

Initialize Ethernet with DHCP:
  DHCP assigned IP 192.168.0.17
connecting to 192.168.0.20...
connection failed.

disconnecting.
Received 0 bytes in 0.0000, rate = 0.00 kbytes/second

Acho que o grande problema está nesta parte aqui

  if (client.connect(server, 80)) // O problema é que não está passando nem desta condição.{
    Serial.print("connected to ");
    Serial.println(client.remoteIP());
    client.println("GET /arduino/webclient1.php");
    client.println("Host: 192.168.0.20");
    client.println("Connection: close");
    client.println();
  } else {
   
    Serial.println("connection failed."); // Está indo direto para essa condição, entende? 
  }

/* entra no laço do if, mas, como a condição é falsa, ele vai para o else, não passa daqui "if (client.connect(server, 80)" */

Já tentei de tudo, mesmo assim não está indo. A porta já troquei (mesmo que nção faça sentido pois estou acessando pelo browser. Troquei IP do server, ja coloquei o IP externo ( "abrindo" a porta 80).. ta tenso..

Baixe um servidor TCP simples, como o SocketTest
Inicie o servidor na porta 80 e teste o sketch do Arduino novamente.

SocketTest.png

O que aparece na caixa de texto do servidor?