INFO: Dieses Forum nutzt Cookies...
Cookies sind für den Betrieb des Forums unverzichtbar. Mit der Nutzung des Forums erklärst Du dich damit einverstanden, dass wir Cookies verwenden.

Es wird in jedem Fall ein Cookie gesetzt um diesen Hinweis nicht mehr zu erhalten. Desweiteren setzen wir Google Adsense und Google Analytics ein.

Antwort schreiben 
 
Themabewertung:
  • 0 Bewertungen - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Ethernet-WebServer: Button-Belegung
07.06.2015, 12:36
Beitrag #9
RE: Ethernet-WebServer: Button-Belegung
Klar!
Also, im ersten Versuch habe ich getestet, ob die Webpage richtig im browser angezeigt wird. Dazu hab ich ein fertiges Bild IMAGE.JPG und die index.htm auf die SD-Card gespeichert. Beim Ausführen des sketch wird die Webpage richtig angezeigt. Tausche ich das Bild auf der SD-Card (manuell) aus, so wird das neue angezeigt. Also die Funktion "Webserver" klappt.
Nun der zweite Teil: Funktion des Button.
Der sketch soll ja nun das Aufnehmen eines Fotos ermöglichen. D.h. wenn ich den Button auf der browser-Seite klicke, dann soll über den sketch bei mir zuhause die cam VC0706 ausgelöst werden. Dazu will ich in der loop den Button auslesen und in den Zeilen danach im Sketch das Foto aufnehmen und auf SD speichern. Wenn die Seite dann refreshed wird, wird dann das neue Bild verwendet.
Dieses funktioniert nicht. Was ich nicht verstehe.

Wenn ich im sketch alle Zeilen bei der Button-Auswertung bis auf die erste Serial.print ... ( Serial.println("Button -Take a Picture- pressed!"); ) als Kommentar ausblende, Wird die Seite im Browser angezeigt. Natürlich wird kein Foto gemacht.
Wenn ich nun zusätzlich die nächsten beiden Serial.print Zeilen im sketch wieder aktiviere (/*....*/ entferne)
Serial.println("VC0706 Camera snapshot test");
Serial.println("");

wird die Webpage nicht mehr angezeigt. Es wurde der Button noch nicht gedrückt. Das ist, was ich nicht verstehe, da ich die mit dem Button verknüpfte Aktion ja noch nicht ausgeführt habe. Eigentlich sollte sich ja erst beim Drücken etwas tun.
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
07.06.2015, 13:03
Beitrag #10
RE: Ethernet-WebServer: Button-Belegung
Hi,
ich kann mir beim besten Willen nicht vorstellen, dass sich an der Web-Seite irgend etwas ändert, wenn Du zwei Serial.println aktivierst. Da hast Du bestimmt noch was anderes gemacht.
Stell doch mal die zwei Versionen des Sketch hier rein. Dann kann man sehen, was Du wirklich treibst.
Gruß,
Thorsten

Falls ich mit einer Antwort helfen konnte, wuerde ich mich freuen, ein paar Fotos oder auch ein kleines Filmchen des zugehoerigen Projekts zu sehen.
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
07.06.2015, 13:18 (Dieser Beitrag wurde zuletzt bearbeitet: 07.06.2015 13:43 von 4711engel.)
Beitrag #11
RE: Ethernet-WebServer: Button-Belegung
Hallo Herr Pferdekämper,
so geht es mir ja auch.
Hier nun die index.htm von der SD-Card:
Code:
<!DOCTYPE html>

<html>

    <head>

        <title>Arduino Ethernet Camera</title>

    </head>

    <body BGColor=#D0F0D0>

        <h1 align=center><Big><TT>Arduino Ethernet Camera</TT></Big></H1>
        <TABLE Bordercolor=#000000 cellspacing=6 align=center border=0>
            <TD>
            <img src="IMAGE.JPG">
            </TD>
        </TABLE>
        <TABLE Bordercolor=#000000 cellspacing=6 align=center border=0>
            <TD>
               <form action="/TakingPicture" method="GET">
               <button name="Take Picture" type="submit">Take Picture</button>
               </form>
            </TD>
        </TABLE>
    </body>

</html>



und die aktuelle Version des sketch. In der loop wird die webpage aufgebaut, das Bild IMAGE.JPG eingeladen und dann der Button abgefragt. Hier habe ich bis auf die Serial.println alle Code-Zeilen auskommentiert.

Code:
/*--------------------------------------------------------------
          Arduino Ethernet Camera
Take a picture using the adafruit_vc0706 , save it on SD-Card
and print it over ethernet on a internet browser
                  Ulrich Engel
  CoAuthor:       W.A. Smith, http://startingelectronics.org
--------------------------------------------------------------*/

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

// size of buffer used to capture HTTP requests
#define REQ_BUF_SZ   20
#define chipSelect 4

// MAC address from Ethernet shield sticker under board
byte mac[] = {0x90, 0xA2, 0xDA, 0x0F, 0x1E, 0x28};
IPAddress ip(192, 168, 178, 45); // IP address, may need to change depending on network
byte gateway[] = { 192, 168, 178, 1 };
byte subnet[] = { 255, 255, 255, 0 };
EthernetServer server(80);  // create a server at port 80
File webFile;
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0;              // index into HTTP_req buffer


SoftwareSerial cameraconnection = SoftwareSerial(2, 3);
Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);

//*************************** void setup ********************************

void setup()
{
    // disable Ethernet chip
    pinMode(10, OUTPUT);
    digitalWrite(10, HIGH);
    
// Open serial communications:
  Serial.begin(9600);

// start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());  

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

// **************  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++;
                }

                // print HTTP request character to serial monitor
                Serial.print(c);
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // open requested web page file
                    if (StrContains(HTTP_req, "GET / ")
                                 || StrContains(HTTP_req, "GET /index.htm")) {
                        client.println("HTTP/1.1 200 OK");
                        client.println("Content-Type: text/html");
                        client.println("Connnection: close");
                        client.println();
                        webFile = SD.open("index.htm");        // open web page file
                    }

                    if (StrContains(HTTP_req, "GET /IMAGE.JPG")) {
                        webFile = SD.open("IMAGE.JPG");
                        if (webFile) {
                            client.println("HTTP/1.1 200 OK");
                            client.println();
                        }
                    }
          
          
          
               if (StrContains(HTTP_req, "GET /TakingPicture")) {
                              client.println("HTTP/1.1 200 OK");
                              client.println("Content-Type: text/html");
                             client.println("Connnection: close");
                             client.println();  
                        
                          Serial.println("Button -Take a Picture- pressed!");                        
                        
                            
                          Serial.println("VC0706 Camera snapshot test");
                          Serial.println("");
/*                        
                        
                              // Try to locate the camera
                             if (cam.begin()) {
                                 Serial.println("Camera Found:");
                              } else {
                                 Serial.println("No camera found?");
                                 return;
                               }

                               // Existing image remove
                         //      SD.remove("IMAGE.JPG");

                               // Set the picture size - you can choose one of 640x480, 320x240 or 160x120
                                  //cam.setImageSize(VC0706_640x480);        // biggest
                                  cam.setImageSize(VC0706_320x240);        // medium
                                  //cam.setImageSize(VC0706_160x120);          // small

                               // You can read the size back from the camera (optional, but maybe useful?)
                                  uint8_t imgsize = cam.getImageSize();
                                  if (imgsize == VC0706_640x480) Serial.println("640x480");
                                  if (imgsize == VC0706_320x240) Serial.println("320x240");
                                  if (imgsize == VC0706_160x120) Serial.println("160x120");

                                  Serial.println("Snap in 3 secs...");
                                    delay(3000);

                                   if (! cam.takePicture())
                                       Serial.println("Failed to snap!");
                                    else
                                       Serial.println("Picture taken!");
  
                                    // Create an image with the name IMAGE.JPG
                                       char filename[10];
                                       strcpy(filename, "IMAGE.JPG");
                                    // Open the file for writing
                                       File imgFile = SD.open(filename, FILE_WRITE);

                                    // Get the size of the image (frame) taken  
                                       uint16_t jpglen = cam.frameLength();
                                       Serial.print("Storing ");
                                       Serial.print(jpglen, DEC);
                                       Serial.print(" byte image.");

                                       int32_t time = millis();
                                       pinMode(4, OUTPUT);
                                       // Read all the data up to # bytes!
                                       byte wCount = 0; // For counting # of writes
                                     while (jpglen > 0) {
                                       // read 32 bytes at a time;
                                       uint8_t *buffer;
                                       uint8_t bytesToRead = min(32, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
                                       buffer = cam.readPicture(bytesToRead);
                                       imgFile.write(buffer, bytesToRead);
                                       jpglen -= bytesToRead;
                                      }
                                       imgFile.close();
                                       time = millis() - time;
                                       Serial.println("done!");
                                       Serial.print(time); Serial.println(" ms elapsed");
                        
                                      webFile = SD.open("index.htm");       // open web page file
  */                                    
                                   }
        
      
          
                    if (webFile) {
                        while(webFile.available()) {
                            client.write(webFile.read()); // send web page to client
                        }
                        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)
}

