Show Posts
Pages: 1 ... 3 4 [5]
61  Forum 2005-2010 (read only) / Interfacing / Re: Ethernet Shield: HTML on: January 07, 2011, 06:04:31 am
Ah, I see, I'm familiar with DOS, so it shouldn't be a problem.
Thanks.


62  Forum 2005-2010 (read only) / Interfacing / Re: Ethernet Shield: HTML on: January 06, 2011, 08:56:51 pm
Thanks a bunch!!!
It works perfectly, now I just need to design a website. smiley-grin
63  Forum 2005-2010 (read only) / Interfacing / Re: Ethernet Shield: HTML on: January 06, 2011, 08:10:49 pm
Thanks, I got it to use HTML files properly, but I cant get it to show pictures, not even in the unedited (except for mac, ip, and port) code in the post you showed me.


Edit: I can view pictures but somehow the the file names are shortened from the original file.

For example, if the file is named "W3SCHOOLS.JPG"
                     it gets changed to "W3SCHO~1.JPG"

Is this a HTML thing or an Arduino thing? This isn't a big problem but can it be fixed?

64  Forum 2005-2010 (read only) / Interfacing / Ethernet Shield: HTML on: January 06, 2011, 03:59:13 pm
First of all, I'm not new to the Arduino, I've made some (advanced) projects before.
Anyways, I have the Ethernet Shield w/ SD Card and am currently using it as a web server. I was wondering if I could have the Arduino display HTML files that are already on the SD card rather then needing to type in all the HTML in the Arduino itself.

If you would like to see my code, which is currently a little messy, here:
Code:
/*
 * local url is http://192.168.1.80:8080/
 */
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <Ethernet.h>
#define greenLEDpin 8
#define redLEDpin 9
boolean led2 = true;
int hits = 0;
int count =0;

/************ ETHERNET STUFF ************/
byte mac[] = {
  0x90, 0xA2, 0xDA, 0x00, 0x1C, 0x0E };
byte ip[] = {
  192, 168, 1, 80 };
Server server(8080);


/************ SDCARD STUFF ************/
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
#define error(s) error_P(PSTR(s))
void error_P(const char* str) {
  PgmPrint("error: ");
  SerialPrintln_P(str);
  if (card.errorCode()) {
    PgmPrint("SD error: ");
    Serial.print(card.errorCode(), HEX);
    Serial.print(',');
    Serial.println(card.errorData(), HEX);
  }
  while(1);
}

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

  pinMode(greenLEDpin, OUTPUT);
  pinMode(redLEDpin, OUTPUT);

  PgmPrint("Free RAM: ");
  Serial.println(FreeRam());  

  pinMode(10, OUTPUT);              
  digitalWrite(10, HIGH);              

  if (!card.init(SPI_FULL_SPEED, 4)) error("card.init failed!");

  if (!volume.init(&card)) error("vol.init failed!");

  PgmPrint("Volume is FAT");
  Serial.println(volume.fatType(),DEC);
  Serial.println();

  if (!root.openRoot(&volume)) error("openRoot failed");

  PgmPrintln("Files found in root:");
  root.ls(LS_DATE | LS_SIZE);
  Serial.println();

  PgmPrintln("Files found in all dirs:");
  root.ls(LS_R);

  Serial.println();
  PgmPrintln("Done");

  Ethernet.begin(mac, ip);
  server.begin();
}

void ListFiles(Client client, uint8_t flags) {

  dir_t p;

  root.rewind();
  client.println("<ul>");
  while (root.readDir(p) > 0) {
    if (p.name[0] == DIR_NAME_FREE) break;

    if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.') continue;

    if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;

    client.print("<li><a href=\"");
    for (uint8_t i = 0; i < 11; i++) {
      if (p.name[i] == ' ') continue;
      if (i == 8) {
        client.print('.');
      }
      client.print(p.name[i]);
    }
    client.print("\">");

    for (uint8_t i = 0; i < 11; i++) {
      if (p.name[i] == ' ') continue;
      if (i == 8) {
        client.print('.');
      }
      client.print(p.name[i]);
    }

    client.print("</a>");

    if (DIR_IS_SUBDIR(&p)) {
      client.print('/');
    }

    if (flags & LS_DATE) {
      root.printFatDate(p.lastWriteDate);
      client.print(' ');
      root.printFatTime(p.lastWriteTime);
    }
    if (!DIR_IS_SUBDIR(&p) && (flags & LS_SIZE)) {
      client.print(' ');
      client.print(p.fileSize);
    }
    client.println("</li>");
  }
  client.println("</ul>");
}

#define BUFSIZ 1024

void loop()
{

// this is red LED blink
  if(count >=500)
  {  
    led2 = !led2;
    digitalWrite(redLEDpin, led2);
    count = 0;
  }
  count +=1;
// end red LED blink

  char clientline[BUFSIZ];
  int index = 0;

  Client client = server.available();
  if (client) {
    boolean current_line_is_blank = true;

    index = 0;

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        if (c != '\n' && c != '\r') {
          clientline[index] = c;
          index++;
          if (index >= BUFSIZ)
            index = BUFSIZ -1;

          continue;
        }

        clientline[index] = 0;

        Serial.println(clientline);

        if (strstr(clientline, "GET / ") != 0) {


          /**************** Main page HTML starts here.*****************/

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html; charset=UTF-8");
          client.println();

          client.println("<html>");
          client.println("<head>");
          client.println("<title>Arduino WebServer</title>");
          client.println("</head>");

          client.println("<body>");
          client.println("<br />");
          client.println("<B>Hello World!!</B>");
          client.println("<br />");
          client.println("<br />");

          hits ++;
          client.print("Hits: ");
          client.print(hits);

          client.println("</body>");

          /**************** Main page HTML ends here.*****************/

        }
        else if (strstr(clientline, "GET /") != 0) {
          char *filename;

          filename = clientline + 5;

          (strstr(clientline, " HTTP"))[0] = 0;

          Serial.println(filename);

          if (! file.open(&root, filename, O_READ)) {
            client.println("HTTP/1.1 404 Not Found");
            client.println("Content-Type: text/html");
            client.println();
            client.println("<h2>Error 404</h2>");
            client.println("<s2>You know what that means...<s2>");
            client.println("");

            break;
          }

          Serial.println("Opened!");

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/plain");
          client.println();

          int16_t c;
          while ((c = file.read()) > 0) {

            client.print((char)c);
          }
          file.close();
        }
        else {
          client.println("HTTP/1.1 404 Not Found");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<h2>Error 404</h2>");
          client.println("<s2>You know what that means...<s2>");
          client.println("");
        }
        break;
      }
    }
    digitalWrite(greenLEDpin, HIGH);
    delay(1);
    digitalWrite(greenLEDpin, LOW);
    client.stop();
  }
}



FYI, I'm using Arduino UNO with the Arduino Ethernet Shield (W5100)

65  Forum 2005-2010 (read only) / Exhibition / Re: My Arduino Web Server on: January 23, 2011, 03:01:26 pm
Just to keep things organized,
When the New Arduino forums are up, I will remake this topic over there.

Don't bother to post in this thread anymore, I'll be asking more questions on the new forum. smiley
66  Forum 2005-2010 (read only) / Exhibition / Re: My Arduino Web Server on: January 19, 2011, 01:26:46 pm
This project is not finished, I'm still working on it.
If I wanted to give it a version number it would be v0.83.

One think I really want to try to do is set it up where I can edit the SD card contents without removing the SD card, perhaps over the Ethernet or serial.
Any Ideas?
67  Forum 2005-2010 (read only) / Exhibition / Re: My Arduino Web Server on: January 18, 2011, 08:06:41 pm
Quote
Very nice project, and that box looks elite!
Thanks,
The case was originally a really old 2 way parallel port selector box. Here is what it looked like before.
http://www.national-tech.com/hires/40d3-17602.jpg

68  Forum 2005-2010 (read only) / Exhibition / Re: My Arduino Web Server on: January 18, 2011, 07:49:38 pm
Quote
Very impressive! Thanks for posting physics-dude. You can learn a lot from doing projects like this  Smiley
Your right arduinomstr, besides learning more about the Arduino, I actually had to teach myself HTML since I decided to build most of the web site through a text editor. ;D

69  Forum 2005-2010 (read only) / Exhibition / Re: My Arduino Web Server on: January 18, 2011, 07:35:30 pm
Quote
How do you do the hit counter?
If you are hosting a web page from HTML files on the SD card you are going to make the Arduino send out data 2 times, one of the HTML file and one from the hit counter and/or other HTML code written directly on to the Arduino which is not part of the requested HTML file.
I have the source on the site already but here are the hit counter sections:

First define the variables:
Code:
int hits = 0;
int bangs = 0;
The following code should come after the main HTML content is sent out,
Code:
        //Hit counter
          if(bangs >= 2)
          {  
            hits ++;
            bangs = 0;
          }
          bangs +=1;

          client.print("Hits: ");  
          client.print(hits);  
          //End hit counter
"Bangs" is simply a random variable I came up with. I'll be uploading new code soon and I changed it to something a little more understandable, "SentItems". It really doesn't matter what it is though.

70  Forum 2005-2010 (read only) / Exhibition / Re: My Arduino Web Server on: January 17, 2011, 09:38:46 pm
470 hits in 24 hours, cool.

I have a question though, is there a way I can change files on the SD card without removing it? Its a pain to take apart everything when I need to do so.

71  Forum 2005-2010 (read only) / Exhibition / My Arduino Web Server on: January 16, 2011, 09:54:01 pm
I went a little overboard on this project, at first it was just a basic "Hello World" type of sketch, and then it turned into this.
    http://physicsdude.dyndns.tv/
Keep in mind that this is an Arduino. So,if the web pages start to load very slowly, its probably because you are not the only one viewing the site.

Thanks to everyone who helped me on these and other forums, it was a fun project. ;D

Don't hesitate to ask me questions, I was thinking about adding an FAQ section in the future.
72  Forum 2005-2010 (read only) / Bar Sport / Re: I'm New To The Arduino Fourms :) on: January 06, 2011, 08:30:13 pm
Quote
BUT RESISTORS MAKE THE LEDS DIM  smiley-sad
Ya, but they also prevent them from dying.  smiley-wink

73  Forum 2005-2010 (read only) / Bar Sport / I'm New To The Arduino Fourms :) on: January 06, 2011, 03:56:03 pm
I'm suppose to post one normal message before I can post an advanced one so, ya, here it is.
FYI, I have only recently discovered this forum.
I'm not new to the Arduino world, I've made some (advanced) projects before.
Lastly, I've known and used Arduinos for a little over a year now and currently have the Duemilanove and UNO along with a handful of shields.

Happy coding.  smiley

Pages: 1 ... 3 4 [5]