I recently got the Web Client working on an Arduino Duemilanove with an Ethernet Shield with a Wiznet W5100 chip. Here's my code:
Here's the output in the serial monitor:
output - Pastebin.com
Why can't I run the PHP script? Please Help Soon
I recently got the Web Client working on an Arduino Duemilanove with an Ethernet Shield with a Wiznet W5100 chip. Here's my code:
Here's the output in the serial monitor:
Why can't I run the PHP script? Please Help Soon
You web hosting company uses virtual hosting. The response you are getting is from your web host's domain, not yours. If you want to access your domain files, you need to add a "Host:" to the GET header. Replace "www.mydomain.com" with your domain name.
// Make a HTTP request:
client.println("GET /prowl/example.php HTTP/1.0");
client.println("Host: www.mydomain.com");
client.println();
edit: I also added the HTTP/1.0 to the GET.
HTTP 1.1 details in RFC2616. Its a good idea to familiarise yourself a bit with the standard.
MarkT:
HTTP 1.1 details in RFC2616. Its a good idea to familiarise yourself a bit with the standard.
That is a good idea, but I think that doc is a bit too technical for the OP. You could have been more specific. Maybe a correction to the OP's code or an example of your own?
I'm waiting on the edge of my seat! ![]()
// Make a HTTP request:
client.println("GET /prowl/example.php HTTP/1.0");
client.println("Host: www.mydomain.com");
client.println();
SurferTim I tried this code, but now I can't connect at all.
Here's my code now:
That change would not affect the ability to connect. It only affects what domain the server will use once the connection is established and the GET is sent.
So it now responds with "Connection failed" on every attempt?
Yes it responds with could not connect, but I had it working before. Also when I type in the IP into google chrome that I got from pinging the website, It comes up to a 404 not found page.
I just tried it (converted to IDE v1.0 code), and that worked fine from here. There is nothing on the page except their Analytics code.
Can you give me some of your code then, because there is php on that website too.
Here is what I used. I had to edit the network settings, so if there are typos in those settings, that is why. This is for IDE v1.0 only.
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,117);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
IPAddress server(31,170,163,17); // Chris
EthernetClient client;
void setup() {
Serial.begin(9600);
Ethernet.begin(mac,ip,gateway,gateway,subnet);
delay(2000);
Serial.println("connecting...");
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /prowl/example.php HTTP/1.0");
client.println("Host: www.chriscosma.co.cc");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
while(client.connected())
{
while(client.available()) {
char c = client.read();
Serial.print(c);
}
}
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
for(;;)
;
}
edit: I just checked that page with my web browser, and the analytics javascript is all that is there.
Uhh, how would I go about using this code in the Arduino IDE? Also PHP code is hidden on that webserver.
That code will work in Arduino IDE v1.0. I recommend upgrading to IDE v1.0. I use Ubuntu v11.10 and I can run both versions. I hear you can do that with Windows also.
If the php code is hidden, then I guess I am seeing exactly what the page displays. Nothing but the webhost-inserted javascript.
Your "other directory" file displayed ok. ![]()
Add: Got busy with the "work" thing. ![]()
Just some advice. You really should turn off your directory browsing feature on your site. I can't navigate outside your "/PUBLIC_HTML/" folder, but I can navigate around in that directory and all subdirectories there. That might prove to be a security hazard someday.
Thank you! I downloaded Arduino 1.0 and it worked. Now I have an iPhone locater XD