/**********************StrClear *********************/

// 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;
    }
}

/**********************StrContains *********************/

// 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;
}


Wenn ich dort alle Zeilen auskommentiere ist die Webpage sofort angezeigt und wenn ich die Serial.println belasse, wird nur eine leere Seite angezeigt. d.h. die index.htm wird nich dargestellt.
Im serial monitor steht beim refreshen des browsers (durch mich) nur

GET / HTTP/1.1
Host: 4711engel.ddns.net
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cache-Control: max-age=0

Hier zwei screenshots:


https://www.dropbox.com/s/19flbjmzlj6q50...M.doc?dl=0

Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
07.06.2015, 14:01
Beitrag #12
RE: Ethernet-WebServer: Button-Belegung
Hi,
ok, jetzt nochmal ganz langsam: Bitte stelle mal BEIDE Versionen hier rein. Also sowohl die, bei der die Seite angezeigt wird als auch die, bei der sie nicht angezeigt wird. Deinen textuellen Beschreibungen glaube ich einfach nicht oder ich verstehe sie nicht.
Dein Dropbox-Link funktioniert bei mir nicht. Bitte das nächste Mal direkt hier dranhängen.
Gruß,
Thorsten

Falls ich mit einer Antwort helfen konnte, wuerde ich mich freuen, ein paar Fotos oder auch ein kleines Filmchen des zugehoerigen Projekts zu sehen.
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
07.06.2015, 14:17
Beitrag #13
RE: Ethernet-WebServer: Button-Belegung

.doc  PROBLEM.doc (Größe: 873,5 KB / Downloads: 30) Hier nun beide Versionen:

Version 1, die funktioniert:

Code:
/*--------------------------------------------------------------
          Arduino Ethernet Camera
Take a picture using the adafruit_vc0706 , save it on SD-Card
and print it over ethernet on a internet browser
                  Ulrich Engel
  CoAuthor:       W.A. Smith, http://startingelectronics.org
--------------------------------------------------------------*/

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

// size of buffer used to capture HTTP requests
#define REQ_BUF_SZ   20
#define chipSelect 4

// MAC address from Ethernet shield sticker under board
byte mac[] = {0x90, 0xA2, 0xDA, 0x0F, 0x1E, 0x28};
IPAddress ip(192, 168, 178, 45); // IP address, may need to change depending on network
byte gateway[] = { 192, 168, 178, 1 };
byte subnet[] = { 255, 255, 255, 0 };
EthernetServer server(80);  // create a server at port 80
File webFile;
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0;              // index into HTTP_req buffer


SoftwareSerial cameraconnection = SoftwareSerial(2, 3);
Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);

//*************************** void setup ********************************

