Send image to a PC using ethernet shield

Batu you wrote:

uint32_t len = size_of_pict + 177; // 177 is the content without the image data
client.println(F("POST /path/to/script.php HTTP/1.0"));
client.println(F("Host: example.com"));
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();
while (has_more_pict_data) {
  client.write(pict_chunk, size_of_pict_chunk);
}
client.println();
client.println(F("--UH3xBZZtzewr09oPP--"));

I see

client.println(); //2
client.println(F("--UH3xBZZtzewr09oPP")); //19 + 2

2 times.
At line 7 and at line 16.
Is it right?

Nic

2 times. At line 7 and at line 16. Is it right?

No, the first occurrence is the boundary with "--" prepended, the second is the boundary with "--" prepended AND appended.

For the calculation you have to count the characters that are sent in addition to the image data. How you do that depends on the tools you use, I copy it to my text editor, omit all escaping characters and save it in DOS style (CR and LF) and use the "wc" command. If you're on Windows you have to use the tools available there. Probably easiest for you is to count the characters that are different to my version and adjust the length accordingly.

No, the first occurrence is the boundary with "--" prepended, the second is the boundary with "--" prepended AND appended.

Ok, excuse me i had not readed the end of the line.

For the calculation you have to count the characters that are sent in addition to the image data.

Ok, but, in the example that you give me, from what line i must to start to count and until what line?

Thanks

Everything after the header. The header ends after the first empty line.

I try to count your 177 bytes, but i find 181.

From

client.println(F("--UH3xBZZtzewr09oPP")); //19 + 2 bytes 21 bytes

to client.println(F("--UH3xBZZtzewr09oPP--")); // 21 + 2 bytes

What's wrong?

N

I've write bytes count after every line.

19 2 70 2 24 2 33 2 2

2 21 2

167 + 14 = 181

uint32_t len = size_of_pict + 177; // 177 is the content without the image data
client.println(F("POST /path/to/script.php HTTP/1.0")); //
client.println(F("Host: example.com"));
client.println(F("Content-type: multipart/form-data, boundary=UH3xBZZtzewr09oPP"));
client.print(F("Content-Length: "));
client.println(len); 
client.println(); //2
client.println(F("--UH3xBZZtzewr09oPP")); //19 + 2
client.println(F("content-disposition: form-data; name=\"picture\"; filename=\"cam.jpg\"")); //70 + 2
client.println(F("Content-Type: image/jpeg")); //24 + 2
client.println(F("Content-Transfer-Encoding: binary")); //33 + 2
client.println(); //2
while (has_more_pict_data) {
  client.write(pict_chunk, size_of_pict_chunk);
}
client.println(); //2
client.println(F("--UH3xBZZtzewr09oPP--")); // 21 + 2
client.println(F("content-disposition: form-data; name=\"picture\"; filename=\"cam.jpg\"")); //70 + 2

This is 66 + 2 (you cannot count the escape characters "\", they are not sent).

OK. Thanks

Perahps i use 177 bytes, I've no change after the beginning lines.

Thanks

Works!!!

Grazie
Nic

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Carica Immagine</title>
  </head>
  <body>
    <?php
      
      $estensioni_consentite = array('image/jpeg', 'image/jpg');
      $base_dir = '';
      $default_name = 'image_uploaded.jpg';
      
      //Se il file è caricato e la sua tipologia è jpg
      if ((isset($_FILES['picture']))&&(is_uploaded_file($_FILES['picture']['tmp_name'])) && (in_array($_FILES['picture']['type'], $estensioni_consentite))) {
        //Sposto il file dalla directory temporanea a quella che mi interessa dandogli il nome che voglio
        if (!move_uploaded_file($_FILES['picture']['tmp_name'], $base_dir.$default_name)) {
          echo"<p align=center><strong>Caricamento immagine riuscito</strong></p>";
        }
      }
     ?>
    <div align='center'>
      <form name='form' method='post' action='' enctype='multipart/form-data'>
        <input name='picture' type='file' />
        <input type='submit' name='Carica' value='Carica' />
      </form>
      <hr />
      L'ultima immagine caricata &egrave;

      <img src="<?php echo $base_dir.$default_name.'?t='.time(); ?>" />
    </div>
  </body>
</html>

Hello, i am also working on sending an image to my localserver, but i havent been able to do it with success. For the moment I can get the image with the same module camera and connect succesfully to the server, but I think my scketch fails when calling the php script and posting the image using client.write. Could anyone help me with this?

#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>    
#include <SPI.h>
#include <Ethernet.h>
#define chipSelect 53


byte mac[] = {  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

SoftwareSerial cameraconnection = SoftwareSerial(69, 3);
Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);


IPAddress server(192,168,0,194);  //my local server IP address
EthernetClient client;


void setup() {
  
  // When using hardware SPI, the SS pin MUST be set to an
  // output (even if not connected or used).  If left as a
  // floating input w/SPI on, this can cause lockuppage.
  #if !defined(SOFTWARE_SPI)
  #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
    if(chipSelect != 53) pinMode(53, OUTPUT); // SS on Mega
  #else
    if(chipSelect != 10) pinMode(10, OUTPUT); // SS on Uno, etc.
  #endif
  #endif
  
  Serial.begin(9600);
  

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }   
   
  delay(1000);
   
  Serial.println("VC0706 Camera snapshot test");
  // Try to locate the camera
  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("-----------------");
  }

  // Set the picture size - you can choose one of 640x480, 320x240 or 160x120 
  // Remember that bigger pictures take longer to transmit!
  
  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");
  
  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(server, 80)) {
    Serial.println("connected");

  // 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  
  
//my path to the PHP script is: localserver/PFM/guardaimagen.php;
client.println(F("POST /PFM/guardaimagen.php HTTP/1.0"));
client.println(F("Host: 192.168.0.194"));  //my localserver ip address
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);

    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 {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }     
}

void loop() {

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

i am not sure if it is either my arduino scketch or my php script what fails. Could anyone give me a hand? I would be totally thankful!

All the best,

Javier.