├── data └── www │ ├── favicon.ico │ ├── src │ └── logo.jpg │ ├── css │ └── main.css │ ├── configupdrequest.htm │ ├── info.htm │ ├── index.htm │ ├── wiki.htm │ ├── setup.htm │ └── camsetup.htm ├── assets ├── readme_first_file_upload │ ├── 01.png │ ├── 02.png │ ├── 03.png │ ├── 04.png │ ├── 05.png │ ├── 06.png │ └── README_First_file_upload.md └── readme_first_wifi_setup │ ├── 01.jpg │ ├── 02.jpg │ ├── 03.jpg │ ├── 04.jpg │ ├── 05.jpg │ ├── 06.png │ ├── 07.png │ ├── 08.png │ ├── 09.png │ ├── 10.png │ ├── 11.png │ └── README_First_wifi_setup.md ├── src ├── setup.h ├── cam.h ├── domoticz.h ├── WebServer.h ├── Main.h ├── _ESP_Board_Settings.h ├── setup.cpp ├── domoticz.cpp ├── Main.cpp ├── cam.cpp └── WebServer.cpp ├── ESP32-Doorbell.code-workspace ├── platformio.ini ├── README.md ├── .gitignore └── LICENSE /data/www/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/data/www/favicon.ico -------------------------------------------------------------------------------- /data/www/src/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/data/www/src/logo.jpg -------------------------------------------------------------------------------- /assets/readme_first_file_upload/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_file_upload/01.png -------------------------------------------------------------------------------- /assets/readme_first_file_upload/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_file_upload/02.png -------------------------------------------------------------------------------- /assets/readme_first_file_upload/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_file_upload/03.png -------------------------------------------------------------------------------- /assets/readme_first_file_upload/04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_file_upload/04.png -------------------------------------------------------------------------------- /assets/readme_first_file_upload/05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_file_upload/05.png -------------------------------------------------------------------------------- /assets/readme_first_file_upload/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_file_upload/06.png -------------------------------------------------------------------------------- /assets/readme_first_wifi_setup/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_wifi_setup/01.jpg -------------------------------------------------------------------------------- /assets/readme_first_wifi_setup/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_wifi_setup/02.jpg -------------------------------------------------------------------------------- /assets/readme_first_wifi_setup/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_wifi_setup/03.jpg -------------------------------------------------------------------------------- /assets/readme_first_wifi_setup/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_wifi_setup/04.jpg -------------------------------------------------------------------------------- /assets/readme_first_wifi_setup/05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_wifi_setup/05.jpg -------------------------------------------------------------------------------- /assets/readme_first_wifi_setup/06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_wifi_setup/06.png -------------------------------------------------------------------------------- /assets/readme_first_wifi_setup/07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_wifi_setup/07.png -------------------------------------------------------------------------------- /assets/readme_first_wifi_setup/08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_wifi_setup/08.png -------------------------------------------------------------------------------- /assets/readme_first_wifi_setup/09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_wifi_setup/09.png -------------------------------------------------------------------------------- /assets/readme_first_wifi_setup/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_wifi_setup/10.png -------------------------------------------------------------------------------- /assets/readme_first_wifi_setup/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hoeby/ESP32-Doorbell/HEAD/assets/readme_first_wifi_setup/11.png -------------------------------------------------------------------------------- /src/setup.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool Restore_ESPConfig_from_SPIFFS(); 4 | void Save_NewESPConfig_to_SPIFFS(AsyncWebServerRequest *request); 5 | 6 | // Define public used funcs 7 | -------------------------------------------------------------------------------- /src/cam.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Define public used funcs 4 | void initcamera(); 5 | void sendJpg(AsyncWebServerRequest *request); 6 | void streamJpg(AsyncWebServerRequest *request); 7 | bool Restore_CamSettings_from_SPIFFS(); 8 | void Save_NewCAMConfig_to_SPIFFS(AsyncWebServerRequest *request); 9 | bool Set_Cam_Settings_from_JSON(char *JSONCamSetting); 10 | char *GetCurrentCamSettings(); 11 | -------------------------------------------------------------------------------- /src/domoticz.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void Button_Check(); 4 | void Button_Pressed(const char* State); 5 | void LedToggle(); 6 | void SetLedtoDefault(bool warn); 7 | 8 | bool Domoticz_JSON_Switch(const char* State); 9 | bool Domoticz_MQTT_Switch(const char* State); 10 | 11 | void Mqtt_begin(); 12 | bool Mqtt_Connect(); 13 | bool Mqtt_Loop(); 14 | void Mqtt_messageReceived(String &topic, String &payload); 15 | 16 | String process_messageReceived(String payload); -------------------------------------------------------------------------------- /ESP32-Doorbell.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | } 6 | ], 7 | "settings": { 8 | "[html]": { 9 | "editor.defaultFormatter": "vscode.html-language-features" 10 | }, 11 | "files.watcherExclude": { 12 | "**/.pio/**": true 13 | }, 14 | "[cpp]": { 15 | "editor.defaultFormatter": "ms-vscode.cpptools" 16 | }, 17 | "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 0, SortIncludes: false}", 18 | "editor.tabSize": 3, 19 | "files.trimFinalNewlines": true, 20 | "files.trimTrailingWhitespace": true, 21 | } 22 | } -------------------------------------------------------------------------------- /data/www/css/main.css: -------------------------------------------------------------------------------- 1 | a{ 2 | font-family: verdana, sans-serif; 3 | padding:0px; 4 | text-decoration:none; 5 | color:#000000; 6 | font-weight: normal; 7 | } 8 | 9 | p { 10 | padding:0px; 11 | margin:0px; 12 | } 13 | 14 | .hrline { 15 | border: none; 16 | height: 15px; 17 | background-color: #408BDC;; 18 | } 19 | 20 | .box{ 21 | background-color: white; 22 | position: absolute; 23 | height: 125px; 24 | top: 15px; 25 | width: 100%; 26 | z-index: -1; 27 | } 28 | 29 | img 30 | { 31 | border: none 0px; 32 | } 33 | 34 | html, body { 35 | margin:0px; 36 | left:0%; 37 | padding:0; 38 | background-color:rgb(232, 237, 241); 39 | z-index:0; 40 | position:relative; 41 | font-family: verdana, sans-serif; 42 | font-size: 12px; 43 | } 44 | 45 | .title { 46 | position: absolute; 47 | top: 60px; 48 | left: 194px; 49 | } 50 | 51 | .scrollable { 52 | font-family: "Lucida Console", Monaco, monospace; 53 | height: 60%; /* or any value */ 54 | width: 98%; /* or any value */ 55 | padding: 5px; 56 | overflow-y: auto; 57 | white-space: nowrap; 58 | background-color:rgb(206, 215, 223); 59 | } 60 | 61 | .iframe { 62 | height:100%; 63 | width:100%; 64 | border:thin; 65 | } 66 | 67 | .inline { 68 | display: inline 69 | } -------------------------------------------------------------------------------- /platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [platformio] 12 | ## Have one active to only build for the single ESP 13 | ## Comment them all and all ESP bins will be build. 14 | default_envs = ESP_4096 15 | 16 | [common] 17 | 18 | 19 | [env] 20 | platform = espressif32 21 | framework = arduino 22 | board = esp32dev 23 | board_build.mcu = esp32 24 | board_build.f_cpu = 240000000L 25 | #board_build.partitions = default.csv 26 | #board_build.partitions = min_spiffs.csv 27 | upload_speed = 460800 28 | monitor_speed = 115200 29 | extra_scripts = 30 | buildscript_versioning.py 31 | 32 | [common_env_data] 33 | build_flags = 34 | -D VERSION=\"v2.0.0\" 35 | -D CAM_LOGSIZE=15000 # max size of SPIFFS cam.log & camprev.log 36 | -D CORE_DEBUG_LEVEL=5 # Set between 0-5 for console messages (none/error/warning/Info/Verbose/Debug) 37 | 38 | lib_deps_builtin = 39 | lib_deps_external = 40 | me-no-dev/AsyncTCP@^1.1.1 41 | me-no-dev/ESP Async WebServer@^1.2.3 42 | alanswx/ESPAsyncWiFiManager@^0.22.0 43 | luc-github/ESP32SSDP@^1.1.1 44 | bblanchon/ArduinoJson@^6.16.1 45 | 256dpi/mqtt@^2.4.7 46 | https://github.com/Lightwell-bg/ssdpAWS 47 | 48 | [env:ESP_4096] 49 | board = esp32dev 50 | lib_deps = 51 | ${common_env_data.lib_deps_builtin} 52 | ${common_env_data.lib_deps_external} 53 | build_flags= 54 | ${common_env_data.build_flags} 55 | -------------------------------------------------------------------------------- /assets/readme_first_file_upload/README_First_file_upload.md: -------------------------------------------------------------------------------- 1 | # ESPCAM V2 2 | 3 | # First time files upload 4 | 5 | This instruction is based on using a FTDI device, to upload files to a ESP-32-CAM. The ESP-EYE is connected with a micro usb connector, this doesn't need the FTDI device. 6 | We don't get in details how to get the FTDI working on you PC, there is enough information online about drivers and how to. 7 | 8 | Prerequisite for this tutorial or else use the available bin files and flash them using your prefered method: 9 | - Install Visual Studio Code: https://code.visualstudio.com/download 10 | - Install PlatformIO IDE Extension: https://platformio.org/install/ide?install=vscode 11 | - Install Git: https://git-scm.com/downloads 12 | 13 | 1). Download the files from github and place them in a folder on you local machine 14 | 15 | 2). Connect the ESP-32-CAM to the FTDI 16 | 17 | 18 | 19 | 3). First build the files which are needed for an upload. 20 | - Open program "Visual Studio Code". 21 | - Open "File" and select "Open Folder". 22 | - Select the folder where the files are extracted which downloaded from github. 23 | 24 | 25 | 26 | 4). Go to the "platformIO" tab in the left column. 27 | Open the menu and select "Build" 28 | The firmware.bin file will be build. Check that the build finishes with a "success" 29 | 30 | 31 | 32 | 5). Connect the ESP32 to your PC and click on "Upload" 33 | 34 | 35 | 36 | 6). After a SUCCESS upload, click on "Upload Filesystem Image" 37 | 38 | 39 | 40 | You are finished uploaden the files to the ESP-32-CAM or ESP-EYE. 41 | 42 | Go to the next step: First time wifi setup 43 | -------------------------------------------------------------------------------- /src/WebServer.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // pio run -t uploadfs 4 | // will upload all files of /data into SPIFFS 5 | 6 | String TranslateTemplateVars(const String& var); 7 | void WebServerInit(AsyncWebServer * server); 8 | 9 | void ESPShowPagewithTemplate(AsyncWebServerRequest *request); 10 | 11 | bool _webAuth(AsyncWebServerRequest *request); 12 | void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len); 13 | void Web_messageReceived(AsyncWebServerRequest *request); 14 | void ESPSaveSettings(AsyncWebServerRequest *request); 15 | void ApplyCamSettings(AsyncWebServerRequest *request); 16 | 17 | void LogClean(AsyncWebServerRequest *request); 18 | void LogDump(AsyncWebServerRequest *request); 19 | void ConfigDump(AsyncWebServerRequest *request); 20 | void ConfigCamDump(AsyncWebServerRequest *request); 21 | void ConfigCamCurrent(AsyncWebServerRequest *request); 22 | 23 | void ConfigFileUploads(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final); 24 | 25 | void WrongPage(AsyncWebServerRequest *request); 26 | 27 | /* 28 | #define ARDUHAL_LOG_LEVEL_NONE (0) 29 | #define ARDUHAL_LOG_LEVEL_ERROR (1) 30 | #define ARDUHAL_LOG_LEVEL_WARN (2) 31 | #define ARDUHAL_LOG_LEVEL_INFO (3) 32 | #define ARDUHAL_LOG_LEVEL_DEBUG (4) 33 | #define ARDUHAL_LOG_LEVEL_VERBOSE (5) 34 | */ 35 | 36 | void AddLogMessage(String msg, String Module, String Function, String Severity, int Line); 37 | #define AddLogMessageE( message ) AddLogMessage(message, __FILE__, __FUNCTION__, "E", __LINE__) 38 | #define AddLogMessageW( message ) AddLogMessage(message, __FILE__, __FUNCTION__, "W", __LINE__) 39 | #define AddLogMessageI( message ) AddLogMessage(message, __FILE__, __FUNCTION__, "I", __LINE__) 40 | #define AddLogMessageD( message ) AddLogMessage(message, __FILE__, __FUNCTION__, "D", __LINE__) 41 | #define AddLogMessageV( message ) AddLogMessage(message, __FILE__, __FUNCTION__, "V", __LINE__) 42 | 43 | // Define public used funcs 44 | void SendNextLogMessage(); 45 | String urlDecode(String input); 46 | -------------------------------------------------------------------------------- /assets/readme_first_wifi_setup/README_First_wifi_setup.md: -------------------------------------------------------------------------------- 1 | # ESPCAM V2 2 | 3 | # First time wifi setup 4 | When you have finished the initial upload to your esp-device, you restart it in normal operation mode. 5 | The first time the ESP is started, it will go into Wifi AP mode, so take your PC/smartphone to scan the wifi ssid's. In this example we have taken a smartphone. 6 | 7 | 1). Open the wifi menu on your device and search for "ESP Doorbell" and select it. 8 | 9 | 10 | 11 | 2). Fill in the password. This is "espadmin" and connect. 12 | 13 | 14 | 15 | 3). When connected to the "ESP Doorbell" AP, you should get a prompt to “Wifi requires login”, click that to open a webbrowser. In case you don’t get a prompt you open de webbrowser and go to http://192.168.4.1. 16 | The wifi-manager will appear. Select "Configure WiFi", to use scan for a visible ssid. When your ssid is invisible, use the "Configure Wifi (No Scan)" 17 | 18 | 19 | 20 | 4). Select the ssid to which the "ESP Doorbell" needs to connect. And fill in the password for this ssid, finish with "save" 21 | 22 | 23 | 24 | 5). The "ESP Doorbell" will try to connect to your selected ssid. 25 | 26 | 27 | 28 | 6). Open "Windows Explorer" and go to "Network". 29 | When the "ESP Doorbell" is succesfully connected to your ssid, than it will be displayed here. 30 | Do a double click on this "ESP Doorbell" 31 | 32 | 33 | 34 | 7). The browser will open and shows the login page of the "ESP Doorbell", login on the "ESP Doorbell" 35 | 36 | Default user: admin 37 | 38 | Default pass: espadmin 39 | 40 | 41 | 42 | 8). After logging in, your first have to select the correct "ESP Board". 43 | 44 | 45 | 46 | 9). Select the correct one. We are not responsible if you select the wrong one and the board gets damaged. 47 | Do a double check if the correct board is selected and "Save" the config. 48 | 49 | 50 | 51 | 10). Config will be saved, "ESP Doorbell" will reboot. 52 | 53 | 54 | 55 | 56 | 11). The "ESP Doorbell" will come back on the "ESP Info" page. 57 | 58 | -------------------------------------------------------------------------------- /src/Main.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include // SSDP for ESPAsyncWebServer 4 | #include // Local DNS Server used for redirecting all requests to the configuration portal 5 | #include // Local WebServer used to server the configuration portal 6 | #include // https://github.com/alanswx/ESPAsyncWiFiManager 7 | 8 | //************************************************************************************************************************************************** 9 | //** Setting Camera type ** 10 | //************************************************************************************************************************************************** 11 | //------------------------------------------------------- 12 | // Global variables defined in Main.cpp 13 | //------------------------------------------------------- 14 | extern uint webloglevel; 15 | extern char esp_board[20]; 16 | extern char esp_name[20]; 17 | extern char esp_uname[10]; 18 | extern char esp_pass[20]; 19 | extern char IPsetting[6]; 20 | extern char IPaddr[16]; 21 | extern char SubNetMask[16]; 22 | extern char GatewayAddr[16]; 23 | extern char SendProtocol[5]; 24 | extern char ServerIP[16]; 25 | extern char ServerPort[5]; 26 | extern char ServerUser[16]; 27 | extern char ServerPass[16]; 28 | extern char DomoticzIDX[5]; 29 | extern char MQTTsubscriber[20]; 30 | extern char MQTTtopicin[20]; 31 | extern const int buttonPushedState; 32 | extern uint Flashcount; 33 | extern uint Flashduration; 34 | extern char Rotation[4]; 35 | extern const char BUILD_MAIN[]; 36 | extern bool reboot; 37 | extern long rebootdelay; 38 | extern bool mqtt_initdone; 39 | 40 | extern int PWDN_GPIO_NUM; 41 | extern int RESET_GPIO_NUM; 42 | extern int XCLK_GPIO_NUM; 43 | extern int SIOD_GPIO_NUM; 44 | extern int SIOC_GPIO_NUM; 45 | extern int Y9_GPIO_NUM; 46 | extern int Y8_GPIO_NUM; 47 | extern int Y7_GPIO_NUM; 48 | extern int Y6_GPIO_NUM; 49 | extern int Y5_GPIO_NUM; 50 | extern int Y4_GPIO_NUM; 51 | extern int Y3_GPIO_NUM; 52 | extern int Y2_GPIO_NUM; 53 | extern int VSYNC_GPIO_NUM; 54 | extern int HREF_GPIO_NUM; 55 | extern int PCLK_GPIO_NUM; 56 | extern int BUTTON_GPIO_NUM; 57 | extern int BUTTONLED_GPIO_NUM; 58 | extern int ON_LED_STATE; 59 | 60 | //------------------------------------------------------- 61 | // Global Functions 62 | 63 | -------------------------------------------------------------------------------- /data/www/configupdrequest.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %esp_name% 8 | 9 | 10 | 11 | 12 |

