Sending an image to a server with the CC3000 breakout board

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
marco26fr
 
Posts: 38
Joined: Sat Jul 28, 2012 5:25 am

Sending an image to a server with the CC3000 breakout board

Post by marco26fr »

Hello,

I am currently trying to send a jpeg picture (taken by a serial TTL camera) over WiFi (but could be over Ethernet) to a server running on my computer. I use the Arduino Uno board + a CC3000 breakout board that I know works perfectly. This is the code I am using on the Arduino side:

Code: Select all

      uint32_t len = jpglen + 177; // 177 is the content without the image data  
      client.println(F("POST /ohs/camera.php HTTP/1.1"));
      client.println(F("Host: 192.168.0.14:8888"));
      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")); // 21
      client.println(F("content-disposition: form-data; name=\"picture\"; filename=\"cam.jpg\"")); // 68
      client.println(F("Content-Type: image/jpeg")); // 26
      client.println(F("Content-Transfer-Encoding: binary")); // 35
      client.println(); // 2
      
      Serial.println(F("Header sent"));
      
      int32_t time = millis();
      // Read all the data up to # bytes!
      byte wCount = 0; // For counting # of writes
      while (jpglen > 0) {
        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; 
  }
  
client.println(); // 2
client.println(F("--UH3xBZZtzewr09oPP--")); // 23
This code is executed when the connection is established. This is the code on the server side:

Code: Select all

<?php

  $estensioni_consentite = array('image/jpeg', 'image/jpg');
  $base_dir = '';
  $default_name = 'cam.jpg';
    
    if (move_uploaded_file($_FILES['picture']['tmp_name'], $base_dir.$default_name)) {
      echo "The file has been uploaded";
    }
    else {
      echo "There was an error uploading the file, please try again!";
    }  

?>
The Arduino does transmit something, I can see the answer from the answer on the terminal. On the server side, an image gets created with the right side but it is corrupted. Does anybody can help me with that ? Did I make a mistake in the code ? Thanks !

User avatar
frank26080115
 
Posts: 126
Joined: Fri Jun 15, 2007 1:04 am

Re: Sending an image to a server with the CC3000 breakout board

Post by frank26080115 »

When you say "corrupted", did you check every single byte to see how the expected result and the actual result are different? That will give you a huge clue as to what went wrong.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”