void setup()
{
    // disable Ethernet chip
    pinMode(10, OUTPUT);
    digitalWrite(10, HIGH);
    
// Open serial communications:
  Serial.begin(9600);

// start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());  

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

// **************  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++;
                }

                // print HTTP request character to serial monitor
                Serial.print(c);
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // open requested web page file
                    if (StrContains(HTTP_req, "GET / ")
                                 || StrContains(HTTP_req, "GET /index.htm")) {
                        client.println("HTTP/1.1 200 OK");
                        client.println("Content-Type: text/html");
                        client.println("Connnection: close");
                        client.println();
                        webFile = SD.open("index.htm");        // open web page file
                    }

                    if (StrContains(HTTP_req, "GET /IMAGE.JPG")) {
                        webFile = SD.open("IMAGE.JPG");
                        if (webFile) {
                            client.println("HTTP/1.1 200 OK");
                            client.println();
                        }
                    }
          
          
          
               if (StrContains(HTTP_req, "GET /TakingPicture")) {
                              client.println("HTTP/1.1 200 OK");
                              client.println("Content-Type: text/html");
                             client.println("Connnection: close");
                             client.println();  
                        
                          Serial.println("Button -Take a Picture- pressed!");                        
                        
/*                            
                          Serial.println("VC0706 Camera snapshot test");
                          Serial.println("");
                        
                        
                              // Try to locate the camera
                             if (cam.begin()) {
                                 Serial.println("Camera Found:");
                              } else {
                                 Serial.println("No camera found?");
                                 return;
                               }

                               // Existing image remove
                         //      SD.remove("IMAGE.JPG");

                               // Set the picture size - you can choose one of 640x480, 320x240 or 160x120
                                  //cam.setImageSize(VC0706_640x480);        // biggest
                                  cam.setImageSize(VC0706_320x240);        // medium
                                  //cam.setImageSize(VC0706_160x120);          // small

                               // You can read the size back from the camera (optional, but maybe useful?)
                                  uint8_t imgsize = cam.getImageSize();
                                  if (imgsize == VC0706_640x480) Serial.println("640x480");
                                  if (imgsize == VC0706_320x240) Serial.println("320x240");
                                  if (imgsize == VC0706_160x120) Serial.println("160x120");

                                  Serial.println("Snap in 3 secs...");
                                    delay(3000);

                                   if (! cam.takePicture())
                                       Serial.println("Failed to snap!");
                                    else
                                       Serial.println("Picture taken!");
  
                                    // Create an image with the name IMAGE.JPG
                                       char filename[10];
                                       strcpy(filename, "IMAGE.JPG");
                                    // Open the file for writing
                                       File imgFile = SD.open(filename, FILE_WRITE);

                                    // Get the size of the image (frame) taken  
                                       uint16_t jpglen = cam.frameLength();
                                       Serial.print("Storing ");
                                       Serial.print(jpglen, DEC);
                                       Serial.print(" byte image.");

                                       int32_t time = millis();
                                       pinMode(4, OUTPUT);
                                       // Read all the data up to # bytes!
                                       byte wCount = 0; // For counting # of writes
                                     while (jpglen > 0) {
                                       // read 32 bytes at a time;
                                       uint8_t *buffer;
                                       uint8_t bytesToRead = min(32, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
                                       buffer = cam.readPicture(bytesToRead);
                                       imgFile.write(buffer, bytesToRead);
                                       jpglen -= bytesToRead;
                                      }
                                       imgFile.close();
                                       time = millis() - time;
                                       Serial.println("done!");
                                       Serial.print(time); Serial.println(" ms elapsed");
                        
                                      webFile = SD.open("index.htm");       // open web page file
  */                                    
                                   }
        
      
          
                    if (webFile) {
                        while(webFile.available()) {
                            client.write(webFile.read()); // send web page to client
                        }
                        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)
}

/**********************StrClear *********************/

// 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;
    }
}

/**********************StrContains *********************/

// 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;
}




Version 2 mit zusätzlichen zwei Zeilen:

Code:
/*--------------------------------------------------------------
          Arduino Ethernet Camera
Take a picture using the adafruit_vc0706 , save it on SD-Card
and print it over ethernet on a internet browser
                  Ulrich Engel
  CoAuthor:       W.A. Smith, http://startingelectronics.org
--------------------------------------------------------------*/

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

// size of buffer used to capture HTTP requests
#define REQ_BUF_SZ   20
#define chipSelect 4

// MAC address from Ethernet shield sticker under board
byte mac[] = {0x90, 0xA2, 0xDA, 0x0F, 0x1E, 0x28};
IPAddress ip(192, 168, 178, 45); // IP address, may need to change depending on network
byte gateway[] = { 192, 168, 178, 1 };
byte subnet[] = { 255, 255, 255, 0 };
EthernetServer server(80);  // create a server at port 80
File webFile;
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0;              // index into HTTP_req buffer


SoftwareSerial cameraconnection = SoftwareSerial(2, 3);
Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);

//*************************** void setup ********************************

