waterlubber

Arduino Code

Feb 25th, 2014
82
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. If you think my spacing is wonky, it isn't, it's Pastebin's fault.
  3. Read the RAW paste data instead. otherwise, continue on */
  4.  
  5. #include <SPI.h>
  6. #include <Ethernet.h>
  7. #include <SD.h>
  8. byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
  9. IPAddress ip(192,168,1,120);
  10. EthernetServer server(80);
  11. char current = '';
  12. char FileName[7];
  13. int x;
  14.  
  15. void setup()
  16. {
  17.   Serial.begin(9600);
  18.   Ethernet.begin(mac, ip);
  19.   server.begin(); //Boot!
  20.   SD.begin(); //Start reading from that SD Car there
  21. }
  22.  
  23. void loop() {
  24.   EthernetClient client = server.available();
  25.   if(client) {
  26.     Serial.println("Request Recieved!");
  27.     while (client.connected()) {
  28.       if (client.available()) {
  29.         char Packet[] = client.read();
  30.         delay(100); //Wait a bit for it to get that request! It's big!
  31.         Serial.print(Packet[0,29]);
  32.         if(Packet[0] == 'G' && Packet[1] == 'E' && Packet[2] == 'T') {
  33.           for(x=5; current != ' '; x++)
  34.           {
  35.           FileName[x-5] = Packet[x];
  36.           current = Packet[x+1];
  37.           }
  38.         }
  39.         Serial.print("File name is: ");
  40.         Serial.println(FileName);
  41.         doc = SD.open(FileName);
  42.         if(doc) {
  43.           client.println("HTTP/1.1 200 OK");
  44.           client.println("Content-Type: text/html");
  45.           client.println("Connection: close");
  46.           client.print(doc);
  47.       }
  48.     }
  49.   }
  50. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×