-
Notifications
You must be signed in to change notification settings - Fork 8
/
TeleView.ino
669 lines (639 loc) · 23.7 KB
/
TeleView.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
/*
Copyright (c) 2020 Ahmed Maklad. All right reserved.
Teleview- A telegram photo sending bot using the ESP32 CAM on Arduino IDE.
This Software is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This Software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this Software; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* To compile and upload:
* Required Installation:
* ESP32 for Arduino IDE https://dl.espressif.com/dl/package_esp32_index.json
* Required Libraries to compile:
* AutoConnect
* ArduinoJson - V5.13.5
* Adafruit SSD1306 and Dependecies such as Adaruit GFX..etc
*/
//****************************************************************//
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <WebServer.h>
#include <AutoConnect.h>
#include <ArduinoJson.h>
#include <Ticker.h>
#include <ESPmDNS.h>
#include <WiFiClient.h>
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
#include "esp_camera.h"
#include <Arduino.h>
static const char* TAG_MAIN = "MAIN";
#include "esp_log.h"
// Select camera model
//#define CAMERA_MODEL_WROVER_KIT
//#define CAMERA_MODEL_ESP_EYE
//#define CAMERA_MODEL_M5STACK_PSRAM // Board definition Boards->ESP32 Arduino->"M5Stack Timer-CAM"
// Don't use the Boards->M5Stack Arduino ->"M5Stack Timer CAM"
//#define CAMERA_MODEL_M5STACK_WIDE
//#define CAMERA_MODEL_AI_THINKER // Board definition "AI Thinker ESP32-CAM"
#define CAMERA_MODEL_TTGO_T1_CAMERA // Board definition "ESP32 WROVER Module" or "TTGO T1"
// to Have OTA Working:
// tools->Patition Schema-> Minimal SPIFFS(1.9MB with OTA/190KB SPIFFS)
//#define CAMERA_MODEL_TTGO_T1_CAMERA_162 // Board definition "ESP32 WROVER Module" or "TTGO T1"
// to Have OTA Working:
// tools->Patition Schema-> Minimal SPIFFS(1.9MB with OTA/190KB SPIFFS)
//#define CAMERA_MODEL_M5CAM // Board Difinition "AI Thinker ESP32-CAM"
////////////////////////////////////// // and set Tools-> Partiton Scheme --> Huge App (3MB No OTA/1MB SPIFF)
#include "camera_pins.h"
framesize_t maxRes=MAX_RESOULTION;
//////////////////////////////////////
String compileDate=String(__DATE__);
String compileTime=String(__TIME__);
String compileCompiler=String(__cplusplus);
int PICTURES_COUNT=0;
//////////////////////////////////////
#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
#include "esp_log.h"
static const char* TAG01 = "SETUP";
//////////////////////////////////////
#include "persist.h"
void applyConfigItem (config_item* ci);
void handle_telegram(void * param);
#include "webPages.h"
#include "motionDetect.h"
#if defined(I2C_DISPLAY_ADDR)
#include "display.h"
#endif
#include "telegram_utils.h"
#define uS_TO_S_FACTOR 1000000
/* One I day I will give up and remove this.. but not today.
#if defined(SD_CARD_ON)
#include "FSBRowser.h"
#endif
*/
const char* ntpServer = "pool.ntp.org";
long gmtOffset_sec = 0;
int daylightOffset_sec = 0;
bool bTakePhotoTick=false;
boolean bMotionDetected=false;
boolean bESPMayGoToSleep=false;
Ticker tkTimeLapse;
//int consequentChangedFrames=0;
//motionDetection
bool haveMotion = false;
// struct tm *startTM; you find it in webPages.h
esp_sleep_wakeup_cause_t print_wakeup_reason();
//****************************************************************//
void setup() {
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // disbale the burnout reset
Serial.begin(115200);
ESP_LOGV(TAG_MAIN,"SETUP START: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
ESP_LOGV(TAG_MAIN,CAMERA_NAME);
psramInit();
ESP_LOGV(TAG_MAIN,"Total heap: %d", ESP.getHeapSize());
ESP_LOGV(TAG_MAIN,"Free heap: %d", ESP.getFreeHeap());
ESP_LOGV(TAG_MAIN,"Total PSRAM: %d", ESP.getPsramSize());
ESP_LOGV(TAG_MAIN,"Free PSRAM: %d", ESP.getFreePsram());
#ifdef CAMERA_MODEL_M5STACK_PSRAM
// will hold bat output
bat_init();
led_init(CAMERA_LED_GPIO);
bmm8563_init();
#endif
delay (1000);
Serial.setDebugOutput(true);
esp_log_level_set("*", ESP_LOG_INFO);
//esp_log_level_set("*", ESP_LOG_ERROR); // set all components to ERROR level
//esp_log_level_set("wifi", ESP_LOG_WARN); // enable WARN logs from WiFi stack
//esp_log_level_set("dhcpc", ESP_LOG_INFO); // enable INFO logs from DHCP client
ESP_LOGV(TAG_MAIN,"Compile Date:%s",compileDate);
ESP_LOGV(TAG_MAIN,"Compile Time:%s",compileTime);
ESP_LOGV(TAG_MAIN,"Compile Compiler:",compileCompiler);
//Print the wakeup reason for ESP32
print_wakeup_reason();
//
//ESP CAMERA
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
config.pin_href = HREF_GPIO_NUM;
config.pin_sscb_sda = SIOD_GPIO_NUM;
config.pin_sscb_scl = SIOC_GPIO_NUM;
config.pin_pwdn = PWDN_GPIO_NUM;
config.pin_reset = RESET_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG;
//init with high specs to pre-allocate larger buffers
if(psramFound()){
maxRes=MAX_RESOULTION;
config.frame_size = FRAMESIZE_UXGA;
config.jpeg_quality = 10; //0-63 lower number means higher quality
config.fb_count = 2;
} else {
maxRes=FRAMESIZE_SVGA;
config.frame_size = FRAMESIZE_SVGA;
config.jpeg_quality = 12; //0-63 lower number means higher quality
config.fb_count = 1;
}
ESP_LOGV(TAG_MAIN,"frame_size: %s:%s",
resolutions[config.frame_size][0],
resolutions[config.frame_size][1]
);
ESP_LOGV(TAG_MAIN,"jpeg_quality: %d",config.jpeg_quality);
// camera init
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
ESP_LOGE(TAG_MAIN,"Camera init failed with error 0x%x", err);
delay(1000);
ESP.restart();
}
bCameraInitiated=true;
////////////////////////////
configItems.frameSize=config.frame_size;
keyboardJson=formulateKeyboardJson();
configItems=loadConfiguration();
applyConfigItem(&configItems);
ESP_LOGV(TAG_MAIN,"%s",printConfiguration(&configItems,""));
////////////////////////////
#if defined(I2C_DISPLAY_ADDR)
display_init();
#endif
////////////////////////////
/*
#if defined(SD_CARD_ON)
setupFSBrowser();
#endif
*/
ESP_LOGV("SETUP","Loading rootpage");
Portal.host().on("/",rootPage);
ESP_LOGV("SETUP","Loading deletePage");
Portal.host().on("/delete",deletePage);
ESP_LOGV("SETUP","Loading capturePage");
Portal.host().on("/capture",capturePage);
ESP_LOGV("SETUP","Loading capturePageJpeg");
Portal.host().on("/capture.jpg",capturePageJpeg);
ESP_LOGV("SETUP","Loading stream_handler");
Portal.host().on("/stream",stream_handler);
//Portal.host().on();
//Portal.append("/capture2","Capture2",capture2Page);
//Portal.append("/stream","Stream",stream_handler);
//
ESP_LOGV("SETUP","Loading AUX_CONFIGPAGE");
auxPageConfig.load(AUX_CONFIGPAGE);
populateResolutionsSelects(auxPageConfig);
auxPageConfig.on(onPage);
//
ESP_LOGV("SETUP","Loading AUX_CONAUX_CONFIG_EMAIL_PAGEFIGPAGE");
auxPageConfigEmail.load(AUX_CONFIG_EMAIL_PAGE);
auxPageConfigEmail.on(onPageEmail);
//
ESP_LOGV("SETUP","Loading AUX_CAPTURE");
auxPageCapture.load(AUX_CAPTURE);
auxPageCapture.on(onCapture);
//
ESP_LOGV("SETUP","Loading AUX_STREAM");
auxPageStream.load(AUX_STREAM);
auxPageStream.on(onStream);
//
//
Portal.join(auxPageCapture);
Portal.join(auxPageConfig);
Portal.join(auxPageConfigEmail);
Portal.join(auxPageStream);
////////////////////////////
acConfig.apid = configItems.deviceName;
acConfig.psk = "tv-ei-694";
acConfig.hostName=configItems.deviceName;
acConfig.autoRise=true;
acConfig.title = "TeleView";
//AUTOCONNECT_USE_PREFERENCES
acConfig.autoSave=AC_SAVECREDENTIAL_AUTO;
//acConfig.portalTimeout = 60000; // It will time out in 60 seconds
#define AC_DEBUG 1
Portal.config(acConfig);
Portal.onDetect(captivePortalStarted);
WiFi.setSleep(false);
WiFi.setHostname(configItems.deviceName.c_str());
/////////////////////////////
#if defined(I2C_DISPLAY_ADDR)
line1=String(acConfig.apid);
line2=String(acConfig.psk);
line3=String(acConfig.apip.toString());
display_Textlines(line1,line2,line3);
#endif
/////////////////////////////
if (Portal.begin()) {
ESP_LOGV(TAG_MAIN,"WiFi connected: %s " , WiFi.localIP().toString().c_str() );
//MDNS
if (!MDNS.begin(configItems.deviceName.c_str())) {
ESP_LOGE(TAG_MAIN,"Error setting up MDNS responder!");
while(1) {
delay(1000);
}
}
// Add service to MDNS-SD
// With applying AutoConnect, the MDNS service must be started after
// establishing a WiFi connection.
MDNS.addService("http", "tcp", 80);
ESP_LOGV(TAG_MAIN,"mDNS responder started");
}else{
ESP_LOGE(TAG_MAIN,"Portal not startd");
}
ESP_LOGV(TAG_MAIN,"HTTP server started");
ESP_LOGV(TAG_MAIN,"Connected SSID: %s",WiFi.SSID() );
ESP_LOGV(TAG_MAIN,"RSSI:%d",WiFi.RSSI());
//
byte mac[6];
WiFi.macAddress(mac);
ESP_LOGV(TAG_MAIN,"WiFi MAC= %x:%x:%x:%x:%x:%x",
mac[5],
mac[4],
mac[3],
mac[2],
mac[1],
mac[0]
);
//
ESP_LOGV(TAG_MAIN,"IP address: %s",WiFi.localIP().toString().c_str());
// NTP //////////////////////////////
//init and get the time
for (int i=0;i<=23;i++) {
Timezone_t tempTz = TZ [i];
//if (strcmp(tempTz.zone,configItems.timeZone.c_str())==0){
if (configItems.timeZone.equals(tempTz.zone) ){
//configItems.timeZone=tempTz.zone;
ntpServer=(char*)tempTz.ntpServer;
gmtOffset_sec=tempTz.tzoff*60*60;
break;
}
}
///////////////////////////////////
daylightOffset_sec=0;
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
#ifdef CAMERA_MODEL_M5STACK_PSRAM
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
ESP_LOGV(TAG_MAIN,"Failed to obtain time");
return;
}
_rtc_data_t timeToSet;
timeToSet.year=timeinfo.tm_year+1900;
timeToSet.month=timeinfo.tm_mon+1;
timeToSet.day=timeinfo.tm_mday;
timeToSet.hour=timeinfo.tm_hour;
timeToSet.second=timeinfo.tm_sec;
bmm8563_setTime(&timeToSet);
#endif
///////////////////////////////////
botClient.setCACert(TELEGRAM_CERTIFICATE_ROOT);
//botClient.setInsecure();
bot.updateToken(configItems.botTTelegram);
if ( !configItems.botTTelegram.equals("0123456789") ) {
ESP_LOGV(TAG_MAIN,"I am Alive :-) ");
//botClient.setCACert(TELEGRAM_CERTIFICATE_ROOT);
//botClient.setInsecure();
if(bot.getMe()){
ESP_LOGV(TAG_MAIN,"bot.getMe():TRUE");
}else{
ESP_LOGV(TAG_MAIN,"bot.getMe():FALSE");
}
//bot.sendMessage(configItems.adminChatIds, "I am Alive!!", "");
bool bSendMessageWithReplyKeyboard=bot.sendMessageWithReplyKeyboard(configItems.adminChatIds, "I am Alive :-) ", "Markdown", formulateKeyboardJson(), true);
if(bSendMessageWithReplyKeyboard){
ESP_LOGV(TAG_MAIN,"bSendMessageWithReplyKeyboard:TRUE");
}else{
ESP_LOGV(TAG_MAIN,"bSendMessageWithReplyKeyboard:FALSE");
}
if (configItems.alertALL && configItems.userChatIds.toDouble()>0){
bot.sendMessageWithReplyKeyboard(configItems.userChatIds,"I am Alive :-) ", "Markdown", formulateKeyboardJson(), true);
}
}else{
ESP_LOGV(TAG_MAIN,"Bot Token not yet set, I am not alive yet :-( ");
}
///////////////////
#if defined(FLASH_LAMP_PIN)
pinMode(FLASH_LAMP_PIN, OUTPUT);
#endif
#if defined(PIR_PIN)
// depends on which type of PIR your are using
if (PIR_PIN_ON)
pinMode(PIR_PIN, INPUT_PULLDOWN); //set default incomming signal to LOW
else
pinMode(PIR_PIN, INPUT_PULLUP); //set default incomming signal to HIGH
#endif
#if defined(BUZZER_PIN)
pinMode(BUZZER_PIN,OUTPUT);
#endif
bTelegramBotInitiated=true;
ESP_LOGV(TAG_MAIN,"SETUP END: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
}
//****************************************************************//
//********************** The LOOP ****************************//
//****************************************************************//
void loop() {
ESP_LOGV(TAG_MAIN,"START LOOP *********");
Portal.handleClient();
#if defined(PIR_PIN)
int vPIR = digitalRead(PIR_PIN);
/*
Serial.print("PIR VALUE:");
ESP_LOGV(TAG_MAIN,vPIR );
*/
if ( configItems.motDetectOn && vPIR==PIR_PIN_ON ) {
String result= alertTelegram("PIR Motion Detected.");
ESP_LOGV(TAG_MAIN,"result: %s ",result);
bMotionDetected=true;
delay(100);
} else{
bMotionDetected=false;
}
#endif
#if defined(BUZZER_PIN)
if (bMotionDetected && configItems.useBuzzer){
// Active Buzzer
ESP_LOGV(TAG_MAIN,"Buzzer ON");
digitalWrite (BUZZER_PIN, BUZZER_PIN_ON); //turn buzzer on
delay(1000);
}else{
//ESP_LOGV(TAG_MAIN,"Buzzer OFF");
digitalWrite (BUZZER_PIN, !BUZZER_PIN_ON); //turn buzzer off
}
#endif
#if defined(I2C_DISPLAY_ADDR)
line1=String(WiFi.SSID());
line2=" ";
line3=WiFi.localIP().toString();
if (displayEnabled){
display_Textlines( line1, line2 , line3 );
}else{
display.clearDisplay();
display.display();
}
#endif
//////////////////////////////////////////////
// Computer Vision Motion Detection
if (configItems.motionDetectVC ){
ESP_LOGV(TAG_MAIN,"CheckMotion before.");
haveMotion = checkMotion(haveMotion , (&configItems)->frameSize ,haveMotion );
ESP_LOGV(TAG_MAIN,"CheckMotion After.");
if (haveMotion) {
alertTelegram("CV Motion detected");
}
}
handle_telegram(NULL);
ESP_LOGV(TAG_MAIN,"END LOOP **********");
}
//****************************************************************//
void handle_telegram(void * param ){
//////////////////////////////////////////////
if (millis() > Bot_lasttime + Bot_mtbs) {
ESP_LOGV(TAG_MAIN,"bot.getUpdates() !");
int numNewMessages = bot.getUpdates((bot.last_message_received) + 1);
while(numNewMessages) {
ESP_LOGV(TAG_MAIN,"got response#1");
handleNewMessages(numNewMessages);
ESP_LOGV(TAG_MAIN,"got response#2");
numNewMessages = bot.getUpdates((bot.last_message_received) + 1);
ESP_LOGV(TAG_MAIN,"got response#3");
}
if (bTakePhotoTick){
alertTelegram("time-lapse tick!");
bTakePhotoTick=false;
}
/////////////////////////////////////////////
#ifdef CAMERA_MODEL_M5STACK_PSRAM
rtc_date_t date;
bmm8563_getTime(&date);
ESP_LOGV(TAG_MAIN,"Time: %d/%d/%d %02d:%02d:%-2d", date.year, date.month, date.day, date.hour, date.minute, date.second);
ESP_LOGV(TAG_MAIN,"volt: %d mv", bat_get_voltage());
ESP_LOGV(TAG_MAIN,"ADC: %d mv", bat_get_adc_raw());
#endif
/////////////////////////////////////////////
#if defined(PIR_PIN)
if (configItems.useDeepSleep && configItems.motDetectOn) {
bMotionDetected=true;
esp_sleep_enable_ext0_wakeup((gpio_num_t)PIR_PIN,PIR_PIN_ON); //1 = High, 0 = Low
bESPMayGoToSleep=true;
//alertTelegram("ESP is going to sleep till PIR is active.",true );
}
#endif
/////////////////////////////////////////////
if (configItems.useDeepSleep && configItems.lapseTime >0){
bTakePhotoTick=true;
#ifdef CAMERA_MODEL_M5STACK_PSRAM
// esp_deep_sleep((uint64_t) configItems.lapseTime*60*uS_TO_S_FACTOR);
// X sec later will wake up
ESP_LOGV(TAG_MAIN,"bmm8563_setTimerIRQ");
bmm8563_setTimerIRQ(configItems.lapseTime*60);
#endif
ESP_LOGV(TAG_MAIN,"esp_sleep_enable_timer_wakeup");
//esp_deep_sleep((uint64_t) configItems.lapseTime*60*uS_TO_S_FACTOR);
esp_sleep_enable_timer_wakeup( (uint64_t) configItems.lapseTime*60*uS_TO_S_FACTOR);
bESPMayGoToSleep=true;
//alertTelegram("Setup ESP32 to sleep for every " + String(configItems.lapseTime) + " minutes",true);
}
/////////////////////////////////////////////
if (configItems.useDeepSleep && bESPMayGoToSleep){
Serial.flush();
String extraMessage;
if (bMotionDetected){
extraMessage="till PIR is active.";
}
if (bTakePhotoTick){
extraMessage="for the next " + String(configItems.lapseTime) + " minutes.";
}
alertTelegram("ESP is going to sleep "+extraMessage,false);
#ifdef CAMERA_MODEL_M5STACK_PSRAM
// disable bat output, will wake up after 5 sec, Sleep current is 1~2μA
ESP_LOGV(TAG_MAIN,"bat_disable_output");
bat_disable_output();
#endif
ESP_LOGV(TAG_MAIN,"esp_deep_sleep_start");
esp_wifi_stop();
esp_deep_sleep_start();
}
/////////////////////////////////////////////
Bot_lasttime = millis();
}
}
////////////////////////////////////////////////////////////////////////////
#ifdef CAMERA_MODEL_M5STACK_PSRAM
void led_breathe_test() {
for (int16_t i = 0; i < 1024; i++) {
led_brightness(i);
vTaskDelay(pdMS_TO_TICKS(1));
}
for (int16_t i = 1023; i >= 0; i--) {
led_brightness(i);
vTaskDelay(pdMS_TO_TICKS(1));
}
}
#endif
////////////////////////////////////////////////////////////////////////////
esp_sleep_wakeup_cause_t print_wakeup_reason(){
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();
switch(wakeup_reason)
{
case ESP_SLEEP_WAKEUP_EXT0 : ESP_LOGV(TAG_MAIN,"Wakeup caused by external signal using RTC_IO"); break;
case ESP_SLEEP_WAKEUP_EXT1 : ESP_LOGV(TAG_MAIN,"Wakeup caused by external signal using RTC_CNTL"); break;
case ESP_SLEEP_WAKEUP_TIMER : ESP_LOGV(TAG_MAIN,"Wakeup caused by timer"); break;
case ESP_SLEEP_WAKEUP_TOUCHPAD : ESP_LOGV(TAG_MAIN,"Wakeup caused by touchpad"); break;
case ESP_SLEEP_WAKEUP_ULP : ESP_LOGV(TAG_MAIN,"Wakeup caused by ULP program"); break;
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
}
return (wakeup_reason);
}
////////////////////////////////////////////////////////////////////////////
void tick(){
bTakePhotoTick=true;
}
////////////////////////////////////////////////////////////////////////////
void applyConfigItem (config_item* ci) {
sensor_t * s = esp_camera_sensor_get();
//
s->set_pixformat(s, PIXFORMAT_JPEG );
s->set_framesize(s, ci->frameSize); // UXGA|SXGA|XGA|SVGA|VGA|CIF|QVGA|HQVGA|QQVGA
s->set_hmirror(s, ci->hMirror);
s->set_vflip(s, ci->vFlip);
//
//s->set_wb_mode(s,ci->set_whitebal);
s->set_brightness(s,ci->set_brightness);
s->set_contrast(s,ci->set_contrast);
s->set_saturation(s,ci->set_saturation);
s->set_quality(s,ci->jpegQuality);
//
ESP_LOGV(TAG_MAIN,"* > s->status.scale:%d",s->status.scale);
ESP_LOGV(TAG_MAIN,"* > s->status.binning:%d",s->status.binning);
ESP_LOGV(TAG_MAIN,"* > s->status.quality:%d",s->status.quality); //0 - 63
ESP_LOGV(TAG_MAIN,"* > s->status.brightness:%d",s->status.brightness); //-2 - 2
ESP_LOGV(TAG_MAIN,"* > s->status.contrast:%d",s->status.contrast); //-2 - 2
ESP_LOGV(TAG_MAIN,"* > s->status.saturation:%d",s->status.saturation); //-2 - 2
ESP_LOGV(TAG_MAIN,"* > s->status.sharpness:%d",s->status.sharpness); //-2 - 2
ESP_LOGV(TAG_MAIN,"* > s->status.denoise:%d",s->status.denoise);
ESP_LOGV(TAG_MAIN,"* > s->status.special_effect:%d",s->status.special_effect); //0 - 6
ESP_LOGV(TAG_MAIN,"* > s->status.wb_mode:%d",s->status.wb_mode); //0 - 4
ESP_LOGV(TAG_MAIN,"* > s->status.awb:%d",s->status.awb);
ESP_LOGV(TAG_MAIN,"* > s->status.awb_gain:%d",s->status.awb_gain);
ESP_LOGV(TAG_MAIN,"* > s->status.aec:%d",s->status.aec);
ESP_LOGV(TAG_MAIN,"* > s->status.aec2:%d",s->status.aec2);
ESP_LOGV(TAG_MAIN,"* > s->status.ae_level:%d",s->status.ae_level); //-2 - 2
ESP_LOGV(TAG_MAIN,"* > s->status.aec_value:%d",s->status.aec_value); //0 - 1200
ESP_LOGV(TAG_MAIN,"* > s->status.agc:%d",s->status.agc);
ESP_LOGV(TAG_MAIN,"* > s->status.agc_gain:%d",s->status.agc_gain); //0 - 30
ESP_LOGV(TAG_MAIN,"* > s->status.gainceiling:%d",s->status.gainceiling); //0 - 6
ESP_LOGV(TAG_MAIN,"* > s->status.bpc:%d",s->status.bpc);
ESP_LOGV(TAG_MAIN,"* > s->status.wpc:%d",s->status.wpc);
ESP_LOGV(TAG_MAIN,"* > s->status.raw_gma:%d",s->status.raw_gma);
ESP_LOGV(TAG_MAIN,"* > s->status.lenc:%d",s->status.lenc);
ESP_LOGV(TAG_MAIN,"* > s->status.hmirror:%d",s->status.hmirror);
ESP_LOGV(TAG_MAIN,"* > s->status.vflip:%d",s->status.vflip);
ESP_LOGV(TAG_MAIN,"* > s->status.dcw:%d",s->status.dcw);
ESP_LOGV(TAG_MAIN,"* > s->status.colorbar:%d",s->status.colorbar);
delay(500);
//*/
// non configurable params:
/*
set_special_effect()
0 – No Effect
1 – Negative
2 – Grayscale
3 – Red Tint
4 – Green Tint
5 – Blue Tint
6 – Sepia
set_wb_mode()
0 – Auto
1 – Sunny
2 – Cloudy
3 – Office
4 – Home
https://github.com/espressif/esp32-camera/blob/ec14f1d6f718571d8a7d2e537e03cebcc05e0ac8/driver/include/sensor.h
typedef struct {
framesize_t framesize;//0 - 10
bool scale;
bool binning;
uint8_t quality;//0 - 63
int8_t brightness;//-2 - 2
int8_t contrast;//-2 - 2
int8_t saturation;//-2 - 2
int8_t sharpness;//-2 - 2
uint8_t denoise;
uint8_t special_effect;//0 - 6
uint8_t wb_mode;//0 - 4
uint8_t awb;
uint8_t awb_gain;
uint8_t aec;
uint8_t aec2;
int8_t ae_level;//-2 - 2
uint16_t aec_value;//0 - 1200
uint8_t agc;
uint8_t agc_gain;//0 - 30
uint8_t gainceiling;//0 - 6
uint8_t bpc;
uint8_t wpc;
uint8_t raw_gma;
uint8_t lenc;
uint8_t hmirror;
uint8_t vflip;
uint8_t dcw;
uint8_t colorbar;
} camera_status_t;
*/
//s->set_gain_ctrl(s, 0); // auto gain off (1 or 0)
//s->set_exposure_ctrl(s, 0); // auto exposure off (1 or 0)
//s->set_agc_gain(s, 0); // set gain manually (0 - 30)
//s->set_aec_value(s, 600); // set exposure manually (0-1200)
// s->set_brightness(s, 0); // (-2 to 2) - set brightness
// s->set_awb_gain(s, 0); // Auto White Balance?
// s->set_lenc(s, 0); // lens correction? (1 or 0)
// s->set_raw_gma(s, 1); // (1 or 0)?
// s->set_quality(s, 10); // (0 - 63)
// s->set_whitebal(s, 1); // white balance
// s->set_wb_mode(s, 1); // white balance mode (0 to 4)
// s->set_aec2(s, 0); // automatic exposure sensor? (0 or 1)
// s->set_aec_value(s, 0); // automatic exposure correction? (0-1200)
// s->set_saturation(s, 0); // (-2 to 2)
// s->set_hmirror(s, 0); // (0 or 1) flip horizontally
// s->set_gainceiling(s, GAINCEILING_32X); // Image gain (GAINCEILING_x2, x4, x8, x16, x32, x64 or x128)
// s->set_contrast(s, 0); // (-2 to 2)
// s->set_sharpness(s, 0); // (-2 to 2)
// s->set_colorbar(s, 0); // (0 or 1) - testcard
// s->set_special_effect(s, 2); // 0 – No Effect,1 – Negative,2 – Grayscale,3 – Red Tint,4 – Green Tint,5 – Blue Tint,6 – Sepia
// s->set_ae_level(s, 0); // auto exposure levels (-2 to 2)
// s->set_bpc(s, 0); // black pixel correction
// s->set_wpc(s, 0); // white pixel correction
// s->set_dcw(s, 1); // downsize enable? (1 or 0)?
//
tkTimeLapse.detach();
if (ci->lapseTime >0){
tkTimeLapse.attach( ci->lapseTime*60 , tick );
}
#if defined(I2C_DISPLAY_ADDR)
if (ci->screenFlip){
display.setRotation(2);
}else{
display.setRotation(0);
}
displayEnabled=ci->screenOn;
#endif
}