Get Arduino data from external web site [SOLVED]

Hi

It still doesn’t work, but I’ve done other tests and now I’m sure the problem comes from the Arduino side.
In fact I was not sure my box (Freebox) or somthing else on the external network didn’t block ports or not coming from the internet. So I went at a friend home where there is the same box and a system is already connected to the box. This system can be accessed from the internet. The system force a fix IP (192.168.1.210). The router is simply configured to route a port on this address (no association between MAC@ and IP@ within the router).
My sketch is a very basic server test. I print on the monitor all characters I get from the client.
So here was my test :

  • 1 - I Checked I can access the current system of my friend from the internet (outside from the LAN) => result : OK
  • 2 – Command Ipconfig from a PC on the LAN to get all information : gateway, mask, DNS
  • 3 - I configured the Arduino server to use the same information : IP , gateway, mask & DNS.
  • 4 – local test on the LAN IP@ => result OK.
  • 5 – local test from the LAN but with the external IP@:port => result OK
  • 6 – Test from outside the LAN on the same external IP@:port => result NOT OK
  • 7 – I remove the Arduino an I connect the initial system
  • 8 – Same test than the last one (6) => result OK.

Strange isn’t it ?

So there is probably something wrong in the Arduino. But what !

I’ve also test the client configuration and that works : The Arduino can send information to an external php script (outside from the LAN), the site answer (simple echo “OK”) and this answer is received by the Arduino. In this configuration the Arduino receive information from ouside. But in this test the initial connection is initiated but the Arduino. So it's different than the server configuration.

For info, within my Arduino sketch I print the IP, Gateway, Mask and DNS information. (I print the following values : Ethernet.localIP(); Ethernet.ubnetMask(); Ethernet.gatewayIP(); Ethernet.dnsServerIP():wink:

I’ve done a test with DHCP (and just Ethernet.begin(mac)) : Gateway, mask and dns are good.
When I force all parameters, they are used.

I’v also done a test with Ethernet.begin(mac,IP) (so I force the IP@ only) : in this case the gateway and dns are wrong (192.168.1.1) : I don't know whether it's normal or not ... maybe this information can help someone to suggest another idea ?

I don’t see now what I can do !

For info, here is my test sketch :

#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:
 IPAddress ip(192,168,1, 140);
 //IPAddress ip(192,168,1, 210);
 byte mac[] = { 0x00, 0x16, 0x38, 0x55, 0x07, 0xF6 }; //00:16:38:55:07:f6
 


  IPAddress dns (212,27,40,240);
  IPAddress gateway  (192,168,1,254);  
  IPAddress subnet (255, 255, 255, 0); 


// 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()
{
    Serial.begin(115200);

  int status;
  Serial.println("Connection ...");
  /*
  status = Ethernet.begin(mac);
  if (status != 1){
    Serial.println ("DHCP connection failed.");
    Ethernet.begin(mac,ip,dns,gateway,subnet);
  }
  //*/
  Ethernet.begin(mac,ip,dns,gateway,subnet);
  
  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();

  
  // print your local subnetMask:
  Serial.print("My subnetMask: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.subnetMask()[thisByte], DEC);
    Serial.print("."); 
  }
  Serial.println();
  
  // print your local IP gateway:
  Serial.print("My IP gateway: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.gatewayIP()[thisByte], DEC);
    Serial.print("."); 
  }
  Serial.println();
  
  // print your local IP dnsserver:
  Serial.print("My IP dnsServer: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.dnsServerIP()[thisByte], DEC);
    Serial.print("."); 
  }
  Serial.println();



  Serial.println("Connection done");

  server.begin();
}

void loop()
{
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.print(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();

          // output 
          client.println("connection OK");
          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();
  }
}