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 bd8f897

Browse files
Telegram Bot text+jpeg send + camera motion detection telegram example
1 parent 77534e6 commit bd8f897

File tree

18 files changed

+1563
-471
lines changed

18 files changed

+1563
-471
lines changed

‎examples/CameraMotionDetection/CameraCaptureExample/CameraCaptureExample.ino

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,10 @@ void setup() {
3535
// in the case of Esp32 camera, highFreq clock = 20 MHz instead of 10 MHz
3636
camera.setHighFreq();
3737

38-
if (!camera.begin()) {
39-
while (true) {
40-
Serial.println(camera.getErrorMessage());
41-
delay(1000);
42-
}
43-
}
44-
else {
45-
Serial.println("Camera init OK");
46-
}
38+
if (!camera.begin())
39+
eloquent::abort(Serial, "Camera init error");
40+
41+
Serial.println("Camera init OK");
4742
}
4843

4944
void loop() {

‎examples/CameraMotionDetection/CameraMotionCaptureExample/CameraMotionCaptureExample.ino

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,10 @@ void setup() {
4646
// turn on high freq for fast streaming speed
4747
camera.setHighFreq();
4848

49-
if (!camera.begin()) {
50-
while (true) {
51-
Serial.println(camera.getErrorMessage());
52-
delay(1000);
53-
}
54-
}
55-
else {
56-
Serial.println("Camera init OK");
57-
}
49+
if (!camera.begin())
50+
eloquent::abort(Serial, "Camera init error");
51+
52+
Serial.println("Camera init OK");
5853

5954
detector.throttle(10);
6055
detector.setIntensityChangeThreshold(15);
@@ -87,7 +82,7 @@ void loop() {
8782
Serial.println(" micros to encode");
8883
}
8984
else {
90-
Serial.print("Jpeg error: ");
85+
Serial.print("Jpeg encoding error: ");
9186
Serial.println(jpeg.getErrorMessage());
9287
}
9388
}

‎examples/CameraMotionDetection/CameraMotionDetectionExample/CameraMotionDetectionExample.ino

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,10 @@ void setup() {
4242
// turn on high freq for fast streaming speed
4343
camera.setHighFreq();
4444

45-
if (!camera.begin()) {
46-
while (true) {
47-
Serial.println(camera.getErrorMessage());
48-
delay(1000);
49-
}
50-
}
51-
else {
52-
Serial.println("Camera init OK");
53-
}
45+
if (!camera.begin())
46+
eloquent::abort(Serial, "Camera init error");
47+
48+
Serial.println("Camera init OK");
5449

5550
// wait for at least 10 frames to be processed before starting to detect
5651
// motion (false triggers at start)
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+
#define TELEGRAM_TOKEN "xxxxxxxxxx:yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
6+
#define CHAT_ID "0123456789"
7+
#define WIFI_SSID "SSID"
8+
#define WIFI_PASSWORD "PASSWORD"
9+
10+
#include <WiFi.h>
11+
#include <eloquent.h>
12+
#include <eloquent/vision/image/gray/custom.h>
13+
#include <eloquent/vision/motion/naive.h>
14+
#include <eloquent/fs/spiffs.h>
15+
#include <eloquent/networking/wifi.h>
16+
#include <eloquent/apps/telegram/bot/wifi.h>
17+
18+
19+
// uncomment based on your camera and resolution
20+
21+
//#include "eloquent/vision/camera/ov767x/gray/vga.h"
22+
//#include "eloquent/vision/camera/ov767x/gray/qvga.h"
23+
//#include "eloquent/vision/camera/ov767x/gray/qqvga.h"
24+
//#include "eloquent/vision/camera/esp32/aithinker/gray/vga.h"
25+
//#include "eloquent/vision/camera/esp32/aithinker/gray/qvga.h"
26+
//#include "eloquent/vision/camera/esp32/aithinker/gray/qqvga.h"
27+
//#include "eloquent/vision/camera/esp32/wrover/gray/vga.h"
28+
//#include "eloquent/vision/camera/esp32/wrover/gray/qvga.h"
29+
//#include "eloquent/vision/camera/esp32/wrover/gray/qqvga.h"
30+
//#include "eloquent/vision/camera/esp32/eye/gray/vga.h"
31+
//#include "eloquent/vision/camera/esp32/eye/gray/qvga.h"
32+
//#include "eloquent/vision/camera/esp32/eye/gray/qqvga.h"
33+
//#include "eloquent/vision/camera/esp32/m5/gray/vga.h"
34+
//#include "eloquent/vision/camera/esp32/m5/gray/qvga.h"
35+
//#include "eloquent/vision/camera/esp32/m5/gray/qqvga.h"
36+
//#include "eloquent/vision/camera/esp32/m5wide/gray/vga.h"
37+
//#include "eloquent/vision/camera/esp32/m5wide/gray/qvga.h"
38+
//#include "eloquent/vision/camera/esp32/m5wide/gray/qqvga.h"
39+
40+
41+
#define THUMB_WIDTH 32
42+
#define THUMB_HEIGHT 24
43+
44+
// allocate memory to store the thumbnail into a new image
45+
Eloquent::Vision::Image::Gray::CustomWithBuffer<THUMB_WIDTH, THUMB_HEIGHT> thumbnail;
46+
Eloquent::Vision::Motion::Naive<THUMB_WIDTH, THUMB_HEIGHT> detector;
47+
48+
49+
void setup() {
50+
delay(4000);
51+
Serial.begin(115200);
52+
filesystem.begin(true);
53+
54+
// turn on high freq for fast streaming speed
55+
camera.setHighFreq();
56+
57+
if (!camera.begin())
58+
eloquent::abort(Serial, "Camera init error");
59+
60+
if (!wifi.connectTo(WIFI_SSID, WIFI_PASSWORD))
61+
eloquent::abort(Serial, "Cannot connect to WiFi");
62+
63+
if (!telegramBot.connect()) {
64+
eloquent::abort(Serial, "Cannot connect to Telegram API");
65+
}
66+
67+
Serial.println("Camera init OK");
68+
Serial.println("WiFi connected OK");
69+
Serial.println("Telegram API connected OK");
70+
71+
detector.throttle(10);
72+
detector.setIntensityChangeThreshold(15);
73+
detector.setPixelChangesThreshold(0.1);
74+
}
75+
76+
77+
void loop() {
78+
if (!camera.capture()) {
79+
Serial.println(camera.getErrorMessage());
80+
delay(1000);
81+
return;
82+
}
83+
84+
// perform motion detection on resized image for fast detection
85+
// but keep original image for capture at full resolution
86+
camera.image.resizeTo<THUMB_WIDTH, THUMB_HEIGHT>(thumbnail);
87+
detector.update(thumbnail);
88+
89+
// if motion is detected, save original image as jpeg
90+
if (detector.isMotionDetected()) {
91+
auto file = filesystem.writeBinary("/capture_best.jpg");
92+
auto jpeg = camera.image.jpeg().bestQuality();
93+
94+
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");
100+
101+
// send to Telegram
102+
file.reopenAs("rb");
103+
bool messageOk = telegramBot.sendMessageTo(CHAT_ID, "Motion detected");
104+
bool jpegOk = telegramBot.sendJpegTo(CHAT_ID, file);
105+
106+
Serial.println(messageOk ? "Message sent OK" : "Message send error");
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+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#define TELEGRAM_TOKEN "xxxxxxxxxx:yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
2+
#define CHAT_ID "0123456789"
3+
#define WIFI_SSID "SSID"
4+
#define WIFI_PASSWORD "PASSWORD"
5+
6+
#include <WiFi.h>
7+
#include <eloquent.h>
8+
#include <eloquent/fs/spiffs.h>
9+
#include <eloquent/networking/wifi.h>
10+
#include <eloquent/apps/telegram/bot/wifi.h>
11+
12+
13+
void setup() {
14+
Serial.begin(115200);
15+
filesystem.begin(true);
16+
delay(2000);
17+
18+
// list files on filesystem
19+
filesystem.listTo(Serial);
20+
wifi.connectTo(WIFI_SSID, WIFI_PASSWORD);
21+
22+
Serial.println("Connected to WiFi. Attempting to connect to Telegram API...");
23+
24+
if (!telegramBot.connect()) {
25+
eloquent::abort(Serial, "Cannot connect to Telegram API");
26+
}
27+
28+
Serial.println("Connected!");
29+
Serial.println("Type a jpeg filename to send to Telegram Bot");
30+
}
31+
32+
void loop() {
33+
if (Serial.available()) {
34+
String filename = Serial.readStringUntil('\n');
35+
36+
Serial.print("Sending file: ");
37+
Serial.println(filename);
38+
39+
auto jpeg = filesystem.readBinary(filename);
40+
bool jpegStatus = telegramBot.sendJpegTo(CHAT_ID, jpeg);
41+
42+
Serial.println(jpegStatus ? "Jpeg sent" : "Jpeg error");
43+
}
44+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#define TELEGRAM_TOKEN "xxxxxxxxxx:yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
2+
#define CHAT_ID "0123456789"
3+
#define WIFI_SSID "SSID"
4+
#define WIFI_PASSWORD "PASSWORD"
5+
6+
#include <WiFi.h>
7+
#include <eloquent.h>
8+
#include <eloquent/networking/wifi.h>
9+
#include <eloquent/apps/telegram/bot/wifi.h>
10+
11+
12+
void setup() {
13+
Serial.begin(115200);
14+
delay(2000);
15+
16+
wifi.connectTo(WIFI_SSID, WIFI_PASSWORD);
17+
Serial.println("Connected to WiFi. Attempting to connect to Telegram API...");
18+
19+
if (!telegramBot.connect()) {
20+
eloquent::abort(Serial, "Cannot connect to Telegram API");
21+
}
22+
23+
Serial.println("Connected!");
24+
Serial.println("Type a message to send to Telegram Bot");
25+
}
26+
27+
void loop() {
28+
if (Serial.available()) {
29+
String message = Serial.readStringUntil('\n');
30+
31+
Serial.print("Sending message: ");
32+
Serial.println(message);
33+
34+
bool messageStatus = telegramBot.sendMessageTo(CHAT_ID, message);
35+
36+
Serial.println(messageStatus ? "Message sent" : "Message error");
37+
}
38+
}

‎src/eloquent/apps/telegram/BaseTelegramBot.h

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
(0)

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