Load Google Translate Hello,
My project is to use the Arduino as a datalogger (for temperature and gas consumption).
The temperature measurement and gas counter work fine.
I would like now to transmit these data to a web page.
The web page is ready to receive the data : this is the url used with my web brower to transmit data :
http://www.xx/NS1.php?P1=counter_value
When the parameter is received, the web page sends an email.
Now I would like to do the same thing with the arduino.
But it doesn’t work : there is no error message but the web page is simply not activated. This is the code used :
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(xx,xx,xx,xx); //my web site IP adress
EthernetClient client;
void setup() {
delay(3000);
Serial.begin(9600);
Serial.println("Starting...");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
}
delay(1000);
Serial.println("connecting...");
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("http://www.xxx.NS1.php?P1=counter_value");
client.println();
Serial.println("Request sent");
}
else {
Serial.println("connection failed");
}
}
void loop()
{
}
Do you have an idea of what is wrong ?
Thanks for your help.
Do you see the serial output from the Arduino ok? For example, does it print "connected".
On the server, does the access log for the web server show requests for "http://www.xxx.NS1.php?P1=counter_value"?
You may also want to use this function to print the local IP address after Ethernet.begin():
http://arduino.cc/en/Reference/EthernetLocalIP
Serial.println(Ethernet.localIP());
You could then see if you are able to ping the IP address from your computer or, ideally, from the server to see if your Arduino is on the network ok.
Hello thanks for your reply.
Yes on the serial output the messages are displayed : "connected" and "request sent"
I can ping the Arduino from my computer without problem.
Actually I do not have access to server access log.
Thanks again for your help.
That's too bad about the access log. It would be good to know if the server receives the request at all or not.
Were you able to run the default Ethernet example? Were it just does a simple GET from Google?
BTW, you can also call client.connect() with a domain name like client.connect("yourdomain.com", 80) if you want to rule out the off chance that you have the wrong ip address.
Also, when I was troubleshooting the WiFly shield which uses similar library, it was very useful to insert debug serial print statements inside the lower level read and write calls to see all the data that was going back forth. You might be able to something similar in utility/socket.cpp or utility/w5100.h.
Hello Drew,
The Webclient sample works fine.
I have just changed IPAddress server(173,194,67,94); // Google
I have tried client.connect("yourdomain.com", 80); // no change
You have right, I must see the server access log.
I have asked to my provider but no response up to now.
Thanks again for your help.
What is wrong is that you have to send an HTTP request, not a URL.
client.println("http://www.xxx.NS1.php?P1=counter_value");
client.println();
should be
client.print("GET /NS1.php?P1=counter_value HTTP/1.0\r\n");
client.print("Host: xxx.xxx\r\n");
client.print("\r\n");
(println may do the right thing with the newlines, I don't know).
Ah ha, it was missing GET. Nice catch! I feel bad for not seeing that
Hopefully this solves dakota77's issue.
Yes !
It works fine now exactly with the 3 lignes suggested by Ben.
Thanks a lot for your help
© 2009 Premier Farnell plc. All Rights Reserved
Premier Farnell plc, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE