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
14.06.2015, 16:02
Beitrag #17
RE: Ethernet-Wetter-Cam
Hi,
das ganze funktioniert eher anders herum. Der Client muss sozusagen periodisch die Seite neu anfordern. Such mal nach HTML reload oder so.
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
14.06.2015, 17:01
Beitrag #18
RE: Ethernet-Wetter-Cam
(14.06.2015 16:02)Thorsten Pferdekämper schrieb:  Hi,
das ganze funktioniert eher anders herum. Der Client muss sozusagen periodisch die Seite neu anfordern. Such mal nach HTML reload oder so.
Gruß,
Thorsten



In den Vorversionen hatte ich ja im sketch mittels client.print .... Code die einzelnen Zeilen der Webpage erstellt. einige Zeilen haben die Sensordaten ausgegeben. Mit einer "Refresh-Zeile" wurde diese Webpage immer wieder aktualisiert und so die Sensordaten neu ausgelesen und ausgegeben.

Code:
// listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // 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: 5");  // refresh the page automatically every 5 sec
          client.println();
        
        client.println("<!DOCTYPE HTML>");
      client.println("<HTML>");
        client.println("<HEAD>");
        client.println("<TITLE>Wetterstation</TITLE>");
        client.println("</HEAD>");
        
      client.println("<BODY BGColor=#D0F0D0>");
        client.println("<H1 align=center><Big><TT>Wetterstation</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.print(":");
        if(second() < 10) {client.print("0");} ;client.print(second());
        client.println("<HR>");
        client.println("<br />");  
        client.println("<TABLE Bordercolor=#000000 cellspacing=6 align=center border=3>");
        client.println("<TR>");        
        client.println("<TD>"); client.print("<B>Feuchte: </B>"); client.println("</TD>");
        client.println("<TD>"); client.print(h); 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(t); 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>");
        client.println("<TD>"); client.print(bmp.readPressure()/100+2); 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>");
        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("<Small>Ethernet-Weather-Station_---DHT22_RTC_BMP085_Photosen.ino</Small>");
      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);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}

Nun suche ich eigentlich nur eine Möglichkeit, wie ich darin die Erstellung des Fotos mit der VC0706 und die direkte Ausgabe in der Webpage realisiere. Also ohne Umweg über die SD-Karte. Huh
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
14.06.2015, 17:19
Beitrag #19
RE: Ethernet-Wetter-Cam
Hi,
Du bindest einfach das Bild über das IMG Tag ein. Wenn dann die Anforderung für die Bilddatei im Sketch ankommt, dann liest Du sie nicht von der SD-Karte, sondern Du schiesst das Foto. Dann schreibst Du den Kram nicht auf die SD-Karte, sondern direkt auf den client.
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
14.06.2015, 17:32 (Dieser Beitrag wurde zuletzt bearbeitet: 14.06.2015 17:34 von 4711engel.)
Beitrag #20
RE: Ethernet-Wetter-Cam
(14.06.2015 17:19)Thorsten Pferdekämper schrieb:  Hi,
Du bindest einfach das Bild über das IMG Tag ein. Wenn dann die Anforderung für die Bilddatei im Sketch ankommt, dann liest Du sie nicht von der SD-Karte, sondern Du schiesst das Foto. Dann schreibst Du den Kram nicht auf die SD-Karte, sondern direkt auf den client.
Gruß,
Thorsten

Hi,
als newbie hört sich dieses erst einmal für mich wie arduino-Chinesisch an.

Was ich verstanden habe ist der IMG-Tag. Am Ende der Tabelle füge ich die Ausgabe des Bildes ein:
client.println("<img src="IMAGE.JPG">")

Was meinst Du mit "Anforderung der Bilddatei"? Wo? Wie? Und wie schreibe ich die Bilddaten direkt auf den Client?
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
14.06.2015, 21:20
Beitrag #21
RE: Ethernet-Wetter-Cam
Hi Thorsten,
ich habe jetzt erst einmal versucht, das Bild IMAGE.JPG, das auf der SD liegt, auszugeben. Die Webpage liegt nun nicht mehr auf der SD, sondern mit client.println Code im sketch.

Leider funktioniert der Teil der Bildausgabe so noch nicht.

Code:
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include "DHT22.h"


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

