Προς το περιεχόμενο

Προτεινόμενες αναρτήσεις

Δημοσ.

Το uno βασίζετε στον ATMega328U ο οποίος έχει μόλις 2KB SRAM. Οπότε ΟΛΕΣ οι μεταβλητές σου και σταθερές σου (συμπεριλαμβανομένων των strings που βρίσκονται στις println εντολές δεν πρέπει να ξεπερνούν τα 2ΚΒ. 

Ο HTML στο ποστ 16 είναι απο μόνος του 1077 bytes. Βάλε και την κλάση String που είναι απο μόνη της μαντάρα, νομίζω ότι παίζεις με την φωτιά....

 

Υπάρχει ένα MACRO στο arduino που λέει στον compiler να μην αποθηκεύει τις σταθερές στην SRAM αλλά να τις διαβάζει απο την FLASH (εκεί δηλαδή που αποθηκεύετε το προς εκτέλεση πρόγραμμα) 

Δοκίμασε στις println να τις βάζεις ώς εξής:

client.println(F("<BODY>"));

Με αυτό τον τρόπο τα strings,  θα μένουν στην PROGMEM και δεν θα πιάνουν χώρο στην SRAM.

 

Λύση για τα CSS δυστηχώς δεν ξέρω, δεν έχω ασχοληθεί ποτέ με το θέμα, αλλά παρακολουθώ με ενδιαφέρον για να μάθω τι θα βγει τελικά  :-)

  • Απαντ. 35
  • Δημ.
  • Τελ. απάντηση

Συχνή συμμετοχή στο θέμα

Συχνή συμμετοχή στο θέμα

Δημοσ.

συγγνώμη που άργησα τόσο πολύ να απαντήσω,αλλά δεν είχα προλάβει να μπώ..ακόμα δεν έχω βρει λύση για το πώς να βλέπει ένα css από την sd..προσπαθώ να τα στήσω τουλάχιστον σε τοπικό δίκτυο,αλλά αντιμετωπίζω κάποιες δυσκολίες..θα δοκιμάσω αυτό που μου είπες με τις println για να ελευθερώσω μνήμη και θα συνεχίσω να ψάχνω λύση για τα css..
θεωρητικά,δε θα μπορούσα να χρησιμοποιήσω αυτό;;με όσα είπαν τα παιδιά πιο πριν μου φαίνεται οτι κάτι θα γινόταν..απλά δεν ξέρω πώς να το συνδέσω με τον κώδικα..

Δημοσ.

παιδιά να ρωτήσω κάτι χαζό;;πώς μπορώ να "μπλέξω" τον κώδικα από το tutorial εδώ: 

#define REQ_BUF_SZ   20

// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 20);   // IP address, may need to change depending on network
EthernetServer server(80);       // create a server at port 80
File webFile;                    // handle to files on SD card
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0;              // index into HTTP_req buffer

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.");

    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients
}

void loop()
{
    EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                // buffer first part of HTTP request in HTTP_req array (string)
                // leave last element in array as 0 to null terminate string (REQ_BUF_SZ - 1)
                if (req_index < (REQ_BUF_SZ - 1)) {
                    HTTP_req[req_index] = c;          // save HTTP request character
                    req_index++;
                }
                Serial.print(c);    // print HTTP request character to serial monitor
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connnection: close");
                    client.println();
                    // open requested web page file
                    if (StrContains(HTTP_req, "GET / ")
                                 || StrContains(HTTP_req, "GET /index.htm")) {
                        webFile = SD.open("index.htm");        // open web page file
                    }
                    else if (StrContains(HTTP_req, "GET /page2.htm")) {
                        webFile = SD.open("page2.htm");        // open web page file
                    }
                    // send web page to client
                    if (webFile) {
                        while(webFile.available()) {
                            client.write(webFile.read());
                        }
                        webFile.close();
                    }
                    // reset buffer index and all buffer elements to 0
                    req_index = 0;
                    StrClear(HTTP_req, REQ_BUF_SZ);
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
}

// sets every element of str to 0 (clears array)
void StrClear(char *str, char length)
{
    for (int i = 0; i < length; i++) {
        str[i] = 0;
    }
}