void setup()
{
    // disable Ethernet chip
    pinMode(10, OUTPUT);
    digitalWrite(10, HIGH);
    
// Open serial communications:
  Serial.begin(9600);

// start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());  

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

// **************  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++;
                }

                // print HTTP request character to serial monitor
                Serial.print(c);
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // open requested web page file
                    if (StrContains(HTTP_req, "GET / ")
                                 || StrContains(HTTP_req, "GET /index.htm")) {
                        client.println("HTTP/1.1 200 OK");
                        client.println("Content-Type: text/html");
                        client.println("Connnection: close");
                        client.println();
                        webFile = SD.open("index.htm");        // open web page file
                    }

                    if (StrContains(HTTP_req, "GET /IMAGE.JPG")) {
                        webFile = SD.open("IMAGE.JPG");
                        if (webFile) {
                            client.println("HTTP/1.1 200 OK");
                            client.println();
                        }
                    }
          
          
          
               if (StrContains(HTTP_req, "GET /TakingPicture")) {
                              client.println("HTTP/1.1 200 OK");
                              client.println("Content-Type: text/html");
                             client.println("Connnection: close");
                             client.println();  
                        
                          Serial.println("Button -Take a Picture- pressed!");                        
                        
                            
                          Serial.println("VC0706 Camera snapshot test");
                          Serial.println("");
                        
/*                        
                              // Try to locate the camera
                             if (cam.begin()) {
                                 Serial.println("Camera Found:");
                              } else {
                                 Serial.println("No camera found?");
                                 return;
                               }

                               // Existing image remove
                         //      SD.remove("IMAGE.JPG");

                               // Set the picture size - you can choose one of 640x480, 320x240 or 160x120
                                  //cam.setImageSize(VC0706_640x480);        // biggest
                                  cam.setImageSize(VC0706_320x240);        // medium
                                  //cam.setImageSize(VC0706_160x120);          // small

                               // You can read the size back from the camera (optional, but maybe useful?)
                                  uint8_t imgsize = cam.getImageSize();
                                  if (imgsize == VC0706_640x480) Serial.println("640x480");
                                  if (imgsize == VC0706_320x240) Serial.println("320x240");
                                  if (imgsize == VC0706_160x120) Serial.println("160x120");

                                  Serial.println("Snap in 3 secs...");
                                    delay(3000);

                                   if (! cam.takePicture())
                                       Serial.println("Failed to snap!");
                                    else
                                       Serial.println("Picture taken!");
  
                                    // Create an image with the name IMAGE.JPG
                                       char filename[10];
                                       strcpy(filename, "IMAGE.JPG");
                                    // Open the file for writing
                                       File imgFile = SD.open(filename, FILE_WRITE);

                                    // Get the size of the image (frame) taken  
                                       uint16_t jpglen = cam.frameLength();
                                       Serial.print("Storing ");
                                       Serial.print(jpglen, DEC);
                                       Serial.print(" byte image.");

                                       int32_t time = millis();
                                       pinMode(4, OUTPUT);
                                       // Read all the data up to # bytes!
                                       byte wCount = 0; // For counting # of writes
                                     while (jpglen > 0) {
                                       // read 32 bytes at a time;
                                       uint8_t *buffer;
                                       uint8_t bytesToRead = min(32, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
                                       buffer = cam.readPicture(bytesToRead);
                                       imgFile.write(buffer, bytesToRead);
                                       jpglen -= bytesToRead;
                                      }
                                       imgFile.close();
                                       time = millis() - time;
                                       Serial.println("done!");
                                       Serial.print(time); Serial.println(" ms elapsed");
                        
                                      webFile = SD.open("index.htm");       // open web page file
  */                                    
                                   }
        
      
          
                    if (webFile) {
                        while(webFile.available()) {
                            client.write(webFile.read()); // send web page to client
                        }
                        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)
}

/**********************StrClear *********************/

// 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;
    }
}

/**********************StrContains *********************/

// 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;
}
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
07.06.2015, 14:31
Beitrag #14
RE: Ethernet-WebServer: Button-Belegung
Hi,
das ist in der Tat seeehr seltsam. Möglicherweise produziert da irgendwas ein Speicherproblem.
1. Was geben die beiden Programme auf Serial aus?
2. Füge mal die unten stehende Funktion ein und gebe deren Ergebnis auf Serial aus, am besten an der Stelle wo die besagten Serial.println stehen.
Gruß,
Thorsten

Code:
int freeRam ()
{
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
};

Falls ich mit einer Antwort helfen konnte, wuerde ich mich freuen, ein paar Fotos oder auch ein kleines Filmchen des zugehoerigen Projekts zu sehen.
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
07.06.2015, 14:39
Beitrag #15
RE: Ethernet-WebServer: Button-Belegung
Version 1 (eine serial):

server is at 192.168.178.45
Initializing SD card...
SUCCESS - SD card initialized.
SUCCESS - Found index.htm file.
GET / HTTP/1.1
Host: 4711engel.ddns.net
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cache-Control: max-age=0

GET /IMAGE.JPG HTTP/1.1
Host: 4711engel.ddns.net
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://4711engel.ddns.net/
Connection: keep-alive



Version 2 (mehr serial):

server is at 192.168.178.45
Initializing SD card...
SUCCESS - SD card initialized.
SUCCESS - Found index.htm file.
GET / HTTP/1.1
Host: 4711engel.ddns.net
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:38.0) Gecko/20100101 Firefox/38.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cache-Control: max-age=0



Und nun mit dem neuen code:

Gibt eine arduino fehlermeldung
Arduino_Ehernet_Camera----1-3.ino: In function 'void loop()':
Arduino_Ehernet_Camera----1-3.ino:126: error: a function-definition is not allowed here before '{' token
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
07.06.2015, 14:52 (Dieser Beitrag wurde zuletzt bearbeitet: 07.06.2015 14:53 von Thorsten Pferdekämper.)
Beitrag #16
RE: Ethernet-WebServer: Button-Belegung
Hi,
wo packst Du denn Funktionsdeklarationen hin? Der neue Code muss außerhalb von allen anderen Funktionen stehen. Du sollst das Ding ja nur im loop aufrufen und das Ergebnis auf Serial ausgeben.
Anscheinend tritt das Problem schon auf, bevor Du überhaupt auf den Button drückst. D.h. der Funktionsaufruf von freeRam ist dort dann auch Blödsinn. Ruf das mal direkt danach auf:
Code:
if (StrContains(HTTP_req, "GET / ")
                                  || StrContains(HTTP_req, "GET /index.htm")) {
...und das nächste Mal, wenn Du wieder eine Fehlermeldung bekommst, dann bitte auch das Coding mit rein kopieren, was den Fehler erzeugt. Sonst gibt's keine Antwort mehr von mir.
Gruß,
Thorsten

Falls ich mit einer Antwort helfen konnte, wuerde ich mich freuen, ein paar Fotos oder auch ein kleines Filmchen des zugehoerigen Projekts zu sehen.
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
Antwort schreiben 


Möglicherweise verwandte Themen...
Thema: Verfasser Antworten: Ansichten: Letzter Beitrag
  Arduino UNO und Ethernet Shield 2 POE und Fritzbox 3272 tr3 2 149 19.11.2016 10:46
Letzter Beitrag: tr3
  ESP8266 ESP12-E Webserver-Frage Claus_M 8 236 14.11.2016 22:02
Letzter Beitrag: Claus_M
  Webserver + Bild als Hintergrund ?! Marc2014 8 244 11.10.2016 21:39
Letzter Beitrag: Bitklopfer
  Ethernet Modul Enc28j60 Pin13 LED Schalten BennIY 16 492 27.09.2016 20:30
Letzter Beitrag: BennIY
  ESP8266 Webserver Programmieren HDT 11 752 23.08.2016 13:28
Letzter Beitrag: HDT
  Hilfe gesucht. Webserver Statsiche und Dynamische HTMl Seite b3ta 11 447 22.08.2016 08:07
Letzter Beitrag: b3ta
  ESP8266 Webserver Marc2014 0 346 30.07.2016 20:15
Letzter Beitrag: Marc2014
Question Webserver, Client, Loop Marc2014 6 363 29.07.2016 21:04
Letzter Beitrag: Marc2014
Sad Die Grafik Kontakt/Pin Belegung ATtiny 85 malsehen 3 258 15.07.2016 19:31
Letzter Beitrag: hotsystems
  Frage zu One Button in Kombination mit Fast LED Wolfgang_2801 3 238 26.06.2016 22:11
Letzter Beitrag: hotsystems

Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste