done some more fine tuning... better but not perfect... Not sure if I don't better use a motion sensor...

This commit is contained in:
Joe Tretter
2024-07-17 17:01:09 -05:00
parent b2a3e23eb7
commit 21eccffc87

View File

@@ -26,123 +26,110 @@ using eloq::telegram;
using eloq::motion::detection; using eloq::motion::detection;
void setup() { void setup() {
delay(3000); delay(5000);
Serial.begin(115200); Serial.begin(115200);
Serial.println("___MOTION DETECTION + Resolution Swtch + Send to Telegram__"); Serial.println("___MOTION DETECTION + Resolution Swtch + Send to Telegram__");
// camera settings // camera settings
// replace with your own model! // replace with your own model!
camera.pinout.aithinker(); camera.pinout.aithinker();
camera.brownout.disable(); camera.brownout.disable();
camera.resolution.vga(); camera.resolution.vga();
camera.quality.high(); camera.quality.high();
// see example of motion detection for config values // see example of motion detection for config values
detection.skip(5); detection.skip(5);
detection.stride(1); detection.stride(1);
detection.threshold(5); detection.threshold(3);
detection.ratio(0.2); detection.ratio(0.1);
detection.rate.atMostOnceEvery(5).seconds(); detection.rate.atMostOnceEvery(1).seconds();
// init camera // init camera
while (!camera.begin().isOk()) while (!camera.begin().isOk())
Serial.println(camera.exception.toString()); Serial.println(camera.exception.toString());
Serial.println("Camera OK"); Serial.println("Camera OK");
// connect to WiFi // connect to WiFi
while (!wifi.connect().isOk()) while (!wifi.connect().isOk())
Serial.println(wifi.exception.toString()); Serial.println(wifi.exception.toString());
Serial.println("Wifi OK"); Serial.println("Wifi OK");
// connect to Telegram API // connect to Telegram API
while (!telegram.begin().isOk()) while (!telegram.begin().isOk())
Serial.println(telegram.exception.toString()); Serial.println(telegram.exception.toString());
Serial.println("Telegram OK"); Serial.println("Telegram OK");
pinMode(4,OUTPUT); pinMode(4,OUTPUT);
Serial.println("Awaiting for motion..."); Serial.println("Awaiting for motion...");
} }
/**
*
*/
void loop() { void loop() {
// capture picture // capture picture
if (!camera.capture().isOk()) { if (!camera.capture().isOk()) {
Serial.println(camera.exception.toString()); Serial.println(camera.exception.toString());
return; return;
} }
// run motion detection // run motion detection
if (!detection.run().isOk()) { if (!detection.run().isOk()) {
Serial.println(detection.exception.toString()); Serial.println(detection.exception.toString());
return; return;
} }
// on motion, perform action // on motion, perform action
if (detection.triggered()) { if (detection.triggered()) {
Serial.printf(
"Motion detected on frame of size %dx%d (%d bytes)\n",
camera.resolution.getWidth(),
camera.resolution.getHeight(),
camera.getSizeInBytes()
);
/*Serial.println("Taking photo of motion at higher resolution");
// Maximum Resolution I can send via telegram is SVGA
camera.resolution.at(FRAMESIZE_SVGA, []() {
Serial.printf( Serial.printf(
"Motion detected on frame of size %dx%d (%d bytes)\n", "Switched to higher resolution: %dx%d. It took %d ms to switch\n",
camera.resolution.getWidth(), camera.resolution.getWidth(),
camera.resolution.getHeight(), camera.resolution.getHeight(),
camera.getSizeInBytes() camera.resolution.benchmark.millis()
); );
*/
// capture new frame
Serial.println("Capturing Frame");
digitalWrite(4,HIGH);
if (!camera.capture().isOk()) {
Serial.println(camera.exception.toString());
return;
}
digitalWrite(4,LOW);
// send text to telegram
/* Serial.println("Sending Text to Telegram");
String text="TEST";
if (telegram.to(TELEGRAM_CHAT).send(text).isOk()){
Serial.println("Message sent to Telegram!");
}else{
Serial.println(telegram.exception.toString());
} */
/* // Send to telegram
Serial.println("Taking photo of motion at higher resolution"); Serial.println("Sending Image to Telegram");
if (telegram.to(TELEGRAM_CHAT1).send(camera.frame).isOk()){
camera.resolution.at(FRAMESIZE_UXGA, []() { Serial.println("Photo sent to Telegram");
Serial.printf( } else {
"Switched to higher resolution: %dx%d. It took %d ms to switch\n", Serial.println(telegram.exception.toString());
camera.resolution.getWidth(), }
camera.resolution.getHeight(), /* if (telegram.to(TELEGRAM_CHAT2).send(camera.frame).isOk()){
camera.resolution.benchmark.millis() Serial.println("Photo sent to Telegram");
); } else {
Serial.println(telegram.exception.toString());
*/ } */
// capture new frame
Serial.println("Capturing Frame");
digitalWrite(4,HIGH);
if (!camera.capture().isOk()) {
Serial.println(camera.exception.toString());
return;
}
digitalWrite(4,LOW);
Serial.printf(
"Frame size is now %d bytes\n",
camera.getSizeInBytes()
);
// send text to telegram
/* Serial.println("Sending Text to Telegram");
String text="TEST";
if (telegram.to(TELEGRAM_CHAT).send(text).isOk()){
Serial.println("Message sent to Telegram!");
}else{
Serial.println(telegram.exception.toString());
} */
// Send to telegram
Serial.println("Sending Image to Telegram");
if (telegram.to(TELEGRAM_CHAT1).send(camera.frame).isOk()){
Serial.println("Photo sent to Telegram");
} else {
Serial.println(telegram.exception.toString());
}
if (telegram.to(TELEGRAM_CHAT2).send(camera.frame).isOk()){
Serial.println("Photo sent to Telegram");
} else {
Serial.println(telegram.exception.toString());
}
/* });
Serial.println("Resolution switched back to VGA");
*/
/* });
Serial.println("Resolution switched back to VGA"); */
} }
} }