Hi,
With a MEGA 2560 R3 + Ethernet shield W5100 I want to make a system to get data (temperature for example) and send it periodically to a php perso.free.fr web page.
My PHP URL web page is : http://lesjno.free.fr/TestArduino/testFromArduino.php
It return date, time, number of GET and POST parameters and the parameters received.
I’ve tried several tips red in forums, but without success …
I don’t know what I can do to perform the connection !
Anyone already performe it ? Any suggestion ?
Thanks…
Yes, It's an error when I put the message into the forum ... my code is "GET /TestArduino/testFromArduino.php/mypage.php?qqq=111 HTTP/1.1", of course...
Strange, I test it again and the result on the monitor is now : connecting... connected disconnecting.
It's normal you get this result when you connect from a web browser.
I try (but I failed) to get the same from the Arduino card but there is certainly something wrong in my sketch, but what ?
I got the same page with this code on my Mega2560/ethernet shield.
#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 };
// Change your network settings
IPAddress ip(192,168,0,2);
IPAddress gateway(192,168,0,1);
IPAddress subnet(255,255,255,0);
IPAddress server(212,27,63,167); // Your server
// 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() {
// start the serial library:
Serial.begin(9600);
// start the Ethernet connection:
Ethernet.begin(mac,ip,gateway,gateway,subnet);
// give the Ethernet shield a second to initialize:
delay(2000);
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 /TestArduino/testFromArduino.php?qqq=111 HTTP/1.0");
client.println("Host: lesjno.free.fr");
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:
while(client.connected())
{
while(client.available()) {
char c = client.read();
Serial.print(c);
}
}
// if the server's disconnected, stop the client:
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
for(;;)
;
}
Thanks for the answer !
I've test with your code but that failed. Here is the result : connecting... connection failed disconnecting.
Compare to your code, I've only change the network parameters : IPAddress ip(192,168,1,140); // ip of the Ethernet shield on the local network IPAddress gateway(192,168,1,254); IPAddress subnet(255,255,255,0);
But After this test, I look your code and I see you wrote : client.println("GET /TestArduino/testFromArduino.php?qqq=111 HTTP/1.0");
I've just change HTTP/1.0 to HTTP/1.1 and now I get this result : connecting... connected HTTP/1.1 200 OK Date: Sun, 12 Feb 2012 22:46:57 GMT Server: Apache/ProXad [Nov 6 2010 15:36:40] X-Powered-By: PHP/4.4.3-dev Connection: close Content-Type: text/html 2012-02-12 23:46:55 NBGET=1,NBPOST=0 GET : qqq => '111' POST : disconnecting.
So, that seems to work !
I wil do other tests later ...
Thanks a lot for your help !
Mine connected and your server responded almost immediately. ??
I only changed the network settings on that code I posted. I use a public ip for testing.
If you have a dhcp server on that localnet, maybe you should use the settings it issues (like your original code).
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
Yes, I confirm now : you 're right. When the network parameters are good all works well.
I've test it with HTTP/1.0 and HTTP1.1 : I get exactly the same result.
Thanks again for your help !
I'm new on this forum. I don't know how to add "[SOLVED]" at the end of the subject. Do you know if it's possible or not ?