Advertisement
j0h

Dope

j0h
Nov 27th, 2021
1,569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SPI.h>
  2. #include <NativeEthernet.h>
  3. #include <SD.h>
  4. void  pageWrite(EthernetClient client);
  5. void listenClient(EthernetClient client);
  6. byte mac[] = {
  7.   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
  8. };
  9. IPAddress ip(10, 1, 0, 177);
  10. EthernetServer server(80);
  11. void setup() {
  12.  
  13.   delay(5000);  //you want this delay. reason: tl;dr
  14.   Serial.begin(9600);
  15.   Ethernet.begin(mac, ip);
  16.  
  17. if (Ethernet.linkStatus() == LinkOFF) {
  18.     Serial.println("Ethernet cable is not connected.");
  19.   }
  20.   // start the server
  21.   server.begin();
  22.   delay(100);
  23.   Serial.print("server is at ");
  24.   Serial.println(Ethernet.localIP());
  25. } //end setup
  26.  
  27. void loop() {
  28.       EthernetClient client = server.available();
  29. listenClient(client);
  30. }  //end loop  
  31. void listenClient(EthernetClient client){
  32.  
  33.    if (client) {
  34.     boolean currentLineIsBlank = true;
  35.     while (client.connected()) {
  36.        if (client.available()) {
  37.           char c = client.read();
  38.        // Serial.write(c);   //tells about the client connection
  39.         if (c == '\n' && currentLineIsBlank) {
  40.           pageWrite(client);
  41.           break;
  42.         }
  43.         if (c == '\n') {
  44.           // you're starting a new line
  45.           currentLineIsBlank = true;
  46.         } else if (c != '\r') {
  47.           // you've gotten a character on the current line
  48.           currentLineIsBlank = false;
  49.         }
  50.       }//end avail
  51.     } //end conect
  52.     // give the web browser time to receive the data
  53.     delay(1);
  54.     // close the connection:
  55.     client.stop();
  56.   } //end client
  57. }//end listenClient()
  58. void  pageWrite(EthernetClient client){
  59.   //svg css url encoder: yoksel.github.io/url-encoder
  60.          client.println("<!DOCTYPE HTML>\n<html>");
  61.           //css stylesheet:
  62.           client.println("\n<head>\n<style>\n body {");
  63.           client.println("background-image:");
  64.           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\");");
  65.           client.println("background-repeat: no-repeat;");
  66.           client.println(" }");
  67.           client.println("</style>\n</head>");
  68.           //end css
  69.           client.println("<body>\n</body>\n</html>");   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement