Pages: [1]   Go Down
Author Topic: storage from the internet  (Read 932 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


hi, I want to save the information from the web page on the internet , I am using the arduino ethernet like web server  programed with  html and I do not know why when you are on the internet in the web page you can not to save the information on the SD card . I try to send the information from a text box and I want to save this string , after that I want to read the information from the SD on the web page with a button.

thanks for your comments
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49385
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
hi, I want to save the information from the web page on the internet
What information? From what web page? Save it where?

Quote
I am using the arduino ethernet like web server  programed with  html and I do not know why when you are on the internet in the web page you can not to save the information on the SD card .
You can.

Quote
I try to send the information from a text box and I want to save this string , after that I want to read the information from the SD on the web page with a button.
Posting the code that is running on the Arduino would be a start. Explaining what parts of what you want to do are not working would be good.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


What information? From what web page? Save it where?
the information from textbox on the html web and save on the SD card .  I want to read the information from the SD on the web page with the READTEXT button.
Thanks for your comments.

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

byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0x5C, 0x16};
IPAddress ip(192,168,1,5);
byte gateway  [] = {192,168,1, 1};
byte subred  [] = {255, 255, 255, 0};
int led = 7;
EthernetServer server(80);
String cad=String(100);
File myFile;

void setup()
{
  pinMode(led, OUTPUT);
  Ethernet.begin(mac,ip,gateway,subred);
  server.begin();
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  pinMode(4, OUTPUT);
  if (!SD.begin(4))
  {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
 
}

void loop()

 
  cad="";
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        cad=cad+c;
        if (c == '\n')
        {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("<head><title> ARDUINO </title></head>");
          client.println("<body bgcolor='#CCCCCC' text='#FFFFFF' marginheight='50' marginwidth='125' link='#0033CC' vlink='#0033CC' alink='#0033CC'>");
          client.println("<center> <font face='Times New Roman, Times, serif' color='#0033CC' size='5'> ARDUINO </center>");
          client.println("<br>");
          client.println("<center> <font face='Times New Roman, Times, serif' color='#0033CC' size='5'><a href='http://www.arduino.cc'>arduino.com </a> </center>");
          client.println("<br>");
          client.println("<form method=get><input type=text name=txt>");
          client.println("<input type=submit value=SAVETEXTO>");
          client.println("</form>");
          client.println("<br>");
          client.println("<form method=get><input type=hidden name=read value=1>");
          client.println("<input type=submit value=READTEXT");
          client.println("</form>");
          if ( cad.lastIndexOf( "txt" ) > 0 )
          {
            digitalWrite(led,HIGH);
          }
          if ( cad.lastIndexOf( "read" ) > 0 )
          {
            read();
            digitalWrite(led,HIGH);
          }         
          client.println("</body>");
          client.println("</html>");
          cad="";
          break;
        }
      }
    }
    client.stop();
  }
}


void read ()
{
  if ( SD.exists("test.txt") )
  {
    myFile = SD.open("test.txt");
    if (myFile) {
    while (myFile.available())
    {
      Serial.write(myFile.read());
      //client.write(myFile.read());    //  I do not know why this line not works
    }
    myFile.close();
    } else {
    Serial.println("error opening test.txt");
    }
  }
  else
  {
    Serial.print("ERROR");
  }
}
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6038
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is some code to speed up your download.
http://arduino.cc/forum/index.php/topic,134868.msg1123725.html#msg1123725

This call is in read()
Code:
      //client.write(myFile.read());    //  I do not know why this line not works
client is a variable local to loop(). If you want to use the client variable, you must either pass that as a parameter in the function call, or declare client as global.

Stay away from the String data type. It is unreliable and prone to crashing. Use character arrays instead.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49385
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
          client.println("<form method=get><input type=text name=txt>");
          client.println("<input type=submit value=SAVETEXTO>");
          client.println("</form>");
          client.println("<br>");
          client.println("<form method=get><input type=hidden name=read value=1>");
          client.println("<input type=submit value=READTEXT");
          client.println("</form>");
You should have ONE form with multiple items, not one item per form.
Logged

Pages: [1]   Go Up
Jump to: