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
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!";
}
?>