Another ethernet / PHP problem for you

Hi guys..

So I have a project that's kicking me a bit...
I've been slowly getting past the hurdles but this one I have right now is not getting anywhere..

Using the ethernet shield, I am trying to access/execute a php file on a web server.
Now I have read and tried so many thread posts and tactics but not getting anywhere..

I want to write data from arduino to mysql.. (end goal)

Now, the PHP side of things is working.

For some reason, the arduino is not executing the php file.
First thing, port is not 80 ... it's 3306

at this point I have not tried sending data through yet.

the php file writes it's own data for now..

Here is the code for arduino:

#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

EthernetClient client;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte myIP[] = { 10, 0, 0, 6 };
byte myGate[] = { 10, 0, 0, 2 };
byte myServer[] = { 197, 242, 144, 236 }; //Web Server IP Address
//char myServer[] = "automatemybusiness.co.za";
IPAddress ip(10, 0, 0, 6); // My Arduino IP Address Setup
IPAddress gateway(10, 0, 0, 2);
IPAddress subnet(255, 255, 255, 0);

char Data1[6] = {'H', 'e', 'l', 'l', 'o', '\0'};
char Data2[6] = {'T', 'h', 'e', 'r', 'e', '\0'};

void setup(){
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print("Setting up "); // print message

Ethernet.begin(mac, myIP, myIP, myGate);

delay (5000);
lcd.setCursor(0,0);
lcd.print("Done "); // print message
delay(1000);
}

void loop(){
lcd.setCursor(0,1);
lcd.print("start loop ");
delay(2000);
int Iloopcount=0;
if (Iloopcount <= 10 ){
Iloopcount++;
lcd.setCursor(0,1);
lcd.print("Loop : ");
lcd.print(Iloopcount);
lcd.print(" ");
delay(1000);
UploadData(Data1, Data2);
}
delay(5000);
}

//Writing the data to the web portal
void UploadData(String Col1, String Col2){
String data;
lcd.setCursor(0,1);
lcd.print("trying to connect ");
delay (1000);
client.connect(myServer , 3306);
lcd.setCursor(0,1);
lcd.print("connect done ");
delay (1000);
if (client.connected()) {
client.println("GET /add.php?celsius=18 HTTP/1.0");
client.println();
delay(1000);
if (client.available()) {
delay(4000);
char c = client.read();
lcd.setCursor(0,0);
lcd.print("Feedback : ");
lcd.print(c);
delay(1000);
}
lcd.setCursor(0,1);
lcd.print("data sent...");
delay (1000);
}
else{
lcd.setCursor(0,1);
lcd.print("didnt connect");
delay (1000);
}
client.stop();
// client.flush();
}

I'm stuck ...

Oh.. I have a lcd connected to try see what is going on in the code.....

... and I know the "I" will loop forever .. I'm concentrating on the php side ...

A couple things stand out.

This is the first:

byte myGate[] = { 10, 0, 0, 2 };

That is not normally a gateway IP. Are you certain that is correct?

This is the second:

 client.connect(myServer , 3306);

You are not evaluating the return value at all. Test for a return value of 1. That is the only return value that indicates connection success. All others indicate a fail of either the dns resolution or the connection attempt.

 if(client.connect(myServer , 3306) == 1) {
    Serial.println("connected");
  }
  else {
    Serial.println("failed");
    return;
  }

Hi
Yes it is the IP Address ...

I'll attach a screen shot of ipconfig..

ok.. edited code with your lines .. still same..

In the "GET" statement there is a "HTTP/1.0" .. I've also tried "HTTP/1.1"
with same result ..
dunno the difference but noticed it in a lot of examples..

ip.png

Then your Ethernet.begin call is incorrect.

// change this
  Ethernet.begin(mac, myIP, myIP, myGate);
// to this
  Ethernet.begin(mac, myIP, myGate, myGate);

How does the connect function call do? Does it return success or fail?

What are your server logs telling you?

SurferTim:
Then your Ethernet.begin call is incorrect.

// change this

Ethernet.begin(mac, myIP, myIP, myGate);
// to this
  Ethernet.begin(mac, myIP, myGate, myGate);



How does the connect function call do? Does it return success or fail?

The connect function is success before your suggested edit .. but will upload your suggestion now and test again

themig:
The connect function is success before your suggested edit .. but will upload your suggestion now and test again

No it didn't. You were not evaluating the return value to determine if it connected or not.

PaulS:
What are your server logs telling you?

Went into the server log .. no access requests from arduino .. only my laptop..

SurferTim:
No it didn't. You were not evaluating the return value to determine if it connected or not.

Hi,
sorry I ment from the new code..

if(client.connect(myServer , 3306) == 1) {
Serial.println("connected");
}
else {
Serial.println("failed");
return;
}

It could not have possibly connected with this begin code.

  Ethernet.begin(mac, myIP, myIP, myGate);

