Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
baby-face-expression-detect-model
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
R24-145
baby-face-expression-detect-model
Commits
28d12dfe
Commit
28d12dfe
authored
Oct 28, 2024
by
Ishankha K.C
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add arduino files
parent
b117ac95
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
550 additions
and
0 deletions
+550
-0
esp_32_dev_other.ino
esp_32_dev_other.ino
+360
-0
esp_32_live.ino
esp_32_live.ino
+190
-0
main_old.py
main_old.py
+0
-0
No files found.
esp_32_dev_other.ino
0 → 100644
View file @
28d12dfe
This diff is collapsed.
Click to expand it.
esp_32_live.ino
0 → 100644
View file @
28d12dfe
#include <WebServer.h>
#include <WiFi.h>
#include <esp32cam.h>
#include <time.h>
#include <ArduinoJson.h>
const
char
*
WIFI_SSID
=
"SLT-Fiber-Home"
;
const
char
*
WIFI_PASS
=
"Home@1122$1"
;
const
char
*
DEVICE_ID
=
"8563efa6"
;
// Flashlight pin
const
int
FLASHLIGHT_PIN
=
4
;
// Time interval to consider as daytime or nighttime
const
int
DAY_START_HOUR
=
6
;
// 6 AM
const
int
NIGHT_START_HOUR
=
18
;
// 6 PM
// Time zone offset (5 hours 30 minutes) in seconds
const
int
TIME_ZONE_OFFSET
=
5
*
3600
+
30
*
60
;
WebServer
server
(
80
);
static
auto
loRes
=
esp32cam
::
Resolution
::
find
(
320
,
240
);
static
auto
midRes
=
esp32cam
::
Resolution
::
find
(
350
,
530
);
static
auto
hiRes
=
esp32cam
::
Resolution
::
find
(
800
,
600
);
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
handleJpgMid
()
{
if
(
!
esp32cam
::
Camera
.
changeResolution
(
midRes
))
{
Serial
.
println
(
"SET-MID-RES FAIL"
);
}
serveJpg
();
}
// API handler to turn the flashlight on
void
handleFlashlightOn
()
{
digitalWrite
(
FLASHLIGHT_PIN
,
HIGH
);
// Create a JSON document
StaticJsonDocument
<
200
>
jsonDoc
;
jsonDoc
[
"status"
]
=
"ON"
;
jsonDoc
[
"message"
]
=
"Flashlight turned ON"
;
// Serialize JSON document to a string
String
response
;
serializeJson
(
jsonDoc
,
response
);
// Send the JSON response
server
.
send
(
200
,
"application/json"
,
response
);
}
// API handler to turn the flashlight off
void
handleFlashlightOff
()
{
digitalWrite
(
FLASHLIGHT_PIN
,
LOW
);
// Create a JSON document
StaticJsonDocument
<
200
>
jsonDoc
;
jsonDoc
[
"status"
]
=
"OFF"
;
jsonDoc
[
"message"
]
=
"Flashlight turned OFF"
;
// Serialize JSON document to a string
String
response
;
serializeJson
(
jsonDoc
,
response
);
// Send the JSON response
server
.
send
(
200
,
"application/json"
,
response
);
}
void
setup
(){
Serial
.
begin
(
115200
);
Serial
.
println
();
pinMode
(
FLASHLIGHT_PIN
,
OUTPUT
);
digitalWrite
(
FLASHLIGHT_PIN
,
LOW
);
// Ensure flashlight is off initially
{
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
(
DEVICE_ID
);
Serial
.
println
(
ok
?
"CAMERA OK"
:
"CAMERA FAIL"
);
}
WiFi
.
persistent
(
false
);
WiFi
.
mode
(
WIFI_STA
);
WiFi
.
begin
(
WIFI_SSID
,
WIFI_PASS
);
Serial
.
print
(
""
);
Serial
.
print
(
"Connecting to WiFi."
);
while
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
delay
(
500
);
Serial
.
print
(
"."
);
}
Serial
.
println
(
""
);
Serial
.
print
(
"http://"
);
Serial
.
print
(
WiFi
.
localIP
());
Serial
.
print
(
"/"
+
String
(
DEVICE_ID
));
Serial
.
println
(
""
);
Serial
.
println
(
" /cam-lo.jpg"
);
Serial
.
println
(
" /cam-hi.jpg"
);
Serial
.
println
(
" /cam-mid.jpg"
);
Serial
.
println
(
" /flashlight/on"
);
Serial
.
println
(
" /flashlight/off"
);
server
.
on
(
"/"
+
String
(
DEVICE_ID
)
+
"/cam-lo.jpg"
,
handleJpgLo
);
server
.
on
(
"/"
+
String
(
DEVICE_ID
)
+
"/cam-hi.jpg"
,
handleJpgHi
);
server
.
on
(
"/"
+
String
(
DEVICE_ID
)
+
"/cam-mid.jpg"
,
handleJpgMid
);
server
.
on
(
"/"
+
String
(
DEVICE_ID
)
+
"/flashlight/on"
,
handleFlashlightOn
);
server
.
on
(
"/"
+
String
(
DEVICE_ID
)
+
"/flashlight/off"
,
handleFlashlightOff
);
server
.
begin
();
// Initialize time
configTime
(
0
,
0
,
"pool.ntp.org"
);
}
unsigned
long
lastPrintTime
=
0
;
// Last time the time was printed
const
unsigned
long
printInterval
=
10000
;
// Interval to print time (10 seconds)
void
loop
()
{
server
.
handleClient
();
unsigned
long
currentMillis
=
millis
();
if
(
currentMillis
-
lastPrintTime
>=
printInterval
)
{
// It's been 10 seconds, so print the time
struct
tm
timeinfo
;
if
(
getLocalTime
(
&
timeinfo
))
{
// Adjust time for GMT+5:30
timeinfo
.
tm_hour
+=
5
;
timeinfo
.
tm_min
+=
30
;
if
(
timeinfo
.
tm_min
>=
60
)
{
timeinfo
.
tm_min
-=
60
;
timeinfo
.
tm_hour
++
;
}
if
(
timeinfo
.
tm_hour
>=
24
)
{
timeinfo
.
tm_hour
-=
24
;
}
int
hour
=
timeinfo
.
tm_hour
;
int
minute
=
timeinfo
.
tm_min
;
int
second
=
timeinfo
.
tm_sec
;
// Print the adjusted time
Serial
.
printf
(
"Time: %02d:%02d:%02d
\n
"
,
hour
,
minute
,
second
);
}
else
{
Serial
.
println
(
"Failed to obtain time"
);
}
// Update the last print time
lastPrintTime
=
currentMillis
;
}
}
\ No newline at end of file
main.py
→
main
_old
.py
View file @
28d12dfe
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment