Arduino Web Server SD card read

I am trying to connect my sd card to my basic authentication(base64) but cannot seem to get it. I have added a simple html on my sd card and when authentication succeeds i want the web page to appear from my sd card.

This is my code. Any help is appreciated.

#include <WebServer.h>
#include <Base64.h>
#include <String.h>
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

// MAC address from Ethernet shield sticker under board
static uint8_t mac = { 0x00, 0x09, 0x34, 0x15, 0x18, 0xEA };

String readString;
String authentication, username, pass;
boolean login = false;

boolean authenticated = false;

WebServer webserver("", 80); // defaults to no prefix, port 80

void privateCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) {
if (server.checkCredentials(“aG9tZTpzZWN1cml0eQ==”)) { // home:security in base64 is YWRtaW46YWRtaW4=
server.httpSuccess();
P(helloMsg) = “

Login

Click the link to authenticate <a href=“dashboard.html”>Login

”;
server.printP(helloMsg);
// User authenticated - ok
authenticated = true;
} else {
server.httpUnauthorized();
}
}

void setup()
{
Serial.begin(9600);

// disable w5100 SPI while starting SD
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);

Serial.print(F(“Starting SD…”));
if(!SD.begin(4)) Serial.println(F(“SD failed”));
else Serial.println(F(“SD Ok”));

Serial.print(F(“Starting ethernet…”));
if(!Ethernet.begin(mac)) Serial.println(F(“Ethernet failed”));
else Serial.println(Ethernet.localIP());
digitalWrite(10, HIGH);

webserver.setDefaultCommand(&privateCmd);
webserver.addCommand(“dashboard.html”, &privateCmd);
webserver.begin();

}

void loop()
{

char buff[64];
int len = 64;

// //* process incoming connections one at a time forever */
webserver.processConnection(buff, &len);

}

Where is the link to the library(ies) you used?

And edit your post to enclose the code parts with code tags (the "#"-button in the editor) to avoid that the forum system is manipulating the code.

Hi I am noob at this so I don't know much. I just want to read my web page from my sd card on arduino. If you can help me with the code I would appreciate it. P.S. I don't know ies is :~

Without providing a link to the libraries you used I won’t help you. I don’t waste my time searching for a library that may match the name just to find some other code than the one you’re using. If you want help from us provide the necessary information and read the sticky note at the top of the forum! There you learn how to correctly post code into this forum.

HERE ARE MY LIBRARIES. IF YOU NEED SOMETHING ELSE JUST TELL ME

libraries.rar (39.7 KB)

Can you describe what exactly you get when you connect to your Arduino? Nothing? Does the browser ask for a password? Describe how a complete connection try happens with as much details as you have, including the URLs you’re using, the error messages you might get, etc.

Your code doesn’t handle reading from the SD card. Why are you expecting it to do anything with the SD card?

Yes as soon as I input the ip address a pop up window appears asking username and password. I want as soon as I login for the arduino to bring me the web page I have stored in my sd card.

I have tired both codes below and nothing works :~

I have tired both codes below and nothing works

What does that mean “nothing works”? The first link dumps the content of a file on the SD card to the serial interface, I guess, that’s not what you’re looking for. The second link should more or less do what you want except for the authentication. So you may need to combine the sketches.

Arduino is a programming platform. Although for some special cases you might get ready made software, for all personalized projects you have to program yourself or hire someone doing it for you. This forum is for helping you if you have specific problems but not a place were you get your programs written for free.

im not asking to write me the code just guidance on what to do(where to input the sd card code). Thnx anyway

Serving web stuff from an SD card.

//zoomkat 2/26/13
//SD server slider test code
//open serial monitor to see what the arduino receives
//browser address will look like http://192.168.1.102:84/servosld.htm when submited
//for use with W5100 based ethernet shields
//put the servosld.htm, slider.js, bluev_sl.gif,
//and bluev_bg.gif on the SD card
//download flies at:
// http://web.comporium.net/~shb/pix/servosld.htm
// http://web.comporium.net/~shb/pix/slider.js
// http://web.comporium.net/~shb/pix/bluev_bg.gif
// http://web.comporium.net/~shb/pix/bluev_sl.gif
// 

#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

#include <Servo.h> 
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo 
Servo myservoe, myservof, myservog; // myservoh not used due to lack of another free pin
String readString, pos;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port

//////////////////////

