Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 559fd35

Browse files
bump dist to 2.0.4
1 parent bd8f897 commit 559fd35

File tree

4 files changed

+131
-9
lines changed

4 files changed

+131
-9
lines changed

‎examples/CameraMotionDetection/CameraMotionToTelegramExample/CameraMotionToTelegramExample.ino

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Camera motion detection + JPEG capture + Telegram Bot demo
33
*/
44

5+
// replace with your own values
56
#define TELEGRAM_TOKEN "xxxxxxxxxx:yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
67
#define CHAT_ID "0123456789"
78
#define WIFI_SSID "SSID"
@@ -88,22 +89,21 @@ void loop() {
8889

8990
// if motion is detected, save original image as jpeg
9091
if (detector.isMotionDetected()) {
92+
Serial.println("Motion detected");
93+
9194
auto file = filesystem.writeBinary("/capture_best.jpg");
9295
auto jpeg = camera.image.jpeg().bestQuality();
9396

9497
if (jpeg.writeTo(file)) {
95-
Serial.print("Best quality jpeg file size in bytes: ");
96-
Serial.print(file.size());
97-
Serial.print(". It took ");
98-
Serial.print(jpeg.getElapsedTime());
99-
Serial.println(" micros to encode");
98+
Serial.println("Jpeg written");
10099

101100
// send to Telegram
102101
file.reopenAs("rb");
103-
bool messageOk = telegramBot.sendMessageTo(CHAT_ID, "Motion detected");
104-
bool jpegOk = telegramBot.sendJpegTo(CHAT_ID, file);
105102

103+
bool messageOk = telegramBot.sendMessageTo(CHAT_ID, "Motion detected");
106104
Serial.println(messageOk ? "Message sent OK" : "Message send error");
105+
106+
bool jpegOk = telegramBot.sendJpegTo(CHAT_ID, file);
107107
Serial.println(jpegOk ? "Jpeg sent OK" : "Jpeg send error");
108108

109109
if (!jpegOk) {
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* Camera motion detection + JPEG capture + Telegram Bot demo
3+
*/
4+
5+
// replace with your own values
6+
#define TELEGRAM_TOKEN "xxxxxxxxxx:yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
7+
#define CHAT_ID "0123456789"
8+
#define WIFI_SSID "SSID"
9+
#define WIFI_PASSWORD "PASSWORD"
10+
11+
#include <WiFi.h>
12+
#include <eloquent.h>
13+
#include <eloquent/vision/image/gray/custom.h>
14+
#include <eloquent/vision/motion/naive.h>
15+
#include <eloquent/fs/spiffs.h>
16+
#include <eloquent/networking/wifi.h>
17+
#include <eloquent/apps/telegram/bot/wifi.h>
18+
19+
20+
// uncomment based on your camera and resolution
21+
22+
//#include "eloquent/vision/camera/ov767x/gray/vga.h"
23+
//#include "eloquent/vision/camera/ov767x/gray/qvga.h"
24+
//#include "eloquent/vision/camera/ov767x/gray/qqvga.h"
25+
//#include "eloquent/vision/camera/esp32/aithinker/gray/vga.h"
26+
//#include "eloquent/vision/camera/esp32/aithinker/gray/qvga.h"
27+
//#include "eloquent/vision/camera/esp32/aithinker/gray/qqvga.h"
28+
//#include "eloquent/vision/camera/esp32/wrover/gray/vga.h"
29+
//#include "eloquent/vision/camera/esp32/wrover/gray/qvga.h"
30+
//#include "eloquent/vision/camera/esp32/wrover/gray/qqvga.h"
31+
//#include "eloquent/vision/camera/esp32/eye/gray/vga.h"
32+
//#include "eloquent/vision/camera/esp32/eye/gray/qvga.h"
33+
//#include "eloquent/vision/camera/esp32/eye/gray/qqvga.h"
34+
//#include "eloquent/vision/camera/esp32/m5/gray/vga.h"
35+
//#include "eloquent/vision/camera/esp32/m5/gray/qvga.h"
36+
//#include "eloquent/vision/camera/esp32/m5/gray/qqvga.h"
37+
//#include "eloquent/vision/camera/esp32/m5wide/gray/vga.h"
38+
//#include "eloquent/vision/camera/esp32/m5wide/gray/qvga.h"
39+
//#include "eloquent/vision/camera/esp32/m5wide/gray/qqvga.h"
40+
41+
42+
#define THUMB_WIDTH 32
43+
#define THUMB_HEIGHT 24
44+
45+
// allocate memory to store the thumbnail into a new image
46+
Eloquent::Vision::Image::Gray::CustomWithBuffer<THUMB_WIDTH, THUMB_HEIGHT> thumbnail;
47+
Eloquent::Vision::Motion::Naive<THUMB_WIDTH, THUMB_HEIGHT> detector;
48+
49+
50+
void setup() {
51+
delay(4000);
52+
Serial.begin(115200);
53+
filesystem.begin(true);
54+
55+
// turn on high freq for fast streaming speed
56+
camera.setHighFreq();
57+
58+
if (!camera.begin())
59+
eloquent::abort(Serial, "Camera init error");
60+
61+
if (!wifi.connectTo(WIFI_SSID, WIFI_PASSWORD))
62+
eloquent::abort(Serial, "Cannot connect to WiFi");
63+
64+
if (!telegramBot.connect()) {
65+
eloquent::abort(Serial, "Cannot connect to Telegram API");
66+
}
67+
68+
Serial.println("Camera init OK");
69+
Serial.println("WiFi connected OK");
70+
Serial.println("Telegram API connected OK");
71+
72+
detector.throttle(10);
73+
detector.setIntensityChangeThreshold(15);
74+
detector.setPixelChangesThreshold(0.1);
75+
}
76+
77+
78+
void loop() {
79+
if (!camera.capture()) {
80+
Serial.println(camera.getErrorMessage());
81+
delay(1000);
82+
return;
83+
}
84+
85+
// perform motion detection on resized image for fast detection
86+
// but keep original image for capture at full resolution
87+
camera.image.resizeTo<THUMB_WIDTH, THUMB_HEIGHT>(thumbnail);
88+
detector.update(thumbnail);
89+
90+
// if motion is detected, save original image as jpeg
91+
if (detector.isMotionDetected()) {
92+
Serial.println("Motion detected");
93+
94+
auto file = filesystem.writeBinary("/capture_best.jpg");
95+
auto jpeg = camera.image.jpeg().bestQuality();
96+
97+
if (jpeg.writeTo(file)) {
98+
Serial.println("Jpeg written");
99+
100+
// send to Telegram
101+
file.reopenAs("rb");
102+
103+
bool messageOk = telegramBot.sendMessageTo(CHAT_ID, "Motion detected");
104+
Serial.println(messageOk ? "Message sent OK" : "Message send error");
105+
106+
bool jpegOk = telegramBot.sendJpegTo(CHAT_ID, file);
107+
Serial.println(jpegOk ? "Jpeg sent OK" : "Jpeg send error");
108+
109+
if (!jpegOk) {
110+
Serial.print("Telegram error: ");
111+
Serial.println(telegramBot.getErrorMessage());
112+
}
113+
}
114+
else {
115+
Serial.print("Jpeg encoding error: ");
116+
Serial.println(jpeg.getErrorMessage());
117+
}
118+
}
119+
120+
// release memory
121+
camera.free();
122+
}

‎library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "git",
77
"url": "https://github.com/eloquentarduino/EloquentArduino"
88
},
9-
"version": "2.0.3",
9+
"version": "2.0.4",
1010
"authors": {
1111
"name": "Simone Salerno",
1212
"url": "https://github.com/eloquentarduino"

‎library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=EloquentArduino
2-
version=2.0.3
2+
version=2.0.4
33
author=Simone Salerno <support@eloquentarduino.com>
44
maintainer=Simone Salerno <support@eloquentarduino.com>
55
sentence=An eloquent interface to common Arduino patterns, data structures and algorithms

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /