Hello everybody,
i am actually seeking the simplest way to add favicon.ico from SD card on ethernet shield to webserver. also wondering is there a way to use php files from sd card too?
thanks alot,
Max
Hello everybody,
i am actually seeking the simplest way to add favicon.ico from SD card on ethernet shield to webserver. also wondering is there a way to use php files from sd card too?
thanks alot,
Max
i am actually seeking the simplest way to add favicon.ico from SD card on ethernet shield to webserver.
Serving up the favicon.ico file from the SD card is no different from serving up any other file, except that you may have to add additional Content: records to the output stream to define the type of file being sent.
also wondering is there a way to use php files from sd card too?
Not a snowball's chance in hell. PHP files are EXECUTED on the server. The output is sent to the client.
can u please give me an example code for the favicon?
will appreciate all ur time and help
thanks,
Max
can u please give me an example code for the favicon?
When you post the code that proves that you need to serve up that data, yes.
what data man? i have some web server and just wish to get a favicon to it. thats all
i have some web server
If this means "I have an Arduino with an Ethernet shield acting as a server", then you have some damned code. Post that code.
If it means something else, you are in the wrong place.
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
modified 02 Sept 2015
by Arturo Guadalupi
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("
");
}
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
this is exactly the one i use just changed the addresses and port to suit my desire.
this is exactly the one i use just changed the addresses and port to suit my desire.
Regardless of what the client asked for, you generate the same response. When the client asked for /, you sent back some html. When the client asked for the favicon.ico file, you sent the same reply.
When you have code to check what the client wants, and serve up appropriate responses, we can talk about what the response should be when the client asks for favicon.ico.
sure i will begin my search right now and hopefully finds how i can check what the client wants
hopefully finds how i can check what the client wants
You already know that.
char c = client.read();
Serial.write(c);
You just need to save that data in a string (NULL terminated array of chars), so you can make decisions based on what the client wants.
got u and if the client requests for favicon in header i send the favicon but i never any requests for it :(. i am using latest of ff browser
got u and if the client requests for favicon in header i send the favicon but i never any requests for it :(. i am using latest of ff browser
Take a deep breath. Slow down, and try again.
I do not understand what "client requests for favicon in header" means. What header are you talking about?
What DO you see the client requesting? If the client is not asking for the favicon.ico file, why are you stressed over serving it?
because i want to add one to my server pages thats all
maxwe11:
because i want to add one to my server pages thats all
You can't force a browser to ask for a favicon. They do that when they want to display an icon on the tab that the page is displayed in. If your browser, or browser settings, don't do that, it will be useless to try to send something un-requested.
but aint most websites we visit have favicon beside the title in the browser tab? why we cant do that with arduino serv?
but aint most websites we visit have favicon beside the title in the browser tab?
I use Firefox, too. Probably not the same version you use. But, it does request favicon.ico for each tab.
My Arduino with Ethernet shield as server DOES get asked for the favicon.ico. I do not supply one, because I'm lazy. I just ignore that request.
When you show us your serial output, we can see what your browser is asking your server for. Is that really asking too much?
just uploaded the fav and added it to my page. was easiest i could think of.
Thanks Pauls
Max