Go Down

Topic: Question for riesens!! (Read 105 times) previous topic - next topic

Hey riesens!

i put this in my code
Code: [Select]
static File SDFile;
void SendWebPage(EthernetClient client) {
   byte buff[32] // The sending buffer; its size (now 32) influences directly RAM-Usage
   SDFile = SD.open("index.htm", FILE_READ); // Open the file index.htm on the root of your SDCard

   if (SDFile) {
      while(SDFile.available()) { // Is there still data to be read in the file
          memset(buff, '\n', sizeof(buff)); // Reset the buffer
          SDFile.read(buff, sizeof(buff)); // Read the next chunk of data to the buffer
          client.write(buff, sizeof(buff)); // Send the just read chunk of data to the client
      }

   } else {
      Serial.println("SDFile Read Error");
   }
 
}

 but i m getting this error, please can u help me?  the error is"expected initalizer before 'SDfile'"

Thanks a lot!

here's the code

Code: [Select]
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);



String readString = String(100); //string for fetching data from address

void setup()
{
    // disable Ethernet chip
    pinMode(10, OUTPUT);
    digitalWrite(10, HIGH);
   
    Serial.begin(9600);       // for debugging
   
    // initialize SD card
    Serial.println("Initializing SD card...");
    if (!SD.begin(4)) {
        Serial.println("ERROR - SD card initialization failed!");
        return;    // init failed
    }
    Serial.println("SUCCESS - SD card initialized.");
    // check for index.htm file
    if (!SD.exists("index.htm")) {
        Serial.println("ERROR - Can't find index.htm file!");
        return;  // can't find index file
    }
    Serial.println("SUCCESS - Found index.htm file.");
    // LEDs
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);

  // start the Ethernet connection and the server:

  Serial.println(F("Initiaizing ethernet..."));

  // this uses a fixed address
  Ethernet.begin(mac, ip);

  // get an address with DHCP
  //if (Ethernet.begin(mac) == 0)
  //  Serial.println("Failed to configure Ethernet using DHCP");

  // give the card a second to initialize
  delay(1000);

  server.begin();

  Serial.print(F("Garage Door Opener Control Ready at IP address "));
  Serial.println(Ethernet.localIP());
}

void loop()
{
  // command received (one character)  '1' - activate garage door button
  char cmd = 0;          // 1 - pulse button
  boolean done = false;  // set to indicate that response is complete

  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {

    Serial.println(F("new client"));
    readString = "";

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        //int i = c;
        //Serial.print("(");
        //Serial.print(i);
        //Serial.print(")");

        // store character received in receive string
        if (readString.length() < 100) {
          readString += (c);
        }

        // check for end of line
        if (c == '\n') {
            //Serial.print("Receved line: ");
            //Serial.print(readString); 

            // process line if its the "GET" request
            // a request looks like "GET /?1" or "GET /?2"
            if (readString.indexOf("GET") != -1) {
                if (readString.indexOf("?1") != -1)
                   cmd = '1';
                // check for other commands here. ie turn on light, etc.
                if (readString.indexOf("?2") != -1)
                   cmd = '2'; 
                                  if (readString.indexOf("?3") != -1)
                   cmd = '3';
                                  if (readString.indexOf("?4") != -1)
                   cmd = '4';
                                  if (readString.indexOf("?5") != -1)
                   cmd = '5';
                                  if (readString.indexOf("?6") != -1)
                   cmd = '6';
                                  if (readString.indexOf("?7") != -1)
                   cmd = '7';
                                 if (readString.indexOf("?8") != -1)
                   cmd = '8';
   
            }             

           // if a blank line was received (just cr lf, length of 2), then its the end of the request
           if (readString.length() == 2) {
             if (cmd == '1'){
                Serial.println(F("Activate Button"));
                digitalWrite(6, HIGH);

             }
                          if (cmd == '2'){
                Serial.println(F("Activate Button"));
                digitalWrite(6, LOW);

             }
                          if (cmd == '3'){
                Serial.println(F("Activate Button"));
                digitalWrite(5, HIGH);

             }
                          if (cmd == '4'){
                Serial.println(F("Activate Button"));
                digitalWrite(5, LOW);

             }
                          if (cmd == '5'){
                Serial.println(F("Activate Button"));
                digitalWrite(7, HIGH);

             }
                          if (cmd == '6'){
                Serial.println(F("Activate Button"));
                digitalWrite(7, LOW);

             }
                          if (cmd == '7'){
                Serial.println(F("Activate Button"));
                digitalWrite(8, HIGH);

             }
                          if (cmd == '8'){
                Serial.println(F("Activate Button"));
                digitalWrite(8, LOW);

             }

             // add other commands here

             // send web page back to client
             Serial.println(F("sending web page"));
             SendWebPage(client);
             Serial.println(F("web page sent"));

             cmd = 0;

             // break out and disconnect. This will tell the browser the request is complete without having to specify content-length
             break;

           }  // end of request reached

           // start line over           
           readString = "";
        }  // end of line reached
      }  // end data is available from client
    }  // end cient is connected
    // give the web browser time to receive the data
    Serial.println(F("delay before disconnect"));
    delay(100);
    // close the connection:
    client.stop();
    Serial.println(F("client disonnected"));
  }  // end client has been created
}

