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-Wetter-Cam
19.06.2015, 17:25 (Dieser Beitrag wurde zuletzt bearbeitet: 19.06.2015 17:27 von 4711engel.)
Beitrag #33
RE: Ethernet-Wetter-Cam
(18.06.2015 20:05)Thorsten Pferdekämper schrieb:  Ok, wenn Du besser weisst, wie es geht, dann mach es so, wie Du denkst.



Hi, ist ja ok. Nur mal etwas Geduld mit einem Anfänger. Es ist eben für mich ein Problem, wenn ich noch am Anfang stehe und wenig Verständliches im Internet finde. Ich will eben nicht nur LEDs blinken lassen. Das habe ich hinter mir.

Ich will nun ein Schritt nach dem anderen machen. Das mit dem Aufnehmen der Bilder und auf der SD abspeichern klappt ja.
Nun will ich testen, wie ich die Bilder wieder laden und anzeigen kann.
Das aktuelle Problem ist zu verstehen, wie das mit dem Ethernet Webclient genau funktioniert. Ich finde aber leider keine richtigen Tutorials, wo erklärt wird, wie man Bilder von der SD auf den Browser bekommt, wenn man keine index.htm von SD verwenden will. Mit der index.htm hatte es ja schon geklappt, aber dann funktionierte es nicht, die Sensordaten auch noch dazu anizeigen.

Jetz habe ich nur einen sketch in der Mache, der dann nur das Bild von SD laden und auf dem browser anzeigen soll und nichts weiter. Aber irgendwo ist noch ein Fehler drin. Ich glaube, es bricht die Verbindung ab. Aber warum?

Kennst Du vielleicht ein solches Tutorial zu meinem aktuellen Teilprojekt oder siehst vielleicht meinen Fehler?


Hier der aktuelle sketch:
Code:
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>

#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


Adafruit_VC0706 cam = Adafruit_VC0706(&Serial1);   // connect RX(Blau) to pin 18 and TX(weiss) to pin19


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

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

  Serial.println(Ethernet.localIP());  

    Serial.println(F("Ini SD"));
    if (!SD.begin(4)) {
        Serial.println(F("SD failed!"));
        return;    // init failed
    }

    if (!SD.exists("IMAGE.JPG")) {
        Serial.println(F("ERROR - Can't find IMAGE.JPG file!"));
        return;  // can't find picture file
    }
    Serial.println(F("IMAGE.JPG found"));

}


void loop() {

Serial.println("Function: EtherClient");
   EtherClient();

delay(10000);

}   //  end void loop





// *********************************** FUNCTION ******************************



// ******************* EtherClient ***************************

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

    if (client) {  // got client?
       Serial.println("Got a 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
                                 }
                    else if (StrContains(HTTP_req, "GET /IMAGE.JPG")) {
                        webFile = SD.open("IMAGE.JPG");
                        if (webFile) {
                            client.println("HTTP/1.1 200 OK");
                            client.println();
                        }
                    }
          
                    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)
}   // end EtherClient

  
// **********************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 find 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
20.06.2015, 15:16 (Dieser Beitrag wurde zuletzt bearbeitet: 20.06.2015 15:17 von 4711engel.)
Beitrag #34
RE: Ethernet-Wetter-Cam
(19.06.2015 17:25)4711engel schrieb:  
(18.06.2015 20:05)Thorsten Pferdekämper schrieb:  Ok, wenn Du besser weisst, wie es geht, dann mach es so, wie Du denkst.



Hi, ist ja ok. Nur mal etwas Geduld mit einem Anfänger. Es ist eben für mich ein Problem, wenn ich noch am Anfang stehe und wenig Verständliches im Internet finde. Ich will eben nicht nur LEDs blinken lassen. Das habe ich hinter mir.

Ich will nun ein Schritt nach dem anderen machen. Das mit dem Aufnehmen der Bilder und auf der SD abspeichern klappt ja.
Nun will ich testen, wie ich die Bilder wieder laden und anzeigen kann.
Das aktuelle Problem ist zu verstehen, wie das mit dem Ethernet Webclient genau funktioniert. Ich finde aber leider keine richtigen Tutorials, wo erklärt wird, wie man Bilder von der SD auf den Browser bekommt, wenn man keine index.htm von SD verwenden will. Mit der index.htm hatte es ja schon geklappt, aber dann funktionierte es nicht, die Sensordaten auch noch dazu anizeigen.

Jetz habe ich nur einen sketch in der Mache, der dann nur das Bild von SD laden und auf dem browser anzeigen soll und nichts weiter. Aber irgendwo ist noch ein Fehler drin. Ich glaube, es bricht die Verbindung ab. Aber warum?

Kennst Du vielleicht ein solches Tutorial zu meinem aktuellen Teilprojekt oder siehst vielleicht meinen Fehler?


Hier der aktuelle sketch:
Code:
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>

#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


Adafruit_VC0706 cam = Adafruit_VC0706(&Serial1);   // connect RX(Blau) to pin 18 and TX(weiss) to pin19


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

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

  Serial.println(Ethernet.localIP());  

    Serial.println(F("Ini SD"));
    if (!SD.begin(4)) {
        Serial.println(F("SD failed!"));
        return;    // init failed
    }

    if (!SD.exists("IMAGE.JPG")) {
        Serial.println(F("ERROR - Can't find IMAGE.JPG file!"));
        return;  // can't find picture file
    }
    Serial.println(F("IMAGE.JPG found"));

}


void loop() {

Serial.println("Function: EtherClient");
   EtherClient();

delay(10000);

}   //  end void loop





// *********************************** FUNCTION ******************************



// ******************* EtherClient ***************************

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

    if (client) {  // got client?
       Serial.println("Got a 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
                                 }
                    else if (StrContains(HTTP_req, "GET /IMAGE.JPG")) {
                        webFile = SD.open("IMAGE.JPG");
                        if (webFile) {
                            client.println("HTTP/1.1 200 OK");
                            client.println();
                        }
                    }
          
                    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)
}   // end EtherClient

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





Hi,
ich habe jetzt fast das Ziel erreicht. Bild wird aufgenommen (Function TakingPicture) und auf SD gespeichert. Ich kann die Browserausgabe wie gewünscht erstellen (Function AusgabeBrowser) und sehe dort mittels client.print("<img src='IMAGE.JPG'>"); auch das Bild. Siehe screenshot:
   

Problem ist aber derzeit noch, dass wegen des Aufruf der Function GetPicture in der loop eine eigene Grafik-Webseite ausgegeben wird.
Noch habe ich keine Lösung. Vielleicht muss ich diese Function statt in der Loop bei der Browserausgabe aufrufen :-(

Hier der aktuelle Code (Alles Funktionen):
Code:
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>
#include <Adafruit_BMP085.h>
#include "DHT22.h"
#include <Wire.h>
#include "DCF77.h"
#include "Time.h"

int eingang= A0;   //Photosensor-Eingang
int sensorWert = 0;
#define REQ_BUF_SZ    20
#define chipSelect 4

#define DHTPIN 3     // data pin 3
#define DHTTYPE DHT22   // DHT22  (AM2302)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor your DHTPIN
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT22 mySensor(DHTPIN);

Adafruit_BMP085 bmp;  //Druck-Sensor

// Connect pin SDA of the sensor to 20
// Connect pin SCL of the sensor to 21
// Connect pin Gnd of the sensor to GROUND
// Connect pin VIN of the sensor to +5V


int alte_sekunde;
char* DayOfWeek[] = { "", "Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag" }; // *** Day of Week
#define DCF_PIN 2        // *** Connection pin 2  to DCF77 device
#define DCF_INTERRUPT 0  // *** Interrupt number associated with pin
time_t time;
DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT,false); // *** pin/pin/(normal(true) or invert signal(false)


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

Adafruit_VC0706 cam = Adafruit_VC0706(&Serial1);   // connect RX(Blau) to pin 18 and TX(weiss) to pin19


void setup() {
    // disable Ethernet chip
    pinMode(53, OUTPUT);
    digitalWrite(53, HIGH);
    
// Open serial communications and wait for port to open:
Serial.begin(9600);
   DCF.Start();
  
// start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  if (!bmp.begin()) {
     Serial.println(F("Could not find a valid BMP085 sensor, check wiring!"));
     while (1) {}
  }

  Serial.println(Ethernet.localIP());  

    Serial.println(F("Ini SD"));
    if (!SD.begin(4)) {
        Serial.println(F("SD failed!"));
        return;    // init failed
    }

    if (!SD.exists("IMAGE.JPG")) {
        Serial.println(F("ERROR - Can't find IMAGE.JPG file!"));
        return;  // can't find picture file
    }
    Serial.println(F("IMAGE.JPG found"));

}




void loop() {


   // Ausgabe Tag, Datum, Uhrzeit
    time_t DCFtime = DCF.getTime();
  if (DCFtime!=0){
    setTime(DCFtime);
     }


  
  Serial.println("Function: TakingPicture");
  TakingPicture();    

// delay(5000);


Serial.println("Function: GetPicture");
   GetPicture();

// delay(10000);


Serial.println("Function: AusgabeBrowser");
  AusgabeBrowser();

// delay(10000);

}   //  end void loop


// ***************************************************************************
// *********************************** FUNCTION ******************************
// ***************************************************************************

// ****************Ausgabe browser *******************

void AusgabeBrowser() {

  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        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("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 1");  // refresh the page automatically every sec
          client.println();        
          client.println("<!DOCTYPE HTML>");
         client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>Wetter-Daten</TITLE>");
          client.println("</HEAD>");    
         client.println("<BODY BGColor=#D0F0D0>");
          client.println("<H1 align=center><Big><TT>Wetter-Daten</TT></Big></H1>");
         client.print(day()); client.print("/"); client.print(month()); client.print("/"); client.print(year()); client.print("  ,  ");

         client.print( DayOfWeek[ weekday() ] ); client.print("  ,  ");
        if(hour() < 10) {client.print("0");};  client.print(hour()); client.print(":");
        if(minute() < 10) {client.print("0");}; client.print(minute());
        client.println("<HR>");
          client.println("<br />");  
          client.println("<TABLE Bordercolor=#000000 cellspacing=6 align=center border=3>");
                    mySensor.readData();
          client.println("<TR>");        
          client.println("<TD>"); client.print("<B>Feuchte: </B>"); client.println("</TD>");
          client.println("<TD>"); client.print(mySensor.getHumidity()); client.print(" %"); client.println("</TD>");
          client.println("</TR>");
          client.println("<TR>");
          client.println("<TD>"); client.print("<B>Temperatur: </B>"); client.println("</TD>");
          client.println("<TD>"); client.print(mySensor.getTemperatureC()); client.println(" °"); client.println("C"); client.println("</TD>");
          client.println("</TR>");
          client.println("<TR>");
          client.println("<TD>"); client.print("<B>Luftdruck: </B>"); client.println("</TD>");
                int p = bmp.readPressure()/100;
          client.println("<TD>"); client.print(p); client.println(" hPa"); client.println("</TD>");
          client.println("</TR>");
          client.println("<TR>");
          client.println("<TD>"); client.print("<B>Helligkeit 1....20: </B>"); client.println("</TD>");
                int wert =analogRead(eingang);
                sensorWert = map(wert, 0, 1023, 0, 19);
          client.println("<TD>"); client.println(sensorWert); client.println("</TD>");
          client.println("</TR>");
          client.println("</TABLE>");  
          client.println("<br />"); client.println("<br />"); client.println("<br />"); client.println("<br />");                        
          client.print("<center>");
          client.print("<img src='IMAGE.JPG'>");
          client.print("</center>");
         client.println("</BODY>");
        client.println("</HTML>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
       delay(1);      // give the web browser time to receive the data
       client.stop(); // close the connection
    } // end if (client)
  



}  // End AusgabeBrowser



// ******************** TakingPicture ******************
void TakingPicture (){

    Serial.println(F("VC0706 test"));
                        
                        
    // Try to locate the camera
    if (cam.begin()) {
           Serial.println(F("Camera Found:"));
       } else {
           Serial.println(F("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

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

     if (! cam.takePicture())
          Serial.println(F("Failed to snap!"));
        else
          Serial.println(F("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(F("Storing "));
      Serial.print(jpglen, DEC);
      Serial.print(F(" 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(F("done!"));
      Serial.print(time); Serial.println(F(" ms elapsed"));                                

}  // End TakingPicture.  Picture saved on SD



// ******************* GetPicture ***************************

void GetPicture() {
  
  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 /IMAGE.JPG")) {
                            client.println("HTTP/1.1 200 OK");
                            client.println("Content-Type: image/jpeg");
                            client.println("Connnection: close");
            client.println("Refresh: 1");
                            client.println();
                         webFile = SD.open("IMAGE.JPG");                          
                    }

                    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)
}   // end GetPicture



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


// *** zeit-anzeige formatieren ******************************************
void printZiffernGenulltOhnePunkt(int zahl) {
  if(zahl < 10) { // wenn kleiner als 10 ...
     Serial.print("0");
     }
  Serial.print(zahl);    
}

// *** zeit-anzeige formatieren ******************************************
void printZiffernGenulltmitPunkt(int zahl) {
  Serial.print(":"); // trennende ":" einfuegen
  if(zahl < 10) { // wenn kleiner als 10 ...
      Serial.print('0'); // fuehrende 0 einfuegen
     }
  Serial.print(zahl); // Ausgabe auf TFT
}
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
22.06.2015, 16:31
Beitrag #35
RE: Ethernet-Wetter-Cam
Hi,
versuch das mal so, dass die beiden Funktionen, die was auf den client ausgeben, wirklich nur ausgeben. Die Entscheidung, was ausgegeben werden soll, würde ich in einer übergeordneten Funktion einbauen.
Also so ungefähr:
Code:
void AusgabeBrowser(EthernetClient* client) {
           // send a standard http response header
           client->println("HTTP/1.1 200 OK");
           client->println("Content-Type: text/html");
           client->println("Connection: close");  // the connection will be closed after completion of the response
           client->println("Refresh: 1");  // refresh the page automatically every sec
           client->println();        
           client->println("<!DOCTYPE HTML>");
          client->println("<HTML>");
// [...]
// und so weiter, also sozusagen die ganze index.html ausgeben
// [...]

          client->println("</BODY>");
         client->println("</HTML>");
}  // End AusgabeBrowser


void GetPicture(EthernetClient* client) {

File webFile;
                              client->println("HTTP/1.1 200 OK");
                             client->println("Content-Type: image/jpeg");
                             client->println("Connnection: close");

           //  client.println("Refresh: 1");  Das wuerde ich hier weglassen

                             client->println();
                          webFile = SD.open("IMAGE.JPG");                          
                    
                     if (webFile) {
                         while(webFile.available()) {
                             client->write(webFile.read()); // send web page to client
                         }
                         webFile.close();
                     }
          }

Die übergeordnete Funktion würde ich in etwa handleWebServer nennen. Also in etwa so:
Code:
void handleWebServer() {
  
  EthernetClient client = server.available();  // try to get client
  
     if (!client) return;  // got client?  (So wird das übersichtlicher)

     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 /IMAGE.JPG")) {
                         getPicture(&client);
                      }else{
                         AusgabeBrowser(&client);
                      }                    
                     // 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
   }

Das Teil wird jetzt einfach in loop immer wieder aufgerufen. Ausserdem solltest Du vermeiden, das takingPicture in jedem Durchlauf aufzurufen. Wahrscheinlich reicht alle 15 Minuten locker aus. Zum Test kannst Du das auch öfter machen. Also in etwa so:
Code:
void loop() {

    // Ausgabe Tag, Datum, Uhrzeit
     time_t DCFtime = DCF.getTime();
   if (DCFtime!=0){
     setTime(DCFtime);
      }

// alle 15 Minuten ein neues Bild machen
   static unsigned long last = 0;
   unsigned long now = millis();  
   if(now - last > 60000) { // eine Minute, 15 Minuten waeren 900000L
       last = now;
       Serial.println("Function: TakingPicture");
       TakingPicture();    
  };

// webServer immer wieder aufrufen
  handleWebServer();
}   //  end void loop

Ich habe das mal schnell aus Deinem Coding zusammenkopiert und den Rest einfach so reingetippt. Nichts davon habe ich ausprobiert.

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
23.06.2015, 16:24 (Dieser Beitrag wurde zuletzt bearbeitet: 23.06.2015 16:26 von 4711engel.)
Beitrag #36
RE: Ethernet-Wetter-Cam
(22.06.2015 16:31)Thorsten Pferdekämper schrieb:  Hi,
versuch das mal so, dass die beiden Funktionen, die was auf den client ausgeben, wirklich nur ausgeben. Die Entscheidung, was ausgegeben werden soll, würde ich in einer übergeordneten Funktion einbauen.
Also so ungefähr:
Code:
void AusgabeBrowser(EthernetClient* client) {
           // send a standard http response header
           client->println("HTTP/1.1 200 OK");
           client->println("Content-Type: text/html");
           client->println("Connection: close");  // the connection will be closed after completion of the response
           client->println("Refresh: 1");  // refresh the page automatically every sec
           client->println();        
           client->println("<!DOCTYPE HTML>");
          client->println("<HTML>");
// [...]
// und so weiter, also sozusagen die ganze index.html ausgeben
// [...]

          client->println("</BODY>");
         client->println("</HTML>");
}  // End AusgabeBrowser


void GetPicture(EthernetClient* client) {

File webFile;
                              client->println("HTTP/1.1 200 OK");
                             client->println("Content-Type: image/jpeg");
                             client->println("Connnection: close");

           //  client.println("Refresh: 1");  Das wuerde ich hier weglassen

                             client->println();
                          webFile = SD.open("IMAGE.JPG");                          
                    
                     if (webFile) {
                         while(webFile.available()) {
                             client->write(webFile.read()); // send web page to client
                         }
                         webFile.close();
                     }
          }

Die übergeordnete Funktion würde ich in etwa handleWebServer nennen. Also in etwa so:
Code:
void handleWebServer() {
  
  EthernetClient client = server.available();  // try to get client
  
     if (!client) return;  // got client?  (So wird das übersichtlicher)

     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 /IMAGE.JPG")) {
                         getPicture(&client);
                      }else{
                         AusgabeBrowser(&client);
                      }                    
                     // 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
   }

Das Teil wird jetzt einfach in loop immer wieder aufgerufen. Ausserdem solltest Du vermeiden, das takingPicture in jedem Durchlauf aufzurufen. Wahrscheinlich reicht alle 15 Minuten locker aus. Zum Test kannst Du das auch öfter machen. Also in etwa so:
Code:
void loop() {

    // Ausgabe Tag, Datum, Uhrzeit
     time_t DCFtime = DCF.getTime();
   if (DCFtime!=0){
     setTime(DCFtime);
      }

// alle 15 Minuten ein neues Bild machen
   static unsigned long last = 0;
   unsigned long now = millis();  
   if(now - last > 60000) { // eine Minute, 15 Minuten waeren 900000L
       last = now;
       Serial.println("Function: TakingPicture");
       TakingPicture();    
  };

// webServer immer wieder aufrufen
  handleWebServer();
}   //  end void loop

Ich habe das mal schnell aus Deinem Coding zusammenkopiert und den Rest einfach so reingetippt. Nichts davon habe ich ausprobiert.

Gruß,
Thorsten


Hi Thorsten,
danke für den Code. Ich habe diesen gleich eingebaut:
Code:
// Arduino Wetter-Daten und WebCam
//
// - Arduino MEGA
// - Temp/Feuchte:  DHT22  Pin1 -> 5V, Pin2 -> 3 , Pin4 -> GRD, 10kOhm zwischen Pin2 und Pin1
// - Druck:  BMP085  Verwendung von Serial1, d.h. SDA an 20, SCL an 21
// - Helligkeit: Photowiderstand
// - Kamera adafruit VC0706 RX an 18, TX an 19
// - Ethernet shield 13 an 52, 12 an 50, 11 an 51  (SPI)
// - Funkuhr RTC Data an 2
// ********************************************************************************​***********

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>
#include <Adafruit_BMP085.h>
#include "DHT22.h"
#include <Wire.h>
#include "DCF77.h"
#include "Time.h"

//Photosensor-Eingang
int eingang= A0;  
int sensorWert = 0;


#define REQ_BUF_SZ    20
#define chipSelect 4


// Temp-Feuchte-Sensor
#define DHTPIN 3     // data pin 3
#define DHTTYPE DHT22   // DHT22  (AM2302)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor your DHTPIN
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT22 mySensor(DHTPIN);

// Druck-Sensor
Adafruit_BMP085 bmp;  //Druck-Sensor

// Connect pin SDA of the sensor to 20
// Connect pin SCL of the sensor to 21
// Connect pin Gnd of the sensor to GROUND
// Connect pin VIN of the sensor to +5V


//  RTC Funkuhr
int alte_sekunde;
char* DayOfWeek[] = { "", "Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag" }; // *** Day of Week
#define DCF_PIN 2        // *** Connection pin 2  to DCF77 device
#define DCF_INTERRUPT 0  // *** Interrupt number associated with pin
time_t time;
DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT,false); // *** pin/pin/(normal(true) or invert signal(false)


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

Adafruit_VC0706 cam = Adafruit_VC0706(&Serial1);   // connect RX(Blau) to pin 18 and TX(weiss) to pin19

// ******************************SETPU **************************

void setup() {
    // disable Ethernet chip
    pinMode(53, OUTPUT);
    digitalWrite(53, HIGH);
    
// Open serial communications and wait for port to open:
Serial.begin(9600);
   DCF.Start();
  
// start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  if (!bmp.begin()) {
     Serial.println(F("Could not find a valid BMP085 sensor, check wiring!"));
     while (1) {}
  }

  Serial.println(Ethernet.localIP());  

    Serial.println(F("Ini SD"));
    if (!SD.begin(4)) {
        Serial.println(F("SD failed!"));
        return;    // init failed
    }

    if (!SD.exists("IMAGE.JPG")) {
        Serial.println(F("ERROR - Can't find IMAGE.JPG file!"));
        return;  // can't find picture file
    }
    Serial.println(F("IMAGE.JPG found"));

}

// *****************************LOOP **************************
void loop() {

    // Ausgabe Tag, Datum, Uhrzeit
     time_t DCFtime = DCF.getTime();
   if (DCFtime!=0){
     setTime(DCFtime);
      }

// alle Minuten ein neues Bild machen
   static unsigned long last = 0;
   unsigned long now = millis();  
   if(now - last > 60000) {              
       last = now;
       Serial.println("Function: TakingPicture");
       TakingPicture();    
  };

// webServer immer wieder aufrufen
  handleWebServer();

}   //  end void loop


// ***************************************************************************
// *********************************** FUNCTION ******************************
// ***************************************************************************

// **************** handleWebServer *******************

void handleWebServer() {
  
  EthernetClient client = server.available();  // try to get client
  
     if (!client) return;  // 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 /IMAGE.JPG")) {
                         GetPicture(&client);
                      }else{
                         AusgabeBrowser(&client);
                      }                    
                     // 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
   }  // handleWebServer


// ****************Ausgabe browser *******************

void AusgabeBrowser(EthernetClient* client) {

           // send a standard http response header
           client.println("HTTP/1.1 200 OK");
           client.println("Content-Type: text/html");
           client.println("Connection: close");  // the connection will be closed after completion of the response
           client.println("Refresh: 1");  // refresh the page automatically every sec
           client.println();        
           client.println("<!DOCTYPE HTML>");
          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>Wetter-Daten</TITLE>");
          client.println("</HEAD>");    
          client.println("<BODY BGColor=#D0F0D0>");
          client.println("<H1 align=center><Big><TT>Wetter-Daten</TT></Big></H1>");
          client.print(day()); client.print("/"); client.print(month()); client.print("/"); client.print(year()); client.print("  ,  ");
          client.print( DayOfWeek[ weekday() ] ); client.print("  ,  ");
                   if(hour() < 10) {client.print("0");};  client.print(hour()); client.print(":");
                   if(minute() < 10) {client.print("0");}; client.print(minute());
          client.println("<HR>");
          client.println("<br />");  
          client.println("<TABLE Bordercolor=#000000 cellspacing=6 align=center border=3>");
                    mySensor.readData();
          client.println("<TR>");        
          client.println("<TD>"); client.print("<B>Feuchte: </B>"); client.println("</TD>");
          client.println("<TD>"); client.print(mySensor.getHumidity()); client.print(" %"); client.println("</TD>");
          client.println("</TR>");
          client.println("<TR>");
          client.println("<TD>"); client.print("<B>Temperatur: </B>"); client.println("</TD>");
          client.println("<TD>"); client.print(mySensor.getTemperatureC()); client.println(" °"); client.println("C");     client.println("</TD>");
          client.println("</TR>");
          client.println("<TR>");
          client.println("<TD>"); client.print("<B>Luftdruck: </B>"); client.println("</TD>");
                   int p = bmp.readPressure()/100;
          client.println("<TD>"); client.print(p); client.println(" hPa"); client.println("</TD>");
          client.println("</TR>");
          client.println("<TR>");
          client.println("<TD>"); client.print("<B>Helligkeit 1....20: </B>"); client.println("</TD>");
                   int wert =analogRead(eingang);
                   sensorWert = map(wert, 0, 1023, 0, 19);
          client.println("<TD>"); client.println(sensorWert); client.println("</TD>");
          client.println("</TR>");
          client.println("</TABLE>");  
          client.println("<br />"); client.println("<br />"); client.println("<br />"); client.println("<br />");                        
          client.print("<center>");
          client.print("<img src='IMAGE.JPG'>");
          client.print("</center>");
          client.println("</BODY>");
          client.println("</HTML>");
}  // End AusgabeBrowser


// ******************** TakingPicture ******************
void TakingPicture (){

    Serial.println(F("VC0706 test"));
                                              
    // Try to locate the camera
    if (cam.begin()) {
           Serial.println(F("Camera Found:"));
       } else {
           Serial.println(F("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

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

     if (! cam.takePicture())
          Serial.println(F("Failed to snap!"));
        else
          Serial.println(F("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(F("Storing "));
      Serial.print(jpglen, DEC);
      Serial.print(F(" 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(F("done!"));
      Serial.print(time); Serial.println(F(" ms elapsed"));                                

}  // End TakingPicture.  Picture saved on SD


// ******************* GetPicture ***************************

void GetPicture(EthernetClient* client) {

File webFile;
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: image/jpeg");
client.println("Connnection: close");
client.println("Refresh: 1");  // refresh the page automatically every sec
client.println();
webFile = SD.open("IMAGE.JPG");                          
                    
if (webFile) {
       while(webFile.available()) {
            client.write(webFile.read()); // send web page to client
             }
       webFile.close();
              }

}   // end GetPicture


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


// *** zeit-anzeige formatieren ******************************************
void printZiffernGenulltOhnePunkt(int zahl) {
  if(zahl < 10) { // wenn kleiner als 10 ...
     Serial.print("0");
     }
  Serial.print(zahl);    
}


void printZiffernGenulltmitPunkt(int zahl) {
  Serial.print(":"); // trennende ":" einfuegen
  if(zahl < 10) { // wenn kleiner als 10 ...
      Serial.print('0'); // fuehrende 0 einfuegen
     }
  Serial.print(zahl); // Ausgabe auf TFT
}

Leider erhalte ich gleich beim Kompilieren diverse Fehlermeldungen, die den Aufruf
void AusgabeBrowser(EthernetClient* client) {

// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");


betreffen. Die Fehlermeldungen lauten:

Sketch-Thorsten.ino: In function 'void AusgabeBrowser(EthernetClient*)':
Sketch-Thorsten.ino:199: error: request for member 'println' in 'client', which is of non-class type 'EthernetClient*'
Sketch-Thorsten.ino:200: error: request for member 'println' in 'client', which is of non-class type 'EthernetClient*'
Sketch-Thorsten.ino:201: error: request for member 'println' in 'client', which is of non-class type 'EthernetClient*'

Da ich den Ausdruck (EthernetClient* client) nicht kenne, kann ich aktuell auch nicht den Fehler finden.

Gleiches erhalte ich auch bei der GetPicture :

Sketch-Thorsten.ino: In function 'void GetPicture(EthernetClient*)':
Sketch-Thorsten.ino:315: error: request for member 'println' in 'client', which is of non-class type 'EthernetClient*'
Sketch-Thorsten.ino:316: error: request for member 'println' in 'client', which is of non-class type 'EthernetClient*'
Sketch-Thorsten.ino:317: error: request for member 'println' in 'client', which is of non-class type 'EthernetClient*'
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
23.06.2015, 17:37
Beitrag #37
RE: Ethernet-Wetter-Cam
Hi,
Du musst etwas genauer hinschauen, dann siehst Du in meinem Coding vielleicht "->" statt ".".
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
23.06.2015, 18:52 (Dieser Beitrag wurde zuletzt bearbeitet: 23.06.2015 19:05 von 4711engel.)
Beitrag #38
RE: Ethernet-Wetter-Cam
Hi,
ich habe nun, auch wenn ich dieses noch nicht verstehe, entsprechend umgeschrieben.
Die Fehlermeldungen haben sich reduziert auf die Funktion AusgabeBrowser

Sketch-Thorsten.ino: In function 'void AusgabeBrowser(EthernetClient*)':
Sketch-Thorsten.ino:211: error: request for member 'print' in 'client', which is of non-class type 'EthernetClient*'
Sketch-Thorsten.ino:211: error: request for member 'print' in 'client', which is of non-class type 'EthernetClient*'
Sketch-Thorsten.ino:211: error: request for member 'print' in 'client', which is of non-class type 'EthernetClient*'
Sketch-Thorsten.ino:211: error: request for member 'print' in 'client', which is of non-class type 'EthernetClient*'

Hier der gesamte Sketch:
Code:
// Arduino Wetter-Daten und WebCam
//
// - Arduino MEGA
// - Temp/Feuchte:  DHT22  Pin1 -> 5V, Pin2 -> 3 , Pin4 -> GRD, 10kOhm zwischen Pin2 und Pin1
// - Druck:  BMP085  Verwendung von Serial1, d.h. SDA an 20, SCL an 21
// - Helligkeit: Photowiderstand
// - Kamera adafruit VC0706 RX an 18, TX an 19
// - Ethernet shield 13 an 52, 12 an 50, 11 an 51  (SPI)
// - Funkuhr RTC Data an 2
// ********************************************************************************​***********

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>
#include <Adafruit_BMP085.h>
#include "DHT22.h"
#include <Wire.h>
#include "DCF77.h"
#include "Time.h"

//Photosensor-Eingang
int eingang= A0;  
int sensorWert = 0;


#define REQ_BUF_SZ    20
#define chipSelect 4


// Temp-Feuchte-Sensor
#define DHTPIN 3     // data pin 3
#define DHTTYPE DHT22   // DHT22  (AM2302)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor your DHTPIN
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT22 mySensor(DHTPIN);

// Druck-Sensor
Adafruit_BMP085 bmp;  //Druck-Sensor

// Connect pin SDA of the sensor to 20
// Connect pin SCL of the sensor to 21
// Connect pin Gnd of the sensor to GROUND
// Connect pin VIN of the sensor to +5V


//  RTC Funkuhr
int alte_sekunde;
char* DayOfWeek[] = { "", "Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag" }; // *** Day of Week
#define DCF_PIN 2        // *** Connection pin 2  to DCF77 device
#define DCF_INTERRUPT 0  // *** Interrupt number associated with pin
time_t time;
DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT,false); // *** pin/pin/(normal(true) or invert signal(false)


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

Adafruit_VC0706 cam = Adafruit_VC0706(&Serial1);   // connect RX(Blau) to pin 18 and TX(weiss) to pin19

// ******************************SETPU **************************

void setup() {
    // disable Ethernet chip
    pinMode(53, OUTPUT);
    digitalWrite(53, HIGH);
    
// Open serial communications and wait for port to open:
Serial.begin(9600);
   DCF.Start();
  
// start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  if (!bmp.begin()) {
     Serial.println(F("Could not find a valid BMP085 sensor, check wiring!"));
     while (1) {}
  }

  Serial.println(Ethernet.localIP());  

    Serial.println(F("Ini SD"));
    if (!SD.begin(4)) {
        Serial.println(F("SD failed!"));
        return;    // init failed
    }

    if (!SD.exists("IMAGE.JPG")) {
        Serial.println(F("ERROR - Can't find IMAGE.JPG file!"));
        return;  // can't find picture file
    }
    Serial.println(F("IMAGE.JPG found"));

}

// *****************************LOOP **************************
void loop() {

    // Ausgabe Tag, Datum, Uhrzeit
     time_t DCFtime = DCF.getTime();
   if (DCFtime!=0){
     setTime(DCFtime);
      }

// alle Minuten ein neues Bild machen
   static unsigned long last = 0;
   unsigned long now = millis();  
   if(now - last > 60000) {              
       last = now;
       Serial.println("Function: TakingPicture");
       TakingPicture();    
  };

// webServer immer wieder aufrufen
  handleWebServer();

}   //  end void loop


// ***************************************************************************
// *********************************** FUNCTION ******************************
// ***************************************************************************

// **************** handleWebServer *******************

void handleWebServer() {
  
  EthernetClient client = server.available();  // try to get client
  
     if (!client) return;  // 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 /IMAGE.JPG")) {
                         GetPicture(&client);
                      }else{
                         AusgabeBrowser(&client);
                      }                    
                     // 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
   }  // handleWebServer


// ****************Ausgabe browser *******************

void AusgabeBrowser(EthernetClient* client) {

           // send a standard http response header
           client->println("HTTP/1.1 200 OK");
           client->println("Content-Type: text/html");
           client->println("Connection: close");  // the connection will be closed after completion of the response
           client->println("Refresh: 1");  // refresh the page automatically every sec
           client->println();        
           client->println("<!DOCTYPE HTML>");
          client->println("<HTML>");
          client->println("<HEAD>");
          client->println("<TITLE>Wetter-Daten</TITLE>");
          client->println("</HEAD>");    
          client->println("<BODY BGColor=#D0F0D0>");
          client->println("<H1 align=center><Big><TT>Wetter-Daten</TT></Big></H1>");
          client->print(day()); client.print("/"); client.print(month()); client.print("/"); client.print(year()); client.print("  ,  ");
          client->print( DayOfWeek[ weekday() ] ); client.print("  ,  ");
                   if(hour() < 10) {client.print("0");};  client.print(hour()); client.print(":");
                   if(minute() < 10) {client.print("0");}; client.print(minute());
          client->println("<HR>");
          client->println("<br />");  
          client->println("<TABLE Bordercolor=#000000 cellspacing=6 align=center border=3>");
                    mySensor.readData();
          client->println("<TR>");        
          client->println("<TD>"); client.print("<B>Feuchte: </B>"); client.println("</TD>");
          client->println("<TD>"); client.print(mySensor.getHumidity()); client.print(" %"); client.println("</TD>");
          client->println("</TR>");
          client->println("<TR>");
          client->println("<TD>"); client.print("<B>Temperatur: </B>"); client.println("</TD>");
          client->println("<TD>"); client.print(mySensor.getTemperatureC()); client.println(" °"); client.println("C");     client.println("</TD>");
          client->println("</TR>");
          client->println("<TR>");
          client->println("<TD>"); client.print("<B>Luftdruck: </B>"); client.println("</TD>");
                   int p = bmp.readPressure()/100;
          client->println("<TD>"); client.print(p); client.println(" hPa"); client.println("</TD>");
          client->println("</TR>");
          client->println("<TR>");
          client->println("<TD>"); client.print("<B>Helligkeit 1....20: </B>"); client.println("</TD>");
                   int wert =analogRead(eingang);
                   sensorWert = map(wert, 0, 1023, 0, 19);
          client->println("<TD>"); client.println(sensorWert); client.println("</TD>");
          client->println("</TR>");
          client->println("</TABLE>");  
          client->println("<br />"); client.println("<br />"); client.println("<br />"); client.println("<br />");                        
          client->print("<center>");
          client->print("<img src='IMAGE.JPG'>");
          client->print("</center>");
          client->println("</BODY>");
          client->println("</HTML>");
}  // End AusgabeBrowser


// ******************** TakingPicture ******************
void TakingPicture (){

    Serial.println(F("VC0706 test"));
                                              
    // Try to locate the camera
    if (cam.begin()) {
           Serial.println(F("Camera Found:"));
       } else {
           Serial.println(F("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

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

     if (! cam.takePicture())
          Serial.println(F("Failed to snap!"));
        else
          Serial.println(F("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(F("Storing "));
      Serial.print(jpglen, DEC);
      Serial.print(F(" 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(F("done!"));
      Serial.print(time); Serial.println(F(" ms elapsed"));                                

}  // End TakingPicture.  Picture saved on SD


// ******************* GetPicture ***************************

void GetPicture(EthernetClient* client) {

File webFile;
client->println("HTTP/1.1 200 OK");
client->println("Content-Type: image/jpeg");
client->println("Connnection: close");
client->println("Refresh: 1");  // refresh the page automatically every sec
client->println();
webFile = SD.open("IMAGE.JPG");                          
                    
if (webFile) {
       while(webFile.available()) {
            client->write(webFile.read()); // send web page to client
             }
       webFile.close();
              }

}   // end GetPicture


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


// *** zeit-anzeige formatieren ******************************************
void printZiffernGenulltOhnePunkt(int zahl) {
  if(zahl < 10) { // wenn kleiner als 10 ...
     Serial.print("0");
     }
  Serial.print(zahl);    
}


void printZiffernGenulltmitPunkt(int zahl) {
  Serial.print(":"); // trennende ":" einfuegen
  if(zahl < 10) { // wenn kleiner als 10 ...
      Serial.print('0'); // fuehrende 0 einfuegen
     }
  Serial.print(zahl); // Ausgabe auf TFT
}



Gerne würde ich verstehen, was du so hinzauberst. Diese code-teile habe ich bis dato noch nie gesehen. Kann man dieses irgendwo nachlesen und verstehen?
Gruß

(23.06.2015 18:52)4711engel schrieb:  Hi,
ich habe nun, auch wenn ich dieses noch nicht verstehe, entsprechend umgeschrieben.
Die Fehlermeldungen haben sich reduziert auf die Funktion AusgabeBrowser

Sketch-Thorsten.ino: In function 'void AusgabeBrowser(EthernetClient*)':
Sketch-Thorsten.ino:211: error: request for member 'print' in 'client', which is of non-class type 'EthernetClient*'
Sketch-Thorsten.ino:211: error: request for member 'print' in 'client', which is of non-class type 'EthernetClient*'
Sketch-Thorsten.ino:211: error: request for member 'print' in 'client', which is of non-class type 'EthernetClient*'
Sketch-Thorsten.ino:211: error: request for member 'print' in 'client', which is of non-class type 'EthernetClient*'

Hier der gesamte Sketch:
Code:
// Arduino Wetter-Daten und WebCam
//
// - Arduino MEGA
// - Temp/Feuchte:  DHT22  Pin1 -> 5V, Pin2 -> 3 , Pin4 -> GRD, 10kOhm zwischen Pin2 und Pin1
// - Druck:  BMP085  Verwendung von Serial1, d.h. SDA an 20, SCL an 21
// - Helligkeit: Photowiderstand
// - Kamera adafruit VC0706 RX an 18, TX an 19
// - Ethernet shield 13 an 52, 12 an 50, 11 an 51  (SPI)
// - Funkuhr RTC Data an 2
// ********************************************************************************​***********

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>
#include <Adafruit_BMP085.h>
#include "DHT22.h"
#include <Wire.h>
#include "DCF77.h"
#include "Time.h"

//Photosensor-Eingang
int eingang= A0;  
int sensorWert = 0;


#define REQ_BUF_SZ    20
#define chipSelect 4


// Temp-Feuchte-Sensor
#define DHTPIN 3     // data pin 3
#define DHTTYPE DHT22   // DHT22  (AM2302)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor your DHTPIN
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT22 mySensor(DHTPIN);

// Druck-Sensor
Adafruit_BMP085 bmp;  //Druck-Sensor

// Connect pin SDA of the sensor to 20
// Connect pin SCL of the sensor to 21
// Connect pin Gnd of the sensor to GROUND
// Connect pin VIN of the sensor to +5V


//  RTC Funkuhr
int alte_sekunde;
char* DayOfWeek[] = { "", "Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag" }; // *** Day of Week
#define DCF_PIN 2        // *** Connection pin 2  to DCF77 device
#define DCF_INTERRUPT 0  // *** Interrupt number associated with pin
time_t time;
DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT,false); // *** pin/pin/(normal(true) or invert signal(false)


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

Adafruit_VC0706 cam = Adafruit_VC0706(&Serial1);   // connect RX(Blau) to pin 18 and TX(weiss) to pin19

// ******************************SETPU **************************

void setup() {
    // disable Ethernet chip
    pinMode(53, OUTPUT);
    digitalWrite(53, HIGH);
    
// Open serial communications and wait for port to open:
Serial.begin(9600);
   DCF.Start();
  
// start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  if (!bmp.begin()) {
     Serial.println(F("Could not find a valid BMP085 sensor, check wiring!"));
     while (1) {}
  }

  Serial.println(Ethernet.localIP());  

    Serial.println(F("Ini SD"));
    if (!SD.begin(4)) {
        Serial.println(F("SD failed!"));
        return;    // init failed
    }

    if (!SD.exists("IMAGE.JPG")) {
        Serial.println(F("ERROR - Can't find IMAGE.JPG file!"));
        return;  // can't find picture file
    }
    Serial.println(F("IMAGE.JPG found"));

}

// *****************************LOOP **************************
void loop() {

    // Ausgabe Tag, Datum, Uhrzeit
     time_t DCFtime = DCF.getTime();
   if (DCFtime!=0){
     setTime(DCFtime);
      }

// alle Minuten ein neues Bild machen
   static unsigned long last = 0;
   unsigned long now = millis();  
   if(now - last > 60000) {              
       last = now;
       Serial.println("Function: TakingPicture");
       TakingPicture();    
  };

// webServer immer wieder aufrufen
  handleWebServer();

}   //  end void loop


// ***************************************************************************
// *********************************** FUNCTION ******************************
// ***************************************************************************

// **************** handleWebServer *******************

void handleWebServer() {
  
  EthernetClient client = server.available();  // try to get client
  
     if (!client) return;  // 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 /IMAGE.JPG")) {
                         GetPicture(&client);
                      }else{
                         AusgabeBrowser(&client);
                      }                    
                     // 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
   }  // handleWebServer


// ****************Ausgabe browser *******************

void AusgabeBrowser(EthernetClient* client) {

           // send a standard http response header
           client->println("HTTP/1.1 200 OK");
           client->println("Content-Type: text/html");
           client->println("Connection: close");  // the connection will be closed after completion of the response
           client->println("Refresh: 1");  // refresh the page automatically every sec
           client->println();        
           client->println("<!DOCTYPE HTML>");
          client->println("<HTML>");
          client->println("<HEAD>");
          client->println("<TITLE>Wetter-Daten</TITLE>");
          client->println("</HEAD>");    
          client->println("<BODY BGColor=#D0F0D0>");
          client->println("<H1 align=center><Big><TT>Wetter-Daten</TT></Big></H1>");
          client->print(day()); client.print("/"); client.print(month()); client.print("/"); client.print(year()); client.print("  ,  ");
          client->print( DayOfWeek[ weekday() ] ); client.print("  ,  ");
                   if(hour() < 10) {client.print("0");};  client.print(hour()); client.print(":");
                   if(minute() < 10) {client.print("0");}; client.print(minute());
          client->println("<HR>");
          client->println("<br />");  
          client->println("<TABLE Bordercolor=#000000 cellspacing=6 align=center border=3>");
                    mySensor.readData();
          client->println("<TR>");        
          client->println("<TD>"); client.print("<B>Feuchte: </B>"); client.println("</TD>");
          client->println("<TD>"); client.print(mySensor.getHumidity()); client.print(" %"); client.println("</TD>");
          client->println("</TR>");
          client->println("<TR>");
          client->println("<TD>"); client.print("<B>Temperatur: </B>"); client.println("</TD>");
          client->println("<TD>"); client.print(mySensor.getTemperatureC()); client.println(" °"); client.println("C");     client.println("</TD>");
          client->println("</TR>");
          client->println("<TR>");
          client->println("<TD>"); client.print("<B>Luftdruck: </B>"); client.println("</TD>");
                   int p = bmp.readPressure()/100;
          client->println("<TD>"); client.print(p); client.println(" hPa"); client.println("</TD>");
          client->println("</TR>");
          client->println("<TR>");
          client->println("<TD>"); client.print("<B>Helligkeit 1....20: </B>"); client.println("</TD>");
                   int wert =analogRead(eingang);
                   sensorWert = map(wert, 0, 1023, 0, 19);
          client->println("<TD>"); client.println(sensorWert); client.println("</TD>");
          client->println("</TR>");
          client->println("</TABLE>");  
          client->println("<br />"); client.println("<br />"); client.println("<br />"); client.println("<br />");                        
          client->print("<center>");
          client->print("<img src='IMAGE.JPG'>");
          client->print("</center>");
          client->println("</BODY>");
          client->println("</HTML>");
}  // End AusgabeBrowser


// ******************** TakingPicture ******************
void TakingPicture (){

    Serial.println(F("VC0706 test"));
                                              
    // Try to locate the camera
    if (cam.begin()) {
           Serial.println(F("Camera Found:"));
       } else {
           Serial.println(F("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

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

     if (! cam.takePicture())
          Serial.println(F("Failed to snap!"));
        else
          Serial.println(F("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(F("Storing "));
      Serial.print(jpglen, DEC);
      Serial.print(F(" 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(F("done!"));
      Serial.print(time); Serial.println(F(" ms elapsed"));                                

}  // End TakingPicture.  Picture saved on SD


// ******************* GetPicture ***************************

void GetPicture(EthernetClient* client) {

File webFile;
client->println("HTTP/1.1 200 OK");
client->println("Content-Type: image/jpeg");
client->println("Connnection: close");
client->println("Refresh: 1");  // refresh the page automatically every sec
client->println();
webFile = SD.open("IMAGE.JPG");                          
                    
if (webFile) {
       while(webFile.available()) {
            client->write(webFile.read()); // send web page to client
             }
       webFile.close();
              }

}   // end GetPicture


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


// *** zeit-anzeige formatieren ******************************************
void printZiffernGenulltOhnePunkt(int zahl) {
  if(zahl < 10) { // wenn kleiner als 10 ...
     Serial.print("0");
     }
  Serial.print(zahl);    
}


void printZiffernGenulltmitPunkt(int zahl) {
  Serial.print(":"); // trennende ":" einfuegen
  if(zahl < 10) { // wenn kleiner als 10 ...
      Serial.print('0'); // fuehrende 0 einfuegen
     }
  Serial.print(zahl); // Ausgabe auf TFT
}



Gerne würde ich verstehen, was du so hinzauberst. Diese code-teile habe ich bis dato noch nie gesehen. Kann man dieses irgendwo nachlesen und verstehen?
Gruß


Habe schon gesehen. Da sind noch weitere client.print Zeilen. Werde die natürlich auch anpassen und dann schaun wir mal.
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
23.06.2015, 19:17
Beitrag #39
RE: Ethernet-Wetter-Cam
Zitat:Gerne würde ich verstehen, was du so hinzauberst. Diese code-teile habe ich bis dato noch nie gesehen. Kann man dieses irgendwo nachlesen und verstehen?
Das mit dem -> sind eigentlich C++-Grundlagen. Das sollte man in jedem C++-Buch oder Tutorial finden.

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
23.06.2015, 19:19
Beitrag #40
RE: Ethernet-Wetter-Cam
(23.06.2015 18:52)4711engel schrieb:  Hi,
ich habe nun, auch wenn ich dieses noch nicht verstehe, entsprechend umgeschrieben.
Die Fehlermeldungen haben sich reduziert auf die Funktion AusgabeBrowser

Sketch-Thorsten.ino: In function 'void AusgabeBrowser(EthernetClient*)':
Sketch-Thorsten.ino:211: error: request for member 'print' in 'client', which is of non-class type 'EthernetClient*'
Sketch-Thorsten.ino:211: error: request for member 'print' in 'client', which is of non-class type 'EthernetClient*'
Sketch-Thorsten.ino:211: error: request for member 'print' in 'client', which is of non-class type 'EthernetClient*'
Sketch-Thorsten.ino:211: error: request for member 'print' in 'client', which is of non-class type 'EthernetClient*'

Hier der gesamte Sketch:
Code:
// Arduino Wetter-Daten und WebCam
//
// - Arduino MEGA
// - Temp/Feuchte:  DHT22  Pin1 -> 5V, Pin2 -> 3 , Pin4 -> GRD, 10kOhm zwischen Pin2 und Pin1
// - Druck:  BMP085  Verwendung von Serial1, d.h. SDA an 20, SCL an 21
// - Helligkeit: Photowiderstand
// - Kamera adafruit VC0706 RX an 18, TX an 19
// - Ethernet shield 13 an 52, 12 an 50, 11 an 51  (SPI)
// - Funkuhr RTC Data an 2
// ********************************************************************************​***********

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>
#include <Adafruit_BMP085.h>
#include "DHT22.h"
#include <Wire.h>
#include "DCF77.h"
#include "Time.h"

//Photosensor-Eingang
int eingang= A0;  
int sensorWert = 0;


#define REQ_BUF_SZ    20
#define chipSelect 4


// Temp-Feuchte-Sensor
#define DHTPIN 3     // data pin 3
#define DHTTYPE DHT22   // DHT22  (AM2302)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor your DHTPIN
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT22 mySensor(DHTPIN);

// Druck-Sensor
Adafruit_BMP085 bmp;  //Druck-Sensor

// Connect pin SDA of the sensor to 20
// Connect pin SCL of the sensor to 21
// Connect pin Gnd of the sensor to GROUND
// Connect pin VIN of the sensor to +5V


//  RTC Funkuhr
int alte_sekunde;
char* DayOfWeek[] = { "", "Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag" }; // *** Day of Week
#define DCF_PIN 2        // *** Connection pin 2  to DCF77 device
#define DCF_INTERRUPT 0  // *** Interrupt number associated with pin
time_t time;
DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT,false); // *** pin/pin/(normal(true) or invert signal(false)


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

Adafruit_VC0706 cam = Adafruit_VC0706(&Serial1);   // connect RX(Blau) to pin 18 and TX(weiss) to pin19

// ******************************SETPU **************************

void setup() {
    // disable Ethernet chip
    pinMode(53, OUTPUT);
    digitalWrite(53, HIGH);
    
// Open serial communications and wait for port to open:
Serial.begin(9600);
   DCF.Start();
  
// start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  if (!bmp.begin()) {
     Serial.println(F("Could not find a valid BMP085 sensor, check wiring!"));
     while (1) {}
  }

  Serial.println(Ethernet.localIP());  

    Serial.println(F("Ini SD"));
    if (!SD.begin(4)) {
        Serial.println(F("SD failed!"));
        return;    // init failed
    }

    if (!SD.exists("IMAGE.JPG")) {
        Serial.println(F("ERROR - Can't find IMAGE.JPG file!"));
        return;  // can't find picture file
    }
    Serial.println(F("IMAGE.JPG found"));

}

// *****************************LOOP **************************
void loop() {

    // Ausgabe Tag, Datum, Uhrzeit
     time_t DCFtime = DCF.getTime();
   if (DCFtime!=0){
     setTime(DCFtime);
      }

// alle Minuten ein neues Bild machen
   static unsigned long last = 0;
   unsigned long now = millis();  
   if(now - last > 60000) {              
       last = now;
       Serial.println("Function: TakingPicture");
       TakingPicture();    
  };

// webServer immer wieder aufrufen
  handleWebServer();

}   //  end void loop


// ***************************************************************************
// *********************************** FUNCTION ******************************
// ***************************************************************************

// **************** handleWebServer *******************

void handleWebServer() {
  
  EthernetClient client = server.available();  // try to get client
  
     if (!client) return;  // 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 /IMAGE.JPG")) {
                         GetPicture(&client);
                      }else{
                         AusgabeBrowser(&client);
                      }                    
                     // 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
   }  // handleWebServer


// ****************Ausgabe browser *******************

void AusgabeBrowser(EthernetClient* client) {

           // send a standard http response header
           client->println("HTTP/1.1 200 OK");
           client->println("Content-Type: text/html");
           client->println("Connection: close");  // the connection will be closed after completion of the response
           client->println("Refresh: 1");  // refresh the page automatically every sec
           client->println();        
           client->println("<!DOCTYPE HTML>");
          client->println("<HTML>");
          client->println("<HEAD>");
          client->println("<TITLE>Wetter-Daten</TITLE>");
          client->println("</HEAD>");    
          client->println("<BODY BGColor=#D0F0D0>");
          client->println("<H1 align=center><Big><TT>Wetter-Daten</TT></Big></H1>");
          client->print(day()); client.print("/"); client.print(month()); client.print("/"); client.print(year()); client.print("  ,  ");
          client->print( DayOfWeek[ weekday() ] ); client.print("  ,  ");
                   if(hour() < 10) {client.print("0");};  client.print(hour()); client.print(":");
                   if(minute() < 10) {client.print("0");}; client.print(minute());
          client->println("<HR>");
          client->println("<br />");  
          client->println("<TABLE Bordercolor=#000000 cellspacing=6 align=center border=3>");
                    mySensor.readData();
          client->println("<TR>");        
          client->println("<TD>"); client.print("<B>Feuchte: </B>"); client.println("</TD>");
          client->println("<TD>"); client.print(mySensor.getHumidity()); client.print(" %"); client.println("</TD>");
          client->println("</TR>");
          client->println("<TR>");
          client->println("<TD>"); client.print("<B>Temperatur: </B>"); client.println("</TD>");
          client->println("<TD>"); client.print(mySensor.getTemperatureC()); client.println(" °"); client.println("C");     client.println("</TD>");
          client->println("</TR>");
          client->println("<TR>");
          client->println("<TD>"); client.print("<B>Luftdruck: </B>"); client.println("</TD>");
                   int p = bmp.readPressure()/100;
          client->println("<TD>"); client.print(p); client.println(" hPa"); client.println("</TD>");
          client->println("</TR>");
          client->println("<TR>");
          client->println("<TD>"); client.print("<B>Helligkeit 1....20: </B>"); client.println("</TD>");
                   int wert =analogRead(eingang);
                   sensorWert = map(wert, 0, 1023, 0, 19);
          client->println("<TD>"); client.println(sensorWert); client.println("</TD>");
          client->println("</TR>");
          client->println("</TABLE>");  
          client->println("<br />"); client.println("<br />"); client.println("<br />"); client.println("<br />");                        
          client->print("<center>");
          client->print("<img src='IMAGE.JPG'>");
          client->print("</center>");
          client->println("</BODY>");
          client->println("</HTML>");
}  // End AusgabeBrowser


// ******************** TakingPicture ******************
void TakingPicture (){

    Serial.println(F("VC0706 test"));
                                              
    // Try to locate the camera
    if (cam.begin()) {
           Serial.println(F("Camera Found:"));
       } else {
           Serial.println(F("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

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

     if (! cam.takePicture())
          Serial.println(F("Failed to snap!"));
        else
          Serial.println(F("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(F("Storing "));
      Serial.print(jpglen, DEC);
      Serial.print(F(" 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(F("done!"));
      Serial.print(time); Serial.println(F(" ms elapsed"));                                

}  // End TakingPicture.  Picture saved on SD


// ******************* GetPicture ***************************

void GetPicture(EthernetClient* client) {

File webFile;
client->println("HTTP/1.1 200 OK");
client->println("Content-Type: image/jpeg");
client->println("Connnection: close");
client->println("Refresh: 1");  // refresh the page automatically every sec
client->println();
webFile = SD.open("IMAGE.JPG");                          
                    
if (webFile) {
       while(webFile.available()) {
            client->write(webFile.read()); // send web page to client
             }
       webFile.close();
              }

}   // end GetPicture


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


// *** zeit-anzeige formatieren ******************************************
void printZiffernGenulltOhnePunkt(int zahl) {
  if(zahl < 10) { // wenn kleiner als 10 ...
     Serial.print("0");
     }
  Serial.print(zahl);    
}


void printZiffernGenulltmitPunkt(int zahl) {
  Serial.print(":"); // trennende ":" einfuegen
  if(zahl < 10) { // wenn kleiner als 10 ...
      Serial.print('0'); // fuehrende 0 einfuegen
     }
  Serial.print(zahl); // Ausgabe auf TFT
}



Gerne würde ich verstehen, was du so hinzauberst. Diese code-teile habe ich bis dato noch nie gesehen. Kann man dieses irgendwo nachlesen und verstehen?
Gruß

(23.06.2015 18:52)4711engel schrieb:  Hi,
ich habe nun, auch wenn ich dieses noch nicht verstehe, entsprechend umgeschrieben.
Die Fehlermeldungen haben sich reduziert auf die Funktion AusgabeBrowser

Sketch-Thorsten.ino: In function 'void AusgabeBrowser(EthernetClient*)':
Sketch-Thorsten.ino:211: error: request for member 'print' in 'client', which is of non-class type 'EthernetClient*'
Sketch-Thorsten.ino:211: error: request for member 'print' in 'client', which is of non-class type 'EthernetClient*'
Sketch-Thorsten.ino:211: error: request for member 'print' in 'client', which is of non-class type 'EthernetClient*'
Sketch-Thorsten.ino:211: error: request for member 'print' in 'client', which is of non-class type 'EthernetClient*'

Hier der gesamte Sketch:
Code:
// Arduino Wetter-Daten und WebCam
//
// - Arduino MEGA
// - Temp/Feuchte:  DHT22  Pin1 -> 5V, Pin2 -> 3 , Pin4 -> GRD, 10kOhm zwischen Pin2 und Pin1
// - Druck:  BMP085  Verwendung von Serial1, d.h. SDA an 20, SCL an 21
// - Helligkeit: Photowiderstand
// - Kamera adafruit VC0706 RX an 18, TX an 19
// - Ethernet shield 13 an 52, 12 an 50, 11 an 51  (SPI)
// - Funkuhr RTC Data an 2
// ********************************************************************************​***********

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>
#include <Adafruit_BMP085.h>
#include "DHT22.h"
#include <Wire.h>
#include "DCF77.h"
#include "Time.h"

//Photosensor-Eingang
int eingang= A0;  
int sensorWert = 0;


#define REQ_BUF_SZ    20
#define chipSelect 4


// Temp-Feuchte-Sensor
#define DHTPIN 3     // data pin 3
#define DHTTYPE DHT22   // DHT22  (AM2302)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor your DHTPIN
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT22 mySensor(DHTPIN);

// Druck-Sensor
Adafruit_BMP085 bmp;  //Druck-Sensor

// Connect pin SDA of the sensor to 20
// Connect pin SCL of the sensor to 21
// Connect pin Gnd of the sensor to GROUND
// Connect pin VIN of the sensor to +5V


//  RTC Funkuhr
int alte_sekunde;
char* DayOfWeek[] = { "", "Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag" }; // *** Day of Week
#define DCF_PIN 2        // *** Connection pin 2  to DCF77 device
#define DCF_INTERRUPT 0  // *** Interrupt number associated with pin
time_t time;
DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT,false); // *** pin/pin/(normal(true) or invert signal(false)


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

Adafruit_VC0706 cam = Adafruit_VC0706(&Serial1);   // connect RX(Blau) to pin 18 and TX(weiss) to pin19

// ******************************SETPU **************************

void setup() {
    // disable Ethernet chip
    pinMode(53, OUTPUT);
    digitalWrite(53, HIGH);
    
// Open serial communications and wait for port to open:
Serial.begin(9600);
   DCF.Start();
  
// start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  if (!bmp.begin()) {
     Serial.println(F("Could not find a valid BMP085 sensor, check wiring!"));
     while (1) {}
  }

  Serial.println(Ethernet.localIP());  

    Serial.println(F("Ini SD"));
    if (!SD.begin(4)) {
        Serial.println(F("SD failed!"));
        return;    // init failed
    }

    if (!SD.exists("IMAGE.JPG")) {
        Serial.println(F("ERROR - Can't find IMAGE.JPG file!"));
        return;  // can't find picture file
    }
    Serial.println(F("IMAGE.JPG found"));

}

// *****************************LOOP **************************
void loop() {

    // Ausgabe Tag, Datum, Uhrzeit
     time_t DCFtime = DCF.getTime();
   if (DCFtime!=0){
     setTime(DCFtime);
      }

// alle Minuten ein neues Bild machen
   static unsigned long last = 0;
   unsigned long now = millis();  
   if(now - last > 60000) {              
       last = now;
       Serial.println("Function: TakingPicture");
       TakingPicture();    
  };

// webServer immer wieder aufrufen
  handleWebServer();

}   //  end void loop


// ***************************************************************************
// *********************************** FUNCTION ******************************
// ***************************************************************************

// **************** handleWebServer *******************

void handleWebServer() {
  
  EthernetClient client = server.available();  // try to get client
  
     if (!client) return;  // 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 /IMAGE.JPG")) {
                         GetPicture(&client);
                      }else{
                         AusgabeBrowser(&client);
                      }                    
                     // 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
   }  // handleWebServer


// ****************Ausgabe browser *******************

void AusgabeBrowser(EthernetClient* client) {

           // send a standard http response header
           client->println("HTTP/1.1 200 OK");
           client->println("Content-Type: text/html");
           client->println("Connection: close");  // the connection will be closed after completion of the response
           client->println("Refresh: 1");  // refresh the page automatically every sec
           client->println();        
           client->println("<!DOCTYPE HTML>");
          client->println("<HTML>");
          client->println("<HEAD>");
          client->println("<TITLE>Wetter-Daten</TITLE>");
          client->println("</HEAD>");    
          client->println("<BODY BGColor=#D0F0D0>");
          client->println("<H1 align=center><Big><TT>Wetter-Daten</TT></Big></H1>");
          client->print(day()); client.print("/"); client.print(month()); client.print("/"); client.print(year()); client.print("  ,  ");
          client->print( DayOfWeek[ weekday() ] ); client.print("  ,  ");
                   if(hour() < 10) {client.print("0");};  client.print(hour()); client.print(":");
                   if(minute() < 10) {client.print("0");}; client.print(minute());
          client->println("<HR>");
          client->println("<br />");  
          client->println("<TABLE Bordercolor=#000000 cellspacing=6 align=center border=3>");
                    mySensor.readData();
          client->println("<TR>");        
          client->println("<TD>"); client.print("<B>Feuchte: </B>"); client.println("</TD>");
          client->println("<TD>"); client.print(mySensor.getHumidity()); client.print(" %"); client.println("</TD>");
          client->println("</TR>");
          client->println("<TR>");
          client->println("<TD>"); client.print("<B>Temperatur: </B>"); client.println("</TD>");
          client->println("<TD>"); client.print(mySensor.getTemperatureC()); client.println(" °"); client.println("C");     client.println("</TD>");
          client->println("</TR>");
          client->println("<TR>");
          client->println("<TD>"); client.print("<B>Luftdruck: </B>"); client.println("</TD>");
                   int p = bmp.readPressure()/100;
          client->println("<TD>"); client.print(p); client.println(" hPa"); client.println("</TD>");
          client->println("</TR>");
          client->println("<TR>");
          client->println("<TD>"); client.print("<B>Helligkeit 1....20: </B>"); client.println("</TD>");
                   int wert =analogRead(eingang);
                   sensorWert = map(wert, 0, 1023, 0, 19);
          client->println("<TD>"); client.println(sensorWert); client.println("</TD>");
          client->println("</TR>");
          client->println("</TABLE>");  
          client->println("<br />"); client.println("<br />"); client.println("<br />"); client.println("<br />");                        
          client->print("<center>");
          client->print("<img src='IMAGE.JPG'>");
          client->print("</center>");
          client->println("</BODY>");
          client->println("</HTML>");
}  // End AusgabeBrowser


// ******************** TakingPicture ******************
void TakingPicture (){

    Serial.println(F("VC0706 test"));
                                              
    // Try to locate the camera
    if (cam.begin()) {
           Serial.println(F("Camera Found:"));
       } else {
           Serial.println(F("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

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

     if (! cam.takePicture())
          Serial.println(F("Failed to snap!"));
        else
          Serial.println(F("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(F("Storing "));
      Serial.print(jpglen, DEC);
      Serial.print(F(" 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(F("done!"));
      Serial.print(time); Serial.println(F(" ms elapsed"));                                

}  // End TakingPicture.  Picture saved on SD


// ******************* GetPicture ***************************

void GetPicture(EthernetClient* client) {

File webFile;
client->println("HTTP/1.1 200 OK");
client->println("Content-Type: image/jpeg");
client->println("Connnection: close");
client->println("Refresh: 1");  // refresh the page automatically every sec
client->println();
webFile = SD.open("IMAGE.JPG");                          
                    
if (webFile) {
       while(webFile.available()) {
            client->write(webFile.read()); // send web page to client
             }
       webFile.close();
              }

}   // end GetPicture


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


// *** zeit-anzeige formatieren ******************************************
void printZiffernGenulltOhnePunkt(int zahl) {
  if(zahl < 10) { // wenn kleiner als 10 ...
     Serial.print("0");
     }
  Serial.print(zahl);    
}


void printZiffernGenulltmitPunkt(int zahl) {
  Serial.print(":"); // trennende ":" einfuegen
  if(zahl < 10) { // wenn kleiner als 10 ...
      Serial.print('0'); // fuehrende 0 einfuegen
     }
  Serial.print(zahl); // Ausgabe auf TFT
}



Gerne würde ich verstehen, was du so hinzauberst. Diese code-teile habe ich bis dato noch nie gesehen. Kann man dieses irgendwo nachlesen und verstehen?
Gruß


Habe schon gesehen. Da sind noch weitere client.print Zeilen. Werde die natürlich auch anpassen und dann schaun wir mal.


So,
jetzt alles aktualisiert und beim Kompilieren gibt es keine Fehler mehr.

Aber er geht in der handleWebServer nur in den Zweig GetPicture . Der ZweigAusgabeBrowser wird nicht durchlaufen.


Code:
// Arduino Wetter-Daten und WebCam
//
// - Arduino MEGA
// - Temp/Feuchte:  DHT22  Pin1 -> 5V, Pin2 -> 3 , Pin4 -> GRD, 10kOhm zwischen Pin2 und Pin1
// - Druck:  BMP085  Verwendung von Serial1, d.h. SDA an 20, SCL an 21
// - Helligkeit: Photowiderstand
// - Kamera adafruit VC0706 RX an 18, TX an 19
// - Ethernet shield 13 an 52, 12 an 50, 11 an 51  (SPI)
// - Funkuhr RTC Data an 2
// ********************************************************************************​***********

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>
#include <Adafruit_BMP085.h>
#include "DHT22.h"
#include <Wire.h>
#include "DCF77.h"
#include "Time.h"

//Photosensor-Eingang
int eingang= A0;  
int sensorWert = 0;


#define REQ_BUF_SZ    20
#define chipSelect 4


// Temp-Feuchte-Sensor
#define DHTPIN 3     // data pin 3
#define DHTTYPE DHT22   // DHT22  (AM2302)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor your DHTPIN
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT22 mySensor(DHTPIN);

// Druck-Sensor
Adafruit_BMP085 bmp;  //Druck-Sensor

// Connect pin SDA of the sensor to 20
// Connect pin SCL of the sensor to 21
// Connect pin Gnd of the sensor to GROUND
// Connect pin VIN of the sensor to +5V


//  RTC Funkuhr
int alte_sekunde;
char* DayOfWeek[] = { "", "Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag" }; // *** Day of Week
#define DCF_PIN 2        // *** Connection pin 2  to DCF77 device
#define DCF_INTERRUPT 0  // *** Interrupt number associated with pin
time_t time;
DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT,false); // *** pin/pin/(normal(true) or invert signal(false)


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

Adafruit_VC0706 cam = Adafruit_VC0706(&Serial1);   // connect RX(Blau) to pin 18 and TX(weiss) to pin19

// ******************************SETPU **************************

void setup() {
    // disable Ethernet chip
    pinMode(53, OUTPUT);
    digitalWrite(53, HIGH);
    
// Open serial communications and wait for port to open:
Serial.begin(9600);
   DCF.Start();
  
// start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  if (!bmp.begin()) {
     Serial.println(F("Could not find a valid BMP085 sensor, check wiring!"));
     while (1) {}
  }

  Serial.println(Ethernet.localIP());  

    Serial.println(F("Ini SD"));
    if (!SD.begin(4)) {
        Serial.println(F("SD failed!"));
        return;    // init failed
    }

    if (!SD.exists("IMAGE.JPG")) {
        Serial.println(F("ERROR - Can't find IMAGE.JPG file!"));
        return;  // can't find picture file
    }
    Serial.println(F("IMAGE.JPG found"));

}

// *****************************LOOP **************************
void loop() {

    // Ausgabe Tag, Datum, Uhrzeit
     time_t DCFtime = DCF.getTime();
   if (DCFtime!=0){
     setTime(DCFtime);
      }

// alle Minuten ein neues Bild machen
   static unsigned long last = 0;
   unsigned long now = millis();  
   if(now - last > 60000) {              
       last = now;
       Serial.println("Function: TakingPicture");
       TakingPicture();    
  };

// webServer immer wieder aufrufen
  handleWebServer();

}   //  end void loop


// ***************************************************************************
// *********************************** FUNCTION ******************************
// ***************************************************************************

// **************** handleWebServer *******************

void handleWebServer() {
  
  EthernetClient client = server.available();  // try to get client
  
     if (!client) return;  // 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 /IMAGE.JPG")) {
               Serial.println("GetPicture-Funktion");          
                         GetPicture(&client);
                      }else{
               Serial.println("AusgabeBrowser-Funktion");                          
                         AusgabeBrowser(&client);
                      }                    
                     // 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
   }  // handleWebServer


// ****************Ausgabe browser *******************

void AusgabeBrowser(EthernetClient* client) {

           // send a standard http response header
           client->println("HTTP/1.1 200 OK");
           client->println("Content-Type: text/html");
           client->println("Connection: close");  // the connection will be closed after completion of the response
           client->println("Refresh: 1");  // refresh the page automatically every sec
           client->println();        
           client->println("<!DOCTYPE HTML>");
          client->println("<HTML>");
          client->println("<HEAD>");
          client->println("<TITLE>Wetter-Daten</TITLE>");
          client->println("</HEAD>");    
          client->println("<BODY BGColor=#D0F0D0>");
          client->println("<H1 align=center><Big><TT>Wetter-Daten</TT></Big></H1>");
          client->print(day()); client->print("/"); client->print(month()); client->print("/"); client->print(year()); client->print("  ,  ");
          client->print( DayOfWeek[ weekday() ] ); client->print("  ,  ");
                   if(hour() < 10) {client->print("0");};  client->print(hour()); client->print(":");
                   if(minute() < 10) {client->print("0");}; client->print(minute());
          client->println("<HR>");
          client->println("<br />");  
          client->println("<TABLE Bordercolor=#000000 cellspacing=6 align=center border=3>");
                    mySensor.readData();
          client->println("<TR>");        
          client->println("<TD>"); client->print("<B>Feuchte: </B>"); client->println("</TD>");
          client->println("<TD>"); client->print(mySensor.getHumidity()); client->print(" %"); client->println("</TD>");
          client->println("</TR>");
          client->println("<TR>");
          client->println("<TD>"); client->print("<B>Temperatur: </B>"); client->println("</TD>");
          client->println("<TD>"); client->print(mySensor.getTemperatureC()); client->println(" °"); client->println("C"); client->println("</TD>");
          client->println("</TR>");
          client->println("<TR>");
          client->println("<TD>"); client->print("<B>Luftdruck: </B>"); client->println("</TD>");
                   int p = bmp.readPressure()/100;
          client->println("<TD>"); client->print(p); client->println(" hPa"); client->println("</TD>");
          client->println("</TR>");
          client->println("<TR>");
          client->println("<TD>"); client->print("<B>Helligkeit 1....20: </B>"); client->println("</TD>");
                   int wert =analogRead(eingang);
                   sensorWert = map(wert, 0, 1023, 0, 19);
          client->println("<TD>"); client->println(sensorWert); client->println("</TD>");
          client->println("</TR>");
          client->println("</TABLE>");  
          client->println("<br />"); client->println("<br />"); client->println("<br />"); client->println("<br />");                        
          client->print("<center>");
          client->print("<img src='IMAGE.JPG'>");
          client->print("</center>");
          client->println("</BODY>");
          client->println("</HTML>");
}  // End AusgabeBrowser


// ******************** TakingPicture ******************
void TakingPicture (){

    Serial.println(F("VC0706 test"));
                                              
    // Try to locate the camera
    if (cam.begin()) {
           Serial.println(F("Camera Found:"));
       } else {
           Serial.println(F("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

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

     if (! cam.takePicture())
          Serial.println(F("Failed to snap!"));
        else
          Serial.println(F("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(F("Storing "));
      Serial.print(jpglen, DEC);
      Serial.print(F(" 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(F("done!"));
      Serial.print(time); Serial.println(F(" ms elapsed"));                                

}  // End TakingPicture.  Picture saved on SD


// ******************* GetPicture ***************************

void GetPicture(EthernetClient* client) {

File webFile;
client->println("HTTP/1.1 200 OK");
client->println("Content-Type: image/jpeg");
client->println("Connnection: close");
client->println("Refresh: 1");  // refresh the page automatically every sec
client->println();
webFile = SD.open("IMAGE.JPG");                          
                    
if (webFile) {
       while(webFile.available()) {
            client->write(webFile.read()); // send web page to client
             }
       webFile.close();
              }

}   // end GetPicture


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


// *** zeit-anzeige formatieren ******************************************
void printZiffernGenulltOhnePunkt(int zahl) {
  if(zahl < 10) { // wenn kleiner als 10 ...
     Serial.print("0");
     }
  Serial.print(zahl);    
}


void printZiffernGenulltmitPunkt(int zahl) {
  Serial.print(":"); // trennende ":" einfuegen
  if(zahl < 10) { // wenn kleiner als 10 ...
      Serial.print('0'); // fuehrende 0 einfuegen
     }
  Serial.print(zahl); // Ausgabe auf TFT
}
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 168 19.11.2016 10:46
Letzter Beitrag: tr3
  Ethernet Modul Enc28j60 Pin13 LED Schalten BennIY 16 522 27.09.2016 20:30
Letzter Beitrag: BennIY
  Wo kann ich hier noch Code spahren? (SPI-,Ethernet-,SD-,GSM-Library) avoid 4 384 05.06.2016 14:16
Letzter Beitrag: avoid
  Daten per Ethernet Shield 2 senden Mark79 3 869 22.03.2016 19:29
Letzter Beitrag: Mark79
  array von Php --> Arduino zu senden (ethernet) Mourti 0 448 27.01.2016 22:11
Letzter Beitrag: Mourti
  Port B vom Arduino Ethernet einlesen magifix 0 354 08.01.2016 10:46
Letzter Beitrag: magifix
  BARCODE Abfrage über Ethernet Shield Wampo 3 797 05.12.2015 12:11
Letzter Beitrag: Wampo
  Probleme mit SPI - Ethernet und nRF24L01 itsy 35 2.994 21.11.2015 19:59
Letzter Beitrag: ardu_arne
  Problem mit der Ethernet Library (client.connect) ardu_arne 3 654 06.10.2015 17:06
Letzter Beitrag: ardu_arne
  Probleme mit Ethernet-Shild und <wire.h> Arne 5 1.006 08.09.2015 21:18
Letzter Beitrag: Arne

Gehe zu:


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