%esp_name% load files or bin to ESP.

13 | Upload options:
    14 |
  • firmware.bin (*1)
  • 15 |
  • spiffs.bin (*1)
  • 16 |
  • ESP_CAM_CONFIG.json (*1)
  • 17 |
  • ESP_CAM_SETTINGS.json
  • 18 |
  • *.htm;*.css;*.js (*2)
  • 19 |
20 | (*1): Only select a single file and ESP will reboot after upload is completed.
21 | (*2): Allows for multiple files to be selected and uploaded.

22 |
23 | 24 | 25 |
26 | 27 |
28 |
29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESPCAM V2 2 | 3 | # Index: 4 | - First time; How to upload files to ESP 5 | - First time; First time wifi setup 6 | - Camera setup (has to be made) 7 | - MQTT setup (has to be made) 8 | - HTTP setup (has to be made) 9 | - Upload new firmware (has to be made) 10 | - Download config (has to be made) 11 | - Download logfile (has to be made) 12 | 13 | 14 | # RoadMap ESP Doorbell 15 | 16 | Project CAM logic is based on: 17 | 18 | - Added Wifi support and WifiManager -> 19 | - Added Webpages: Home page; Camera options; Setup dummy en OTA bin update 20 | - Added Camera support 21 | - Added SSDP to "see" the ESP device in Windows/Network and can double click it to show the HomePage. 22 | - Added basics for all variables to start building the domoticz functionality and make the Web Setup page 23 | - Added Loginpage. default defined in esp_uname & esp_pass. 24 | - Setup WebPage and store info to SPIFFS done 25 | - Domoticz integration, with json/mqtt (none secure or secure). 26 | - Static/DHCP network settings. 27 | - Json/mqtt incomming-command, to activate a script part. 28 | - Multi-board builds, which uses fixed camera, gpio-in, gpio-out settings 29 | - Upload/download config. 30 | - LED Flashcounter and Time. 31 | - Both serial logging in Webbrowser and SPIFFS download. 32 | - On wifi loss LED will flash in a certain way 33 | - Info page which shows, nothing can be changed here: 34 | - Device name 35 | - Device dhcp/static 36 | - wifi credentials 37 | - network credentials 38 | - build number 39 | - maybe settings, to have everything on 1 page 40 | - Camera variable: 41 | - Framesize (s, SVGA) // QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA 42 | - brightness(s, 0); // -2 to 2 43 | - contrast(s, 0); // -2 to 2 44 | - saturation(s, 0); // -2 to 2 45 | - special_effect(s, 0); // 0 to 6 (0 - No Effect, 1 - Negative, 2 - Grayscale, 3 - Red Tint, 4 - Green Tint, 5 - Blue Tint, 6 - Sepia) 46 | - whitebal(s, 1); // 0 = disable , 1 = enable 47 | - awb_gain(s, 1); // 0 = disable , 1 = enable 48 | - wb_mode(s, 0); // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home) 49 | - exposure_ctrl(s, 1); // 0 = disable , 1 = enable 50 | - aec2(s, 0); // 0 = disable , 1 = enable 51 | - ae_level(s, 0); // -2 to 2 52 | - aec_value(s, 300); // 0 to 1200 53 | - gain_ctrl(s, 1); // 0 = disable , 1 = enable 54 | - agc_gain(s, 0); // 0 to 30 55 | - gainceiling(s, (gainceiling_t)0); // 0 to 6 56 | - bpc(s, 0); // 0 = disable , 1 = enable 57 | - wpc(s, 1); // 0 = disable , 1 = enable 58 | - raw_gma(s, 1); // 0 = disable , 1 = enable 59 | - lenc(s, 1); // 0 = disable , 1 = enable 60 | - hmirror(s, 0); // 0 = disable , 1 = enable 61 | - vflip(s, 0); // 0 = disable , 1 = enable 62 | - dcw(s, 1); // 0 = disable , 1 = enable 63 | - colorbar(s, 0); // 0 = disable , 1 = enable 64 | - Added rotation to setup options. 65 | 66 | Road Map Optional: 67 | 68 | - Motion detection 69 | 70 | Road Map Excluded: 71 | 72 | - Face detection. This is in conflict with AVG(NL)/Privacy laws (EU). 73 | -------------------------------------------------------------------------------- /src/_ESP_Board_Settings.h: -------------------------------------------------------------------------------- 1 | // Set camera options 2 | #include "Main.h" 3 | // Define your settings for the specified ESP Board 4 | void ESP_Standard_Settings() { 5 | if (strcmp(esp_board, "WROVER_KIT") == 0) { 6 | PWDN_GPIO_NUM = -1; 7 | RESET_GPIO_NUM = -1; 8 | XCLK_GPIO_NUM = 21; 9 | SIOD_GPIO_NUM = 26; 10 | SIOC_GPIO_NUM = 27; 11 | Y9_GPIO_NUM = 35; 12 | Y8_GPIO_NUM = 34; 13 | Y7_GPIO_NUM = 39; 14 | Y6_GPIO_NUM = 36; 15 | Y5_GPIO_NUM = 19; 16 | Y4_GPIO_NUM = 18; 17 | Y3_GPIO_NUM = 5; 18 | Y2_GPIO_NUM = 4; 19 | VSYNC_GPIO_NUM = 25; 20 | HREF_GPIO_NUM = 23; 21 | PCLK_GPIO_NUM = 22; 22 | BUTTON_GPIO_NUM = 12; 23 | BUTTONLED_GPIO_NUM = 13; 24 | ON_LED_STATE = HIGH; 25 | 26 | } else if (strcmp(esp_board, "ESP_EYE") == 0) { 27 | PWDN_GPIO_NUM = -1; 28 | RESET_GPIO_NUM = -1; 29 | XCLK_GPIO_NUM = 4; 30 | SIOD_GPIO_NUM = 18; 31 | SIOC_GPIO_NUM = 23; 32 | Y9_GPIO_NUM = 36; 33 | Y8_GPIO_NUM = 37; 34 | Y7_GPIO_NUM = 38; 35 | Y6_GPIO_NUM = 39; 36 | Y5_GPIO_NUM = 35; 37 | Y4_GPIO_NUM = 14; 38 | Y3_GPIO_NUM = 13; 39 | Y2_GPIO_NUM = 34; 40 | VSYNC_GPIO_NUM = 5; 41 | HREF_GPIO_NUM = 27; 42 | PCLK_GPIO_NUM = 25; 43 | BUTTON_GPIO_NUM = 15; 44 | BUTTONLED_GPIO_NUM = 21; 45 | ON_LED_STATE = HIGH; 46 | 47 | } else if (strcmp(esp_board, "M5STACK_PSRAM") == 0) { 48 | PWDN_GPIO_NUM = -1; 49 | RESET_GPIO_NUM = 15; 50 | XCLK_GPIO_NUM = 27; 51 | SIOD_GPIO_NUM = 25; 52 | SIOC_GPIO_NUM = 23; 53 | Y9_GPIO_NUM = 19; 54 | Y8_GPIO_NUM = 36; 55 | Y7_GPIO_NUM = 18; 56 | Y6_GPIO_NUM = 39; 57 | Y5_GPIO_NUM = 5; 58 | Y4_GPIO_NUM = 34; 59 | Y3_GPIO_NUM = 35; 60 | Y2_GPIO_NUM = 32; 61 | VSYNC_GPIO_NUM = 22; 62 | HREF_GPIO_NUM = 26; 63 | PCLK_GPIO_NUM = 21; 64 | BUTTON_GPIO_NUM = 12; 65 | BUTTONLED_GPIO_NUM = 13; 66 | ON_LED_STATE = HIGH; 67 | 68 | } else if (strcmp(esp_board, "M5STACK_WIDE") == 0) { 69 | PWDN_GPIO_NUM = -1; 70 | RESET_GPIO_NUM = 15; 71 | XCLK_GPIO_NUM = 27; 72 | SIOD_GPIO_NUM = 22; 73 | SIOC_GPIO_NUM = 23; 74 | Y9_GPIO_NUM = 19; 75 | Y8_GPIO_NUM = 36; 76 | Y7_GPIO_NUM = 18; 77 | Y6_GPIO_NUM = 39; 78 | Y5_GPIO_NUM = 5; 79 | Y4_GPIO_NUM = 34; 80 | Y3_GPIO_NUM = 35; 81 | Y2_GPIO_NUM = 32; 82 | VSYNC_GPIO_NUM = 25; 83 | HREF_GPIO_NUM = 26; 84 | PCLK_GPIO_NUM = 21; 85 | BUTTON_GPIO_NUM = 12; 86 | BUTTONLED_GPIO_NUM = 13; 87 | ON_LED_STATE = HIGH; 88 | 89 | } else if (strcmp(esp_board, "AI_THINKER") == 0) { 90 | PWDN_GPIO_NUM = 32; 91 | RESET_GPIO_NUM = -1; 92 | XCLK_GPIO_NUM = 0; 93 | SIOD_GPIO_NUM = 26; 94 | SIOC_GPIO_NUM = 27; 95 | Y9_GPIO_NUM = 35; 96 | Y8_GPIO_NUM = 34; 97 | Y7_GPIO_NUM = 39; 98 | Y6_GPIO_NUM = 36; 99 | Y5_GPIO_NUM = 21; 100 | Y4_GPIO_NUM = 19; 101 | Y3_GPIO_NUM = 18; 102 | Y2_GPIO_NUM = 5; 103 | VSYNC_GPIO_NUM = 25; 104 | HREF_GPIO_NUM = 23; 105 | PCLK_GPIO_NUM = 22; 106 | BUTTON_GPIO_NUM = 12; 107 | BUTTONLED_GPIO_NUM = 13; 108 | ON_LED_STATE = HIGH; 109 | } 110 | } -------------------------------------------------------------------------------- /data/www/info.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %esp_name% 5 | 6 | 7 | 8 | 9 |

Camera state: ????

10 |

ESP info

11 |
    12 |
  • VersionBuild: %VERSION%
  • 13 |
  • WiFi SSID: %wifi_ssid%     RSSI: %wifi_rssi%
  • 14 |
  • Ip: %ipaddr% / %ipnetm% / %ipgate%
  • 15 |
  • CAM: %esp_board% / button-gpio=%BUTTON_GPIO_NUM% / Led gpio=%BUTTONLED_GPIO_NUM%
  • 16 |
  • Spiffs: %SPIFFS_tot%-%SPIFFS_used%=%SPIFFS_free%kB free
  • 17 |
  • Server: %SendProtocol% / %ServerIP% / %ServerPort%
  • 18 |
19 | 20 |

ESP Logging

21 | 22 | 23 |

24 | 25 |
26 |

27 |
28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /data/www/index.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %esp_name% 7 | 8 | 9 | 10 | 11 |
12 |
13 |

doorbell

14 |
15 |

%esp_name% (%VERSION_MAJOR%)

16 |
17 | 18 | 19 | 63 | 66 | 67 |
20 | 21 | 22 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |
33 |

Config

34 | 35 | 36 | 39 | 40 | 41 | 44 | 45 | 46 | 49 | 50 | 51 | 54 | 55 | 56 | 58 | 59 | 61 |
57 |

60 |
62 |
64 | 65 |
68 |
69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | 352 | # Added by dev 353 | /.pio 354 | /.vscode 355 | /ESP-Doorbell.code-workspace 356 | /data/*ESP_CAM_CONFIG*.json 357 | /data/*ESP_CAM_SETTINGS*.json 358 | *.bak 359 | -------------------------------------------------------------------------------- /src/setup.cpp: -------------------------------------------------------------------------------- 1 | // Project: ESP32-Doorbell 2 | // Programmers: Jos van der Zande 3 | // Paul Hermans 4 | // 5 | // Setup module 6 | // 7 | #include // Local WebServer used to server the configuration portal 8 | #include 9 | #include 10 | #include "ArduinoJson.h" 11 | #include "setup.h" 12 | #include "WebServer.h" 13 | #include "Main.h" 14 | #include "domoticz.h" 15 | //#include "camera_pins.h" 16 | #ifndef VERSION 17 | #define VERSION 2.0.0 18 | #endif 19 | 20 | // Define private used funcs 21 | bool GetJsonField(String key, DynamicJsonDocument doc, char *variable); 22 | bool GetJsonField(String key, DynamicJsonDocument doc, uint *variable); 23 | 24 | extern AsyncWebServer webserver; 25 | 26 | // Get Variable info from JSON input CHAR STRINGS 27 | bool GetJsonField(String key, DynamicJsonDocument doc, char *variable) { 28 | const char *value = doc[key]; 29 | String msg = F("Key "); 30 | msg += key; 31 | if (value) { 32 | strcpy(variable, value); 33 | msg += F("="); 34 | msg += String(value); 35 | msg += F("\n"); 36 | AddLogMessageD(msg); 37 | return true; 38 | } 39 | msg += F(" not in configfile, using default\n"); 40 | AddLogMessageW(msg); 41 | return false; 42 | } 43 | 44 | // Get Variable info from JSON input unsigned INT Values 45 | bool GetJsonField(String key, DynamicJsonDocument doc, uint *variable) { 46 | const char *value = doc[key]; 47 | String msg = F("Key "); 48 | msg += key; 49 | if (value) { 50 | *variable = atoi(value); 51 | msg += F("="); 52 | msg += String(*variable); 53 | msg += F("\n"); 54 | AddLogMessageD(msg); 55 | return true; 56 | } 57 | msg += F(" not in configfile, using default\n"); 58 | AddLogMessageW(msg); 59 | return false; 60 | } 61 | 62 | // Restore ESP settings From SPIFFS 63 | bool Restore_ESPConfig_from_SPIFFS() { 64 | // SPIFFS 65 | AddLogMessageI(F("Restore configuration from SPIFF\n")); 66 | File file = SPIFFS.open("/ESP_CAM_CONFIG.json", "r"); 67 | if (!file || file.isDirectory()) { 68 | AddLogMessageD(F("- empty file or failed to open file\n")); 69 | return false; 70 | } 71 | String fileContent; 72 | while (file.available()) { 73 | fileContent += String((char)file.read()); 74 | if (fileContent.length() > 5000) { 75 | AddLogMessageE(F("- file too large, assume it is corrupt and use defaults\n")); 76 | fileContent = ""; 77 | file.close(); 78 | SPIFFS.remove("/ESP_CAM_CONFIG.json"); 79 | break; 80 | } 81 | } 82 | DynamicJsonDocument doc(1024); 83 | DeserializationError error = deserializeJson(doc, fileContent); 84 | if (error) { 85 | AddLogMessageD(F("Config Parsing failed\n")); 86 | return false; 87 | } 88 | GetJsonField("webloglevel", doc, &webloglevel); 89 | GetJsonField("esp_board", doc, esp_board); 90 | GetJsonField("esp_name", doc, esp_name); 91 | GetJsonField("esp_uname", doc, esp_uname); 92 | GetJsonField("esp_pass", doc, esp_pass); 93 | GetJsonField("IPsetting", doc, IPsetting); 94 | GetJsonField("IPaddr", doc, IPaddr); 95 | GetJsonField("SubNetMask", doc, SubNetMask); 96 | GetJsonField("GatewayAddr", doc, GatewayAddr); 97 | GetJsonField("SendProtocol", doc, SendProtocol); 98 | GetJsonField("ServerIP", doc, ServerIP); 99 | GetJsonField("ServerPort", doc, ServerPort); 100 | GetJsonField("ServerUser", doc, ServerUser); 101 | GetJsonField("ServerPass", doc, ServerPass); 102 | GetJsonField("DomoticzIDX", doc, DomoticzIDX); 103 | GetJsonField("MQTTsubscriber", doc, MQTTsubscriber); 104 | GetJsonField("MQTTtopicin", doc, MQTTtopicin); 105 | GetJsonField("Flashcount", doc, &Flashcount); 106 | GetJsonField("Flashduration", doc, &Flashduration); 107 | GetJsonField("Rotation", doc, Rotation); 108 | return true; 109 | } 110 | 111 | // Save the information from SETUP.HTM to SPIFFS 112 | void Save_NewESPConfig_to_SPIFFS(AsyncWebServerRequest *request) { 113 | static char json_response[1024]; 114 | char *p = json_response; 115 | *p++ = '{'; 116 | p += sprintf(p, "\"webloglevel\":\"%s\",", urlDecode(request->arg("webloglevel")).c_str()); 117 | p += sprintf(p, "\"esp_board\":\"%s\",", urlDecode(request->arg("esp_board")).c_str()); 118 | p += sprintf(p, "\"esp_name\":\"%s\",", urlDecode(request->arg("esp_name")).c_str()); 119 | p += sprintf(p, "\"esp_uname\":\"%s\",", urlDecode(request->arg("esp_uname")).c_str()); 120 | p += sprintf(p, "\"esp_pass\":\"%s\",", urlDecode(request->arg("esp_pass")).c_str()); 121 | p += sprintf(p, "\"IPsetting\":\"%s\",", urlDecode(request->arg("IPsetting")).c_str()); 122 | p += sprintf(p, "\"IPaddr\":\"%s\",", urlDecode(request->arg("IPaddr")).c_str()); 123 | p += sprintf(p, "\"SubNetMask\":\"%s\",", urlDecode(request->arg("SubNetMask")).c_str()); 124 | p += sprintf(p, "\"GatewayAddr\":\"%s\",", urlDecode(request->arg("GatewayAddr")).c_str()); 125 | p += sprintf(p, "\"SendProtocol\":\"%s\",", urlDecode(request->arg("Send_Protocol")).c_str()); 126 | p += sprintf(p, "\"ServerIP\":\"%s\",", urlDecode(request->arg("ServerIP")).c_str()); 127 | p += sprintf(p, "\"ServerPort\":\"%s\",", urlDecode(request->arg("ServerPort")).c_str()); 128 | p += sprintf(p, "\"ServerUser\":\"%s\",", urlDecode(request->arg("ServerUser")).c_str()); 129 | p += sprintf(p, "\"ServerPass\":\"%s\",", urlDecode(request->arg("ServerPass")).c_str()); 130 | p += sprintf(p, "\"DomoticzIDX\":\"%s\",", urlDecode(request->arg("DomoticzIDX")).c_str()); 131 | p += sprintf(p, "\"MQTTsubscriber\":\"%s\",", urlDecode(request->arg("MQTTsubscriber")).c_str()); 132 | p += sprintf(p, "\"MQTTtopicin\":\"%s\",", urlDecode(request->arg("MQTTtopicin")).c_str()); 133 | p += sprintf(p, "\"Flashcount\":\"%s\",", urlDecode(request->arg("Flashcount")).c_str()); 134 | p += sprintf(p, "\"Flashduration\":\"%s\",", urlDecode(request->arg("Flashduration")).c_str()); 135 | p += sprintf(p, "\"Rotation\":\"%s\",", urlDecode(request->arg("Rotation")).c_str()); 136 | p += sprintf(p, "\"dummy\":\"\""); 137 | *p++ = '}'; 138 | *p++ = 0; 139 | File file = SPIFFS.open("/ESP_CAM_CONFIG.json", "w"); 140 | String msg = F("Saving ESPCAM configuration to SPIFF, "); 141 | if (!file) { 142 | msg += F(" failed to open file for writing\n"); 143 | AddLogMessageE(msg); 144 | return; 145 | } 146 | if (file.print(json_response)) { 147 | msg += F("- config saved\n"); 148 | AddLogMessageI(msg); 149 | } else { 150 | msg += F("- config save failed!!!!"); 151 | AddLogMessageE(msg); 152 | } 153 | file.close(); 154 | } 155 | 156 | // Add possible template variables for the webpages 157 | String TranslateTemplateVars(const String &var) { 158 | if (var == "VERSION") { 159 | char tmp[40]; 160 | sprintf(tmp, "%s - %s", VERSION, BUILD_MAIN); 161 | return tmp; 162 | } 163 | if (var == "VERSION_MAJOR") 164 | return VERSION; 165 | if (var == "esp_board") 166 | return esp_board; 167 | if (var == "BUTTON_GPIO_NUM") 168 | return String(BUTTON_GPIO_NUM); 169 | if (var == "BUTTONLED_GPIO_NUM") 170 | return String(BUTTONLED_GPIO_NUM); 171 | if (var == "webloglevel") 172 | return String(webloglevel); 173 | if (var == "esp_board") 174 | return esp_board; 175 | if (var == "esp_name") 176 | return esp_name; 177 | if (var == "esp_uname") 178 | return esp_uname; 179 | if (var == "esp_pass") 180 | return esp_pass; 181 | if (var == "IPsetting") 182 | return IPsetting; 183 | if (var == "IPaddr") 184 | return IPaddr; 185 | if (var == "SubNetMask") 186 | return SubNetMask; 187 | if (var == "GatewayAddr") 188 | return GatewayAddr; 189 | if (var == "SendProtocol") 190 | return SendProtocol; 191 | if (var == "ServerIP") 192 | return ServerIP; 193 | if (var == "ServerPort") 194 | return ServerPort; 195 | if (var == "ServerUser") 196 | return ServerUser; 197 | if (var == "ServerPass") 198 | return ServerPass; 199 | if (var == "DomoticzIDX") 200 | return DomoticzIDX; 201 | if (var == "MQTTsubscriber") 202 | return MQTTsubscriber; 203 | if (var == "MQTTtopicin") 204 | return MQTTtopicin; 205 | if (var == "Flashcount") 206 | return String(Flashcount); 207 | if (var == "Flashduration") 208 | return String(Flashduration); 209 | if (var == "Rotation") 210 | return Rotation; 211 | if (var == "ipaddr") 212 | return WiFi.localIP().toString(); 213 | if (var == "ipgate") 214 | return WiFi.gatewayIP().toString(); 215 | if (var == "ipnetm") 216 | return WiFi.subnetMask().toString(); 217 | if (var == "wifi_ssid") 218 | return String(WiFi.SSID()); 219 | if (var == "wifi_rssi") 220 | return String(WiFi.RSSI()); 221 | if (var == "SPIFFS_tot") 222 | return String(SPIFFS.totalBytes() / 1000); 223 | if (var == "SPIFFS_used") 224 | return String(SPIFFS.usedBytes() / 1000); 225 | if (var == "SPIFFS_free") 226 | return String((SPIFFS.totalBytes() - SPIFFS.usedBytes()) / 1000); 227 | if (var == "CamStatus") { 228 | if (strcmp(esp_board, "none") == 0) { 229 | return F("Camera not yet defined in ESP Settings!"); 230 | } 231 | sensor_t *cst = esp_camera_sensor_get(); 232 | if (cst == NULL) { 233 | return F("not detected"); 234 | } else { 235 | return F("working"); 236 | } 237 | } 238 | return String(); 239 | } -------------------------------------------------------------------------------- /src/domoticz.cpp: -------------------------------------------------------------------------------- 1 | // Project: ESP32-Doorbell 2 | // Programmers: Jos van der Zande 3 | // Paul Hermans 4 | // 5 | // Domoticz functions sourcefile 6 | // 7 | #include "domoticz.h" 8 | #include "Main.h" 9 | #include "WebServer.h" 10 | #include 11 | #include 12 | #include "ArduinoJson.h" 13 | 14 | WiFiClient client; // wifi client object 15 | MQTTClient MqttClient; 16 | 17 | uint Flash_done = 0; //How many time has led has flashed 18 | long Flash_timer = 0; //Flash timer 19 | bool ButtonProcessActive = false; //Button pressed process started 20 | int ledState = ON_LED_STATE; //the current state of LED High/Low 21 | bool ledon_bydefault = true; //is the default state for the LED ON? True/False 22 | 23 | //-4 : MQTT_CONNECTION_TIMEOUT - the server didn't respond within the keepalive time 24 | //-3 : MQTT_CONNECTION_LOST - the network connection was broken 25 | //-2 : MQTT_CONNECT_FAILED - the network connection failed 26 | //-1 : MQTT_DISCONNECTED - the client is disconnected cleanly 27 | // 0 : MQTT_CONNECTED - the client is connected 28 | // 1 : MQTT_CONNECT_BAD_PROTOCOL - the server doesn't support the requested version of MQTT 29 | // 2 : MQTT_CONNECT_BAD_CLIENT_ID - the server rejected the client identifier 30 | // 3 : MQTT_CONNECT_UNAVAILABLE - the server was unable to accept the connection 31 | // 4 : MQTT_CONNECT_BAD_CREDENTIALS - the username/password were rejected 32 | // 5 : MQTT_CONNECT_UNAUTHORIZED - 33 | 34 | void Mqtt_begin() { 35 | if (strcmp(SendProtocol, "mqtt") != 0) 36 | return; 37 | 38 | AddLogMessageI("Init MQTT\n"); 39 | MqttClient.begin(ServerIP, atoi(ServerPort), client); 40 | MqttClient.onMessage(Mqtt_messageReceived); // subscribe to mqtt for input messages 41 | Mqtt_Connect(); 42 | } 43 | 44 | bool Mqtt_Connect() { 45 | if (strcmp(SendProtocol, "mqtt") != 0) 46 | return false; 47 | 48 | if (MqttClient.connected()) 49 | return true; 50 | 51 | if (MqttClient.connect(esp_name, ServerUser, ServerPass)) { 52 | AddLogMessageI("MQTT connected, subscribing to:" + String(MQTTsubscriber) + "\n"); 53 | MqttClient.subscribe(MQTTsubscriber); 54 | return true; 55 | } else { 56 | AddLogMessageE("MQTT failed to connect! Err:" + String(MqttClient.lastError()) + "\n"); 57 | } 58 | return false; 59 | } 60 | 61 | // Check for new MQTT messages 62 | bool Mqtt_Loop() { 63 | // return immediately when not using mqtt 64 | if (strcmp(SendProtocol, "mqtt") != 0) 65 | return false; 66 | // Check connection to mqtt and messages 67 | if (Mqtt_Connect()) { 68 | // check for queued messages 69 | return MqttClient.loop(); 70 | } 71 | return false; 72 | } 73 | 74 | void Mqtt_messageReceived(String &topic, String &payload) { 75 | AddLogMessageI("MQTT incoming msg: " + payload + "\n"); 76 | process_messageReceived(payload); 77 | } 78 | 79 | //================================================================== 80 | // Put here the received tasks logic from either MQTT or Webserver 81 | String process_messageReceived(String payload) { 82 | DynamicJsonDocument doc(1024); 83 | // translate JSON payload into doc 84 | DeserializationError error = deserializeJson(doc, urlDecode(payload)); 85 | if (error) { 86 | String msg = "{\"status\":\"Error\",\"Message:\":\""; 87 | msg += error.c_str(); 88 | msg += "\"}\n"; 89 | AddLogMessageE("Command Parsing failed for payload:" + payload + "\n"); 90 | AddLogMessageE(msg); 91 | return msg; 92 | } 93 | // Loop through provided keywords 94 | AddLogMessageI("Processing command: " + payload + "\n"); 95 | JsonObject root = doc.as(); 96 | for (JsonPair kv : root) { 97 | const char *key = kv.key().c_str(); 98 | const char *value = kv.value().as(); 99 | Serial.printf("key:%s value:%s", key, value); 100 | if (strcasecmp(key, "led") == 0) { 101 | AddLogMessageI(String("Switch LED to ") + String(value) + "\n"); 102 | if (strcasecmp(value, "on") == 0) 103 | ledon_bydefault = true; 104 | else 105 | ledon_bydefault = false; 106 | // Set the led to the new default 107 | SetLedtoDefault(true); 108 | } else if (strcasecmp(key, "reboot") == 0) { 109 | AddLogMessageI("Rebooting ESP now.\n"); 110 | reboot = true; 111 | rebootdelay = millis(); 112 | } else { 113 | AddLogMessageE("Invalid Key=" + String(key) + " value=" + String(value) + "\n"); 114 | } 115 | } 116 | 117 | return "{\"status\":\"Ok\"}"; 118 | } 119 | 120 | // Check the button state and process the Flash & Switch action 121 | void Button_Check() { 122 | // Check if button is activated 123 | if (digitalRead(BUTTON_GPIO_NUM) == buttonPushedState && !ButtonProcessActive) { 124 | ButtonProcessActive = true; 125 | AddLogMessageI(F("Button Pressed.\n")); 126 | // Perform Domoticz action when button is pressed 127 | Button_Pressed("On"); 128 | AddLogMessageI(F("LED")); 129 | Flash_done = 1; 130 | // Switch led on before Sending command to Domoticz 131 | LedToggle(); 132 | Flash_timer = millis(); 133 | return; 134 | } 135 | // perform flashes and switch Off 136 | if (ButtonProcessActive) { 137 | if (Flash_done > Flashcount * 2) { 138 | LedToggle(); 139 | AddLogMessageI(" Done.\n"); 140 | Button_Pressed("Off"); 141 | ButtonProcessActive = false; 142 | // ensure the LED is off again at the end of the cycle 143 | SetLedtoDefault(false); 144 | } else { 145 | if (Flash_timer + (Flashduration / 2) < millis()) { 146 | LedToggle(); 147 | Flash_timer = millis(); 148 | Flash_done++; 149 | } 150 | } 151 | } 152 | } 153 | 154 | // Function to process when button is pressed 155 | void Button_Pressed(const char *State) { 156 | AddLogMessageI("Button :" + String(State) + "\n"); 157 | if (!strcmp(SendProtocol, "json")) { 158 | Domoticz_JSON_Switch(State); 159 | } else if (!strcmp(SendProtocol, "mqtt")) { 160 | Domoticz_MQTT_Switch(State); 161 | } else { 162 | AddLogMessageW(F("SendProtocol = \"none\", No command to send\n")); 163 | } 164 | } 165 | 166 | // function to switch domoticz switch on/off 167 | bool Domoticz_JSON_Switch(const char *State) { 168 | client.stop(); // Clear any current connections 169 | bool respok = true; 170 | if (!client.connect(ServerIP, atoi(ServerPort))) { 171 | AddLogMessageE(F("Domoticz JSON Connection failed\n")); 172 | return false; 173 | } 174 | // Set UserVarible to button pressed 175 | String url = F("/json.htm?type=command¶m=switchlight&idx="); 176 | url += String(DomoticzIDX); 177 | url += F("&switchcmd="); 178 | url += State; 179 | client.print(F("GET ")); 180 | client.print(url); 181 | // add header 182 | client.print(F(" HTTP/1.1\r\n")); 183 | // Add Authentication to the HTTP header when USER or Password is defined 184 | if (!(strcmp(ServerUser, "") == 0) || !(strcmp(ServerPass, "") == 0)) { 185 | String auth = base64::encode(String(ServerUser) + ":" + String(ServerPass)); 186 | AddLogMessageI(" -> Use basic Authentication: " + auth + "\n"); 187 | client.printf("Authorization: Basic %s\r\n", auth.c_str()); 188 | } 189 | client.print(F("\r\n\r\n Connection: close\r\n\r\n")); 190 | unsigned long timeout = millis(); 191 | AddLogMessageD("Domoticz URL " + url + "\n"); 192 | while (client.available() == 0) { 193 | if (millis() - timeout > 2000) { 194 | AddLogMessageE(F("Domoticz JSON Connection timeout\n")); 195 | client.stop(); 196 | return false; 197 | } 198 | } 199 | String response = client.readString(); 200 | if ((response.indexOf("200 OK") > 0) && (response.indexOf("\"ERR\"") < 0)) { 201 | AddLogMessageI(F("Domoticz Switch command send\n")); 202 | respok = true; 203 | } else { 204 | AddLogMessageE("Domoticz Switch command failed:" + response + "\n"); 205 | respok = false; 206 | } 207 | client.stop(); 208 | return respok; 209 | } 210 | 211 | bool Domoticz_MQTT_Switch(const char *State) { 212 | String MqttMessage = F("{\"command\": \"switchlight\", \"idx\": "); 213 | MqttMessage += String(DomoticzIDX); 214 | MqttMessage += F(", \"switchcmd\": \""); 215 | MqttMessage += State; 216 | MqttMessage += F("\"}"); 217 | if (Mqtt_Connect()) { 218 | String msg = F("mqtt publish t= "); 219 | msg += MQTTtopicin; 220 | msg += F(" m="); 221 | msg += MqttMessage; 222 | msg += F("\n"); 223 | AddLogMessageI(msg); 224 | MqttClient.publish(MQTTtopicin, ((char *)MqttMessage.c_str())); 225 | return true; 226 | } else { 227 | AddLogMessageE(F("Mqtt not connected so Switch message not send!\n")); 228 | return false; 229 | } 230 | } 231 | 232 | void LedToggle() { 233 | ledState = !ledState; 234 | if (ledState) 235 | AddLogMessageI(".On"); 236 | else 237 | AddLogMessageI(".Off "); 238 | digitalWrite(BUTTONLED_GPIO_NUM, ledState); 239 | #if defined(LED_BUILTIN) 240 | digitalWrite(LED_BUILTIN, ledState); 241 | #endif 242 | } 243 | 244 | // Set LED to the requested default in case the state is different 245 | void SetLedtoDefault(bool warn) { 246 | if (ledon_bydefault) { 247 | if (ledState != ON_LED_STATE) { 248 | ledState = ON_LED_STATE; 249 | digitalWrite(BUTTONLED_GPIO_NUM, ledState); 250 | AddLogMessageI(F("Led changed to default On\n")); 251 | } else { 252 | if (warn) AddLogMessageI(F("Led already On\n")); 253 | } 254 | } else { 255 | if (ledState == ON_LED_STATE) { 256 | ledState = !ON_LED_STATE; 257 | digitalWrite(BUTTONLED_GPIO_NUM, ledState); 258 | AddLogMessageI(F("Led changed to default Off\n")); 259 | } else { 260 | if (warn) AddLogMessageI(F("Led already Off\n")); 261 | } 262 | } 263 | } 264 | -------------------------------------------------------------------------------- /src/Main.cpp: -------------------------------------------------------------------------------- 1 | // Project: ESP32-Doorbell V2.0 (jan-2021) 2 | // Programmers: Jos van der Zande 3 | // Paul Hermans 4 | // 5 | // Main ESP32-Doorbell module 6 | // 7 | #include 8 | #include 9 | #include "Main.h" 10 | #include "WebServer.h" 11 | #include "domoticz.h" 12 | #include "setup.h" 13 | #include "cam.h" 14 | 15 | const char BUILD_MAIN[] = __DATE__ " " __TIME__; 16 | //************************************************************************************************************************************************** 17 | //** Setting Wifi credentials ** 18 | //************************************************************************************************************************************************** 19 | uint webloglevel = 3; //loglevel to show in WebConsole. 0-5 20 | 21 | char esp_board[20] = "none"; //ESP type selection 22 | char esp_name[20] = "ESP Doorbell"; //Wifi SSID waarop ESP32-cam zich moet aanmelden. 23 | char esp_uname[10] = "admin"; //Username voor weblogin. 24 | char esp_pass[20] = "espadmin"; //Bijbehorend wachtwoord voor SSID & Weblogin, moet min 8 characters zijn voor WifiManager 25 | 26 | //************************************************************************************************************************************************** 27 | //** IP settings device ** 28 | //************************************************************************************************************************************************** 29 | char IPsetting[6] = "DHCP"; // DHCP/Fixed 30 | char IPaddr[16] = "192.168.0.0"; // IP adres 31 | char SubNetMask[16] = "255.255.255.0"; // subnet mask 32 | char GatewayAddr[16] = "192.168.0.1"; // Gateway adres 33 | //Als device geen internet nodig heeft, voer een fake gateway in. 34 | 35 | //************************************************************************************************************************************************** 36 | //** Setting Server credentials ** 37 | //************************************************************************************************************************************************** 38 | char SendProtocol[5] = "none"; //Define protocol to use 39 | char ServerIP[16] = "192.168.0.0"; //Domoticz Server IP adres. 40 | char ServerPort[5] = "8080"; //Domoticz Server poort adres. 41 | char ServerUser[16] = ""; //MQTT username 42 | char ServerPass[16] = ""; //MQTT password 43 | char DomoticzIDX[5] = "999"; //Domoticz IDX nummer welke geschakeld moet worden. 44 | char MQTTsubscriber[20] = "ESP32CAM/Input"; //MQTT MQTTsubscriber name 45 | char MQTTtopicin[20] = "domoticz/in"; //MQTT Topic name 46 | 47 | //************************************************************************************************************************************************** 48 | //** Setting PUSH button ** 49 | //************************************************************************************************************************************************** 50 | uint Flashcount = 5; //How many time has led to flash (1 time equals 1 sec) 51 | uint Flashduration = 500; //length of one On/Off 52 | //************************************************************************************************************************************************** 53 | //** Setting CAMERA ** 54 | //************************************************************************************************************************************************** 55 | char Rotation[4] = "0"; //Define Capture/Stream WebPage camera rotation in degrees (-)0-180 56 | //************************************************************************************************************************************************** 57 | //** Static ESP-BOARD Settings variables, use _ESP_Board_Settings.h to define all these per ESP_BOARD type. ** 58 | //************************************************************************************************************************************************** 59 | int PWDN_GPIO_NUM = 0; 60 | int RESET_GPIO_NUM = 0; 61 | int XCLK_GPIO_NUM = 0; 62 | int SIOD_GPIO_NUM = 0; 63 | int SIOC_GPIO_NUM = 0; 64 | int Y9_GPIO_NUM = 0; 65 | int Y8_GPIO_NUM = 0; 66 | int Y7_GPIO_NUM = 0; 67 | int Y6_GPIO_NUM = 0; 68 | int Y5_GPIO_NUM = 0; 69 | int Y4_GPIO_NUM = 0; 70 | int Y3_GPIO_NUM = 0; 71 | int Y2_GPIO_NUM = 0; 72 | int VSYNC_GPIO_NUM = 0; 73 | int HREF_GPIO_NUM = 0; 74 | int PCLK_GPIO_NUM = 0; 75 | int BUTTON_GPIO_NUM = 12; // Set the BUTTON GPIO pin 76 | int BUTTONLED_GPIO_NUM = 13; // Set the LED GPIO pin 77 | int ON_LED_STATE = HIGH; // Set the default State of the LED GPIO pin 78 | 79 | //************************************************************************************************************************************************** 80 | //** END SETTINGS END ** 81 | //************************************************************************************************************************************************** 82 | 83 | // Define private used funcs 84 | void start_ssdp_service(); 85 | 86 | AsyncWebServer webserver(80); 87 | 88 | DNSServer dns; 89 | ssdpAWS mySSDP(&webserver); 90 | 91 | // Define whether the pushbutton changes to LOW or HIGH when pushed 92 | #if defined(BUTTOM_PUSH_STATE) 93 | const int buttonPushedState = BUTTOM_PUSH_STATE; 94 | #else 95 | const int buttonPushedState = HIGH; 96 | #endif 97 | 98 | unsigned long MQTT_lasttime; // MQTT check lasttime 99 | bool WifiOK = false; // WiFi status 100 | bool mqtt_initdone = false; // MQTT status 101 | bool reboot = false; // Pending reboot status 102 | long rebootdelay = 0; // used to calculate the delay 103 | 104 | void setup() { 105 | //EEPROM.begin(200); 106 | Serial.begin(115200); 107 | Serial.setDebugOutput(true); 108 | 109 | // Initialize SPIFFS 110 | if (!SPIFFS.begin(true)) 111 | ESP_LOGE(TAG, "An Error has occurred while mounting SPIFFS"); 112 | 113 | // restore previous ESP saved settings 114 | Restore_ESPConfig_from_SPIFFS(); 115 | 116 | //WiFiManager 117 | //Local intialization. Once its business is done, there is no need to keep it around 118 | AsyncWiFiManager wifiManager(&webserver, &dns); 119 | //reset saved settings 120 | // wifiManager.resetSettings(); 121 | // Previous line doesn't always work so this is another option to erase the EEPROM and all saved settings 122 | // pio run --target erase 123 | 124 | // Set hardcoded IP Stettings when Fixed IP is defined 125 | if (strcmp(IPsetting, "Fixed") == 0) { 126 | AddLogMessageI(F("==>Set Static IP\n")); 127 | IPAddress ip; 128 | IPAddress nm; 129 | IPAddress gw; 130 | ip.fromString(IPaddr); 131 | nm.fromString(SubNetMask); 132 | gw.fromString(GatewayAddr); 133 | wifiManager.setSTAStaticIPConfig(ip, gw, nm); 134 | } 135 | // Try connecting to previous saved WiFI settings or else start as AP 136 | wifiManager.autoConnect(esp_name, esp_pass); 137 | //if you get here you have connected to the WiFi 138 | WifiOK = true; 139 | 140 | // Get Network time 141 | const char *NTPpool = "nl.pool.ntp.org"; 142 | const char *defaultTimezone = "CET-1CEST,M3.5.0/2,M10.5.0/3"; 143 | configTzTime(defaultTimezone, NTPpool); //sets TZ and starts NTP sync 144 | // wait max 5 secs till time is synced 145 | AddLogMessageI("Wifi connected " + WiFi.SSID() + " IP:" + WiFi.localIP().toString() + " RSSI:" + String(WiFi.RSSI()) + "\n"); 146 | struct tm timeinfo; 147 | for (uint i = 0; i < 10; i++) { 148 | if (getLocalTime(&timeinfo,500)) { 149 | AddLogMessageI(F("Time synced.\n")); 150 | break; 151 | } 152 | } 153 | // Init Camera 154 | initcamera(); 155 | 156 | // Set Button GPIO for INPUT and PULL UP/DOWN depending of the definition 157 | pinMode(BUTTON_GPIO_NUM, (buttonPushedState ? INPUT_PULLDOWN : INPUT_PULLUP)); 158 | // Set LED output and optional the same flashes for the defined LED_BUILTIN 159 | pinMode(BUTTONLED_GPIO_NUM, OUTPUT); 160 | digitalWrite(BUTTONLED_GPIO_NUM, ON_LED_STATE); 161 | //Necessary for ESP_EYE (Jos:Not sure about this as this is for the other onboard buttons) 162 | if (strcmp(esp_board, "ESP_EYE") == 0) { 163 | pinMode(13, INPUT_PULLUP); 164 | pinMode(14, INPUT_PULLUP); 165 | } 166 | 167 | // start mqtt 168 | if (!strcmp(SendProtocol, "mqtt")) { 169 | Mqtt_begin(); 170 | mqtt_initdone = true; 171 | } 172 | MQTT_lasttime = millis(); 173 | 174 | // Init WebServer 175 | WebServerInit(&webserver); 176 | 177 | // Make ESP-CAM "known" in the network under it's ESP_NAME 178 | start_ssdp_service(); 179 | AddLogMessageI(F("ESP Doorbell initialized\n")); 180 | } 181 | 182 | void loop() { 183 | // Don't do anything when shutting down and wait 1 second before rebooting 184 | if (reboot) { 185 | if (rebootdelay + 1000 > millis()) { 186 | Serial.flush(); 187 | SPIFFS.end(); 188 | delay(500); 189 | ESP.restart(); 190 | delay(2000); 191 | } 192 | return; 193 | } 194 | 195 | // Check button or open actions for it 196 | Button_Check(); 197 | 198 | // Flash LED when WiFi is lost 199 | if (!WiFi.isConnected()) { 200 | // Add a WiFI log record when WiFI goes down 201 | if (WifiOK) { 202 | WifiOK = false; 203 | AddLogMessageE(F("WiFi connection lost!\n")); 204 | } 205 | LedToggle(); 206 | delay(100); 207 | LedToggle(); 208 | delay(100); 209 | } else { 210 | // Add a WiFI log record when WiFI is restored 211 | if (!WifiOK) { 212 | WifiOK = true; 213 | AddLogMessageW(F("WiFi connection restored\n")); 214 | } 215 | // Process MQTT when selected 216 | if (mqtt_initdone && (millis() > MQTT_lasttime + 500)) { 217 | Mqtt_Loop(); 218 | MQTT_lasttime = millis(); 219 | } 220 | // Send any logmessages to the browser 221 | SendNextLogMessage(); 222 | } 223 | 224 | // short pause 225 | delay(10); 226 | } 227 | 228 | void start_ssdp_service() { 229 | //initialize mDNS service 230 | //Define SSDP and model name 231 | const char *SSDP_Name = esp_name; 232 | const char *modelName = esp_board; 233 | const char *nVersion = BUILD_MAIN; 234 | const char *SerialNumber = ""; 235 | const char *Manufacturer = "ESP32CAM"; 236 | const char *ManufacturerURL = "https://github.com/jvanderzande/ESPCAM"; 237 | mySSDP.begin(SSDP_Name, SerialNumber, modelName, nVersion, Manufacturer, ManufacturerURL); 238 | AddLogMessageI(F("SSDP started\n")); 239 | } -------------------------------------------------------------------------------- /data/www/wiki.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %esp_name% 5 | 6 | 7 | 8 | 9 | 10 |

