sicherung2023-04-12
This commit is contained in:
commit
0906077ba7
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
10
.vscode/extensions.json
vendored
Normal file
10
.vscode/extensions.json
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
],
|
||||||
|
"unwantedRecommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
]
|
||||||
|
}
|
1
data/fotos.txt
Normal file
1
data/fotos.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
0
|
39
include/README
Normal file
39
include/README
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the usual convention is to give header files names that end with `.h'.
|
||||||
|
It is most portable to use only letters, digits, dashes, and underscores in
|
||||||
|
header file names, and at most one dot.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
46
lib/README
Normal file
46
lib/README
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a an own separate directory
|
||||||
|
("lib/your_library_name/[here are source files]").
|
||||||
|
|
||||||
|
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- README --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
and a contents of `src/main.c`:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
27
platformio.ini
Normal file
27
platformio.ini
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:esp32cam]
|
||||||
|
platform = espressif32
|
||||||
|
board = esp32cam
|
||||||
|
framework = arduino
|
||||||
|
board_build.filesystem = littlefs
|
||||||
|
monitor_speed = 115200
|
||||||
|
monitor_port = /dev/ttyUSB0
|
||||||
|
monitor_dtr = 0
|
||||||
|
monitor_rts = 0
|
||||||
|
monitor_filters = time
|
||||||
|
upload_port = /dev/ttyUSB0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
lib_deps =
|
||||||
|
espressif/esp32-camera @ 2.0.0
|
||||||
|
;avinabmalla/ESP32_BleSerial @ 1.0.4
|
272
src/main.cpp
Normal file
272
src/main.cpp
Normal file
|
@ -0,0 +1,272 @@
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
Project: ESP32-CAM Time lapse - save pictures on SD-Card
|
||||||
|
Author: Thomas Edlinger for www.edistechlab.com
|
||||||
|
Date: Created 07.11.2020
|
||||||
|
Version: V1.0
|
||||||
|
IDE: Arduino IDE 1.8.13
|
||||||
|
|
||||||
|
Required Board (Tools -> Board -> Boards Manager...)
|
||||||
|
- Board: esp32 by Espressif Systems V1.0.4
|
||||||
|
*/
|
||||||
|
#include <FS.h>
|
||||||
|
#include <LittleFS.h>
|
||||||
|
|
||||||
|
/* #include <BleSerial.h>
|
||||||
|
|
||||||
|
const int BUFFER_SIZE = 8192;
|
||||||
|
char msg[20] = {0};
|
||||||
|
char msgHelp[20] = {0};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BleSerial ble;
|
||||||
|
|
||||||
|
uint8_t bleReadBuffer[BUFFER_SIZE]; */
|
||||||
|
|
||||||
|
#include "esp_camera.h"
|
||||||
|
#include "SD_MMC.h"
|
||||||
|
#include "driver/rtc_io.h"
|
||||||
|
#include "soc/soc.h" // Schaltet das brownour Problem aus
|
||||||
|
#include "soc/rtc_cntl_reg.h" // Schaltet das brownour Problem aus
|
||||||
|
|
||||||
|
#define sleepTime 30e6 // Deep Sleep Zeit 10 Sekunden
|
||||||
|
uint16_t fotoNummer = 0;
|
||||||
|
|
||||||
|
int readFotos();
|
||||||
|
void saveFotoNr(int fotosnr);
|
||||||
|
bool isNumeric(const char *str);
|
||||||
|
void ClearLFCR(char *str, int len);
|
||||||
|
void ZeigeFehler();
|
||||||
|
//void readBLE();
|
||||||
|
|
||||||
|
long startTime;
|
||||||
|
|
||||||
|
void NeuStart()
|
||||||
|
{
|
||||||
|
//readBLE();
|
||||||
|
Serial.println(" Kamara wird in 10 Sekunden\nneu gestartet.");
|
||||||
|
esp_sleep_enable_timer_wakeup(3e6); // 10 Sekunden
|
||||||
|
esp_deep_sleep_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
startTime = millis();
|
||||||
|
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // Schaltet den brownour Sensor aus
|
||||||
|
Serial.begin(115200);
|
||||||
|
/* ble.begin("BleHJKTestNEU");
|
||||||
|
ble.println("Hello!");
|
||||||
|
*/
|
||||||
|
if(!LittleFS.begin(false)) {
|
||||||
|
Serial.println("Fehler beim mounten....");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Serial.printf("Fotos auf der SD-Karte = %03d \n", readFotos());
|
||||||
|
pinMode(4, OUTPUT);
|
||||||
|
rtc_gpio_hold_dis(GPIO_NUM_4);
|
||||||
|
|
||||||
|
// Pin Definition für CAMERA_MODEL_AI_THINKER aus dem Webserver Beispiel unter camera_pins.h
|
||||||
|
camera_config_t config;
|
||||||
|
config.ledc_channel = LEDC_CHANNEL_0;
|
||||||
|
config.ledc_timer = LEDC_TIMER_0;
|
||||||
|
config.pin_d0 = 5;
|
||||||
|
config.pin_d1 = 18;
|
||||||
|
config.pin_d2 = 19;
|
||||||
|
config.pin_d3 = 21;
|
||||||
|
config.pin_d4 = 36;
|
||||||
|
config.pin_d5 = 39;
|
||||||
|
config.pin_d6 = 34;
|
||||||
|
config.pin_d7 = 35;
|
||||||
|
config.pin_xclk = 0;
|
||||||
|
config.pin_pclk = 22;
|
||||||
|
config.pin_vsync = 25;
|
||||||
|
config.pin_href = 23;
|
||||||
|
config.pin_sscb_sda = 26;
|
||||||
|
config.pin_sscb_scl = 27;
|
||||||
|
config.pin_pwdn = 32;
|
||||||
|
config.pin_reset = -1;
|
||||||
|
config.xclk_freq_hz = 20000000;
|
||||||
|
config.pixel_format = PIXFORMAT_JPEG;
|
||||||
|
|
||||||
|
if(psramFound()){
|
||||||
|
#ifdef TEST
|
||||||
|
delay(1000);
|
||||||
|
#endif
|
||||||
|
config.frame_size = FRAMESIZE_SVGA; // 800 * 600
|
||||||
|
config.jpeg_quality = 12; // Bild mit hoher Qualität
|
||||||
|
config.fb_count = 2;
|
||||||
|
} else {
|
||||||
|
Serial.println("PSRam nicht gefunden.");
|
||||||
|
delay(1000);
|
||||||
|
config.frame_size = FRAMESIZE_SVGA;
|
||||||
|
config.jpeg_quality = 12;
|
||||||
|
config.fb_count = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kamera initialisieren
|
||||||
|
esp_err_t err = esp_camera_init(&config);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
Serial.printf("Kamera Initialisierung fehlgeschlagen Fehler NR: 0x%x", err);
|
||||||
|
NeuStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
sensor_t * s = esp_camera_sensor_get();
|
||||||
|
//initial sensors are flipped vertically and colors are a bit saturated
|
||||||
|
if (s->id.PID == OV3660_PID) {
|
||||||
|
s->set_vflip(s, 1);//flip it back
|
||||||
|
s->set_brightness(s, 1);//up the blightness just a bit
|
||||||
|
s->set_saturation(s, -2);//lower the saturation
|
||||||
|
}
|
||||||
|
//drop down frame size for higher initial frame rate
|
||||||
|
s->set_framesize(s, FRAMESIZE_SVGA);
|
||||||
|
s->set_vflip(s, 1);
|
||||||
|
s->set_hmirror(s, 1);
|
||||||
|
s->set_bpc(s, 1);
|
||||||
|
s->set_dcw(s,1);
|
||||||
|
s->set_gain_ctrl(s, 1);
|
||||||
|
|
||||||
|
#if defined(CAMERA_MODEL_M5STACK_WIDE)
|
||||||
|
s->set_vflip(s, 1);
|
||||||
|
s->set_hmirror(s, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Mounten der SD-Karte
|
||||||
|
if(!SD_MMC.begin()) {
|
||||||
|
Serial.println("Kann die SD-Karte nicht mounten");
|
||||||
|
saveFotoNr(0);
|
||||||
|
NeuStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t cardType = SD_MMC.cardType();
|
||||||
|
if(cardType == CARD_NONE) {
|
||||||
|
Serial.println("Keine SD-Karte eingelegt");
|
||||||
|
NeuStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
fotoNummer = readFotos();
|
||||||
|
fotoNummer += 1;
|
||||||
|
|
||||||
|
|
||||||
|
// Foto machen
|
||||||
|
camera_fb_t * fb = NULL;
|
||||||
|
fb = esp_camera_fb_get();
|
||||||
|
if (!fb) {
|
||||||
|
Serial.println("Fotografieren fehlgeschlagen!");
|
||||||
|
NeuStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Foto unter diesem Pfad speichern
|
||||||
|
|
||||||
|
char topic[30] ={0};
|
||||||
|
sprintf(topic, "/Foto%05d.jpg", fotoNummer );
|
||||||
|
String path = topic;
|
||||||
|
fs::FS &fs = SD_MMC;
|
||||||
|
|
||||||
|
File file = fs.open(path.c_str(), FILE_WRITE);
|
||||||
|
if(!file) {
|
||||||
|
Serial.println("Fehler beim File erstellen");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
file.write(fb->buf, fb->len);
|
||||||
|
saveFotoNr(fotoNummer);
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
esp_camera_fb_return(fb);
|
||||||
|
|
||||||
|
Serial.printf("Foto gespeichert: %s\n", path.c_str());
|
||||||
|
pinMode(4, OUTPUT);
|
||||||
|
digitalWrite(4, LOW); //flash LED aus
|
||||||
|
rtc_gpio_hold_en(GPIO_NUM_4);
|
||||||
|
delay(1000);
|
||||||
|
long endTime = millis();
|
||||||
|
Serial.println("Gehe in den deep-sleep mode");
|
||||||
|
long schlaf = sleepTime - (endTime -startTime);
|
||||||
|
esp_sleep_enable_timer_wakeup(schlaf);
|
||||||
|
esp_deep_sleep_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
}
|
||||||
|
|
||||||
|
int readFotos(){
|
||||||
|
int Fotos;
|
||||||
|
File k = LittleFS.open("/fotos.txt", "r");
|
||||||
|
if(!k){
|
||||||
|
//Serial.println("file open failed");
|
||||||
|
Fotos = 0;
|
||||||
|
}else{
|
||||||
|
String data = k.readString();
|
||||||
|
Fotos = data.toInt();
|
||||||
|
k.close();
|
||||||
|
}
|
||||||
|
return Fotos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveFotoNr(int fotosnr){
|
||||||
|
File k = LittleFS.open("/fotos.txt", "w");
|
||||||
|
if(!k){
|
||||||
|
Serial.println("file open failed");
|
||||||
|
}else{
|
||||||
|
k.println(fotosnr);
|
||||||
|
k.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isNumeric(const char *str)
|
||||||
|
{
|
||||||
|
while(*str != '\0')
|
||||||
|
{
|
||||||
|
if(*str < '0' || *str > '9')
|
||||||
|
return false;
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClearLFCR(char *str, int len)
|
||||||
|
{
|
||||||
|
for (unsigned int i=0; i < len; i++)
|
||||||
|
{
|
||||||
|
if (str[i] == 0x0d || str[i] == 0x0a)
|
||||||
|
{
|
||||||
|
str[i] = 0x00;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZeigeFehler()
|
||||||
|
{
|
||||||
|
for(unsigned int z = 0; z < 10; z++)
|
||||||
|
{
|
||||||
|
digitalWrite(4, HIGH);
|
||||||
|
delay(150);
|
||||||
|
digitalWrite(4, LOW);
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* void readBLE()
|
||||||
|
{
|
||||||
|
bool bleError = false;
|
||||||
|
int n = 0;
|
||||||
|
Serial.println("TEST TEST TEST");
|
||||||
|
ZeigeFehler();
|
||||||
|
ble.begin("BleHJKTestNEU");
|
||||||
|
|
||||||
|
while (n < 20){
|
||||||
|
|
||||||
|
while (ble.available()){
|
||||||
|
auto ZeichenAnzahl = ble.readBytes(bleReadBuffer, BUFFER_SIZE);
|
||||||
|
Serial.printf("Im Buffer sind %d Zeichen\n",ZeichenAnzahl);
|
||||||
|
for (unsigned int i = 0; i < ZeichenAnzahl; i++) {
|
||||||
|
msg[i] = (char)bleReadBuffer[i];
|
||||||
|
Serial.printf("Zeigen Nr. %d = 0x%02x\n", i, msg[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delay(500);
|
||||||
|
n += 1;
|
||||||
|
}
|
||||||
|
} */
|
11
test/README
Normal file
11
test/README
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
This directory is intended for PlatformIO Test Runner and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PlatformIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
Loading…
Reference in New Issue
Block a user