// send web page
static File SDFile;
void SendWebPage(EthernetClient client) {
   byte buff[32] // The sending buffer; its size (now 32) influences directly RAM-Usage
   SDFile = SD.open("index.htm", FILE_READ); // Open the file index.htm on the root of your SDCard

   if (SDFile) {
      while(SDFile.available()) { // Is there still data to be read in the file
          memset(buff, '\n', sizeof(buff)); // Reset the buffer
          SDFile.read(buff, sizeof(buff)); // Read the next chunk of data to the buffer
          client.write(buff, sizeof(buff)); // Send the just read chunk of data to the client
      }

   } else {
      Serial.println("SDFile Read Error");
   }
 
}

SurferTim

I'm not riesens, but I can answer your question. You forgot a semicolon.
Code: [Select]
// change this
   byte buff[32] // The sending buffer; its size (now 32) influences directly RAM-Usage
// to this
   byte buff[32]; // The sending buffer; its size (now 32) influences directly RAM-Usage

I'm not riesens, but I can answer your question. You forgot a semicolon.
Code: [Select]
// change this
   byte buff[32] // The sending buffer; its size (now 32) influences directly RAM-Usage
// to this
   byte buff[32]; // The sending buffer; its size (now 32) influences directly RAM-Usage


Thanks a lot!

Can u help me out with this problem:






My problem: I have an htm file in the sd card and i just want it to turn on/off my digital outputs  I 'll put the arduino source code and the htm file.

Code: [Select]
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);



String readString = String(100); //string for fetching data from address

void setup()
{
    // disable Ethernet chip
    pinMode(10, OUTPUT);
    digitalWrite(10, HIGH);
    
    Serial.begin(9600);       // for debugging
    
    // initialize SD card
    Serial.println("Initializing SD card...");
    if (!SD.begin(4)) {
        Serial.println("ERROR - SD card initialization failed!");
        return;    // init failed
    }
    Serial.println("SUCCESS - SD card initialized.");
    // check for index.htm file
    if (!SD.exists("index.htm")) {
        Serial.println("ERROR - Can't find index.htm file!");
        return;  // can't find index file
    }
    Serial.println("SUCCESS - Found index.htm file.");
    // LEDs
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);

  // start the Ethernet connection and the server:

  Serial.println(F("Initiaizing ethernet..."));

  // this uses a fixed address
  Ethernet.begin(mac, ip);

  // get an address with DHCP
  //if (Ethernet.begin(mac) == 0)
  //  Serial.println("Failed to configure Ethernet using DHCP");

  // give the card a second to initialize
  delay(1000);

  server.begin();

  Serial.print(F("Garage Door Opener Control Ready at IP address "));
  Serial.println(Ethernet.localIP());
}