ESP Camera wiki page

11 |
12 |
13 | 14 |
15 |

URL's that are supported by the ESP Doorbell

16 |
      Camera JPG Capture
17 |
- http://%ipaddr%/capture
18 |
      Camera JPG Stream
19 |
- http://%ipaddr%/stream
20 |
21 |

Json commands

22 |
      LED On
23 |
- http://%ipaddr%/message?command={%22led%22:%22on%22}
24 |
      LED Off
25 |
- http://%ipaddr%/message?command={%22led%22:%22off%22}
26 |
      ESP Reboot
27 |
- http://%ipaddr%/message?command={"reboot":""}
28 |
29 |

MQTT commands

30 |
      LED On
31 |
- mosquitto_pub -h %ServerIP% -t 'ESP32CAM/Input' -m '{"Led":"on"}'
32 |
      LED Off
33 |
- mosquitto_pub -h %ServerIP% -t 'ESP32CAM/Input' -m '{"Led":"off"}'
34 |
      ESP Reboot
35 |
- mosquitto_pub -h %ServerIP% -t 'ESP32CAM/Input' -m '{"reboot":""}'
36 |
37 |
38 |
39 | 40 |

  Page: ESP Info

41 |

    Camera State

42 |
43 |
      The state of the camera
44 |
45 | 46 |

    ESP Info

47 |
48 |
      Versionbuild:
49 |
- The ESP Doorbell firmware and date.
50 |
      Wifi SSID:
51 |
- To which SSID is the ESP Doorbell connected and what is it's RSSI Value.
52 |
      Ip:
53 |
- The IP address, Subnet mask, Default gateway.
54 |
      CAM:
55 |
- Which board is selected, the GPIO-pinnumber for the button, the GPIO-pinnumber for de LED.
56 |
      Spiffs:
57 |
- The maximum, used and free memory for spiffs.
58 |
      Server:
59 |
- Sending protocol, IP address server en port number of the server.
60 |
61 | 62 |

    ESP Logging

63 |
64 |
      DumpLog
65 |
- Saves the log to a file, on the device which is logged-in.
66 |
      CleanLog
67 |
- Cleans the log-field.
68 |
69 | 70 |
71 |
72 | 73 |

  Page: Get JPG Snapshot

74 |
75 |
    Makes 1 still image capture from the camera.
76 |
77 | 78 |
79 |
80 | 81 |

  Page: Stream JPG

82 |
83 |
    Streams image capture from the camera.
84 |
85 | 86 |
87 |
88 | 89 |

  Page: ESP Settings

90 |
91 |
      WebLog Display Level:
92 |
- Sets the level of log.
93 |
(None, Error, Warning, Info, Debug)
94 |
      ESP Board:
95 |
- Sets the type of board and the gpio's that come with the selected board.
96 |
(None, AI_Thinker, ESP-EYE), these are tested.
97 |
      ESP name:
98 |
- Sets the name of the device.
99 |
      Web Userid:
100 |
- Login name for secure login on ESP-doorbell. If security is not needed, clear this field.
101 |
      Password:
102 |
- Login password for secure login on ESP-doorbell. If security is not needed, clear this field.
103 |
      FlashCount:
104 |
- How many time the LED flashes, when button is pushed.
105 |
      Flashduration:
106 |
- How long is the LED ON, when flashing. Value in milli-seconds.
107 |
      Camera Rotation:
108 |
- Rotates the image. Note that landscape will rotate to portrait.
109 |
(none, 90, 180, 270 degrees.)
110 |
      Network:
111 |
☛ Selected "DHCP" to get network credentials from network.
112 |
☛ Select "Fixed" to set your own netwerk credentials.
113 |
          IP Address:
114 |
    - Set the IP for the ESP Doorbell.
115 |
          Subnetmask:
116 |
    - Set the subnetmask for the ESP Doorbell.
117 |
          Gateway Addr:
118 |
    - Set the gateway address for the ESP Doorbell.
119 |
      Send Protocol:
120 |
☛ Sets the protocol how to send doorbell button push to server
121 |
(none, json, mqtt)
122 |
          Server IP:
123 |
    - Set the IP for the server, where the message needs to be send to.
124 |
     (This function is the same for json and mqtt)
125 |
          Server Port:
126 |
    - Set the port number for the server, where the message needs to be send to.
127 |
     (This function is the same for json and mqtt)
128 |
          Server Userid:
129 |
    - When using secure connection, user ID/name can be added.
130 |
     (This optional, is the same for json and mqtt)
131 |
          Server Password:
132 |
    - When using secure connection, password can be added.
133 |
     (This optional, is the same for json and mqtt)
134 |
          Domoticz IDX:
135 |
    - The Domoticz IDX number of the device which needs to be controlled by ESP Doorbell.
136 |
     (This function is the same for json and mqtt)
137 |
          MQTT subscriber:
138 |
    - The MQTT subscriber name to receive the mqtt messages.
139 |
          MQTT TopicIn::
140 |
    - The MQTT topic name, when sending mqtt messages.
141 |
142 | 143 |
144 |
145 | 146 |

  Page: Camera Settings

147 |
148 |
      Frame size:
149 |
- Set camera frame size.
150 |
(QVGA, CIF, VGA, SVGA, XGA, SXGA, UXGA)
151 |
      Brightness:
152 |
- Set camera brightness.
153 |
(Between -2 and 2)
154 |
      Contrast:
155 |
- Set camera contrast.
156 |
(Between -2 and 2)
157 |
      Saturation:
158 |
- Set camera saturation.
159 |
(Between -2 and 2)
160 |
      Special effect:
161 |
- Set image special effect.
162 |
(No effect, Negative, Grayscale, Red tint, Green tint, Blue tint, Sepia)
163 |
      Whiteball:
164 |
- Set white balance.
165 |
(Enable, Disable)
166 |
      Awb_gain:
167 |
- Set white balance gain.
168 |
(Enable, Disable)
169 |
      Wb_mode:
170 |
- Set white balance mode.
171 |
(Auto, Sunny, Cloudy, Office, Home)
172 |
      Exposure_ctrl:
173 |
- Set exposure control.
174 |
(Enable, Disable)
175 |
      Aec2:
176 |
(Enable, Disable)
177 |
      Ae_level:
178 |
(Between -2 and 2)
179 |
      Aec_value:
180 |
(0, 300, 600, 900, 1200)
181 |
      Gain_ctrl:
182 |
(Enable, Disable)
183 |
      Agc_gain:
184 |
(0, 6, 12, 18, 24, 30)
185 |
      Gainceiling:
186 |
(0, 1, 2, 3, 4, 5, 6)
187 |
      Bpc:
188 |
(Enable, Disable)
189 |
      Wpc:
190 |
(Enable, Disable)
191 |
      Lenc:
192 |
- Set lens correction.
193 |
(Enable, Disable)
194 |
      Hmirror:
195 |
- Mirror image horizontal
196 |
(Enable, Disable)
197 |
      Vflip:
198 |
- Flip image vertical
199 |
(Enable, Disable)
200 |
      Dcw:
201 |
(Enable, Disable)
202 |
      Colorbar:
203 |
- Set a colorbar
204 |
(Enable, Disable)
205 |
206 | 207 |
208 |
209 | 210 | 211 | 212 | -------------------------------------------------------------------------------- /data/www/setup.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %esp_name% 5 | 6 | 7 | 8 | 9 |

%esp_name% settings

10 |
11 | 12 | 13 | 14 | 15 | 16 | 25 | 26 | 27 | 28 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 75 | 76 | 77 | 78 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 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 | 138 | 139 | 140 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 155 | 156 | 157 | 158 |
WebLog Display Level 17 | 24 |
ESP Board 29 | 43 |
ESP name:
Web Userid:
Password:
FlashCount:
Flashduration: msec
Camera Rotation: 68 | 74 |
Network 79 | 83 |
IP Address:
Subnetmask:
Gateway Addr:
Send Protocol 100 | 105 |
Server IP:
Server Port:
Server Userid:
Server Password:
Domoticz IDX:
MQTT subscriber:
MQTT TopicIn:
137 |
141 |    142 |    144 |    146 |


Clear wifi credentails:
(be carefull to use) 154 |
159 |
160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /data/www/camsetup.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %esp_name% 6 | 7 | 8 | 9 | 10 |

%esp_name% camera settings

