I am doing a project using Arduino UNO, cc3000 WIFI chip, micro SD card shield, and a TTL serial camera in order 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 Flash 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 HTTP 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 13KB and UNO only has 2kb of dynamic memory).
My full code is here: https://www.dropbox.com/s/arxa253mxwvqtg1/HomeProj.rtf?dl=0
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 existing, 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");
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);
}
}
}