#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

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

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

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

// 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 index file
    }
    Serial.println(F("IMAGE.JPG found"));




}


void loop() {


  //Photosensor
  int wert =analogRead(eingang);
  sensorWert = map(wert, 0, 1023, 0, 19);
  
  // Measure the Druck
  int p = bmp.readPressure()/100+2;

    Serial.print("Luftdruck:    ");
    Serial.print(p);
    Serial.println(" hPa");

  // Reading temperature or humidity
  mySensor.readData();
  float h = mySensor.getHumidity();
  float t = mySensor.getTemperatureC();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Feuchte:    ");
    Serial.print(h);
    Serial.println(" %");
    Serial.print("Temperatur: ");
    Serial.print(t);
    Serial.println(" C");
    Serial.print("Helligkeit 1....20: ");
    Serial.println(sensorWert);
    Serial.println(" ");
    delay(5000);
  }

  // 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: 5");  // refresh the page automatically every 5 sec
          client.println();
        
        client.println("<!DOCTYPE HTML>");
      client.println("<HTML>");
        client.println("<HEAD>");
        client.println("<TITLE>Wetterstation</TITLE>");
        client.println("</HEAD>");    
       client.println("<BODY BGColor=#D0F0D0>");
        client.println("<H1 align=center><Big><TT>Wetterstation</TT></Big></H1>");
        client.println("<HR>");
        client.println("<br />");  
        client.println("<TABLE Bordercolor=#000000 cellspacing=6 align=center border=3>");
        client.println("<TR>");        
        client.println("<TD>"); client.print("<B>Feuchte: </B>"); client.println("</TD>");
        client.println("<TD>"); client.print(h); 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(t); 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>");
        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>");
        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 />");



                        webFile = SD.open("IMAGE.JPG");
                        if (webFile) {
                            client.println("<IMG SRC=IMAGE.JPG>");
                            client.println();
                        }
                        
                        
                        
         client.println("<br />"); client.println("<br />"); client.println("<br />"); client.println("<br />");                
        client.println("<Small>Ethernet-Weather-Station_---DHT22_BMP085_Photosen-CAM--MEGA.ino</Small>");
      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);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
15.06.2015, 10:11
Beitrag #22
RE: Ethernet-Wetter-Cam
Hi,
hatte der andere Sketch nicht schon alles? Da war doch Coding, um die Daten von der Kamera zu lesen und ausserdem wurde die Bilddatei auch schon vom Sketch bereit gestellt.
Gruss,
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
15.06.2015, 19:29 (Dieser Beitrag wurde zuletzt bearbeitet: 15.06.2015 20:10 von 4711engel.)
Beitrag #23
RE: Ethernet-Wetter-Cam
(15.06.2015 10:11)Thorsten Pferdekämper schrieb:  Hi,
hatte der andere Sketch nicht schon alles? Da war doch Coding, um die Daten von der Kamera zu lesen und ausserdem wurde die Bilddatei auch schon vom Sketch bereit gestellt.
Gruss,
Thorsten

Hi Thorsten,
also ich schicke Dir mal den aktuellen sketch. Dieser gibt richtig die gemessenen Sensorendaten aus, nimmt von der Cam regelmäßig ein Bild und speichert dieses auf der SD ab. Die Ausgabe auf dem Browser klappt noch nicht.

Code:
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include "DHT22.h"


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

#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

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

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);
  Wire.begin();

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

// 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 index file
    }
    Serial.println(F("IMAGE.JPG found"));

}


void loop() {


  //Photosensor
  int wert =analogRead(eingang);
  sensorWert = map(wert, 0, 1023, 0, 19);
  
  // Measure the Druck
  int p = bmp.readPressure()/100+2;

    Serial.print(F("Luftdruck:    "));
    Serial.print(p);
    Serial.println(F(" hPa"));

  // Reading temperature or humidity
  mySensor.readData();
  float h = mySensor.getHumidity();
  float t = mySensor.getTemperatureC();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println(F("Failed to read from DHT"));
  } else {
    Serial.print(F("Feuchte:    "));
    Serial.print(h);
    Serial.println(F(" %"));
    Serial.print(F("Temperatur: "));
    Serial.print(t);
    Serial.println(F(" C"));
    Serial.print(F("Helligkeit 1....20: "));
    Serial.println(sensorWert);
    Serial.println(F(" "));
    delay(5000);
  }

  // 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: 5");  // refresh the page automatically every 5 sec
          client.println();
        
        client.println("<!DOCTYPE HTML>");
      client.println("<HTML>");
        client.println("<HEAD>");
        client.println("<TITLE>Wetterstation</TITLE>");
        client.println("</HEAD>");    
       client.println("<BODY BGColor=#D0F0D0>");
        client.println("<H1 align=center><Big><TT>Wetterstation</TT></Big></H1>");
        client.println("<HR>");
        client.println("<br />");  
        client.println("<TABLE Bordercolor=#000000 cellspacing=6 align=center border=3>");
        client.println("<TR>");        
        client.println("<TD>"); client.print("<B>Feuchte: </B>"); client.println("</TD>");
        client.println("<TD>"); client.print(h); 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(t); 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>");
        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>");
        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 />");

                            
// ***************Start TakingPicture **********************************************
       delay(10000);
                          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 *************************************************


                        webFile = SD.open("IMAGE.JPG");
                        if (webFile) {
                            client.println("<IMG SRC='IMAGE.JPG'>");
                            client.println();
                        }
                        
                    
                        
         client.println("<br />"); client.println("<br />"); client.println("<br />"); client.println("<br />");                
        client.println("<Small>Ethernet-Weather-Station_---DHT22_BMP085_Photosen-CAM--MEGA.ino</Small>");
      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);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}

(15.06.2015 19:29)4711engel schrieb:  [quote='Thorsten Pferdekämper' pid='18509' dateline='1434359491']
Hi,
hatte der andere Sketch nicht schon alles? Da war doch Coding, um die Daten von der Kamera zu lesen und ausserdem wurde die Bilddatei auch schon vom Sketch bereit gestellt.
Gruss,
Thorsten

Hi Thorsten,
also ich schicke Dir mal den aktuellen sketch. Dieser gibt richtig die gemessenen Sensorendaten aus, nimmt von der Cam regelmäßig ein Bild und speichert dieses auf der SD ab. Die Ausgabe auf dem Browser klappt noch nicht.

Code:
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include "DHT22.h"


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

#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

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

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);
  Wire.begin();

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

// 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 index file
    }
    Serial.println(F("IMAGE.JPG found"));

}


void loop() {


  //Photosensor
  int wert =analogRead(eingang);
  sensorWert = map(wert, 0, 1023, 0, 19);
  
  // Measure the Druck
  int p = bmp.readPressure()/100+2;

    Serial.print(F("Luftdruck:    "));
    Serial.print(p);
    Serial.println(F(" hPa"));

  // Reading temperature or humidity
  mySensor.readData();
  float h = mySensor.getHumidity();
  float t = mySensor.getTemperatureC();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println(F("Failed to read from DHT"));
  } else {
    Serial.print(F("Feuchte:    "));
    Serial.print(h);
    Serial.println(F(" %"));
    Serial.print(F("Temperatur: "));
    Serial.print(t);
    Serial.println(F(" C"));
    Serial.print(F("Helligkeit 1....20: "));
    Serial.println(sensorWert);
    Serial.println(F(" "));
    delay(5000);
  }

  // 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: 5");  // refresh the page automatically every 5 sec
          client.println();
        
        client.println("<!DOCTYPE HTML>");
      client.println("<HTML>");
        client.println("<HEAD>");
        client.println("<TITLE>Wetterstation</TITLE>");
        client.println("</HEAD>");    
       client.println("<BODY BGColor=#D0F0D0>");
        client.println("<H1 align=center><Big><TT>Wetterstation</TT></Big></H1>");
        client.println("<HR>");
        client.println("<br />");  
        client.println("<TABLE Bordercolor=#000000 cellspacing=6 align=center border=3>");
        client.println("<TR>");        
        client.println("<TD>"); client.print("<B>Feuchte: </B>"); client.println("</TD>");
        client.println("<TD>"); client.print(h); 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(t); 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>");
        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>");
        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 />");

                            