11 |
12 | 13 | 14 | 141 | 237 | 238 | 239 | 246 | 247 |
15 | 16 | 17 | 18 | 19 | 20 | 29 | 30 | 31 | 32 | 39 | 40 | 41 | 42 | 43 | 50 | 51 | 52 | 53 | 54 | 61 | 62 | 63 | 64 | 65 | 74 | 75 | 76 | 77 | 78 | 82 | 83 | 84 | 85 | 86 | 90 | 91 | 92 | 93 | 94 | 101 | 102 | 103 | 104 | 105 | 109 | 110 | 111 | 112 | 116 | 117 | 118 | 119 | 120 | 127 | 128 | 129 | 130 | 131 | 138 | 139 |
Framesize
Brightness
Contrast
Saturation
Special effect
Whiteball
Awb_gain
Wb_mode
Exposure_ctrl
Aec2
Ae_level
Aec_value
140 |
142 | 143 | 144 | 145 | 146 | 147 | 148 | 152 | 153 | 154 | 155 | 156 | 164 | 165 | 166 | 167 | 168 | 177 | 178 | 179 | 180 | 181 | 185 | 186 | 187 | 188 | 189 | 193 | 194 | 195 | 196 | 197 | 201 | 202 | 203 | 204 | 205 | 209 | 210 | 211 | 212 | 213 | 217 | 218 | 219 | 220 | 221 | 225 | 226 | 227 | 228 | 229 | 233 | 234 | 235 |
Gain_ctrl
Agc_gain
Gainceiling
Bpc
Wpc
Lenc
Hmirror
Vflip
Dcw
Colorbar
236 |
240 |     241 |     243 |     245 |
248 |
249 | 250 | 251 | 252 | 253 | -------------------------------------------------------------------------------- /src/cam.cpp: -------------------------------------------------------------------------------- 1 | // Project: ESP32-Doorbell 2 | // Programmers: Jos van der Zande 3 | // Paul Hermans 4 | // 5 | // Camera module for ESP-CAM 6 | // Partly based on: // https://gist.github.com/me-no-dev/d34fba51a8f059ac559bf62002e61aa3 7 | // 8 | #include // https://github.com/alanswx/ESPAsyncWiFiManager 9 | #include 10 | #include 11 | #include "ArduinoJson.h" 12 | 13 | #include "cam.h" 14 | #include "Main.h" 15 | #include "Webserver.h" 16 | #include "setup.h" 17 | #include "_ESP_Board_Settings.h" 18 | 19 | // Define private used funcs 20 | bool GetJsonField_UpdateCam(sensor_t *s, DynamicJsonDocument doc, char *variable); 21 | void ESP_Standard_Settings(); 22 | 23 | typedef struct 24 | { 25 | camera_fb_t *fb; 26 | size_t index; 27 | } camera_frame_t; 28 | 29 | #define PART_BOUNDARY "123456789000000000000987654321" 30 | static const char *STREAM_CONTENT_TYPE = "multipart/x-mixed-replace;boundary=" PART_BOUNDARY; 31 | static const char *STREAM_BOUNDARY = "\r\n--" PART_BOUNDARY "\r\n"; 32 | static const char *STREAM_PART = "Content-Type: %s\r\nContent-Length: %u\r\n\r\n"; 33 | 34 | static const char *JPG_CONTENT_TYPE = "image/jpeg"; 35 | //static const char *BMP_CONTENT_TYPE = "image/x-windows-bmp"; 36 | 37 | class AsyncBufferResponse : public AsyncAbstractResponse { 38 | private: 39 | uint8_t *_buf; 40 | size_t _len; 41 | size_t _index; 42 | 43 | public: 44 | AsyncBufferResponse(uint8_t *buf, size_t len, const char *contentType) { 45 | _buf = buf; 46 | _len = len; 47 | _callback = nullptr; 48 | _code = 200; 49 | _contentLength = _len; 50 | _contentType = contentType; 51 | _index = 0; 52 | } 53 | ~AsyncBufferResponse() { 54 | if (_buf != nullptr) { 55 | free(_buf); 56 | } 57 | } 58 | bool _sourceValid() const { return _buf != nullptr; } 59 | virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override { 60 | size_t ret = _content(buf, maxLen, _index); 61 | if (ret != RESPONSE_TRY_AGAIN) { 62 | _index += ret; 63 | } 64 | return ret; 65 | } 66 | size_t _content(uint8_t *buffer, size_t maxLen, size_t index) { 67 | memcpy(buffer, _buf + index, maxLen); 68 | if ((index + maxLen) == _len) { 69 | free(_buf); 70 | _buf = nullptr; 71 | } 72 | return maxLen; 73 | } 74 | }; 75 | 76 | class AsyncFrameResponse : public AsyncAbstractResponse { 77 | private: 78 | camera_fb_t *fb; 79 | size_t _index; 80 | 81 | public: 82 | AsyncFrameResponse(camera_fb_t *frame, const char *contentType) { 83 | _callback = nullptr; 84 | _code = 200; 85 | _contentLength = frame->len; 86 | _contentType = contentType; 87 | _index = 0; 88 | fb = frame; 89 | } 90 | ~AsyncFrameResponse() { 91 | if (fb != nullptr) { 92 | esp_camera_fb_return(fb); 93 | } 94 | } 95 | bool _sourceValid() const { return fb != nullptr; } 96 | virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override { 97 | size_t ret = _content(buf, maxLen, _index); 98 | if (ret != RESPONSE_TRY_AGAIN) { 99 | _index += ret; 100 | } 101 | return ret; 102 | } 103 | size_t _content(uint8_t *buffer, size_t maxLen, size_t index) { 104 | memcpy(buffer, fb->buf + index, maxLen); 105 | if ((index + maxLen) == fb->len) { 106 | esp_camera_fb_return(fb); 107 | fb = nullptr; 108 | } 109 | return maxLen; 110 | } 111 | }; 112 | 113 | class AsyncJpegStreamResponse : public AsyncAbstractResponse { 114 | private: 115 | camera_frame_t _frame; 116 | size_t _index; 117 | size_t _jpg_buf_len; 118 | uint8_t *_jpg_buf; 119 | long lastAsyncRequest; 120 | 121 | public: 122 | AsyncJpegStreamResponse() { 123 | _callback = nullptr; 124 | _code = 200; 125 | _contentLength = 0; 126 | _contentType = STREAM_CONTENT_TYPE; 127 | _sendContentLength = false; 128 | _chunked = true; 129 | _index = 0; 130 | _jpg_buf_len = 0; 131 | _jpg_buf = NULL; 132 | lastAsyncRequest = 0; 133 | memset(&_frame, 0, sizeof(camera_frame_t)); 134 | } 135 | ~AsyncJpegStreamResponse() { 136 | if (_frame.fb) { 137 | if (_frame.fb->format != PIXFORMAT_JPEG) { 138 | free(_jpg_buf); 139 | } 140 | esp_camera_fb_return(_frame.fb); 141 | } 142 | } 143 | bool _sourceValid() const { 144 | return true; 145 | } 146 | virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override { 147 | size_t ret = _content(buf, maxLen, _index); 148 | if (ret != RESPONSE_TRY_AGAIN) { 149 | _index += ret; 150 | } 151 | return ret; 152 | } 153 | size_t _content(uint8_t *buffer, size_t maxLen, size_t index) { 154 | if (!_frame.fb || _frame.index == _jpg_buf_len) { 155 | if (index && _frame.fb) { 156 | long end = millis(); 157 | int fp = (end - lastAsyncRequest); 158 | log_d("Size: %uKB, Time: %ums (%ifps)\n", _jpg_buf_len / 1024, fp, 1000 / fp); 159 | lastAsyncRequest = end; 160 | if (_frame.fb->format != PIXFORMAT_JPEG) { 161 | free(_jpg_buf); 162 | } 163 | esp_camera_fb_return(_frame.fb); 164 | _frame.fb = NULL; 165 | _jpg_buf_len = 0; 166 | _jpg_buf = NULL; 167 | } 168 | if (maxLen < (strlen(STREAM_BOUNDARY) + strlen(STREAM_PART) + strlen(JPG_CONTENT_TYPE) + 8)) { 169 | //log_w("Not enough space for headers"); 170 | return RESPONSE_TRY_AGAIN; 171 | } 172 | //get frame 173 | _frame.index = 0; 174 | 175 | _frame.fb = esp_camera_fb_get(); 176 | if (_frame.fb == NULL) { 177 | log_e("Camera frame failed"); 178 | return 0; 179 | } 180 | 181 | if (_frame.fb->format != PIXFORMAT_JPEG) { 182 | unsigned long st = millis(); 183 | bool jpeg_converted = frame2jpg(_frame.fb, 80, &_jpg_buf, &_jpg_buf_len); 184 | if (!jpeg_converted) { 185 | log_e("JPEG compression failed"); 186 | esp_camera_fb_return(_frame.fb); 187 | _frame.fb = NULL; 188 | _jpg_buf_len = 0; 189 | _jpg_buf = NULL; 190 | return 0; 191 | } 192 | log_i("JPEG: %lums, %uB", millis() - st, _jpg_buf_len); 193 | } else { 194 | _jpg_buf_len = _frame.fb->len; 195 | _jpg_buf = _frame.fb->buf; 196 | } 197 | 198 | //send boundary 199 | size_t blen = 0; 200 | if (index) { 201 | blen = strlen(STREAM_BOUNDARY); 202 | memcpy(buffer, STREAM_BOUNDARY, blen); 203 | buffer += blen; 204 | } 205 | //send header 206 | size_t hlen = sprintf((char *)buffer, STREAM_PART, JPG_CONTENT_TYPE, _jpg_buf_len); 207 | buffer += hlen; 208 | //send frame 209 | hlen = maxLen - hlen - blen; 210 | if (hlen > _jpg_buf_len) { 211 | maxLen -= hlen - _jpg_buf_len; 212 | hlen = _jpg_buf_len; 213 | } 214 | memcpy(buffer, _jpg_buf, hlen); 215 | _frame.index += hlen; 216 | return maxLen; 217 | } 218 | 219 | size_t available = _jpg_buf_len - _frame.index; 220 | if (maxLen > available) { 221 | maxLen = available; 222 | } 223 | memcpy(buffer, _jpg_buf + _frame.index, maxLen); 224 | _frame.index += maxLen; 225 | 226 | return maxLen; 227 | } 228 | }; 229 | 230 | // ---------------------------------------------------------------------------------------------------------------- 231 | // ------ Camera Webfunctions ------------------------------------------------------------------------------------ 232 | // ---------------------------------------------------------------------------------------------------------------- 233 | 234 | void sendJpg(AsyncWebServerRequest *request) { 235 | if (!_webAuth(request)) 236 | return; 237 | if (strcmp(esp_board, "none") == 0) { 238 | AddLogMessageE(F("Webrequest: \"/capture\" -> No ESP Board type selected yet.\n")); 239 | String s = F("No ESP Board type selected yet."); 240 | request->send(200, "text/html", s); 241 | return; 242 | } 243 | camera_fb_t *fb = esp_camera_fb_get(); 244 | if (fb == NULL) { 245 | AddLogMessageE(F("Webrequest: \"/capture\" -> Camera not Detected.\n")); 246 | String s = F("Camera not Detected."); 247 | request->send(200, "text/html", s); 248 | return; 249 | } 250 | AddLogMessageI(F("Start JPG Capture\n")); 251 | if (fb->format == PIXFORMAT_JPEG) { 252 | AsyncFrameResponse *response = new AsyncFrameResponse(fb, JPG_CONTENT_TYPE); 253 | if (response == NULL) { 254 | log_e("Response alloc failed"); 255 | request->send(501); 256 | return; 257 | } 258 | response->addHeader("Access-Control-Allow-Origin", "*"); 259 | request->send(response); 260 | return; 261 | } 262 | 263 | size_t jpg_buf_len = 0; 264 | uint8_t *jpg_buf = NULL; 265 | unsigned long st = millis(); 266 | bool jpeg_converted = frame2jpg(fb, 80, &jpg_buf, &jpg_buf_len); 267 | esp_camera_fb_return(fb); 268 | if (!jpeg_converted) { 269 | log_e("JPEG compression failed: %lu", millis()); 270 | request->send(501); 271 | return; 272 | } 273 | log_i("JPEG: %lums, %uB", millis() - st, jpg_buf_len); 274 | 275 | AsyncBufferResponse *response = new AsyncBufferResponse(jpg_buf, jpg_buf_len, JPG_CONTENT_TYPE); 276 | if (response == NULL) { 277 | log_e("Response alloc failed"); 278 | request->send(501); 279 | return; 280 | } 281 | response->addHeader("Access-Control-Allow-Origin", "*"); 282 | request->send(response); 283 | } 284 | 285 | void streamJpg(AsyncWebServerRequest *request) { 286 | if (!_webAuth(request)) 287 | return; 288 | if (strcmp(esp_board, "none") == 0) { 289 | AddLogMessageE(F("Webrequest: \"/stream\" -> No ESP Board type selected yet.\n")); 290 | String s = F("No ESP Board type selected yet."); 291 | request->send(200, "text/html", s); 292 | return; 293 | } 294 | camera_fb_t *fb = esp_camera_fb_get(); 295 | if (fb == NULL) { 296 | AddLogMessageE(F("Webrequest: \"/stream\" -> Camera not Detected.\n")); 297 | String s = F("Camera not Detected."); 298 | request->send(200, "text/html", s); 299 | return; 300 | } 301 | AddLogMessageI(F("Start JPG streaming\n")); 302 | if (strcmp(esp_board, "none") == 0) { 303 | AddLogMessageE(F("No ESP Board type selected yet")); 304 | request->send(501); 305 | return; 306 | } 307 | AsyncJpegStreamResponse *response = new AsyncJpegStreamResponse(); 308 | if (!response) { 309 | request->send(501); 310 | return; 311 | } 312 | response->addHeader("Access-Control-Allow-Origin", "*"); 313 | request->send(response); 314 | } 315 | 316 | // ---------------------------------------------------------------------------------------------------------------- 317 | // ------ Camera other functions ------------------------------------------------------------------------------------ 318 | // ---------------------------------------------------------------------------------------------------------------- 319 | 320 | // Initialise cameras 321 | void initcamera() { 322 | // No ESP Board type selected yet. 323 | if (strcmp(esp_board, "none") == 0) 324 | return; 325 | //Set Camera config - from camera_pins.h 326 | ESP_Standard_Settings(); 327 | // 328 | camera_config_t config; 329 | config.ledc_channel = LEDC_CHANNEL_0; 330 | config.ledc_timer = LEDC_TIMER_0; 331 | config.pin_d0 = Y2_GPIO_NUM; 332 | config.pin_d1 = Y3_GPIO_NUM; 333 | config.pin_d2 = Y4_GPIO_NUM; 334 | config.pin_d3 = Y5_GPIO_NUM; 335 | config.pin_d4 = Y6_GPIO_NUM; 336 | config.pin_d5 = Y7_GPIO_NUM; 337 | config.pin_d6 = Y8_GPIO_NUM; 338 | config.pin_d7 = Y9_GPIO_NUM; 339 | config.pin_xclk = XCLK_GPIO_NUM; 340 | config.pin_pclk = PCLK_GPIO_NUM; 341 | config.pin_vsync = VSYNC_GPIO_NUM; 342 | config.pin_href = HREF_GPIO_NUM; 343 | config.pin_sscb_sda = SIOD_GPIO_NUM; 344 | config.pin_sscb_scl = SIOC_GPIO_NUM; 345 | config.pin_pwdn = PWDN_GPIO_NUM; 346 | config.pin_reset = RESET_GPIO_NUM; 347 | config.xclk_freq_hz = 20000000; 348 | config.pixel_format = PIXFORMAT_JPEG; 349 | 350 | //Setup size of image 351 | if (psramFound()) { 352 | config.frame_size = FRAMESIZE_SVGA; 353 | config.jpeg_quality = 10; 354 | config.fb_count = 2; 355 | } else { 356 | config.frame_size = FRAMESIZE_VGA; 357 | config.jpeg_quality = 12; 358 | config.fb_count = 1; 359 | } 360 | 361 | // Camera init 362 | esp_err_t err = esp_camera_init(&config); 363 | if (err != ESP_OK) { 364 | AddLogMessageE(F("Camera init failed!\n")); 365 | 366 | return; 367 | } 368 | 369 | // restore the saved settings from SPIFFS 370 | Restore_CamSettings_from_SPIFFS(); 371 | 372 | AddLogMessageI(F("Camera initialised!\n")); 373 | } 374 | 375 | // Update the settings in the CAM when changed 376 | bool GetJsonField_UpdateCam(sensor_t *s, DynamicJsonDocument doc, char *variable) { 377 | int ncharvalue = doc[variable]; 378 | //if (!ncharvalue) 379 | if (!doc.containsKey(variable)) { 380 | AddLogMessageW("!! Config key " + String(variable) + " doesn't exist in ESP_CAM_CONFIG.json!!\n"); 381 | return false; 382 | } 383 | int nvalue = ncharvalue; 384 | log_d(" -> key %s new=%i", variable, (int)nvalue); 385 | 386 | // Update requested parameter 387 | if (!strcmp(variable, "framesize")) 388 | s->set_framesize(s, (framesize_t)nvalue); 389 | else if (!strcmp(variable, "quality")) 390 | s->set_quality(s, nvalue); 391 | else if (!strcmp(variable, "contrast")) 392 | s->set_contrast(s, nvalue); 393 | else if (!strcmp(variable, "brightness")) 394 | s->set_brightness(s, nvalue); 395 | else if (!strcmp(variable, "saturation")) 396 | s->set_saturation(s, nvalue); 397 | else if (!strcmp(variable, "sharpness")) 398 | s->set_sharpness(s, nvalue); 399 | else if (!strcmp(variable, "gainceiling")) 400 | s->set_gainceiling(s, (gainceiling_t)nvalue); 401 | else if (!strcmp(variable, "colorbar")) 402 | s->set_colorbar(s, nvalue); 403 | else if (!strcmp(variable, "awb")) 404 | s->set_whitebal(s, nvalue); 405 | else if (!strcmp(variable, "agc")) 406 | s->set_gain_ctrl(s, nvalue); 407 | else if (!strcmp(variable, "aec")) 408 | s->set_exposure_ctrl(s, nvalue); 409 | else if (!strcmp(variable, "hmirror")) 410 | s->set_hmirror(s, nvalue); 411 | else if (!strcmp(variable, "vflip")) 412 | s->set_vflip(s, nvalue); 413 | else if (!strcmp(variable, "awb_gain")) 414 | s->set_awb_gain(s, nvalue); 415 | else if (!strcmp(variable, "agc_gain")) 416 | s->set_agc_gain(s, nvalue); 417 | else if (!strcmp(variable, "aec_value")) 418 | s->set_aec_value(s, nvalue); 419 | else if (!strcmp(variable, "aec2")) 420 | s->set_aec2(s, nvalue); 421 | else if (!strcmp(variable, "denoise")) 422 | s->set_denoise(s, nvalue); 423 | else if (!strcmp(variable, "dcw")) 424 | s->set_dcw(s, nvalue); 425 | else if (!strcmp(variable, "bpc")) 426 | s->set_bpc(s, nvalue); 427 | else if (!strcmp(variable, "wpc")) 428 | s->set_wpc(s, nvalue); 429 | else if (!strcmp(variable, "raw_gma")) 430 | s->set_raw_gma(s, nvalue); 431 | else if (!strcmp(variable, "lenc")) 432 | s->set_lenc(s, nvalue); 433 | else if (!strcmp(variable, "special_effect")) 434 | s->set_special_effect(s, nvalue); 435 | else if (!strcmp(variable, "wb_mode")) 436 | s->set_wb_mode(s, nvalue); 437 | else if (!strcmp(variable, "ae_level")) 438 | s->set_ae_level(s, nvalue); 439 | else { 440 | AddLogMessageW("skipping unknown setting:" + String(variable) + "\n"); 441 | return false; 442 | } 443 | 444 | return true; 445 | } 446 | 447 | // Restore Camera settings From SPIFFS 448 | bool Restore_CamSettings_from_SPIFFS() { 449 | // SPIFFS 450 | File file = SPIFFS.open("/ESP_CAM_SETTINGS.json", "r"); 451 | if (!file || file.isDirectory()) { 452 | log_e("- empty file or failed to open file"); 453 | return false; 454 | } 455 | static char json_response[1024]; 456 | char *p = json_response; 457 | while (file.available()) { 458 | *p++ = file.read(); 459 | if (*p > 1022) { 460 | log_e("---ERROR: file larger than 1022 char so assume the config is corrupt."); 461 | json_response[0] = '\0'; // reset content 462 | file.close(); 463 | break; 464 | } 465 | } 466 | if (Set_Cam_Settings_from_JSON(json_response)) { 467 | AddLogMessageI(F("Camera settings loaded from SPIFFS\n")); 468 | return false; 469 | } else { 470 | AddLogMessageE(F("Camera settings load failed!\n")); 471 | } 472 | return true; 473 | } 474 | 475 | // Read updated values from camsetup.htm webpage and set the Camera settings 476 | void Save_NewCAMConfig_to_SPIFFS(AsyncWebServerRequest *request) { 477 | static char json_response[1024]; 478 | char *p = json_response; 479 | *p++ = '{'; 480 | p += sprintf(p, "\"framesize\":%u,", atoi(request->arg("framesize").c_str())); 481 | //p += sprintf(p, "\"quality\":%u,", s->status.quality); 482 | p += sprintf(p, "\"brightness\":%d,", atoi(request->arg("brightness").c_str())); 483 | p += sprintf(p, "\"contrast\":%d,", atoi(request->arg("contrast").c_str())); 484 | p += sprintf(p, "\"saturation\":%d,", atoi(request->arg("saturation").c_str())); 485 | //p += sprintf(p, "\"sharpness\":%d,", s->status.sharpness); 486 | p += sprintf(p, "\"special_effect\":%u,", atoi(request->arg("special_effect").c_str())); 487 | p += sprintf(p, "\"wb_mode\":%u,", atoi(request->arg("wb_mode").c_str())); 488 | p += sprintf(p, "\"awb\":%u,", atoi(request->arg("awb").c_str())); 489 | p += sprintf(p, "\"awb_gain\":%u,", atoi(request->arg("awb_gain").c_str())); 490 | p += sprintf(p, "\"aec\":%u,", atoi(request->arg("aec").c_str())); 491 | p += sprintf(p, "\"aec2\":%u,", atoi(request->arg("aec2").c_str())); 492 | //p += sprintf(p, "\"denoise\":%u,", s->status.denoise); 493 | p += sprintf(p, "\"ae_level\":%d,", atoi(request->arg("aec2").c_str())); 494 | p += sprintf(p, "\"aec_value\":%u,", atoi(request->arg("aec_value").c_str())); 495 | p += sprintf(p, "\"agc\":%u,", atoi(request->arg("agc").c_str())); 496 | p += sprintf(p, "\"agc_gain\":%u,", atoi(request->arg("agc_gain").c_str())); 497 | p += sprintf(p, "\"gainceiling\":%u,", atoi(request->arg("gainceiling").c_str())); 498 | p += sprintf(p, "\"bpc\":%u,", atoi(request->arg("bpc").c_str())); 499 | p += sprintf(p, "\"wpc\":%u,", atoi(request->arg("wpc").c_str())); 500 | //p += sprintf(p, "\"raw_gma\":%u,", s->status.raw_gma); 501 | p += sprintf(p, "\"lenc\":%u,", atoi(request->arg("lenc").c_str())); 502 | p += sprintf(p, "\"hmirror\":%u,", atoi(request->arg("hmirror").c_str())); 503 | p += sprintf(p, "\"vflip\":%u,", atoi(request->arg("vflip").c_str())); 504 | p += sprintf(p, "\"dcw\":%u,", atoi(request->arg("dcw").c_str())); 505 | p += sprintf(p, "\"colorbar\":%u", atoi(request->arg("colorbar").c_str())); 506 | *p++ = '}'; 507 | *p++ = 0; 508 | 509 | File file = SPIFFS.open("/ESP_CAM_SETTINGS.json", "w"); 510 | String msg = F("Saving Camera Settings to SPIFF, "); 511 | if (!file) { 512 | msg += F(" failed to open file for writing\n"); 513 | AddLogMessageE(msg); 514 | return; 515 | } 516 | if (file.print(json_response)) { 517 | msg += F("- config saved\n"); 518 | AddLogMessageI(msg); 519 | } else { 520 | msg += F("- config save failed!!!!"); 521 | AddLogMessageE(msg); 522 | } 523 | file.close(); 524 | } 525 | 526 | // Update Camera settings from JSON input 527 | bool Set_Cam_Settings_from_JSON(char *JSONCamSetting) { 528 | String fileContent = JSONCamSetting; 529 | DynamicJsonDocument doc(1024); 530 | DeserializationError error = deserializeJson(doc, fileContent); 531 | if (error) { 532 | AddLogMessageE(F("Config not set: JSON Parsing failed\n")); 533 | return false; 534 | } 535 | sensor_t *s = esp_camera_sensor_get(); 536 | if (s == NULL) { 537 | AddLogMessageE(F("Config not set: Camera init failed\n")); 538 | return false; 539 | } else { 540 | //UINT 541 | GetJsonField_UpdateCam(s, doc, (char *)"framesize"); 542 | //GetJsonField_UpdateCam(s, doc, (char *)"quality"); 543 | GetJsonField_UpdateCam(s, doc, (char *)"special_effect"); 544 | GetJsonField_UpdateCam(s, doc, (char *)"wb_mode"); 545 | GetJsonField_UpdateCam(s, doc, (char *)"awb"); 546 | GetJsonField_UpdateCam(s, doc, (char *)"awb_gain"); 547 | GetJsonField_UpdateCam(s, doc, (char *)"aec"); 548 | GetJsonField_UpdateCam(s, doc, (char *)"aec2"); 549 | //GetJsonField_UpdateCam(s, doc, (char *)"denoise"); 550 | GetJsonField_UpdateCam(s, doc, (char *)"aec_value"); 551 | GetJsonField_UpdateCam(s, doc, (char *)"agc"); 552 | GetJsonField_UpdateCam(s, doc, (char *)"agc_gain"); 553 | GetJsonField_UpdateCam(s, doc, (char *)"gainceiling"); 554 | GetJsonField_UpdateCam(s, doc, (char *)"bpc"); 555 | GetJsonField_UpdateCam(s, doc, (char *)"wpc"); 556 | //GetJsonField_UpdateCam(s, doc, (char *)"raw_gma"); 557 | GetJsonField_UpdateCam(s, doc, (char *)"lenc"); 558 | GetJsonField_UpdateCam(s, doc, (char *)"hmirror"); 559 | GetJsonField_UpdateCam(s, doc, (char *)"vflip"); 560 | GetJsonField_UpdateCam(s, doc, (char *)"dcw"); 561 | GetJsonField_UpdateCam(s, doc, (char *)"colorbar"); 562 | //Double 563 | GetJsonField_UpdateCam(s, doc, (char *)"brightness"); 564 | GetJsonField_UpdateCam(s, doc, (char *)"contrast"); 565 | GetJsonField_UpdateCam(s, doc, (char *)"saturation"); 566 | //GetJsonField_UpdateCam(s, doc, (char *)"sharpness"); 567 | GetJsonField_UpdateCam(s, doc, (char *)"ae_level"); 568 | } 569 | 570 | return true; 571 | } 572 | 573 | // Read Current CAM settings from the Camera itself. 574 | char *GetCurrentCamSettings() { 575 | static char json_response[1024]; 576 | char *p = json_response; 577 | *p++ = '{'; 578 | sensor_t *s = esp_camera_sensor_get(); 579 | if (s == NULL) { 580 | AddLogMessageW(F("Could get current setting: Camera init failed\n")); 581 | p += sprintf(p, "\"Error\":\"Camera failed\""); 582 | } else { 583 | p += sprintf(p, "\"framesize\":%u,", s->status.framesize); 584 | p += sprintf(p, "\"quality\":%u,", s->status.quality); 585 | p += sprintf(p, "\"brightness\":%d,", s->status.brightness); 586 | p += sprintf(p, "\"contrast\":%d,", s->status.contrast); 587 | p += sprintf(p, "\"saturation\":%d,", s->status.saturation); 588 | p += sprintf(p, "\"sharpness\":%d,", s->status.sharpness); 589 | p += sprintf(p, "\"special_effect\":%u,", s->status.special_effect); 590 | p += sprintf(p, "\"wb_mode\":%u,", s->status.wb_mode); 591 | p += sprintf(p, "\"awb\":%u,", s->status.awb); 592 | p += sprintf(p, "\"awb_gain\":%u,", s->status.awb_gain); 593 | p += sprintf(p, "\"aec\":%u,", s->status.aec); 594 | p += sprintf(p, "\"aec2\":%u,", s->status.aec2); 595 | p += sprintf(p, "\"denoise\":%u,", s->status.denoise); 596 | p += sprintf(p, "\"ae_level\":%d,", s->status.ae_level); 597 | p += sprintf(p, "\"aec_value\":%u,", s->status.aec_value); 598 | p += sprintf(p, "\"agc\":%u,", s->status.agc); 599 | p += sprintf(p, "\"agc_gain\":%u,", s->status.agc_gain); 600 | p += sprintf(p, "\"gainceiling\":%u,", s->status.gainceiling); 601 | p += sprintf(p, "\"bpc\":%u,", s->status.bpc); 602 | p += sprintf(p, "\"wpc\":%u,", s->status.wpc); 603 | p += sprintf(p, "\"raw_gma\":%u,", s->status.raw_gma); 604 | p += sprintf(p, "\"lenc\":%u,", s->status.lenc); 605 | p += sprintf(p, "\"hmirror\":%u,", s->status.hmirror); 606 | p += sprintf(p, "\"vflip\":%u,", s->status.vflip); 607 | p += sprintf(p, "\"dcw\":%u,", s->status.dcw); 608 | p += sprintf(p, "\"colorbar\":%u", s->status.colorbar); 609 | } 610 | *p++ = '}'; 611 | *p++ = 0; 612 | return json_response; 613 | } 614 | -------------------------------------------------------------------------------- /src/WebServer.cpp: -------------------------------------------------------------------------------- 1 | // Project: ESP32-Doorbell 2 | // Programmers: Jos van der Zande 3 | // Paul Hermans 4 | // 5 | // WebServer module 6 | // Partly based on: // https://gist.github.com/me-no-dev/d34fba51a8f059ac559bf62002e61aa3 7 | // 8 | #include 9 | #include // Local WebServer used to server the configuration portal 10 | #include 11 | #include 12 | #include "ArduinoJson.h" 13 | 14 | #include "Main.h" 15 | #include "WebServer.h" 16 | #include "setup.h" 17 | #include "domoticz.h" 18 | #include "cam.h" 19 | 20 | // Define private used funcs 21 | String makePage(String title, String contents); 22 | 23 | // Define the CAMLOG size when not defined yet and make it min 15000 bytes 24 | #ifndef CAM_LOGSIZE 25 | #define CAM_LOGSIZE 15000 26 | #endif 27 | 28 | AsyncWebSocket ws("/ws"); 29 | uint LogId = 999; 30 | String LogMessage[50]; // amount of messages to log 31 | uint LogMessageIndexI = 0; 32 | uint LogMessageIndexO = 0; 33 | bool LogMessageSuccess = false; 34 | unsigned long LogMessage_Send_time; // time a logmessage was send. 35 | uint LogMessage_Send_tries = 0; // number of tries. 36 | bool LogMessage_NewLine = true; // remember wether the last line had a \n 37 | 38 | String tfile; // target SPIFFS file 39 | File hfile; // target SPIFFS file handle 40 | bool EspConfig = false; // target SPIFFS file config? 41 | bool CamConfig = false; // target SPIFFS file config? 42 | bool tbin = false; // target bin file? 43 | 44 | bool _webAuth(AsyncWebServerRequest *request) { 45 | /* 46 | // Print header for debugging 47 | Serial.printf("url:%s Headers: %s:\n", request->url().c_str(), String(request->headers()).c_str()); 48 | for (uint i = 0; i < request->headers(); i++) 49 | { 50 | Serial.printf(" %i %s=%s\n", i, request->headerName(i).c_str(), request->header(i).c_str()); 51 | } 52 | // 53 | */ 54 | if (!request->authenticate(esp_uname, esp_pass, NULL, false)) { 55 | request->requestAuthentication(NULL, false); // force basic auth 56 | return false; 57 | } 58 | return true; 59 | } 60 | 61 | void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) { 62 | if (type == WS_EVT_CONNECT) { 63 | // close previous session first 64 | if (LogId != 999) 65 | client->close(LogId); 66 | 67 | LogId = client->id(); 68 | LogMessageSuccess = true; 69 | // set Output to current last input message as we add 1 when confirmed 70 | LogMessageIndexO = LogMessageIndexI + 1; 71 | // find first none empty message record 72 | for (uint i = LogMessageIndexI; i < 50; i++) { 73 | if (LogMessage[LogMessageIndexO] != "") 74 | break; 75 | LogMessageIndexO++; 76 | if (LogMessageIndexO > 49) 77 | LogMessageIndexO = 0; 78 | } 79 | log_d("Websocket client connection received %i start sending messages: %i", LogId, LogMessageIndexO); 80 | } else if (type == WS_EVT_DISCONNECT) { 81 | log_d("Client disconnected"); 82 | LogId = 999; 83 | } else if (type == WS_EVT_ERROR) { 84 | //error was received from the other end 85 | //Serial.printf("ws[%s][%u] error(%u): %s\n", server->url(), client->id(), *((uint16_t *)arg), (char *)data); 86 | } else if (type == WS_EVT_PONG) { 87 | //pong message was received (in response to a ping request maybe) 88 | //Serial.printf("ws[%s][%u] pong[%u]: %s\n", server->url(), client->id(), len, (len) ? (char *)data : ""); 89 | } else if (type == WS_EVT_DATA) { 90 | //data packet 91 | AwsFrameInfo *info = (AwsFrameInfo *)arg; 92 | if (info->final && info->index == 0 && info->len == len) { 93 | //the whole message is in a single frame and we got all of it's data 94 | //Serial.printf("ws[%s][%u] %s-message[%llu]: ", server->url(), client->id(), (info->opcode == WS_TEXT) ? "text" : "binary", info->len); 95 | if (info->opcode == WS_TEXT) { 96 | data[len] = 0; 97 | //Serial.printf("%s\n", (char *)data); 98 | if (strcmp((char *)data, "ok") == 0) { 99 | // log message confirmed received so reset the array entry and set indeex to next 100 | //log_d("Ok msg:%i", LogMessageIndexO); 101 | LogMessageSuccess = true; 102 | LogMessageIndexO++; 103 | } 104 | } 105 | } 106 | } 107 | } 108 | 109 | // Define all specific webpages to service by the ESP 110 | void WebServerInit(AsyncWebServer *webserver) { 111 | // WebSockets 112 | ws.onEvent(onWsEvent); 113 | webserver->addHandler(&ws); 114 | 115 | // Define all weboptions with TEMPLATE variables or specific functions 116 | webserver->on("/", HTTP_GET, ESPShowPagewithTemplate); 117 | webserver->on("/index.html", HTTP_GET, ESPShowPagewithTemplate); 118 | webserver->on("/info", HTTP_GET, ESPShowPagewithTemplate); 119 | webserver->on("/logger", HTTP_GET, ESPShowPagewithTemplate); 120 | webserver->on("/setup", HTTP_GET, ESPShowPagewithTemplate); 121 | webserver->on("/camsetup", HTTP_GET, ESPShowPagewithTemplate); 122 | webserver->on("/configupdrequest", HTTP_GET, ESPShowPagewithTemplate); 123 | webserver->on("/wiki", HTTP_GET, ESPShowPagewithTemplate); 124 | webserver->on("/wificlear", HTTP_GET, ESPShowPagewithTemplate); 125 | webserver->on("/reboot", HTTP_GET, ESPShowPagewithTemplate); 126 | webserver->on("/logout", HTTP_GET, ESPShowPagewithTemplate); 127 | 128 | // special pages/functions 129 | webserver->on("/message", HTTP_GET, Web_messageReceived); // Receive command via HTTP 130 | webserver->on("/savesettings", HTTP_GET, ESPSaveSettings); // Save ESP settings to Spiffs 131 | webserver->on("/applycamsettings", HTTP_GET, ApplyCamSettings); // Apply Camera settings to Camera and Save to SPIFFS 132 | webserver->on("/logclean", HTTP_GET, LogClean); // remove Spiffs logs and clean message array 133 | webserver->on("/logdump", HTTP_GET, LogDump); // dump spiffs logs 134 | webserver->on("/configdump", HTTP_GET, ConfigDump); // Dump ESPCAM Saved configuration 135 | webserver->on("/configcamdump", HTTP_GET, ConfigCamDump); // Dump Camera Saved Settings Configuration 136 | webserver->on("/configcamcurrent", HTTP_GET, ConfigCamCurrent); // Dump Camera current Settings Configuration 137 | webserver->on( 138 | "/ConfigFileUploads", HTTP_POST, [](AsyncWebServerRequest *request) { request->send(200); }, ConfigFileUploads); 139 | 140 | // Cam links 141 | webserver->on("/capture", HTTP_GET, sendJpg); 142 | webserver->on("/stream", HTTP_GET, streamJpg); 143 | 144 | // serving other static information from SPIFFS 145 | webserver->serveStatic("/", SPIFFS, "/www/"); 146 | // .setAuthentication(esp_uname, esp_pass); 147 | 148 | // process invalid requests 149 | webserver->onNotFound(WrongPage); 150 | // Start Webserver 151 | webserver->begin(); 152 | 153 | AddLogMessageI(F("Webserver started\n")); 154 | } 155 | 156 | // ---------------------------------------------------------------------------------------------------------------- 157 | // ------ General Webfunctions ----------------------------------------------------------------------------------- 158 | // ---------------------------------------------------------------------------------------------------------------- 159 | 160 | void WrongPage(AsyncWebServerRequest *request) { 161 | //Serial.print(request->url()); 162 | //Serial.println(F(" -> invalid request")); 163 | String s = F("