// searches for the string sfind in the string str
// returns 1 if string found
// returns 0 if string not found
char StrContains(char *str, char *sfind)
{
    char found = 0;
    char index = 0;
    char len;

    len = strlen(str);
    
    if (strlen(sfind) > len) {
        return 0;
    }
    while (index < len) {
        if (str[index] == sfind[found]) {
            found++;
            if (strlen(sfind) == found) {
                return 1;
            }
        }
        else {
            found = 0;
        }
        index++;
    }

    return 0;
}

με το δικό μου,ώστε ναι μεν να μπαίνει στην index.htm σελίδα,όπως του τύπου,αλλά μετά να παίζει με τα pin όπως αυτός που έχω τώρα;;

Δημοσ.

Εκεί που λέει open requested web file.

Το if απο κάτω το κανεις else if, και απο πανω βάζεις τα δικά σου if else if.

 

 

Βασικά τι δεν καταλαβαινεις στο παράδειγμα;

Δημοσ.

αν το κάνω else if και βάλω τα δικά μου if και else if,δεν θα ανοίξει αυτό σαν αρχική σελίδα..σωστά;εγώ θέλω να μου ανοίξει το index.htm και μετά,ανάλογα με τις επιλογές μου να δώσει τις εξόδους στα αντίστοιχα pin..επίσης,αυτό που με μπέρδεψε(μπορεί να είναι τελείως χαζό,ειλικρινά) είναι πώς μετά θα μπλέξω το pinmode από τον κώδικα που χρησιμοποιώ τώρα,σε αυτό.θα έπρεπε να αντιγράψω το

 pinMode(4, OUTPUT);
  pinMode(6, OUTPUT);

στις δηλώσεις και μετά το

    if(readString.indexOf("?lighton1") >0)//checks for on
          {
            digitalWrite(4, HIGH);    // set pin 4 high
            Serial.println("Led On");
          }
          else{
          if(readString.indexOf("?lightoff1") >0)//checks for off
          {
            digitalWrite(4, LOW);    // set pin 4 low
            Serial.println("Led Off");
          }
          }
          
          if(readString.indexOf("?lighton2") >0)//checks for on
          {
            digitalWrite(6, LOW);    // set pin 4 high
            Serial.println("Led On");
          }
          else{
          if(readString.indexOf("?lightoff2") >0)//checks for off
          {
            digitalWrite(6, HIGH);    // set pin 4 low
            Serial.println("Led Off");
          }
          }
           //clearing string for next read
           readString="";

πριν κλείσω το void loop;;

Δημοσ.
void loop()
{
EthernetClient client = server.available(); // try to get client

if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
// buffer first part of HTTP request in HTTP_req array (string)
// leave last element in array as 0 to null terminate string (REQ_BUF_SZ - 1)
if (req_index < (REQ_BUF_SZ - 1)) {
HTTP_req[req_index] = c; // save HTTP request character
req_index++;
}
Serial.print(c); // print HTTP request character to serial monitor
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
// open requested web page file
//
//
//
if (StrContains(HTTP_req, "GET /index.htm?lighton1") )
{
digitalWrite(4, HIGH);
Serial.println("led1 on");
webFile = SD.open("index.htm");
}
else if(StrContains(HTTP_req, "GET /index.htm?lightoff1") )
{
digitalWrite(4, LOW);
Serial.println("led1 off");
webFile = SD.open("index.htm");
}
else if(....)
{
...
}
else if (StrContains(HTTP_req, "GET / ")
|| StrContains(HTTP_req, "GET /index.htm")) {
webFile = SD.open("index.htm"); // open web page file
}
else if (StrContains(HTTP_req, "GET /page2.htm")) {
webFile = SD.open("page2.htm"); // open web page file
}
// send web page to client
if (webFile) {
while(webFile.available()) {
client.write(webFile.read());
}
webFile.close();
}
// reset buffer index and all buffer elements to 0
req_index = 0;
StrClear(HTTP_req, REQ_BUF_SZ);
break;
}
// every line of text received from the client ends with \r\n
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
}
edit lol δες mac address hahahaha

Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε

Πρέπει να είστε μέλος για να αφήσετε σχόλιο

Δημιουργία λογαριασμού

Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!

Δημιουργία νέου λογαριασμού

Σύνδεση

Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.

Συνδεθείτε τώρα

  • Δημιουργία νέου...