You are using the ethernet shield's IP as the dns server. It will not resolve the domain.

edit: If you use an IP, you must send a Host parameter to get your website. Your domain is hosted by a virtual server.

if (client.connected() == 1) {
    client.println("GET /add.php?celsius=18 HTTP/1.0");
// add this
    client.println(("Host: automatemybusiness.co.za");
    client.println();

SurferTim:
It could not have possibly connected with this begin code.

  Ethernet.begin(mac, myIP, myIP, myGate);

You are using the ethernet shield's IP as the dns server. It will not resolve the domain.

but it is returning the connected println of the new code..

but so is the new "Ethernet.begin(mac, myIP, myGate, myGate);"

..

It is a virtual server. See my previous post edit. You must send a Host parameter to get the correct page.

SurferTim:
It is a virtual server. See my previous post edit. You must send a Host parameter to get the correct page.

its a single "(" in "client.println(("Host: automatemybusiness.co.za");" right ?

themig:
its a single "(" in "client.println(("Host: automatemybusiness.co.za");" right ?

Yes. My keyboard stutters sometimes,

Yes. My keyboard stutters sometimes,

It''s a pooor wooooorkman that blaaaaames his tooooools. 8)

SurferTim:
Yes. My keyboard stutters sometimes,

lol .. yeah .. done..

I'll post the code now as is ..

what else am I doing wrong ..
Thanks for taking the time to help BTW ...

#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

EthernetClient client;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte myIP[] = { 10, 0, 0, 6 };
byte myGate[] = { 10, 0, 0, 2 };
byte myServer[] = { 197, 242, 144, 236 }; //Web Server IP Address
//char myServer[] = "automatemybusiness.co.za";
IPAddress ip(10, 0, 0, 6); // My Arduino IP Address Setup
IPAddress gateway(10, 0, 0, 2);
IPAddress subnet(255, 255, 255, 0);

char Data1[6] = {'H', 'e', 'l', 'l', 'o', '\0'};
char Data2[6] = {'T', 'h', 'e', 'r', 'e', '\0'};

void setup(){
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print("Setting up "); // print message

Ethernet.begin(mac, myIP, myGate, myGate);

delay (5000);
lcd.setCursor(0,0);
lcd.print("Done "); // print message
delay(1000);
}

void loop(){
lcd.setCursor(0,1);
lcd.print("start loop ");
delay(2000);
int Iloopcount=0;
if (Iloopcount <= 10 ){
Iloopcount++;
lcd.setCursor(0,1);
lcd.print("Loop : ");
lcd.print(Iloopcount);
lcd.print(" ");
delay(1000);
UploadData(Data1, Data2);
}
delay(5000);
}

//Writing the data to the web portal
void UploadData(String Col1, String Col2){
String data;

if(client.connect(myServer , 3306) == 1) {
lcd.println("connected");
delay(1000);
}
else {
lcd.println("failed");
delay(1000);
return;
}
if (client.connected()== 1) {
client.println("GET /add.php?celsius=18 HTTP/1.0");
client.println("Host: automatemybusiness.co.za");
client.println();
delay(1000);
if (client.available()) {
delay(4000);
char c = client.read();
lcd.setCursor(0,0);
lcd.print("Feedback : ");
lcd.print(c);
delay(1000);
}
lcd.setCursor(0,1);
lcd.print("data sent...");
delay (1000);
}
else{
lcd.setCursor(0,1);
lcd.print("didnt connect");
delay (1000);
}
client.stop();
// client.flush();
}

I'll post the code now as is ..

If only you'd learn to do it right. Is it that difficult to click the </> icon on the top row first?

if (client.available()) {
      delay(4000);
    char c = client.read();
    lcd.setCursor(0,0);
    lcd.print("Feedback : ");
    lcd.print(c);
    delay(1000);
    }

If the GET request is accepted, and the server generates a response, read one character of that response, after twiddling your thumbs for a while. Why?

Get rid of the useless delay()s in your code.

The function to send data wastes resources taking two Strings as input that it never uses. Why?

Have you tried the example web client application?

PaulS:
If only you'd learn to do it right. Is it that difficult to click the </> icon on the top row first?

if (client.available()) {

delay(4000);
    char c = client.read();
    lcd.setCursor(0,0);
    lcd.print("Feedback : ");
    lcd.print(c);
    delay(1000);
    }



If the GET request is accepted, and the server generates a response, read one character of that response, after twiddling your thumbs for a while. Why?

Get rid of the useless delay()s in your code.

The function to send data wastes resources taking two Strings as input that it never uses. Why?

Have you tried the example web client application?

I hardly post on forums... not familiar with your guys code to posting ..

... and I can't see the </> icon you mention...

yes I have .. changed the port to 3306, pointed in right direction, etc .. yet somehow making a mistake somewhere.. hence asking for help ...