I am doing a project using the arduino unoArduino UNO, cc3000 wifiWIFI chip, micro sdSD card shield, and a ttlTTL serial camera in the hopesorder to make a security system that will post a picture online (not enough processing power for video) when motion is detected on the camera.
Thankfully, the hardware works after a few shortcomings, but my program seems to be taking up 97% of the flashFlash storage.
Also, I am looking for a better way to transfer the image than saving it 32 bits at a time and then waiting about 10 sec so the httpHTTP request will send it to the server.
One thing I do know is that I have tested all the hardware and those functions are working. My problem is in the logic.
Any help appreciated! (Image is around 13kb13KB and unoUNO only has 2kb of dynamic memory).
void loop(void)
{
cam.setMotionDetect(true);
while (1) {
if (cam.motionDetected()) {
Serial.println("Motion!");
cam.setMotionDetect(false);
if (! cam.takePicture())
Serial.println("Failed to snap!");
else
Serial.println("Picture taken!");
uint16_t jpglen = cam.frameLength();
Serial.print(jpglen, DEC);
Serial.println(" byte image");
char filename[13];
strcpy(filename, "IMAGE00.JPG");
for (int i = 0; i < 100; i++) {
filename[5] = '0' + i/10;
filename[6] = '0' + i%10;
// create if does not exist, do not open existi
ngexisting, write, sync after write
if (! SD.exists(filename)) {
break;
}
}
File imgFile = SD.open(filename, FILE_WRITE);
while(jpglen > 0) {
uint8_t *buffer;
uint8_t bytesToRead = min(32, jpglen);
buffer = cam.readPicture(bytesToRead);
imgFile.write(buffer, bytesToRead);
//Send Request
Adafruit_CC3000_Client client = cc3000.connectTCP
(ip, 80);
if (client.connected()) {
Serial.println("Connected!");
client.println("POST /upload HTTP/1.0");
client.println("From: Arduino");
client.println("Host:
fierce-chamber-5675.herokuapp.com
"com");
client.println("Content-Type: image/jpeg")
;
client.println("Content-Length: " + 32);
client.print("Connection: close");
client.println();
for(int i = 0; i < 32; i++) {
client.print(buffer[i], HEX);
}
client.println();
} else {
Serial.println(F("Connection failed"));
return;
}
client.close();
Serial.println(F("-------------------------------------"));
jpglen -= bytesToRead;
}
imgFile.close();
cam.resumeVideo();
cam.setMotionDetect(true);
}
}
}