// ***************Start TakingPicture **********************************************
       delay(10000);
                          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 *************************************************


                        webFile = SD.open("IMAGE.JPG");
                        if (webFile) {
                            client.println("<IMG SRC='IMAGE.JPG'>");
                            client.println();
                        }
                        
                    
                        
         client.println("<br />"); client.println("<br />"); client.println("<br />"); client.println("<br />");                
        client.println("<Small>Ethernet-Weather-Station_---DHT22_BMP085_Photosen-CAM--MEGA.ino</Small>");
      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);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}


   
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
16.06.2015, 18:10
Beitrag #24
RE: Ethernet-Wetter-Cam
Hi,
ich habe nun an meinem Problem weitergearbeitet. Ich habe aber noch keine Lösung gefunden, wie ich das von der Cam aufgenommene und auf der SD gespeicherte IMAGE.JPG am Browser anzeigen kann.
Im aktuellen sketch werden statt des Bildes nur kryptische Zeichen angezeigt.

Hier der aktuelle sketch:

Code:
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include "DHT22.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

// 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);
  Wire.begin();

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

// 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() {


  //Photosensor
  int wert =analogRead(eingang);
  sensorWert = map(wert, 0, 1023, 0, 19);
  
  // Measure the Druck
  int p = bmp.readPressure()/100+2;

    Serial.print(F("Luftdruck:    "));
    Serial.print(p);
    Serial.println(F(" hPa"));

  // Reading temperature or humidity
  mySensor.readData();
  float h = mySensor.getHumidity();
  float t = mySensor.getTemperatureC();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println(F("Failed to read from DHT"));
  } else {
    Serial.print(F("Feuchte:    "));
    Serial.print(h);
    Serial.println(F(" %"));
    Serial.print(F("Temperatur: "));
    Serial.print(t);
    Serial.println(F(" C"));
    Serial.print(F("Helligkeit 1....20: "));
    Serial.println(sensorWert);
    Serial.println(F(" "));
    delay(5000);
  }

  // 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: 5");  // refresh the page automatically every 5 sec
          client.println();
        
        client.println("<!DOCTYPE HTML>");
      client.println("<HTML>");
        client.println("<HEAD>");
        client.println("<TITLE>Wetterstation</TITLE>");
        client.println("</HEAD>");    
       client.println("<BODY BGColor=#D0F0D0>");
        client.println("<H1 align=center><Big><TT>Wetterstation</TT></Big></H1>");
        client.println("<HR>");
        client.println("<br />");  
        client.println("<TABLE Bordercolor=#000000 cellspacing=6 align=center border=3>");
        client.println("<TR>");        
        client.println("<TD>"); client.print("<B>Feuchte: </B>"); client.println("</TD>");
        client.println("<TD>"); client.print(h); 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(t); 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>");
        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>");
        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 />");

                            
// ***************Start TakingPicture **********************************************
       delay(10000);
                          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 *************************************************
// Get picture from SD and print in the browser

                          webFile = SD.open("IMAGE.JPG");
                          File webFile = SD.open(filename, FILE_READ);
          
                  Serial.print("filename:   ");  Serial.println(filename);  
                            
                        if (webFile) {
                        while(webFile.available()) {
                            client.write(webFile.read()); // send Picture to client
                        }
                           webFile.close();
                    }    
                            
              
                    
                        
         client.println("<br />"); client.println("<br />"); client.println("<br />"); client.println("<br />");                
        client.println("<Small>Ethernet-Weather-Station_---DHT22_BMP085_Photosen-CAM--MEGA.ino</Small>");
      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);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}

und der screenshot. Dieser zeigt rechts die sketch-stelle, wo das Bild angezeigt werden soll und links die Webseite mit den richtigen Sensordaten und statt des Bildes die zeichen:
   

Wer hat eine Idee für mich und kann mir vielleicht meinen Fehler korrigieren. Habe aktuell keine Idee, da mir die Erfahrung damit fehlt.
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 162 19.11.2016 10:46
Letzter Beitrag: tr3
  Ethernet Modul Enc28j60 Pin13 LED Schalten BennIY 16 519 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 868 22.03.2016 19:29
Letzter Beitrag: Mark79
  array von Php --> Arduino zu senden (ethernet) Mourti 0 447 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 796 05.12.2015 12:11
Letzter Beitrag: Wampo
  Probleme mit SPI - Ethernet und nRF24L01 itsy 35 2.986 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