void loop()
{
  // command received (one character)  '1' - activate garage door button
  char cmd = 0;          // 1 - pulse button
  boolean done = false;  // set to indicate that response is complete

  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {

    Serial.println(F("new client"));
    readString = "";

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        //int i = c;
        //Serial.print("(");
        //Serial.print(i);
        //Serial.print(")");

        // store character received in receive string
        if (readString.length() < 100) {
          readString += (c);
        }

        // check for end of line
        if (c == '\n') {
            //Serial.print("Receved line: ");
            //Serial.print(readString);  

            // process line if its the "GET" request
            // a request looks like "GET /?1" or "GET /?2"
            if (readString.indexOf("GET") != -1) {
                if (readString.indexOf("?1") != -1)
                   cmd = '1';
                // check for other commands here. ie turn on light, etc.
                if (readString.indexOf("?2") != -1)
                   cmd = '2';  
                                  if (readString.indexOf("?3") != -1)
                   cmd = '3';
                                  if (readString.indexOf("?4") != -1)
                   cmd = '4';
                                  if (readString.indexOf("?5") != -1)
                   cmd = '5';
                                  if (readString.indexOf("?6") != -1)
                   cmd = '6';
                                  if (readString.indexOf("?7") != -1)
                   cmd = '7';
                                 if (readString.indexOf("?8") != -1)
                   cmd = '8';
  
            }              

           // if a blank line was received (just cr lf, length of 2), then its the end of the request
           if (readString.length() == 2) {
             if (cmd == '1'){
                Serial.println(F("Activate Button"));
                digitalWrite(6, HIGH);

             }
                          if (cmd == '2'){
                Serial.println(F("Activate Button"));
                digitalWrite(6, LOW);

             }
                          if (cmd == '3'){
                Serial.println(F("Activate Button"));
                digitalWrite(5, HIGH);

             }
                          if (cmd == '4'){
                Serial.println(F("Activate Button"));
                digitalWrite(5, LOW);

             }
                          if (cmd == '5'){
                Serial.println(F("Activate Button"));
                digitalWrite(7, HIGH);

             }
                          if (cmd == '6'){
                Serial.println(F("Activate Button"));
                digitalWrite(7, LOW);

             }
                          if (cmd == '7'){
                Serial.println(F("Activate Button"));
                digitalWrite(8, HIGH);

             }
                          if (cmd == '8'){
                Serial.println(F("Activate Button"));
                digitalWrite(8, LOW);

             }

             // add other commands here

             // send web page back to client
             Serial.println(F("sending web page"));
             SendWebPage(client);
             Serial.println(F("web page sent"));

             cmd = 0;

             // break out and disconnect. This will tell the browser the request is complete without having to specify content-length
             break;

           }  // end of request reached

           // start line over            
           readString = "";
        }  // end of line reached
      }  // end data is available from client
    }  // end cient is connected
    // give the web browser time to receive the data
    Serial.println(F("delay before disconnect"));
    delay(100);
    // close the connection:
    client.stop();
    Serial.println(F("client disonnected"));
  }  // end client has been created
}

// send web page
static File SDFile;
void SendWebPage(EthernetClient client) {
   byte buff[32]; // The sending buffer; its size (now 32) influences directly RAM-Usage
   SDFile = SD.open("index.htm", FILE_READ); // Open the file index.htm on the root of your SDCard

   if (SDFile) {
      while(SDFile.available()) { // Is there still data to be read in the file
          memset(buff, '\n', sizeof(buff)); // Reset the buffer
          SDFile.read(buff, sizeof(buff)); // Read the next chunk of data to the buffer
          client.write(buff, sizeof(buff)); // Send the just read chunk of data to the client
      }

   } else {
      Serial.println("SDFile Read Error");
   }
 
}


this is the htm file, but it does not switch on the digital outputs of the arduino, can you tell me what am i supposed to do? this post is my last and final problem

Code: [Select]
<!DOCTYPE HTML>
<html>
<head>
<title>Home Automation Control</title>

<style type='text/css'>
.label {font-size: 30px; text-align:center;}
button {width: 160px; height: 70px; font-size: 30px; -webkit-appearance: none; background-color:#dfe3ee; }
</style>

<script type='text/javascript'>

function OnButtonClicked(parm) { window.location.href=\"X?\" + parm; }

</script>

</head>

<body style=\"background-color:#3b5998\">

<div class=\"label\">

Home Auotmation Control<br/><br/>


  


<button onclick=\"OnButtonClicked('1');\">1ON</button><br/><br/>
<button onclick=\"OnButtonClicked('2');\">1Off</button><br/><br/>
<button onclick=\"OnButtonClicked('3');\">2ON</button><br/><br/>
<button onclick=\"OnButtonClicked('4');\">2Off</button><br/><br/>
<button onclick=\"OnButtonClicked('5');\">3ON</button><br/><br/>
<button onclick=\"OnButtonClicked('6');\">3Off</button><br/><br/>

<button onclick=\"OnButtonClicked('7');\">4ON</button><br/><br/>

    
<button onclick=\"OnButtonClicked('8');\">4Off</button><br/><br/>
  




</div>

</body>
</html>

Hey riesens i figured it out, it was just a missing semicolon(;)

You have helped me throughout my project and i have finally come to finish it, i just need one last problem sorted out and I'll be forever grateful

  If u could give me your email id so i can contact you directly, i would love to donate as a token of thanks for helping me out!

My problem: I just want you to help me with the "I usualy separate presentation ("the webpage") and data (ON/OFF) with AJAX." that you mentoined in the earlier post.  I 'll put the arduino source code and the htm file. Please sort out my last problem

Code: [Select]
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);



String readString = String(100); //string for fetching data from address

void setup()
{
    // disable Ethernet chip
    pinMode(10, OUTPUT);
    digitalWrite(10, HIGH);
    
    Serial.begin(9600);       // for debugging
    
    // initialize SD card
    Serial.println("Initializing SD card...");
    if (!SD.begin(4)) {
        Serial.println("ERROR - SD card initialization failed!");
        return;    // init failed
    }
    Serial.println("SUCCESS - SD card initialized.");
    // check for index.htm file
    if (!SD.exists("index.htm")) {
        Serial.println("ERROR - Can't find index.htm file!");
        return;  // can't find index file
    }
    Serial.println("SUCCESS - Found index.htm file.");
    // LEDs
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);

  // start the Ethernet connection and the server:

  Serial.println(F("Initiaizing ethernet..."));

  // this uses a fixed address
  Ethernet.begin(mac, ip);

  // get an address with DHCP
  //if (Ethernet.begin(mac) == 0)
  //  Serial.println("Failed to configure Ethernet using DHCP");

  // give the card a second to initialize
  delay(1000);

  server.begin();

  Serial.print(F("Garage Door Opener Control Ready at IP address "));
  Serial.println(Ethernet.localIP());
}

void loop()
{
  // command received (one character)  '1' - activate garage door button
  char cmd = 0;          // 1 - pulse button
  boolean done = false;  // set to indicate that response is complete

  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {

    Serial.println(F("new client"));
    readString = "";

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        //int i = c;
        //Serial.print("(");
        //Serial.print(i);
        //Serial.print(")");

        // store character received in receive string
        if (readString.length() < 100) {
          readString += (c);
        }

        // check for end of line
        if (c == '\n') {
            //Serial.print("Receved line: ");
            //Serial.print(readString);  

            // process line if its the "GET" request
            // a request looks like "GET /?1" or "GET /?2"
            if (readString.indexOf("GET") != -1) {
                if (readString.indexOf("?1") != -1)
                   cmd = '1';
                // check for other commands here. ie turn on light, etc.
                if (readString.indexOf("?2") != -1)
                   cmd = '2';  
                                  if (readString.indexOf("?3") != -1)
                   cmd = '3';
                                  if (readString.indexOf("?4") != -1)
                   cmd = '4';
                                  if (readString.indexOf("?5") != -1)
                   cmd = '5';
                                  if (readString.indexOf("?6") != -1)
                   cmd = '6';
                                  if (readString.indexOf("?7") != -1)
                   cmd = '7';
                                 if (readString.indexOf("?8") != -1)
                   cmd = '8';
  
            }              

           // if a blank line was received (just cr lf, length of 2), then its the end of the request
           if (readString.length() == 2) {
             if (cmd == '1'){
                Serial.println(F("Activate Button"));
                digitalWrite(6, HIGH);

             }
                          if (cmd == '2'){
                Serial.println(F("Activate Button"));
                digitalWrite(6, LOW);

             }
                          if (cmd == '3'){
                Serial.println(F("Activate Button"));
                digitalWrite(5, HIGH);

             }
                          if (cmd == '4'){
                Serial.println(F("Activate Button"));
                digitalWrite(5, LOW);

             }
                          if (cmd == '5'){
                Serial.println(F("Activate Button"));
                digitalWrite(7, HIGH);

             }
                          if (cmd == '6'){
                Serial.println(F("Activate Button"));
                digitalWrite(7, LOW);

             }
                          if (cmd == '7'){
                Serial.println(F("Activate Button"));
                digitalWrite(8, HIGH);

             }
                          if (cmd == '8'){
                Serial.println(F("Activate Button"));
                digitalWrite(8, LOW);

             }

             // add other commands here

             // send web page back to client
             Serial.println(F("sending web page"));
             SendWebPage(client);
             Serial.println(F("web page sent"));

             cmd = 0;

             // break out and disconnect. This will tell the browser the request is complete without having to specify content-length
             break;

           }  // end of request reached

           // start line over            
           readString = "";
        }  // end of line reached
      }  // end data is available from client
    }  // end cient is connected
    // give the web browser time to receive the data
    Serial.println(F("delay before disconnect"));
    delay(100);
    // close the connection:
    client.stop();
    Serial.println(F("client disonnected"));
  }  // end client has been created
}

// send web page
static File SDFile;
void SendWebPage(EthernetClient client) {
   byte buff[32]; // The sending buffer; its size (now 32) influences directly RAM-Usage
   SDFile = SD.open("index.htm", FILE_READ); // Open the file index.htm on the root of your SDCard

   if (SDFile) {
      while(SDFile.available()) { // Is there still data to be read in the file
          memset(buff, '\n', sizeof(buff)); // Reset the buffer
          SDFile.read(buff, sizeof(buff)); // Read the next chunk of data to the buffer
          client.write(buff, sizeof(buff)); // Send the just read chunk of data to the client
      }

   } else {
      Serial.println("SDFile Read Error");
   }
 
}


this is the htm file, but it does not switch on the digital outputs of the arduino, can you tell me what am i supposed to do? this post is my last and final problem

Code: [Select]
<!DOCTYPE HTML>
<html>
<head>
<title>Home Automation Control</title>

<style type='text/css'>
.label {font-size: 30px; text-align:center;}
button {width: 160px; height: 70px; font-size: 30px; -webkit-appearance: none; background-color:#dfe3ee; }
</style>

<script type='text/javascript'>

function OnButtonClicked(parm) { window.location.href=\"X?\" + parm; }

</script>

</head>

<body style=\"background-color:#3b5998\">

<div class=\"label\">

Home Auotmation Control<br/><br/>


  


<button onclick=\"OnButtonClicked('1');\">1ON</button><br/><br/>
<button onclick=\"OnButtonClicked('2');\">1Off</button><br/><br/>
<button onclick=\"OnButtonClicked('3');\">2ON</button><br/><br/>
<button onclick=\"OnButtonClicked('4');\">2Off</button><br/><br/>
<button onclick=\"OnButtonClicked('5');\">3ON</button><br/><br/>
<button onclick=\"OnButtonClicked('6');\">3Off</button><br/><br/>

<button onclick=\"OnButtonClicked('7');\">4ON</button><br/><br/>

    
<button onclick=\"OnButtonClicked('8');\">4Off</button><br/><br/>
  




</div>

</body>
</html>

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy