Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-esp32
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-esp32
Commits
20db2ee4
Commit
20db2ee4
authored
Dec 14, 2017
by
me-no-dev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Time and TimerWDT examples
parent
79e5d4c4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
0 deletions
+86
-0
libraries/ESP32/examples/Time/SimpleTime/SimpleTime.ino
libraries/ESP32/examples/Time/SimpleTime/SimpleTime.ino
+47
-0
libraries/ESP32/examples/Timer/WatchdogTimer/WatchdogTimer.ino
...ries/ESP32/examples/Timer/WatchdogTimer/WatchdogTimer.ino
+39
-0
No files found.
libraries/ESP32/examples/Time/SimpleTime/SimpleTime.ino
0 → 100644
View file @
20db2ee4
#include <WiFi.h>
#include "time.h"
const
char
*
ssid
=
"YOUR_SSID"
;
const
char
*
password
=
"YOUR_PASS"
;
const
char
*
ntpServer
=
"pool.ntp.org"
;
const
long
gmtOffset_sec
=
3600
;
const
int
daylightOffset_sec
=
3600
;
void
printLocalTime
()
{
struct
tm
timeinfo
;
if
(
!
getLocalTime
(
&
timeinfo
)){
Serial
.
println
(
"Failed to obtain time"
);
return
;
}
Serial
.
println
(
&
timeinfo
,
"%A, %B %d %Y %H:%M:%S"
);
}
void
setup
()
{
Serial
.
begin
(
115200
);
//connect to WiFi
Serial
.
printf
(
"Connecting to %s "
,
ssid
);
WiFi
.
begin
(
ssid
,
password
);
while
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
delay
(
500
);
Serial
.
print
(
"."
);
}
Serial
.
println
(
" CONNECTED"
);
//init and get the time
configTime
(
gmtOffset_sec
,
daylightOffset_sec
,
ntpServer
);
printLocalTime
();
//disconnect WiFi as it's no longer needed
WiFi
.
disconnect
(
true
);
WiFi
.
mode
(
WIFI_OFF
);
}
void
loop
()
{
delay
(
1000
);
printLocalTime
();
}
libraries/ESP32/examples/Timer/WatchdogTimer/WatchdogTimer.ino
0 → 100644
View file @
20db2ee4
#include "esp_system.h"
const
int
button
=
0
;
//gpio to use to trigger delay
const
int
wdtTimeout
=
3000
;
//time in ms to trigger the watchdog
hw_timer_t
*
timer
=
NULL
;
void
IRAM_ATTR
resetModule
()
{
ets_printf
(
"reboot
\n
"
);
esp_restart_noos
();
}
void
setup
()
{
Serial
.
begin
(
115200
);
Serial
.
println
();
Serial
.
println
(
"running setup"
);
pinMode
(
button
,
INPUT_PULLUP
);
//init control pin
timer
=
timerBegin
(
0
,
80
,
true
);
//timer 0, div 80
timerAttachInterrupt
(
timer
,
&
resetModule
,
true
);
//attach callback
timerAlarmWrite
(
timer
,
wdtTimeout
*
1000
,
false
);
//set time in us
timerAlarmEnable
(
timer
);
//enable interrupt
}
void
loop
()
{
Serial
.
println
(
"running main loop"
);
timerWrite
(
timer
,
0
);
//reset timer (feed watchdog)
long
loopTime
=
millis
();
//while button is pressed, delay up to 3 seconds to trigger the timer
while
(
!
digitalRead
(
button
))
{
Serial
.
println
(
"button pressed"
);
delay
(
500
);
}
delay
(
1000
);
//simulate work
loopTime
=
millis
()
-
loopTime
;
Serial
.
print
(
"loop time is = "
);
Serial
.
println
(
loopTime
);
//should be under 3000
}
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