28 |
29 |
30 |
31 |
32 | # :notebook_with_decorative_cover: Table of Contents
33 |
34 | - [About the Project](#star2-about-the-project)
35 | * [Pictures](#camera-Pictures)
36 | * [Features](#dart-features)
37 | - [Getting Started](#toolbox-getting-started)
38 | * [Schematic](#electric_plug-Schematic)
39 | * [Installation](#gear-installation)
40 | - [Usage](#eyes-usage)
41 | - [Contributing](#wave-contributing)
42 | - [License](#warning-license)
43 | - [Contact](#handshake-contact)
44 |
45 |
46 |
47 |
48 | ## :star2: About the Project
49 | In the this tutorials of the ESP32-CAM series, we saw that using the original code, we will be able to process face image from face recognition to face separation, but in cases where we need to recognize different objects, different models must be introduced to our code. To be able to identify the objects we want with self-learning. But no matter how high the processing power of ESP chips, we can not leave all this complex processing to this small chip, so we will use Tensorflow.JS to combine it with the video sent from ESP32-CAM. Note that in this tutorial, Tensorflow.JS runs in the computer browser and therefore the machine learning model runs inside your browser.
50 |
51 |
52 | ### :camera: Pictures
53 |
54 |
55 |
56 |
57 |
58 |
59 | ### :dart: Features
60 |
61 | - Selection of the desired objects in the web server
62 | - Real-time object detection
63 | - No need to run the second code on the computer
64 |
65 |
66 | ## :toolbox: Getting Started
67 |
68 | In this project, by streaming images using the ESP32-CAM board and receiving and displaying them in the browser, we will also use Tensorflow.JS to process images using the default models applied.
69 |
70 | - ESP32-CAM
71 | - USB-To-TTL
72 |
73 |
74 | ### :electric_plug: Schematic
75 |
76 | To program the ESP-CAM board, we need Arduino-IDE software, and of course, download the relevant board in the software environment, as well as install the required libraries. For information on these cases, you can refer to this tutorial. Make the connections according to the schematic below according to the USB TO TTL used. Note that when programming code, ie after compiling the code, the two pins GPIO 0 and GND are connected to each other, and after successfully compiling the code, you must disconnect this connection to run the project.
77 |
78 | Make the connections according to the table and schematic below.
79 |
80 | | ESP32CAM | USB-To-TTL |
81 | | ---- | -----|
82 | | U0T | RXD |
83 | | U0R | TXD |
84 | | 5v | VCC |
85 | | GND | GND |
86 |
87 |
88 | * Complete Schematic
89 |
90 |
91 |
92 |
93 |
94 | ### :gear: Installation
95 |
96 | In this part of the action code, we will introduce Tensorflow.js to analyze the received images in the browser. In the next line, we will also import COCO-SSD models along with Tensorflow.js.
97 | ```c++
98 |
99 |
100 |
101 | ```
102 |
103 | In the next section, we will load the introduced models so that they can be recognized as a result of processing the received image for our machine.
104 | ```c++
105 | function ObjectDetect() {
106 | result.innerHTML = "Please wait for loading model.";
107 | cocoSsd.load().then(cocoSsd_Model => {
108 | Model = cocoSsd_Model;
109 | result.innerHTML = "";
110 | getStill.style.display = "block";
111 | });
112 | }
113 | ```
114 |
115 | After our machine detects an object in the image, it should now be visible to the user in the form that squares around the detected image are usually used in image processing, the following code is for this.
116 | ```c++
117 | if (Predictions.length>0) {
118 | result.innerHTML = "";
119 | for (var i=0;i
138 | ## :eyes: Usage
139 |
140 | After uploading the desired code, I reset the board in the serial ip of the web server will be displayed for us, such as 192.168.1.103, which we will search for in the browser to enter the web server page, we have to wait for a while until Load the related models, then click on the StartDetect icon to display the images and recognize the defined items. Also, if there is a problem with the image processing or other parts, click on the Restart option.
141 |
142 |
143 |
144 | - In the web server, it is possible to count it by specifying the desired item. By selecting the desired object, the number of detected items will be displayed in front of it.
145 |
146 |
147 | - In this section you adjust the output video settings. For example, it is possible to change the resolution or mirror the image in this section.
148 |
149 |
150 | - In this section, the contrast, quality and brightness of the received image can be adjusted.
151 |
152 |
153 | - If the object is detected, its name will be displayed in this section, and also the percentage of probability that our machine analysis is correct, as well as the coordinates and number of detected objects can be displayed in this section.
154 |
155 |
156 | - Finally, we have the received image, which will inform the user if he detects an object with a square and also enters its name.
157 |
158 |
159 |
160 |
161 |
162 | ## :wave: Contributing
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 | ## :warning: License
171 |
172 | Distributed under the MIT License. See LICENSE.txt for more information.
173 |
174 |
175 |
176 | ## :handshake: Contact
177 |
178 | CiferTech - [@twitter](https://twitter.com/cifertech1) - CiferTech@gmali.com
179 |
180 | Project Link: [https://github.com/cifertech/ObjectDetection_ESP32cam](https://github.com/cifertech/ObjectDetection_ESP32cam)
181 |
--------------------------------------------------------------------------------
/ObjectDetection_ESP32cam/CppProperties.json:
--------------------------------------------------------------------------------
1 | {
2 | "configurations": [
3 | {
4 | "name": "Visual Micro",
5 | "intelliSenseMode": "windows-msvc-x86",
6 | "includePath": [
7 | "${projectRoot}..\\ObjectDetection_ESP32cam",
8 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\libraries\\WiFi\\src",
9 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\libraries\\WiFiClientSecure\\src",
10 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\cores\\esp32",
11 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\cores\\esp32\\apps",
12 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\cores\\esp32\\libb64",
13 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\variants\\esp32",
14 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\config",
15 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\app_trace",
16 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\app_update",
17 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\asio",
18 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\bootloader_support",
19 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\bt",
20 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\coap",
21 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\console",
22 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\driver",
23 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\efuse",
24 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\esp-tls",
25 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\esp32",
26 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\esp_adc_cal",
27 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\esp_event",
28 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\esp_http_client",
29 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\esp_http_server",
30 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\esp_https_ota",
31 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\esp_https_server",
32 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\esp_ringbuf",
33 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\esp_websocket_client",
34 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\espcoredump",
35 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\ethernet",
36 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\expat",
37 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\fatfs",
38 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\freemodbus",
39 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\freertos",
40 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\heap",
41 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\idf_test",
42 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\jsmn",
43 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\json",
44 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\libsodium",
45 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\log",
46 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\lwip",
47 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\mbedtls",
48 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\mdns",
49 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\micro-ecc",
50 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\mqtt",
51 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\newlib",
52 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\nghttp",
53 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\nimble",
54 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\nvs_flash",
55 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\openssl",
56 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\protobuf-c",
57 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\protocomm",
58 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\pthread",
59 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\sdmmc",
60 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\smartconfig_ack",
61 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\soc",
62 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\spi_flash",
63 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\spiffs",
64 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\tcp_transport",
65 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\tcpip_adapter",
66 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\ulp",
67 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\unity",
68 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\vfs",
69 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\wear_levelling",
70 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\wifi_provisioning",
71 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\wpa_supplicant",
72 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\xtensa-debug-module",
73 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\esp-face",
74 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\esp32-camera",
75 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include\\fb_gfx",
76 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\tools\\xtensa-esp32-elf-gcc\\1.22.0-97-gc752ad5-5.2.0\\lib\\gcc\\xtensa-esp32-elf\\5.2.0\\include",
77 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\tools\\xtensa-esp32-elf-gcc\\1.22.0-97-gc752ad5-5.2.0\\xtensa-esp32-elf\\include\\c++\\5.2.0\\xtensa-esp32-elf",
78 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\tools\\xtensa-esp32-elf-gcc\\1.22.0-97-gc752ad5-5.2.0\\xtensa-esp32-elf\\include",
79 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\tools\\xtensa-esp32-elf-gcc\\1.22.0-97-gc752ad5-5.2.0\\xtensa-esp32-elf\\include\\c++\\5.2.0",
80 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\tools\\xtensa-esp32-elf-gcc\\1.22.0-97-gc752ad5-5.2.0\\include\\c++\\5.2.0",
81 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\tools\\xtensa-esp32-elf-gcc\\1.22.0-97-gc752ad5-5.2.0\\include",
82 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp8266\\tools\\xtensa-lx106-elf-gcc\\2.5.0-4-b40a506\\xtensa-lx106-elf\\include\\c++\\4.8.2",
83 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp8266\\tools\\xtensa-lx106-elf-gcc\\2.5.0-4-b40a506\\xtensa-lx106-elf\\include\\c++\\4.8.2\\xtensa-lx106-elf",
84 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp8266\\tools\\xtensa-lx106-elf-gcc\\2.5.0-4-b40a506\\xtensa-lx106-elf\\include",
85 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp8266\\tools\\xtensa-lx106-elf-gcc\\2.5.0-4-b40a506\\lib\\gcc\\xtensa-lx106-elf\\4.8.2\\include",
86 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\hardware\\esp32\\1.0.5\\tools\\sdk\\include",
87 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\tools\\xtensa-esp32-elf-gcc\\1.22.0-97-gc752ad5-5.2.0\\lib\\gcc\\xtensa-esp32-elf\\5.2.0\\new",
88 | "${projectRoot}..\\..\\..\\AppData\\Local\\arduino15\\packages\\esp32\\tools\\xtensa-esp32-elf-gcc\\1.22.0-97-gc752ad5-5.2.0\\lib\\gcc\\xtensa-esp32-elf\\5.2.0\\bits"
89 | ],
90 | "defines": [
91 | "__ESP32_esp32__",
92 | "__ESP32_ESP32__",
93 | "ESP_PLATFORM",
94 | "HAVE_CONFIG_H",
95 | "GCC_NOT_5_2_0=0",
96 | "WITH_POSIX",
97 | "F_CPU=240000000L",
98 | "ARDUINO=108013",
99 | "ARDUINO_ESP32_DEV",
100 | "ARDUINO_ARCH_ESP32",
101 | "ESP32",
102 | "CORE_DEBUG_LEVEL=0",
103 | "BOARD_HAS_PSRAM",
104 | "__cplusplus=201103L",
105 | "_VMICRO_INTELLISENSE"
106 | ]
107 | }
108 | ]
109 | }
--------------------------------------------------------------------------------
/ObjectDetection_ESP32cam/ObjectDetection_ESP32cam.ino:
--------------------------------------------------------------------------------
1 | const char* ssid = "CiferTech";
2 | const char* password = "1234567891";
3 |
4 | const char* apssid = "ESP32-CAM";
5 | const char* appassword = "12345678";
6 |
7 | #include
8 | #include
9 | #include "esp_camera.h"
10 | #include "soc/soc.h"
11 | #include "soc/rtc_cntl_reg.h"
12 |
13 | String Feedback="";
14 |
15 | String Command="",cmd="",P1="",P2="",P3="",P4="",P5="",P6="",P7="",P8="",P9="";
16 |
17 | byte ReceiveState=0,cmdState=1,strState=1,questionstate=0,equalstate=0,semicolonstate=0;
18 |
19 |
20 | #define PWDN_GPIO_NUM 32
21 | #define RESET_GPIO_NUM -1
22 | #define XCLK_GPIO_NUM 0
23 | #define SIOD_GPIO_NUM 26
24 | #define SIOC_GPIO_NUM 27
25 |
26 | #define Y9_GPIO_NUM 35
27 | #define Y8_GPIO_NUM 34
28 | #define Y7_GPIO_NUM 39
29 | #define Y6_GPIO_NUM 36
30 | #define Y5_GPIO_NUM 21
31 | #define Y4_GPIO_NUM 19
32 | #define Y3_GPIO_NUM 18
33 | #define Y2_GPIO_NUM 5
34 | #define VSYNC_GPIO_NUM 25
35 | #define HREF_GPIO_NUM 23
36 | #define PCLK_GPIO_NUM 22
37 |
38 | WiFiServer server(80);
39 |
40 | void ExecuteCommand()
41 | {
42 | //Serial.println("");
43 | //Serial.println("Command: "+Command);
44 | if (cmd!="getstill") {
45 | Serial.println("cmd= "+cmd+" ,P1= "+P1+" ,P2= "+P2+" ,P3= "+P3+" ,P4= "+P4+" ,P5= "+P5+" ,P6= "+P6+" ,P7= "+P7+" ,P8= "+P8+" ,P9= "+P9);
46 | Serial.println("");
47 | }
48 |
49 | if (cmd=="your cmd") {
50 | // You can do anything.
51 | // Feedback="Hello World";
52 | }
53 | else if (cmd=="ip") {
54 | Feedback="AP IP: "+WiFi.softAPIP().toString();
55 | Feedback+=", ";
56 | Feedback+="STA IP: "+WiFi.localIP().toString();
57 | }
58 | else if (cmd=="mac") {
59 | Feedback="STA MAC: "+WiFi.macAddress();
60 | }
61 | else if (cmd=="resetwifi") {
62 | WiFi.begin(P1.c_str(), P2.c_str());
63 | Serial.print("Connecting to ");
64 | Serial.println(P1);
65 | long int StartTime=millis();
66 | while (WiFi.status() != WL_CONNECTED)
67 | {
68 | delay(500);
69 | if ((StartTime+5000) < millis()) break;
70 | }
71 | Serial.println("");
72 | Serial.println("STAIP: "+WiFi.localIP().toString());
73 | Feedback="STAIP: "+WiFi.localIP().toString();
74 | }
75 | else if (cmd=="restart") {
76 | ESP.restart();
77 | }
78 | else if (cmd=="digitalwrite") {
79 | ledcDetachPin(P1.toInt());
80 | pinMode(P1.toInt(), OUTPUT);
81 | digitalWrite(P1.toInt(), P2.toInt());
82 | }
83 | else if (cmd=="analogwrite") {
84 | if (P1="4") {
85 | ledcAttachPin(4, 4);
86 | ledcSetup(4, 5000, 8);
87 | ledcWrite(4,P2.toInt());
88 | }
89 | else {
90 | ledcAttachPin(P1.toInt(), 5);
91 | ledcSetup(5, 5000, 8);
92 | ledcWrite(5,P2.toInt());
93 | }
94 | }
95 | else if (cmd=="flash") {
96 | ledcAttachPin(4, 4);
97 | ledcSetup(4, 5000, 8);
98 |
99 | int val = P1.toInt();
100 | ledcWrite(4,val);
101 | }
102 | else if (cmd=="framesize") {
103 | sensor_t * s = esp_camera_sensor_get();
104 | if (P1=="QQVGA")
105 | s->set_framesize(s, FRAMESIZE_QQVGA);
106 | else if (P1=="HQVGA")
107 | s->set_framesize(s, FRAMESIZE_HQVGA);
108 | else if (P1=="QVGA")
109 | s->set_framesize(s, FRAMESIZE_QVGA);
110 | else if (P1=="CIF")
111 | s->set_framesize(s, FRAMESIZE_CIF);
112 | else if (P1=="VGA")
113 | s->set_framesize(s, FRAMESIZE_VGA);
114 | else if (P1=="SVGA")
115 | s->set_framesize(s, FRAMESIZE_SVGA);
116 | else if (P1=="XGA")
117 | s->set_framesize(s, FRAMESIZE_XGA);
118 | else if (P1=="SXGA")
119 | s->set_framesize(s, FRAMESIZE_SXGA);
120 | else if (P1=="UXGA")
121 | s->set_framesize(s, FRAMESIZE_UXGA);
122 | else
123 | s->set_framesize(s, FRAMESIZE_QVGA);
124 | }
125 | else if (cmd=="quality") {
126 | sensor_t * s = esp_camera_sensor_get();
127 | int val = P1.toInt();
128 | s->set_quality(s, val);
129 | }
130 | else if (cmd=="contrast") {
131 | sensor_t * s = esp_camera_sensor_get();
132 | int val = P1.toInt();
133 | s->set_contrast(s, val);
134 | }
135 | else if (cmd=="brightness") {
136 | sensor_t * s = esp_camera_sensor_get();
137 | int val = P1.toInt();
138 | s->set_brightness(s, val);
139 | }
140 | else if (cmd=="serial") {
141 | Serial.println(P1);
142 | }
143 | else if (cmd=="detectCount") {
144 | Serial.println(P1+" = "+P2);
145 | }
146 | else if (cmd=="tcp") {
147 | String domain=P1;
148 | int port=P2.toInt();
149 | String request=P3;
150 | int wait=P4.toInt(); // wait = 0 or 1
151 |
152 | if ((port==443)||(domain.indexOf("https")==0)||(domain.indexOf("HTTPS")==0))
153 | Feedback=tcp_https(domain,request,port,wait);
154 | else
155 | Feedback=tcp_http(domain,request,port,wait);
156 | }
157 | else if (cmd=="linenotify") { //message=xxx&stickerPackageId=xxx&stickerId=xxx
158 | String token = P1;
159 | String request = P2;
160 | Feedback=LineNotify(token,request,1);
161 | if (Feedback.indexOf("status")!=-1) {
162 | int s=Feedback.indexOf("{");
163 | Feedback=Feedback.substring(s);
164 | int e=Feedback.indexOf("}");
165 | Feedback=Feedback.substring(0,e);
166 | Feedback.replace("\"","");
167 | Feedback.replace("{","");
168 | Feedback.replace("}","");
169 | }
170 | }
171 | else if (cmd=="sendCapturedImageToLineNotify") {
172 | Feedback=sendCapturedImageToLineNotify(P1);
173 | if (Feedback=="") Feedback="The image failed to send. The framesize may be too large.";
174 | }
175 | else {
176 | Feedback="Command is not defined.";
177 | }
178 | if (Feedback=="") Feedback=Command;
179 | }
180 |
181 | void setup() {
182 | WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
183 |
184 | Serial.begin(115200);
185 | Serial.setDebugOutput(true);
186 | Serial.println();
187 |
188 |
189 | camera_config_t config;
190 | config.ledc_channel = LEDC_CHANNEL_0;
191 | config.ledc_timer = LEDC_TIMER_0;
192 | config.pin_d0 = Y2_GPIO_NUM;
193 | config.pin_d1 = Y3_GPIO_NUM;
194 | config.pin_d2 = Y4_GPIO_NUM;
195 | config.pin_d3 = Y5_GPIO_NUM;
196 | config.pin_d4 = Y6_GPIO_NUM;
197 | config.pin_d5 = Y7_GPIO_NUM;
198 | config.pin_d6 = Y8_GPIO_NUM;
199 | config.pin_d7 = Y9_GPIO_NUM;
200 | config.pin_xclk = XCLK_GPIO_NUM;
201 | config.pin_pclk = PCLK_GPIO_NUM;
202 | config.pin_vsync = VSYNC_GPIO_NUM;
203 | config.pin_href = HREF_GPIO_NUM;
204 | config.pin_sscb_sda = SIOD_GPIO_NUM;
205 | config.pin_sscb_scl = SIOC_GPIO_NUM;
206 | config.pin_pwdn = PWDN_GPIO_NUM;
207 | config.pin_reset = RESET_GPIO_NUM;
208 | config.xclk_freq_hz = 20000000;
209 | config.pixel_format = PIXFORMAT_JPEG;
210 | //init with high specs to pre-allocate larger buffers
211 | if(psramFound()){
212 | config.frame_size = FRAMESIZE_UXGA;
213 | config.jpeg_quality = 10; //0-63 lower number means higher quality
214 | config.fb_count = 2;
215 | } else {
216 | config.frame_size = FRAMESIZE_SVGA;
217 | config.jpeg_quality = 12; //0-63 lower number means higher quality
218 | config.fb_count = 1;
219 | }
220 |
221 | // camera init
222 | esp_err_t err = esp_camera_init(&config);
223 | if (err != ESP_OK) {
224 | Serial.printf("Camera init failed with error 0x%x", err);
225 | delay(1000);
226 | ESP.restart();
227 | }
228 |
229 | //drop down frame size for higher initial frame rate
230 | sensor_t * s = esp_camera_sensor_get();
231 | s->set_framesize(s, FRAMESIZE_QVGA); //UXGA|SXGA|XGA|SVGA|VGA|CIF|QVGA|HQVGA|QQVGA
232 |
233 | ledcAttachPin(4, 4);
234 | ledcSetup(4, 5000, 8);
235 |
236 | WiFi.mode(WIFI_AP_STA);
237 |
238 | //WiFi.config(IPAddress(192, 168, 201, 100), IPAddress(192, 168, 201, 2), IPAddress(255, 255, 255, 0));
239 |
240 | WiFi.begin(ssid, password);
241 |
242 | delay(1000);
243 | Serial.println("");
244 | Serial.print("Connecting to ");
245 | Serial.println(ssid);
246 |
247 | long int StartTime=millis();
248 | while (WiFi.status() != WL_CONNECTED)
249 | {
250 | delay(500);
251 | if ((StartTime+10000) < millis()) break;
252 | }
253 |
254 | if (WiFi.status() == WL_CONNECTED) {
255 | WiFi.softAP((WiFi.localIP().toString()+"_"+(String)apssid).c_str(), appassword);
256 | Serial.println("");
257 | Serial.println("STAIP address: ");
258 | Serial.println(WiFi.localIP());
259 |
260 | for (int i=0;i<5;i++) {
261 | ledcWrite(4,10);
262 | delay(200);
263 | ledcWrite(4,0);
264 | delay(200);
265 | }
266 | }
267 | else {
268 | WiFi.softAP((WiFi.softAPIP().toString()+"_"+(String)apssid).c_str(), appassword);
269 |
270 | for (int i=0;i<2;i++) {
271 | ledcWrite(4,10);
272 | delay(1000);
273 | ledcWrite(4,0);
274 | delay(1000);
275 | }
276 | }
277 |
278 |
279 | //WiFi.softAPConfig(IPAddress(192, 168, 4, 1), IPAddress(192, 168, 4, 1), IPAddress(255, 255, 255, 0));
280 | Serial.println("");
281 | Serial.println("APIP address: ");
282 | Serial.println(WiFi.softAPIP());
283 |
284 | pinMode(4, OUTPUT);
285 | digitalWrite(4, LOW);
286 |
287 | server.begin();
288 | }
289 |
290 | static const char PROGMEM INDEX_HTML[] = R"rawliteral(
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |