Sto cercando di afre in modo che Arduino faccia una foto e la mandi ad un Pc.
Ho una cam seriale Adafruit compatibile e un ethernet shield originale.
Allora sto cercando di mettere insieme un po' di pezzi che da soli funzionavano.
La foto sono riuscito a farla e salvarla sulla SD.
Unendo altre librerie ho problemi di memoria e non va piu niente
Fino a questo punto l'unica cosa che sono riuscito a fare e farla al massimo in 320x240 e mandarla ad un server FTP.
Già facendola 640x480 la connessione con l'FTP cade.
Ho provato a fare un POST su un web serve ma non sono riuscito.
Qualcuno ha idee o sugerimenti?
Sotto il codice.
Ciao
Nic
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
SoftwareSerial cameraconnection = SoftwareSerial(6, 7);
Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);
char serverName[] = "web1.ogilvy.it";
EthernetClient client;
void setup() {
Serial.begin(38400);
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
while(true);
}
delay(1000);
Serial.println("VC0706 Camera snapshot test");
if (cam.begin()) {
Serial.println("Camera Found:");
} else {
Serial.println("No camera found?");
return;
}
// Print out the camera version information (optional)
char *reply = cam.getVersion();
if (reply == 0) {
Serial.print("Failed to get version");
} else {
Serial.println("-----------------");
Serial.print(reply);
Serial.println("-----------------");
}
cam.setImageSize(VC0706_640x480); // biggest
//cam.setImageSize(VC0706_320x240); // medium
//cam.setImageSize(VC0706_160x120); // small
uint8_t imgsize = cam.getImageSize();
Serial.print("Image size: ");
if (imgsize == VC0706_640x480) Serial.println("640x480");
if (imgsize == VC0706_320x240) Serial.println("320x240");
if (imgsize == VC0706_160x120) Serial.println("160x120");
Serial.println("Snap in 3 secs...");
delay(3000);
if (! cam.takePicture())
Serial.println("Failed to snap!");
else
Serial.println("Picture taken!");
Serial.println("Server connecting...");
// if (client.connect(mioserver, 8080)) {
if (client.connect(serverName, 80)) {
Serial.println("connected");
// Make a HTTP request:
// Get the size of the image (frame) taken
uint16_t jpglen = cam.frameLength();
Serial.print("Storing ");
Serial.print(jpglen, DEC);
Serial.print(" byte image.");
uint32_t len = jpglen + 177; // 177 is the content without the image data
//client.println(F("POST /path/to/script.php HTTP/1.0"));
client.println(F("POST /ARDUINO/savepicture.cfm HTTP/1.1"));
//client.println(F("POST /ARDUINO/savepicture.cfm"));
client.println(F("Host: web1.ogilvy.it"));
client.println(F("Content-type: multipart/form-data, boundary=UH3xBZZtzewr09oPP"));
client.print(F("Content-Length: "));
client.println(len);
client.println();
client.println(F("--UH3xBZZtzewr09oPP"));
client.println(F("content-disposition: form-data; name=\"picture\"; filename=\"cam.jpg\""));
client.println(F("Content-Type: image/jpeg"));
client.println(F("Content-Transfer-Encoding: binary"));
client.println();
int32_t time = millis();
pinMode(8, 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);
//Scrittura
// imgFile.write(buffer, bytesToRead);
client.write(buffer, bytesToRead);
if(++wCount >= 64) { // Every 2K, give a little feedback so it doesn't appear locked up
Serial.print('.');
wCount = 0;
}
//Serial.print("Read "); Serial.print(bytesToRead, DEC); Serial.println(" bytes");
jpglen -= bytesToRead;
}
// imgFile.close();
client.println();
client.println(F("--UH3xBZZtzewr09oPP--"));
time = millis() - time;
Serial.println("done!");
Serial.print(time); Serial.println(" ms elapsed");
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
// Get the size of the image (frame) taken
uint16_t jpglen = cam.frameLength();
Serial.print("Storing ");
Serial.print(jpglen, DEC);
Serial.print(" byte image.");
}
// This is where all the magic happens...
void loop() {
//Preso da DnsWebClient
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while(true);
}
}