Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
November 2021 Blimp Competition
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Shahrul Kamil bin Hassan
November 2021 Blimp Competition
Commits
1025059d
Commit
1025059d
authored
3 years ago
by
Zhiying Li
Browse files
Options
Downloads
Patches
Plain Diff
Fixed IP of ESP32CAM
parent
74027172
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/ESP32_Cam/WifiCam_fixIP/WifiCam_fixIP.ino
+172
-0
172 additions, 0 deletions
Code/ESP32_Cam/WifiCam_fixIP/WifiCam_fixIP.ino
with
172 additions
and
0 deletions
Code/ESP32_Cam/WifiCam_fixIP/WifiCam_fixIP.ino
0 → 100644
+
172
−
0
View file @
1025059d
#include
<WebServer.h>
#include
<WiFi.h>
#include
<esp32cam.h>
// const char* WIFI_SSID = "lemur";
// const char* WIFI_PASS = "lemur9473";
// const char* WIFI_SSID = "uclahci";
// const char* WIFI_PASS = "94739473";
const
char
*
WIFI_SSID
=
"NETGEAR33"
;
const
char
*
WIFI_PASS
=
"freestreet163"
;
// const char* WIFI_SSID = "LEMUR_ESP32_EYE_AP_1";
// const char* WIFI_PASS = "123456789";
WebServer
server
(
80
);
static
auto
loRes
=
esp32cam
::
Resolution
::
find
(
320
,
240
);
static
auto
hiRes
=
esp32cam
::
Resolution
::
find
(
800
,
600
);
void
handleBmp
()
{
if
(
!
esp32cam
::
Camera
.
changeResolution
(
loRes
))
{
Serial
.
println
(
"SET-LO-RES FAIL"
);
}
auto
frame
=
esp32cam
::
capture
();
if
(
frame
==
nullptr
)
{
Serial
.
println
(
"CAPTURE FAIL"
);
server
.
send
(
503
,
""
,
""
);
return
;
}
Serial
.
printf
(
"CAPTURE OK %dx%d %db
\n
"
,
frame
->
getWidth
(),
frame
->
getHeight
(),
static_cast
<
int
>
(
frame
->
size
()));
if
(
!
frame
->
toBmp
())
{
Serial
.
println
(
"CONVERT FAIL"
);
server
.
send
(
503
,
""
,
""
);
return
;
}
Serial
.
printf
(
"CONVERT OK %dx%d %db
\n
"
,
frame
->
getWidth
(),
frame
->
getHeight
(),
static_cast
<
int
>
(
frame
->
size
()));
server
.
setContentLength
(
frame
->
size
());
server
.
send
(
200
,
"image/bmp"
);
WiFiClient
client
=
server
.
client
();
frame
->
writeTo
(
client
);
}
void
serveJpg
()
{
auto
frame
=
esp32cam
::
capture
();
if
(
frame
==
nullptr
)
{
Serial
.
println
(
"CAPTURE FAIL"
);
server
.
send
(
503
,
""
,
""
);
return
;
}
Serial
.
printf
(
"CAPTURE OK %dx%d %db
\n
"
,
frame
->
getWidth
(),
frame
->
getHeight
(),
static_cast
<
int
>
(
frame
->
size
()));
server
.
setContentLength
(
frame
->
size
());
server
.
send
(
200
,
"image/jpeg"
);
WiFiClient
client
=
server
.
client
();
frame
->
writeTo
(
client
);
}
void
handleJpgLo
()
{
if
(
!
esp32cam
::
Camera
.
changeResolution
(
loRes
))
{
Serial
.
println
(
"SET-LO-RES FAIL"
);
}
serveJpg
();
}
void
handleJpgHi
()
{
if
(
!
esp32cam
::
Camera
.
changeResolution
(
hiRes
))
{
Serial
.
println
(
"SET-HI-RES FAIL"
);
}
serveJpg
();
}
void
handleJpg
()
{
server
.
sendHeader
(
"Location"
,
"/cam-hi.jpg"
);
server
.
send
(
302
,
""
,
""
);
}
void
handleMjpeg
()
{
if
(
!
esp32cam
::
Camera
.
changeResolution
(
hiRes
))
{
Serial
.
println
(
"SET-HI-RES FAIL"
);
}
Serial
.
println
(
"STREAM BEGIN"
);
WiFiClient
client
=
server
.
client
();
auto
startTime
=
millis
();
int
res
=
esp32cam
::
Camera
.
streamMjpeg
(
client
);
if
(
res
<=
0
)
{
Serial
.
printf
(
"STREAM ERROR %d
\n
"
,
res
);
return
;
}
auto
duration
=
millis
()
-
startTime
;
Serial
.
printf
(
"STREAM END %dfrm %0.2ffps
\n
"
,
res
,
1000.0
*
res
/
duration
);
}
void
setup
()
{
Serial
.
begin
(
115200
);
Serial
.
println
();
// We set a Static IP address
IPAddress
local_IP
(
192
,
168
,
0
,
114
);
// We set a Gateway IP address
IPAddress
gateway
(
192
,
168
,
0
,
1
);
IPAddress
subnet
(
255
,
255
,
255
,
0
);
{
using
namespace
esp32cam
;
Config
cfg
;
cfg
.
setPins
(
pins
::
AiThinker
);
cfg
.
setResolution
(
hiRes
);
cfg
.
setBufferCount
(
2
);
cfg
.
setJpeg
(
80
);
bool
ok
=
Camera
.
begin
(
cfg
);
Serial
.
println
(
ok
?
"CAMERA OK"
:
"CAMERA FAIL"
);
}
WiFi
.
persistent
(
false
);
WiFi
.
mode
(
WIFI_STA
);
WiFi
.
begin
(
WIFI_SSID
,
WIFI_PASS
);
if
(
!
WiFi
.
config
(
local_IP
,
gateway
,
subnet
))
{
Serial
.
println
(
"STA Failed to configure"
);
}
while
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
delay
(
500
);
}
Serial
.
print
(
"http://"
);
Serial
.
println
(
WiFi
.
localIP
());
// Serial.println(" /cam.bmp");
Serial
.
println
(
" /cam-lo.jpg"
);
Serial
.
println
(
" /cam-hi.jpg"
);
// Serial.println(" /cam.mjpeg");
// server.on("/cam.bmp", handleBmp);
server
.
on
(
"/cam-lo.jpg"
,
handleJpgLo
);
server
.
on
(
"/cam-hi.jpg"
,
handleJpgHi
);
// server.on("/cam.jpg", handleJpg);
// server.on("/cam.mjpeg", handleMjpeg);
server
.
begin
();
}
void
loop
()
{
server
.
handleClient
();
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment