Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <NativeEthernet.h>
- #include <SD.h>
- void pageWrite(EthernetClient client);
- void listenClient(EthernetClient client);
- byte mac[] = {
- 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
- };
- IPAddress ip(10, 1, 0, 177);
- EthernetServer server(80);
- void setup() {
- delay(5000); //you want this delay. reason: tl;dr
- Serial.begin(9600);
- Ethernet.begin(mac, ip);
- if (Ethernet.linkStatus() == LinkOFF) {
- Serial.println("Ethernet cable is not connected.");
- }
- // start the server
- server.begin();
- delay(100);
- Serial.print("server is at ");
- Serial.println(Ethernet.localIP());
- } //end setup
- void loop() {
- EthernetClient client = server.available();
- listenClient(client);
- } //end loop
- void listenClient(EthernetClient client){
- if (client) {
- boolean currentLineIsBlank = true;
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- // Serial.write(c); //tells about the client connection
- if (c == '\n' && currentLineIsBlank) {
- pageWrite(client);
- 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;
- }
- }//end avail
- } //end conect
- // give the web browser time to receive the data
- delay(1);
- // close the connection:
- client.stop();
- } //end client
- }//end listenClient()
- void pageWrite(EthernetClient client){
- //svg css url encoder: yoksel.github.io/url-encoder
- client.println("<!DOCTYPE HTML>\n<html>");
- //css stylesheet:
- client.println("\n<head>\n<style>\n body {");
- client.println("background-image:");
- client.println("url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 227.35277 156.29323' height='6.1532764in' width='8.9508963in' %3E%3Cpath style='fill:%23ff0000; stroke:%23ff0000; stroke-width:1.32300019;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1' d='m 12.000819,0.66145838 c -6.2819637,0 -11.33936062,5.05739692 -11.33936062,11.33936062 V 144.29249 c 0,6.28197 5.05739692,11.33936 11.33936062,11.33936 H 215.35224 c 6.28197,0 11.33885,-5.05739 11.33885,-11.33936 V 12.000819 c 0,-6.2819637 -5.05688,-11.33936062 -11.33885,-11.33936062 z M 18.932696,12.696383 H 205.5854 c 5.02557,0 9.07128,4.04571 9.07128,9.071282 v 77.03923 c 0,5.025575 -4.04571,9.071285 -9.07128,9.071285 H 18.932696 c -5.025572,0 -9.0712819,-4.04571 -9.0712819,-9.071285 v -77.03923 c 0,-5.025572 4.0457099,-9.071282 9.0712819,-9.071282 z' /%3E%3Cellipse style='fill:%23ffffff;fill-opacity:1; stroke:%23ff0000; stroke-width:1.32300007; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1' cx='21.16666' cy='130.59085' rx='10.583334' ry='9.0714283' /%3E%3Cellipse style='fill:%23ffffff; fill-opacity:1; stroke:%23ff0000; stroke-width:1.32300007; stroke-miterlimit:4; stroke-dasharray:none;stroke-opacity:1' cx='200.62982' cy='131.57361' rx='10.583334' ry='9.0714283' /%3E%3C/svg%3E%0A\");");
- client.println("background-repeat: no-repeat;");
- client.println(" }");
- client.println("</style>\n</head>");
- //end css
- client.println("<body>\n</body>\n</html>"); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement