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