From 21eccffc8795a4d1b55e0acd8c997ebd001f6bfc Mon Sep 17 00:00:00 2001 From: Joe Tretter Date: Wed, 17 Jul 2024 17:01:09 -0500 Subject: [PATCH] done some more fine tuning... better but not perfect... Not sure if I don't better use a motion sensor... --- src/main.cpp | 167 ++++++++++++++++++++++++--------------------------- 1 file changed, 77 insertions(+), 90 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d884f59..4169e4e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,123 +26,110 @@ using eloq::telegram; using eloq::motion::detection; void setup() { - delay(3000); - Serial.begin(115200); - Serial.println("___MOTION DETECTION + Resolution Swtch + Send to Telegram__"); + delay(5000); + Serial.begin(115200); + Serial.println("___MOTION DETECTION + Resolution Swtch + Send to Telegram__"); - // camera settings - // replace with your own model! - camera.pinout.aithinker(); - camera.brownout.disable(); - camera.resolution.vga(); - camera.quality.high(); + // camera settings + // replace with your own model! + camera.pinout.aithinker(); + camera.brownout.disable(); + camera.resolution.vga(); + camera.quality.high(); - // see example of motion detection for config values - detection.skip(5); - detection.stride(1); - detection.threshold(5); - detection.ratio(0.2); - detection.rate.atMostOnceEvery(5).seconds(); + // see example of motion detection for config values + detection.skip(5); + detection.stride(1); + detection.threshold(3); + detection.ratio(0.1); + detection.rate.atMostOnceEvery(1).seconds(); - // init camera - while (!camera.begin().isOk()) - Serial.println(camera.exception.toString()); + // init camera + while (!camera.begin().isOk()) + Serial.println(camera.exception.toString()); - Serial.println("Camera OK"); + Serial.println("Camera OK"); - // connect to WiFi - while (!wifi.connect().isOk()) - Serial.println(wifi.exception.toString()); + // connect to WiFi + while (!wifi.connect().isOk()) + Serial.println(wifi.exception.toString()); - Serial.println("Wifi OK"); + Serial.println("Wifi OK"); - // connect to Telegram API - while (!telegram.begin().isOk()) - Serial.println(telegram.exception.toString()); + // connect to Telegram API + while (!telegram.begin().isOk()) + Serial.println(telegram.exception.toString()); - Serial.println("Telegram OK"); + Serial.println("Telegram OK"); - pinMode(4,OUTPUT); - Serial.println("Awaiting for motion..."); + pinMode(4,OUTPUT); + Serial.println("Awaiting for motion..."); } -/** - * - */ void loop() { // capture picture if (!camera.capture().isOk()) { - Serial.println(camera.exception.toString()); - return; + Serial.println(camera.exception.toString()); + return; } // run motion detection if (!detection.run().isOk()) { - Serial.println(detection.exception.toString()); - return; + Serial.println(detection.exception.toString()); + return; } // on motion, perform action 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( - "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.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()); + } */ - /* - Serial.println("Taking photo of motion at higher resolution"); - - camera.resolution.at(FRAMESIZE_UXGA, []() { - Serial.printf( - "Switched to higher resolution: %dx%d. It took %d ms to switch\n", - camera.resolution.getWidth(), - camera.resolution.getHeight(), - 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); - - 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"); - */ + // 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"); */ } } \ No newline at end of file