Arduino Ethernet : no character received

Hello all
Here is my code, supposed to run on an Ethernet Arduino board that will be the core of a distant control receiver.
As its IP is changing, it is supposed to ask regularely my joomla! server, thus giving it its present IP.
Then, its web server part (not in my question, it works well) will be able to be reached.

The problem is that my card with this code is not able to reach my Joomla! server.

Here is the code

/*
Web client

This sketch connects to my local Joomla! v3 website (//192.168.1.36/Xyz)
using an Arduino Ethernet board.

created 15 Dec 2014
based on the WebClient.ino example

*/

#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 = { 0x90, 0xA2, 0xDA, 0x0F, 0x54, 0x54 };

// if you don’t want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
char server = “//192.168.1.36/Xyz/index.php”; //

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

// 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;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

// disable the SD card by switching pin 4 high
// not using the SD card in this program, but if an SD card is left in the socket,
// it may cause a problem with accessing the Ethernet chip, unless disabled
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);

// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println(“Failed to configure Ethernet using DHCP”);
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println(“connecting…”);

// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println(“connected”);
// Make a HTTP request:
client.println(“GET /index.php?psw=titi HTTP/1.1”);
client.println(“Host: //192.168.1.36/Xyz”);

client.println(“Connection: close”);
client.println();
}
else {
// kf you didn’t get a connection to the server:
Serial.println(“connection failed”);
}
}

void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}

// if the server’s disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println(“disconnecting.”);
client.stop();

// do nothing forevermore:
while(true);
}
}

The answer, on the Arduino terminal, is :

connecting…
connected

disconnecting.

even if I suppress the
client.println(“Connection: close”);
line, replacing it by
client.println(“Connection: Keep-Alive”); // same with keep-open

I tried many combinations with: the content of the variable server, the argument of GET, the argument of Host:
I NEVER get any character back

I even tried to replace the line
client.println(“GET /index.php?psw=titi HTTP/1.1”);
by
client.println(“GET /logs/state1.txt HTTP/1.1”); // the file exists!
without any success.

But, adding a line like
if (client.connected()) { Serial.println("-Connected-"); }
at the beginning of loop(), I discovered that the client is actually never connected …

What’s wrong?

The code disabling the SD card does not change anything.

I must specify that, using Chrome or IE, if I use the url
//192.168.1.36/Xyz/index.php?psw=titi
everything is functionning, including the log of the call in the database Joomla! I placed in the code.

192.168.1.36 and 192.168.1.100 are static address under my Livebox LAN

If the fact that I check this software on a local network were THE reason why it doesn’t work, how do you suggest me to do to debug it?
However, replacing my site url by “google.fr”, nothing appears either.

For all of you, Merry Christmas

char server[] = "//192.168.1.36/Xyz/index.php";    //

That is NOT the server identification. "192.168.1.36" would be.

Please use code tags for your code as explained in #7 below. Bottom is some client test code you can try un modified to see if you get a response from the server.

http://forum.arduino.cc/index.php/topic,148850.0.html

//zoomkat 3-1-13
//simple client checkip test
//for use with IDE 1.0.1 or later
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields

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

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

char serverName[] = "checkip.dyndns.com"; // test web page server
EthernetClient client;

//////////////////////

void setup(){

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600); 
  Serial.println("Better client ip test 3/1/13"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET / HTTP/1.0"); //download text
    client.println("Host: checkip.dyndns.com");
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

Hi you 2 Thanks for these answers.

Thanks to them, I succeeded, but I'd better explain my real bugs for those who could be interested in my difficulties :

  • PaulS you were right (I was sure but I didn't discover why immediately) : the 2 characters // at the begining of the server name are forbidden

  • zoomkat, your code gave me a lot of trouble : the main reason why you code runs where mine didn't is because there is a delay between the begining of loop() and the sentGET() call. For you it is through the waiting of the 'e' key press. For me, I solved it in my test software in introducing a delay(1000); at the begining of loop(). In the final code, the sendGET() will be called through a timer one or twice a day.

If you find it useful, I can repost the corrected code.

Oh, zoomkat, sorry to have forgotten to format my code (§7) in my question. I was so implicated in not asking for an existing question (actually, I did'nt find anything similar) that I forgot to respect all other rules.

Have a very good New Year

For you it is through the waiting of the 'e' key press. For me, I solved it in my test software in introducing a delay(1000); at the begining of loop(). In the final code, the sendGET() will be called through a timer one or twice a day.

The code you originally posted will only run once, only when the arduino is rebooted and no more. Is your timer going to reboot the arduino twice a day? The code I posted has the arduino running all the time and sends the GET request based on an event (receiving an e on the serial port in the posted code). I would think you would want your GET request sent on an event, such as your timer timing out.

Sorry, I didn't answer you immediately. Yes, I will modify my code to be waked up several time a day through to the timer. I will for that set up a boolean, read it in the loop and activate the part of your code as if it were a 'e' keyin. It seems that now, everything is working properly. Happy New Year.

LeLampiste: Hi you 2 Thanks for these answers.

Thanks to them, I succeeded, but I'd better explain my real bugs for those who could be interested in my difficulties :

  • PaulS you were right (I was sure but I didn't discover why immediately) : the 2 characters // at the begining of the server name are forbidden

::::SNIP::::

Have a very good New Year

To LeLampiste & PaulS,

on the server listed as:

"//192.168.1.36/Xyz/index.php"

Currently, web applications (and most especially mobile apps) are trying out a new protocol. Personally, I don't like it, but it is what it is.

As it is, an issue arises when a web page or a web app needs a library (usually javascript) that is on a secure server.

The situation usually develops like this: The end-user would load a page not on a secure server, but it would load libraries from both non-SSL web servers and secure (ssl) servers. In this case, the end-user might have a warning from the web browser - if browser was not told to ignore this type of error.

The work-around (the so-called solution) is to leave off the http: or https:, and the browser is to assume that the library should be loaded - regardless of the type of connection that is available - secure or otherwise.

AGAIN: as I said, I don't like this, but it is what it is.

We are likely to see more of this in the future.

Jesse

The work-around (the so-called solution) is to leave off the http: or https:, and the browser is to assume that the library should be loaded - regardless of the type of connection that is available - secure or otherwise.

That does not change the fact that the server name does NOT include the protocol OR the script that is to be executed on the server.

PaulS: That does not change the fact that the server name does NOT include the protocol OR the script that is to be executed on the server.

PaulS, needless to say, You Are Correct. However, the point I have is simple enough - you will see more of this in the future, and for the novice programmer there is no difference between a "server" and a "url". TRUE, technically they are two different items, and I understand your message. But being aware of this - especially just after x-mas with Arduino being such a popular toy, can save one heartache.

Cheers, Jesse