void setup(){

  Serial.begin(9600);

  // disable w5100 while setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);
  Serial.print("Starting SD..");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");

  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  //delay(2000);
  server.begin();
  Serial.println("Ready");

  myservoa.attach(2);  //the pin for the servoa control
  myservob.attach(3);  //the pin for the servob control
  myservoc.attach(5);  //the pin for the servoc control
  myservod.attach(6);  //the pin for the servod control 
  myservoe.attach(7);  //the pin for the servoa control
  myservof.attach(8);  //the pin for the servob control
  myservog.attach(9);  //the pin for the servoc control
  //myservoh.attach(10);  //the pin for the servod control 

}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string 
          readString += c; 
          //Serial.print(c);
        } 
        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging

            //select proper header for file to be sent to browser

          client.println("HTTP/1.1 200 OK"); //send new page
          if(readString.indexOf("servosld") >=0) {
            client.println("Content-Type: text/html");
            client.println(); 
          }

          if(readString.indexOf("slider") >=0) {
            client.println("Content-Type: application/x-javascript");
            client.println(); 
          }

          if(readString.indexOf("bluev") >=0) {
            client.println("Content-Type: image/gif");
            client.println(); 
          }

          //select file to send to browser
          if(readString.indexOf("servosld") >=0) {
            File myFile = SD.open("SERVOSLD.HTM");
            if (myFile) {

              byte clientBuf[64];
              int clientCount = 0;              

              while (myFile.available()) 
              {
                clientBuf[clientCount] = myFile.read();
                clientCount++;

                if(clientCount > 63)
                {
                  client.write(clientBuf,64);
                  clientCount = 0;
                }                
              }
              if(clientCount > 0) client.write(clientBuf,clientCount);            
              myFile.close();
            }
          }

          if(readString.indexOf("slider") >=0) {
            File myFile = SD.open("slider.js");
            if (myFile) {

              byte clientBuf[64];
              int clientCount = 0;              

              while (myFile.available()) 
              {
                clientBuf[clientCount] = myFile.read();
                clientCount++;

                if(clientCount > 63)
                {
                  client.write(clientBuf,64);
                  clientCount = 0;
                }                
              }
              if(clientCount > 0) client.write(clientBuf,clientCount); 
              myFile.close();
            }
          }

          if(readString.indexOf("bluev_sl") >=0) {
            File myFile = SD.open("bluev_sl.gif");
            if (myFile) {

              byte clientBuf[64];
              int clientCount = 0;              

              while (myFile.available()) 
              {
                clientBuf[clientCount] = myFile.read();
                clientCount++;

                if(clientCount > 63)
                {
                  client.write(clientBuf,64);
                  clientCount = 0;
                }                
              }
              if(clientCount > 0) client.write(clientBuf,clientCount); 
              myFile.close();
            }
          }

          if(readString.indexOf("bluev_bg") >=0) {
            File myFile = SD.open("bluev_bg.gif");
            if (myFile) {

              byte clientBuf[64];
              int clientCount = 0;              

              while (myFile.available()) 
              {
                clientBuf[clientCount] = myFile.read();
                clientCount++;

                if(clientCount > 63)
                {
                  client.write(clientBuf,64);
                  clientCount = 0;
                }                
              }
              if(clientCount > 0) client.write(clientBuf,clientCount); 
              myFile.close();
            }
          }

          delay(1);
          //stopping client
          client.stop();

          //process GET string request from client and and position servo

          pos = readString.substring(8, 12); //get the first four characters         
          //Serial.println(pos);
          int n = pos.toInt();  //convert readString into a number   
          Serial.println(n); 
          Serial.println();

          if(readString.indexOf("?0") >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf("?1") >0) myservob.writeMicroseconds(n);
          if(readString.indexOf("?2") >0) myservoc.writeMicroseconds(n);
          if(readString.indexOf("?3") >0) myservod.writeMicroseconds(n);
          if(readString.indexOf("?4") >0) myservoe.writeMicroseconds(n);
          if(readString.indexOf("?5") >0) myservof.writeMicroseconds(n);
          if(readString.indexOf("?6") >0) myservog.writeMicroseconds(n);
          //only seven servo pins, so back to myservoa for testing
          if(readString.indexOf("?7") >0) myservoa.writeMicroseconds(n);

          //clearing string for next read
          readString="";
          pos="";
        }
      }
    }
  } 
}