Skip to content

Commit f862831

Browse files
authored
Add files via upload
0 parents  commit f862831

File tree

22 files changed

+2574
-0
lines changed

22 files changed

+2574
-0
lines changed

Blynk-Server/camera_pins.h

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
2+
#if defined(CAMERA_MODEL_WROVER_KIT)
3+
#define PWDN_GPIO_NUM -1
4+
#define RESET_GPIO_NUM -1
5+
#define XCLK_GPIO_NUM 21
6+
#define SIOD_GPIO_NUM 26
7+
#define SIOC_GPIO_NUM 27
8+
9+
#define Y9_GPIO_NUM 35
10+
#define Y8_GPIO_NUM 34
11+
#define Y7_GPIO_NUM 39
12+
#define Y6_GPIO_NUM 36
13+
#define Y5_GPIO_NUM 19
14+
#define Y4_GPIO_NUM 18
15+
#define Y3_GPIO_NUM 5
16+
#define Y2_GPIO_NUM 4
17+
#define VSYNC_GPIO_NUM 25
18+
#define HREF_GPIO_NUM 23
19+
#define PCLK_GPIO_NUM 22
20+
21+
#elif defined(CAMERA_MODEL_ESP_EYE)
22+
#define PWDN_GPIO_NUM -1
23+
#define RESET_GPIO_NUM -1
24+
#define XCLK_GPIO_NUM 4
25+
#define SIOD_GPIO_NUM 18
26+
#define SIOC_GPIO_NUM 23
27+
28+
#define Y9_GPIO_NUM 36
29+
#define Y8_GPIO_NUM 37
30+
#define Y7_GPIO_NUM 38
31+
#define Y6_GPIO_NUM 39
32+
#define Y5_GPIO_NUM 35
33+
#define Y4_GPIO_NUM 14
34+
#define Y3_GPIO_NUM 13
35+
#define Y2_GPIO_NUM 34
36+
#define VSYNC_GPIO_NUM 5
37+
#define HREF_GPIO_NUM 27
38+
#define PCLK_GPIO_NUM 25
39+
40+
#elif defined(CAMERA_MODEL_M5STACK_PSRAM)
41+
#define PWDN_GPIO_NUM -1
42+
#define RESET_GPIO_NUM 15
43+
#define XCLK_GPIO_NUM 27
44+
#define SIOD_GPIO_NUM 25
45+
#define SIOC_GPIO_NUM 23
46+
47+
#define Y9_GPIO_NUM 19
48+
#define Y8_GPIO_NUM 36
49+
#define Y7_GPIO_NUM 18
50+
#define Y6_GPIO_NUM 39
51+
#define Y5_GPIO_NUM 5
52+
#define Y4_GPIO_NUM 34
53+
#define Y3_GPIO_NUM 35
54+
#define Y2_GPIO_NUM 32
55+
#define VSYNC_GPIO_NUM 22
56+
#define HREF_GPIO_NUM 26
57+
#define PCLK_GPIO_NUM 21
58+
59+
#elif defined(CAMERA_MODEL_M5STACK_WIDE)
60+
#define PWDN_GPIO_NUM -1
61+
#define RESET_GPIO_NUM 15
62+
#define XCLK_GPIO_NUM 27
63+
#define SIOD_GPIO_NUM 22
64+
#define SIOC_GPIO_NUM 23
65+
66+
#define Y9_GPIO_NUM 19
67+
#define Y8_GPIO_NUM 36
68+
#define Y7_GPIO_NUM 18
69+
#define Y6_GPIO_NUM 39
70+
#define Y5_GPIO_NUM 5
71+
#define Y4_GPIO_NUM 34
72+
#define Y3_GPIO_NUM 35
73+
#define Y2_GPIO_NUM 32
74+
#define VSYNC_GPIO_NUM 25
75+
#define HREF_GPIO_NUM 26
76+
#define PCLK_GPIO_NUM 21
77+
78+
#elif defined(CAMERA_MODEL_AI_THINKER)
79+
#define PWDN_GPIO_NUM 32
80+
#define RESET_GPIO_NUM -1
81+
#define XCLK_GPIO_NUM 0
82+
#define SIOD_GPIO_NUM 26
83+
#define SIOC_GPIO_NUM 27
84+
85+
#define Y9_GPIO_NUM 35
86+
#define Y8_GPIO_NUM 34
87+
#define Y7_GPIO_NUM 39
88+
#define Y6_GPIO_NUM 36
89+
#define Y5_GPIO_NUM 21
90+
#define Y4_GPIO_NUM 19
91+
#define Y3_GPIO_NUM 18
92+
#define Y2_GPIO_NUM 5
93+
#define VSYNC_GPIO_NUM 25
94+
#define HREF_GPIO_NUM 23
95+
#define PCLK_GPIO_NUM 22
96+
97+
#else
98+
#error "Camera model not selected"
99+
#endif

Blynk-Server/esp32_camera_mjpeg.ino

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
3+
This is a simple MJPEG streaming webserver implemented for AI-Thinker ESP32-CAM and
4+
ESP32-EYE modules.
5+
This is tested to work with VLC and Blynk video widget.
6+
7+
Inspired by and based on this Instructable: $9 RTSP Video Streamer Using the ESP32-CAM Board
8+
(https://www.instructables.com/id/9-RTSP-Video-Streamer-Using-the-ESP32-CAM-Board/)
9+
10+
Board: AI-Thinker ESP32-CAM
11+
12+
*/
13+
14+
#include "src/OV2640.h"
15+
#include <WiFi.h>
16+
#include <WebServer.h>
17+
#include <WiFiClient.h>
18+
19+
// Select camera model
20+
//#define CAMERA_MODEL_WROVER_KIT
21+
//#define CAMERA_MODEL_ESP_EYE
22+
//#define CAMERA_MODEL_M5STACK_PSRAM
23+
//#define CAMERA_MODEL_M5STACK_WIDE
24+
#define CAMERA_MODEL_AI_THINKER
25+
26+
#include "camera_pins.h"
27+
28+
#define SSID1 "VIETTEL_TUNG HONDA"
29+
#define PWD1 "01685127737"
30+
31+
OV2640 cam;
32+
33+
WebServer server(80);
34+
35+
const char HEADER[] = "HTTP/1.1 200 OK\r\n" \
36+
"Access-Control-Allow-Origin: *\r\n" \
37+
"Content-Type: multipart/x-mixed-replace; boundary=123456789000000000000987654321\r\n";
38+
const char BOUNDARY[] = "\r\n--123456789000000000000987654321\r\n";
39+
const char CTNTTYPE[] = "Content-Type: image/jpeg\r\nContent-Length: ";
40+
const int hdrLen = strlen(HEADER);
41+
const int bdrLen = strlen(BOUNDARY);
42+
const int cntLen = strlen(CTNTTYPE);
43+
44+
void handle_jpg_stream(void)
45+
{
46+
char buf[32];
47+
int s;
48+
49+
WiFiClient client = server.client();
50+
51+
client.write(HEADER, hdrLen);
52+
client.write(BOUNDARY, bdrLen);
53+
54+
while (true)
55+
{
56+
if (!client.connected()) break;
57+
cam.run();
58+
s = cam.getSize();
59+
client.write(CTNTTYPE, cntLen);
60+
sprintf( buf, "%d\r\n\r\n", s );
61+
client.write(buf, strlen(buf));
62+
client.write((char *)cam.getfb(), s);
63+
client.write(BOUNDARY, bdrLen);
64+
}
65+
}
66+
67+
const char JHEADER[] = "HTTP/1.1 200 OK\r\n" \
68+
"Content-disposition: inline; filename=capture.jpg\r\n" \
69+
"Content-type: image/jpeg\r\n\r\n";
70+
const int jhdLen = strlen(JHEADER);
71+
72+
void handle_jpg(void)
73+
{
74+
WiFiClient client = server.client();
75+
76+
cam.run();
77+
if (!client.connected()) return;
78+
79+
client.write(JHEADER, jhdLen);
80+
client.write((char *)cam.getfb(), cam.getSize());
81+
}
82+
83+
void handleNotFound()
84+
{
85+
String message = "Server is running!\n\n";
86+
message += "URI: ";
87+
message += server.uri();
88+
message += "\nMethod: ";
89+
message += (server.method() == HTTP_GET) ? "GET" : "POST";
90+
message += "\nArguments: ";
91+
message += server.args();
92+
message += "\n";
93+
server.send(200, "text / plain", message);
94+
}
95+
96+
void setup()
97+
{
98+
99+
Serial.begin(115200);
100+
//while (!Serial); //wait for serial connection.
101+
102+
camera_config_t config;
103+
config.ledc_channel = LEDC_CHANNEL_0;
104+
config.ledc_timer = LEDC_TIMER_0;
105+
config.pin_d0 = Y2_GPIO_NUM;
106+
config.pin_d1 = Y3_GPIO_NUM;
107+
config.pin_d2 = Y4_GPIO_NUM;
108+
config.pin_d3 = Y5_GPIO_NUM;
109+
config.pin_d4 = Y6_GPIO_NUM;
110+
config.pin_d5 = Y7_GPIO_NUM;
111+
config.pin_d6 = Y8_GPIO_NUM;
112+
config.pin_d7 = Y9_GPIO_NUM;
113+
config.pin_xclk = XCLK_GPIO_NUM;
114+
config.pin_pclk = PCLK_GPIO_NUM;
115+
config.pin_vsync = VSYNC_GPIO_NUM;
116+
config.pin_href = HREF_GPIO_NUM;
117+
config.pin_sscb_sda = SIOD_GPIO_NUM;
118+
config.pin_sscb_scl = SIOC_GPIO_NUM;
119+
config.pin_pwdn = PWDN_GPIO_NUM;
120+
config.pin_reset = RESET_GPIO_NUM;
121+
config.xclk_freq_hz = 20000000;
122+
config.pixel_format = PIXFORMAT_JPEG;
123+
124+
// Frame parameters
125+
// config.frame_size = FRAMESIZE_UXGA;
126+
config.frame_size = FRAMESIZE_QVGA;
127+
config.jpeg_quality = 12;
128+
config.fb_count = 2;
129+
130+
#if defined(CAMERA_MODEL_ESP_EYE)
131+
pinMode(13, INPUT_PULLUP);
132+
pinMode(14, INPUT_PULLUP);
133+
#endif
134+
135+
cam.init(config);
136+
137+
IPAddress ip;
138+
139+
WiFi.mode(WIFI_STA);
140+
WiFi.begin(SSID1, PWD1);
141+
while (WiFi.status() != WL_CONNECTED)
142+
{
143+
delay(500);
144+
Serial.print(F("."));
145+
}
146+
ip = WiFi.localIP();
147+
Serial.println(F("WiFi connected"));
148+
Serial.println("");
149+
Serial.println(ip);
150+
Serial.print("Stream Link: http://");
151+
Serial.print(ip);
152+
Serial.println("/mjpeg/1");
153+
server.on("/mjpeg/1", HTTP_GET, handle_jpg_stream);
154+
server.on("/jpg", HTTP_GET, handle_jpg);
155+
server.onNotFound(handleNotFound);
156+
server.begin();
157+
}
158+
159+
void loop()
160+
{
161+
server.handleClient();
162+
}

0 commit comments

Comments
 (0)