Hello,
I have an uno + ethernet shield (w5100) and I am trying to get the incoming url coming into the url
i paste this url in my browser http://10.0.0.77/led1/on and I would like a string that has that url inside the arduino. Is this possible?
#include <SPI.h>
#include <Ethernet.h>
// network configuration. gateway and subnet are optional.
// the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//the IP address for the shield:
byte ip[] = { 10, 0, 0, 177 };
// the router's gateway address:
byte gateway[] = { 10, 0, 0, 1 };
// the subnet:
byte subnet[] = { 255, 255, 0, 0 };
// telnet defaults to port 23
EthernetServer server = EthernetServer(23);
void setup()
{
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients
server.begin();
}
void loop()
{
// if an incoming client connects, there will be bytes available to read:
EthernetClient client = server.available();
if (client == true) {
// read bytes from the incoming client and write them back
// to any clients connected to the server:
server.write(client.read());
}
}
Thanks in advance
The below has a discussion on getting the remote IP address.
http://forum.arduino.cc/index.php/topic,82416.0.html
Thanks but I am not looking for the IP address. I am looking for the url.
If in my example I browsed to http://10.0.0.77/led1/on on the arduino
I am interested in "/led1/on"
I am interested in "/led1/on"
What is your interest in this? If you capture what the browser sent, then that will be included.
@Everydaydiesal- do you not get "led/on" in the string read from client.read()? Try this fragment inside your loop and see the results. (from Ethernet - Arduino Reference)
if (client.available()) {
char c = client.read();
Serial.print(c);
}
The only way to get the original URL is to parse the request for the "Host:" variable, and this is not as reliable as you think. By the time the server gets the request, the web browser has performed a dns resolution on the domain name, and sends the request to the resolved IP address.
Hi
This is an example of the http request for my application received by an Arduino EthernetClient object that you can read and parse:
GET /15330/ HTTP/1.1
ACCEPT: TEXT/HTML, APPLICATION/XHTML+XML, */*
REFERER: HTTP://WWW.2WG.CO.NZ/
ACCEPT-LANGUAGE: EN-US
USER-AGENT: MOZILLA/5.0 (WINDOWS NT 6.1; WOW64; TRIDENT/7.0; RV:11.0) LIKE GECKO
ACCEPT-ENCODING: GZIP, DEFLATE
HOST: WWW.2WG.CO.NZ
DNT: 1
CONNECTION: KEEP-ALIVE
<<AND A BLANK LINE HERE>>
The user typed http://www.2wg.co.nz/15330/ into their browser. The /15330/ URL is listed in the first line of the http request prefixed by the request type (GET, POST, etc) and terminated by HTTP/1.1
Is this what you are after?
Cheers
Catweazle NZ