"); 164 | s += esp_name; 165 | s += F("

Wrong request

"); 166 | s += F("

Home

"); 167 | request->send(500, "text/html", makePage(esp_name, s)); 168 | } 169 | 170 | void ESPShowPagewithTemplate(AsyncWebServerRequest *request) { 171 | if (!_webAuth(request)) 172 | return; 173 | String page = request->url(); 174 | String msg; 175 | msg = F("Webrequest: \""); 176 | msg += page; 177 | msg += "\""; 178 | 179 | if (page == "/" || page == "/index.html") { 180 | page = "/www/index.htm"; 181 | } else if (page == "/wificlear") { 182 | String msg = F("Webrequest: \"ESP wifi clearing\"\n"); 183 | AddLogMessageI(msg); 184 | String s = F(""); 185 | s += F("ESP will clear wifi credentials and reboot now.
"); 186 | s += F("Search for wifi-ssid \"ESP-Doorbell\" and run the wifi-manager, to connect again.
"); 187 | request->send(200, "text/html", makePage(esp_name, s)); 188 | WiFi.disconnect(true,true); 189 | reboot = true; 190 | rebootdelay = millis(); 191 | } else if (page == "/reboot") { 192 | String msg = F("Webrequest: \"Reboot ESP\"\n"); 193 | AddLogMessageI(msg); 194 | reboot = true; 195 | rebootdelay = millis(); 196 | String s = F(""); 197 | s += F("ESP will reboot now.
"); 198 | request->send(200, "text/html", makePage(esp_name, s)); 199 | } else if (page == "/logout") { 200 | String s = F("Logout done."); 201 | request->send(401, "text/html", makePage(esp_name, s)); 202 | msg += F("Logout done\n"); 203 | AddLogMessageD(msg); 204 | return; 205 | } else if (page == "/info" && strcmp(esp_board,"none") == 0) { 206 | // force setup page when ESP_board type isn't selected yet. 207 | page = "/www/setup.htm"; 208 | } else { 209 | page = "/www" + page + ".htm"; 210 | } 211 | 212 | msg += F(" -> "); 213 | msg += page; 214 | if (SPIFFS.exists(page)) { 215 | request->send(SPIFFS, page.c_str(), String(), false, TranslateTemplateVars); 216 | } else { 217 | msg += F(" file missing so show bin upload!"); 218 | String s = F("

"); 219 | s += esp_name; 220 | s += F("
File missing in SPIFFS:"); 221 | s += page; 222 | s += F(".


Please upload the correct version of spiffs.bin or this file.

"); 223 | s += F("
"); 224 | s += F("
"); 225 | request->send(200, "text/html", makePage(esp_name, s)); 226 | } 227 | msg += F("\n"); 228 | AddLogMessageI(msg); 229 | } 230 | 231 | void Web_messageReceived(AsyncWebServerRequest *request) { 232 | String s = ""; 233 | String webcmd = urlDecode(request->arg("command")); 234 | if (webcmd != "") 235 | s += process_messageReceived(webcmd); 236 | else { 237 | String msg = F("Webrequest: \"/message\" -> \"?command=\" not provided or empty.\n"); 238 | AddLogMessageW(msg); 239 | s = F("\"?command=\" not provided or empty."); 240 | } 241 | request->send(200, "text/html", s); 242 | } 243 | 244 | void ESPSaveSettings(AsyncWebServerRequest *request) { 245 | String msg = F("Webrequest: \"save ESP Settings \" \n"); 246 | AddLogMessageI(msg); 247 | // reboot to load new CONFIG 248 | Save_NewESPConfig_to_SPIFFS(request); 249 | reboot = true; 250 | rebootdelay = millis(); // give 2 extra seconds to save config 251 | String s = F(""); 252 | s += F("Config saved.
"); 253 | s += F("ESP will reboot now.
"); 254 | request->send(200, "text/html", makePage(esp_name, s)); 255 | } 256 | 257 | void ApplyCamSettings(AsyncWebServerRequest *request) { 258 | String msg = F("Webrequest: \"/Applycamsetting\" ->"); 259 | // get WebForm data back in a JSON format for easy updating of settings 260 | String s = F(""); 261 | // Save to SPIFFS 262 | Save_NewCAMConfig_to_SPIFFS(request); 263 | // And activate new settings 264 | Restore_CamSettings_from_SPIFFS(); 265 | request->send(200, "text/html", makePage(esp_name, s)); 266 | } 267 | 268 | void ConfigDump(AsyncWebServerRequest *request) { 269 | if (!_webAuth(request)) 270 | return; 271 | String msg = F("Webrequest: \"/configdump\" \n"); 272 | AddLogMessageI(msg); 273 | request->send(SPIFFS, "/ESP_CAM_CONFIG.json", String(), true); 274 | } 275 | 276 | void ConfigCamDump(AsyncWebServerRequest *request) { 277 | if (!_webAuth(request)) 278 | return; 279 | String msg = F("Webrequest: \"/configcamdump\" \n"); 280 | AddLogMessageI(msg); 281 | request->send(SPIFFS, "/ESP_CAM_SETTINGS.json", String(), true); 282 | } 283 | 284 | void ConfigCamCurrent(AsyncWebServerRequest *request) { 285 | if (!_webAuth(request)) 286 | return; 287 | char *json_response = GetCurrentCamSettings(); 288 | String msg = F("Webrequest: \"/configcamcurrent\" \n"); 289 | AddLogMessageI(msg); 290 | 291 | AsyncResponseStream *response = request->beginResponseStream("text/html"); 292 | response->addHeader("Content-Disposition", "attachment; filename=\"cam.log\""); 293 | response->print(json_response); 294 | // Start download of the current Cam Config 295 | request->send(response); 296 | } 297 | 298 | void LogClean(AsyncWebServerRequest *request) { 299 | String msg = F("Webrequest: \"/LogClean\" ->"); 300 | // get WebForm data back in a JSON format for easy updating of settings 301 | String s = F(""); 302 | // Clean message array 303 | for (uint i = 0; i < 50; i++) { 304 | LogMessage[i] = ""; 305 | } 306 | LogMessageIndexI = 0; 307 | LogMessageIndexO = 999; 308 | LogMessage_NewLine = true; 309 | AddLogMessageI("Start clean logs\n"); 310 | s += "Delete Logfiles: "; 311 | if (SPIFFS.exists("/camprev.log")) 312 | if (SPIFFS.remove("/camprev.log")) 313 | msg += F("camprev.log removed"); 314 | else 315 | msg += F("camprev.log remove failed"); 316 | else 317 | msg += F("camprev.log not there"); 318 | msg += F(", "); 319 | if (SPIFFS.exists("/cam.log")) 320 | if (SPIFFS.remove("/cam.log")) 321 | msg += F("cam.log removed"); 322 | else 323 | msg += F("cam.log remove failed"); 324 | else 325 | msg += F("cam.log not there"); 326 | msg += F("\n"); 327 | AddLogMessageI(msg); 328 | s += msg; 329 | request->send(200, "text/html", makePage(esp_name, s)); 330 | } 331 | 332 | void LogDump(AsyncWebServerRequest *request) { 333 | if (!_webAuth(request)) 334 | return; 335 | String msg = F("Webrequest: \"/logdump\" \n"); 336 | // First dump the previous cam.log 337 | File ofile = SPIFFS.open("/espcam.log", "w"); 338 | File file = SPIFFS.open("/camprev.log", "r"); 339 | if (file || !file.isDirectory()) { 340 | if (file.size() > CAM_LOGSIZE + 500) { 341 | msg += F("---ERROR: camprev.log larger than CAM_LOGSIZE, so assume it is corrupt."); 342 | msg += file.size(); 343 | msg += "\n"; 344 | file.close(); 345 | } else { 346 | while (file.available()) { 347 | ofile.write((char)file.read()); 348 | } 349 | } 350 | file.close(); 351 | } 352 | Serial.println("Start cam.log"); 353 | Serial.flush(); 354 | file = SPIFFS.open("/cam.log", "r"); 355 | if (file || !file.isDirectory()) { 356 | Serial.printf("Size cam.log %i\n", file.size()); 357 | if (file.size() > CAM_LOGSIZE + 500) { 358 | msg += F("---ERROR: cam.log larger than CAM_LOGSIZE, so assume it is corrupt."); 359 | msg += file.size(); 360 | msg += "\n"; 361 | file.close(); 362 | } else { 363 | while (file.available()) { 364 | ofile.write((char)file.read()); 365 | } 366 | } 367 | file.close(); 368 | ofile.close(); 369 | } 370 | Serial.println("Done"); 371 | // Then dump the current cam.log 372 | AddLogMessageI(msg); 373 | request->send(SPIFFS, "/espcam.log", String(), true); 374 | } 375 | 376 | void ConfigFileUploads(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final) { 377 | String msg = F("Webrequest: \"/configfileuploads\" "); 378 | if (!_webAuth(request)) 379 | return; 380 | if (!index) { 381 | msg += F("Load file start: "); 382 | if (filename.indexOf(".bin") > 0) { 383 | tbin = true; 384 | // if filename includes spiffs, update the spiffs partition 385 | msg += F(" BIN: "); 386 | msg += filename; 387 | int cmd = (filename.indexOf("spiffs") > -1) ? U_SPIFFS : U_FLASH; 388 | 389 | if (!Update.begin(UPDATE_SIZE_UNKNOWN, cmd)) { 390 | Update.printError(Serial); 391 | } 392 | } else { 393 | if (filename.indexOf(".htm") > 0) { 394 | tfile = "/www/" + filename; 395 | msg += F(" HTM: "); 396 | } else if (filename.indexOf(".css") > 0) { 397 | tfile = "/www/css/" + filename; 398 | msg += F(" CSS: "); 399 | } else if ((filename.indexOf(".jpg") > 0) || (filename.indexOf(".png") > 0)) { 400 | tfile = "/www/src/" + filename; 401 | msg += F(" IMAGE: "); 402 | } else if (filename.indexOf(".js") > 0 && filename.indexOf(".json") < 0) { 403 | tfile = "/www/js/" + filename; 404 | msg += F(" JS: "); 405 | } else if (filename == "favicon.ico") { 406 | tfile = "/www/favicon.ico"; 407 | msg += F("favicon.ico: "); 408 | } else if (filename.indexOf("CAM_CONFIG.json") > 0) { 409 | tfile = "/ESP_CAM_CONFIG.json"; 410 | msg += F("ESP-JSON: "); 411 | EspConfig = true; 412 | } else if (filename.indexOf("CAM_SETTINGS.json") > 0) { 413 | tfile = "/ESP_CAM_SETTINGS.json"; 414 | msg += F("CAM-JSON: "); 415 | CamConfig = true; 416 | } 417 | msg += filename; 418 | msg += " -> "; 419 | msg += tfile; 420 | msg += " :"; 421 | // Write received data to config file 422 | hfile = SPIFFS.open(tfile, "w"); 423 | if (!hfile) { 424 | msg += "failed to open file for writing\n"; 425 | AddLogMessageI(msg); 426 | return; 427 | } 428 | } 429 | } 430 | if (tbin) { 431 | // Write the BIN datablocks 432 | if (Update.write(data, len) != len) { 433 | Update.printError(Serial); 434 | } 435 | } else { 436 | // Write the SPIFFS FILE datablocks 437 | for (size_t i = 0; i < len; i++) { 438 | hfile.write(data[i]); 439 | } 440 | } 441 | if (final) { 442 | String s = F(""); 453 | s += (tbin ? F("New bin is loaded.
") : F("New config is loaded.
")); 454 | s += F("The ESPCAM will now reboot to activate the update."); 455 | msg += F("Finished updating file"); 456 | msg += F(" -> will reboot now."); 457 | } else { 458 | hfile.close(); 459 | s += F("\"/\";}, 1000);"); 460 | s += tfile; 461 | s += F(" Updated.
"); 462 | msg += F("Finished updating file:"); 463 | msg += tfile; 464 | } 465 | msg += "\n"; 466 | AddLogMessageI(msg); 467 | // reboot only when BIN or CAM CONFIG is loaded 468 | if (tbin || EspConfig) { 469 | // reboot to load new BIN 470 | reboot = true; 471 | rebootdelay = millis(); 472 | request->send(200, "text/html", makePage(esp_name, s)); 473 | } 474 | // Don't send a response to allow for multiple uploads 475 | //request->send(200, "text/html", makePage(esp_name, s)); 476 | // Restore settings from SPIFFS when new file is loaded. 477 | if (CamConfig) { 478 | Restore_CamSettings_from_SPIFFS(); 479 | } 480 | } 481 | } 482 | 483 | // ---------------------------------------------------------------------------------------------------------------- 484 | // ------ Helper functions --------------------------------------------------------------------------------------- 485 | // ---------------------------------------------------------------------------------------------------------------- 486 | // Add log message to queue 487 | 488 | void AddLogMessage(String msg, String Module, String Function, String Severity, int Line) { 489 | if (msg == "") 490 | return; 491 | // Get current local time 492 | char logprefix[20]; 493 | if (LogMessage_NewLine) { 494 | struct tm timeinfo; 495 | strcpy(logprefix,("[" + Severity + "]").c_str()); 496 | if (getLocalTime(&timeinfo, 100)) { 497 | char logtime[18]; 498 | strftime(logtime, 20, " %m/%d %H:%M:%S", &timeinfo); 499 | strcat(logprefix,logtime); 500 | } 501 | } 502 | /* 503 | #define ARDUHAL_LOG_LEVEL_NONE (0) 504 | #define ARDUHAL_LOG_LEVEL_ERROR (1) 505 | #define ARDUHAL_LOG_LEVEL_WARN (2) 506 | #define ARDUHAL_LOG_LEVEL_INFO (3) 507 | #define ARDUHAL_LOG_LEVEL_DEBUG (4) 508 | #define ARDUHAL_LOG_LEVEL_VERBOSE (5) 509 | */ 510 | if ((Severity == "E" && CORE_DEBUG_LEVEL > 0) || 511 | (Severity == "W" && CORE_DEBUG_LEVEL > 1) || 512 | (Severity == "I" && CORE_DEBUG_LEVEL > 2) || 513 | (Severity == "D" && CORE_DEBUG_LEVEL > 3) || 514 | (Severity == "V" && CORE_DEBUG_LEVEL > 4)) { 515 | Module.replace("src\\", ""); // initial directory src to make it look like the standard log_i() function 516 | // print the actual line to Serial 517 | if (LogMessage_NewLine) 518 | //Serial.printf("[%s][%s:%i] %s(): %s", Severity.c_str(), Module.c_str(), Line, Function.c_str(), msg.c_str()); 519 | Serial.printf("%s [%s:%i] %s(): %s", logprefix, Module.c_str(), Line, Function.c_str(), msg.c_str()); 520 | else 521 | Serial.print(msg); 522 | } 523 | 524 | // Set bool to know whether we need to add the Time to the next line 525 | LogMessage_NewLine = false; 526 | if (msg.indexOf("\n") > 0) 527 | LogMessage_NewLine = true; 528 | // Also log to SPIFFS 529 | File hlogfile = SPIFFS.open("/cam.log", FILE_APPEND); 530 | if (!hlogfile) { 531 | log_e("Error opening cam.log"); 532 | } else { 533 | if (hlogfile.print(String(logprefix) + ' ' + msg)) { 534 | //Serial.println("File was written"); 535 | } else { 536 | log_e("cam.log write failed"); 537 | } 538 | // cycle logfile when greater than define size 539 | if (hlogfile.size() > CAM_LOGSIZE) { 540 | hlogfile.close(); 541 | SPIFFS.remove("/camprev.log"); 542 | SPIFFS.rename("/cam.log", "/camprev.log"); 543 | AddLogMessageI("Start new cam.log.\n"); 544 | } 545 | hlogfile.close(); 546 | } 547 | // Add message to queue when level is requested 548 | if ((Severity == "E" && webloglevel > 0) || 549 | (Severity == "W" && webloglevel > 1) || 550 | (Severity == "I" && webloglevel > 2) || 551 | (Severity == "D" && webloglevel > 3) || 552 | (Severity == "V" && webloglevel > 4)) { 553 | //Serial.printf("Queued: %s : %i %s", Severity.c_str(), webloglevel, msg.c_str()); 554 | LogMessage[LogMessageIndexI] = String(logprefix) + ' ' + msg; 555 | // Set pointer to next message row 556 | LogMessageIndexI++; 557 | if (LogMessageIndexI > 49) 558 | LogMessageIndexI = 0; 559 | } 560 | //else 561 | //Serial.printf("NOT Queued: %s : %i %s", Severity.c_str(), webloglevel, msg.c_str()); 562 | } 563 | 564 | // Send next message from queue 565 | void SendNextLogMessage() { 566 | // Check if session is active 567 | if (LogId == 999) 568 | return; 569 | // Check if Last message is confirmed 570 | if (LogMessageSuccess) { 571 | //Serial.printf("-s %i / %i\n", LogMessageIndexI, LogMessageIndexO); 572 | if (LogMessageIndexO > 49) 573 | LogMessageIndexO = 0; 574 | 575 | //Serial.printf("check for send next message:%i",LogMessageIndexO); 576 | if (LogMessageIndexO == LogMessageIndexI) 577 | return; 578 | 579 | String tmp = LogMessage[LogMessageIndexO]; 580 | tmp.replace("\n", ""); // remove ending Newline 581 | //log_d("send next message:%i - %s", LogMessageIndexO, tmp.c_str()); 582 | LogMessageSuccess = false; 583 | ws.text(LogId, LogMessage[LogMessageIndexO]); 584 | LogMessage_Send_time = millis(); 585 | LogMessage_Send_tries = 1; 586 | } else { 587 | // Close socket when 5 tries failed 588 | if (LogMessage_Send_tries >= 5) { 589 | log_e("Websocket client connection closed after 5 retries: %i\n", LogId); 590 | ws.close(LogId); 591 | LogId = 999; 592 | } 593 | // retry 4 times in case no confirm was received, else assume de client sn't there anymore. 594 | else if (LogMessage_Send_time > millis() + 1000) { 595 | ws.text(LogId, LogMessage[LogMessageIndexO]); 596 | LogMessage_Send_time = millis(); 597 | LogMessage_Send_tries++; 598 | } 599 | } 600 | } 601 | 602 | String makePage(String title, String contents) { 603 | String s = F("\n"); 604 | 605 | s += F(""); 606 | s += F(""); 607 | s += title; 608 | s += F("\n"); 609 | s += contents; 610 | s += F("\n\n"); 611 | return s; 612 | } 613 | 614 | String urlDecode(String input) { 615 | String s = input; 616 | 617 | s.replace("%20", " "); 618 | s.replace("+", " "); 619 | s.replace("%21", "!"); 620 | s.replace("%22", "\""); 621 | s.replace("%23", "#"); 622 | s.replace("%24", "$"); 623 | s.replace("%25", "%"); 624 | s.replace("%26", "&"); 625 | s.replace("%27", "\'"); 626 | s.replace("%28", "("); 627 | s.replace("%29", ")"); 628 | s.replace("%30", "*"); 629 | s.replace("%31", "+"); 630 | s.replace("%2C", ","); 631 | s.replace("%2E", "."); 632 | s.replace("%2F", "/"); 633 | s.replace("%2C", ","); 634 | s.replace("%3A", ":"); 635 | s.replace("%3A", ";"); 636 | s.replace("%3C", "<"); 637 | s.replace("%3D", "="); 638 | s.replace("%3E", ">"); 639 | s.replace("%3F", "?"); 640 | s.replace("%40", "@"); 641 | s.replace("%5B", "["); 642 | s.replace("%5C", "\\"); 643 | s.replace("%5D", "]"); 644 | s.replace("%5E", "^"); 645 | s.replace("%5F", "-"); 646 | s.replace("%60", "`"); 647 | 648 | // int str_len = s.length() + 1; 649 | // char char_array[str_len]; 650 | // s.toCharArray(char_array, str_len); 651 | return s; 652 | } 653 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------