Pages: [1]   Go Down
Author Topic: Fare due foto conAdafruit/LinkSprite serial camera  (Read 1296 times)
0 Members and 1 Guest are viewing this topic.
Milan
Offline Offline
Sr. Member
****
Karma: 0
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ciao, riesco a fare una foto con arduino e mandarla via POST al server.
Ne vorrei afre un'altra ma se rilancio cam.takePicture() tutto funziona ma ottengo la stessa foto.

Come mai?

Ciao
Nic
Logged

Dueville (VI)
Offline Offline
Edison Member
*
Karma: 28
Posts: 1740
http://cesarecacitti.wordpress.com/
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

forse devi cancellare la precedente?  smiley-cool
Logged

Arduino UNO r3, Arduino MEGA 1280, adafruit motor shield, bluetooth module, enc28j60 shield.
Ultimi acquisti: un sacco di componenti elettronici, ATTEN AT 8586

Milan
Offline Offline
Sr. Member
****
Karma: 0
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Cancellare da dove?
Io leggo lo stream dalla camera e faccio un POST sul webserv.
Se lancio 2 volte il programma funziona, se lo rilancio, vedo che manda la foto, ma la prima che ho scattato.

N
Logged

Offline Offline
Edison Member
*
Karma: 28
Posts: 2031
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

prova a usare serial.flush,pulisci il buffer seriale e non dovrebbe darti piu questi problemi!
Logged

"Due cose sono infinite: l'universo e la stupidità umana, ma riguardo l'universo ho ancora dei dubbi..." Albert Einstein

Milan
Offline Offline
Sr. Member
****
Karma: 0
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lo facevo ma niente.
Stamattina alla priva prova è andato.
Però poi non si connette al web server la seconda volta.

Trovo tutto molto instabile, il codice riutilizzandolo, ha comportamenti diversi.
Boh...sembra di muoversi sui gusci d'uova.
N
Logged

Offline Offline
Edison Member
*
Karma: 28
Posts: 2031
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

se non posti il codice sarà difficile darti una mano  smiley-sweat
Logged

"Due cose sono infinite: l'universo e la stupidità umana, ma riguardo l'universo ho ancora dei dubbi..." Albert Einstein

Milan
Offline Offline
Sr. Member
****
Karma: 0
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Scusa ecco.
Ti dico che stamattina son riuscito a fare 3 foto.
Adesso non fa neanche la prima ma non si connette al server e ci potrebbe stare anche se da web lo raggiungo.

Code:
#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);

//http://www.theshaker.org/test_nicola/image_upload.php
char serverName[] = "www.theshaker.org";

int32_t time = millis();
int32_t ritorno;
EthernetClient client;

void setup() {
  Serial.begin(38400);
  ritorno = -1;

  pinMode(10, OUTPUT);     // change this to 53 on a mega
  digitalWrite(10, HIGH);
 

  if (Ethernet.begin(mac) == 0) {
    Serial.println(F("ETH KO"));
    // no point in carrying on, so do nothing forevermore:
    while(true);
  } else
  {
     Serial.println(F("ETH OK"));
  }
 
   
  delay(1000);
   
  if (cam.begin()) {
    Serial.println(F("OK CAM"));
  } else {
    Serial.println("NO CAM");
    return;
  }
 
  //cam.setImageSize(VC0706_640x480);        // biggest
  cam.setImageSize(VC0706_320x240);        // medium
  //cam.setImageSize(VC0706_160x120);          // small

/*

  // You can read the size back from the camera (optional, but maybe useful?)
  uint8_t imgsize = cam.getImageSize();
  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");
 
*/ 
   
  ritorno =  takefoto();
  Serial.print("Ritorno ");
  Serial.println(ritorno);
   
}



// This is where all the magic happens...
void loop() {
 
  byte inChar;
  inChar = Serial.read();
 
  //Preso da DnsWebClient
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (inChar == 'f')
  {
    Serial.flush();
    client.flush();
    client.stop();
//    cam.reset();    //non si connette al serve con sta linea
   
    ritorno = -1;     
    Serial.println("");
    Serial.println("Riscatto");
    ritorno = takefoto();
  } 
 
}

int takefoto() {
  Serial.println("Snap in 3 secs...");
//  cam.reset();
  cam.setImageSize(VC0706_320x240); 
  // You can read the size back from the camera (optional, but maybe useful?)
  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");
 
 
  delay(3000); 
  if (! cam.takePicture())
    Serial.println("Failed to snap!");
  else
    Serial.println("Picture taken!");
   
  Serial.println("Server connecting...");   

   
//  client.stop();
  if (client.connect(serverName, 80))     {
    Serial.println("connected");
    // Make a HTTP request:
//    client.println("GET /ARDUINO/savepicture.cfm");
//    client.println();
   
   
  // 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.0"));
//http://www.theshaker.org/test_nicola/image_upload.php
//www.theshaker.org
client.println(F("POST /test_nicola/image_upload.php HTTP/1.0"));
//client.println(F("POST /ARDUINO/savepicture.cfm"));
client.println(F("Host: www.theshaker.org"));
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();
 
 
 
  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);
//    Serial.write(buffer, HEX);   

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

 
 
  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.flush();
    client.stop();

    // do nothing forevermore:
    while(true);
  } 
 
 
 
 
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }   
 
 
   
  return time;
 
}


N
Logged

Milan
Offline Offline
Sr. Member
****
Karma: 0
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Adesso sta funzionando.
Sia in 320x200 che facendo la  foto ogni volta che premo f.

N
Logged

Pages: [1]   Go Up
Jump to: