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-pico
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-pico
Commits
c889a3c1
Unverified
Commit
c889a3c1
authored
Jul 23, 2022
by
Earle F. Philhower, III
Committed by
GitHub
Jul 23, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add NTP waitSet callback (#705)
Allows printing "."s or flashing an LED while NTP is waiting for sync.
parent
cfc05dab
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
23 deletions
+41
-23
docs/wifintp.rst
docs/wifintp.rst
+18
-0
libraries/WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino
...ies/WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino
+4
-5
libraries/WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino
...les/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino
+3
-6
libraries/WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino
...aries/WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino
+4
-5
libraries/WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino
...s/WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino
+4
-6
libraries/WiFi/src/WiFiNTP.h
libraries/WiFi/src/WiFiNTP.h
+8
-1
No files found.
docs/wifintp.rst
View file @
c889a3c1
...
...
@@ -51,6 +51,24 @@ it is not already running. Using this method, the above code becomes:
void setClock() {
NTP.begin("pool.ntp.org", "time.nist.gov");
NTP.waitSet();
time_t now = time(nullptr);
struct tm timeinfo;
gmtime_r(&now, &timeinfo);
Serial.print("Current time: ");
Serial.print(asctime(&timeinfo));
}
bool NTP.waitSet(void (\*cb)(), uint32_t timeout)
-------------------------------------------------
Allows for a callback that will be called every 1/10th of a second while waiting for
NTP sync. For example, using lambdas you can simply print "."s:"
.. code :: cpp
void setClock() {
NTP.begin("pool.ntp.org", "time.nist.gov");
NTP.waitSet([]() { Serial.print("."); });
time_t now = time(nullptr);
struct tm timeinfo;
gmtime_r(&now, &timeinfo);
Serial.print("Current time: ");
...
...
libraries/WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino
View file @
c889a3c1
...
...
@@ -57,13 +57,12 @@ void setClock() {
NTP
.
begin
(
"pool.ntp.org"
,
"time.nist.gov"
);
Serial
.
print
(
"Waiting for NTP time sync: "
);
time_t
now
=
time
(
nullptr
);
while
(
now
<
8
*
3600
*
2
)
{
delay
(
500
);
NTP
.
waitSet
([]()
{
Serial
.
print
(
"."
);
now
=
time
(
nullptr
);
}
});
Serial
.
println
(
""
);
time_t
now
=
time
(
nullptr
);
struct
tm
timeinfo
;
gmtime_r
(
&
now
,
&
timeinfo
);
Serial
.
print
(
"Current time: "
);
...
...
libraries/WiFi/examples/BearSSL_ServerClientCert/BearSSL_ServerClientCert.ino
View file @
c889a3c1
...
...
@@ -164,13 +164,10 @@ void setClock() {
NTP
.
begin
(
"pool.ntp.org"
,
"time.nist.gov"
);
Serial
.
print
(
"Waiting for NTP time sync: "
);
time_t
now
=
time
(
nullptr
);
while
(
now
<
8
*
3600
*
2
)
{
delay
(
500
);
Serial
.
print
(
"."
);
now
=
time
(
nullptr
);
}
NTP
.
waitSet
([]()
{
Serial
.
print
(
"."
);
}
);
Serial
.
println
(
""
);
time_t
now
=
time
(
nullptr
);
struct
tm
timeinfo
;
gmtime_r
(
&
now
,
&
timeinfo
);
Serial
.
print
(
"Current time: "
);
...
...
libraries/WiFi/examples/BearSSL_Sessions/BearSSL_Sessions.ino
View file @
c889a3c1
...
...
@@ -45,13 +45,12 @@ void setup() {
NTP
.
begin
(
"pool.ntp.org"
,
"time.nist.gov"
);
Serial
.
print
(
"Waiting for NTP time sync: "
);
time_t
now
=
time
(
nullptr
);
while
(
now
<
8
*
3600
*
2
)
{
delay
(
500
);
NTP
.
waitSet
([]()
{
Serial
.
print
(
"."
);
now
=
time
(
nullptr
);
}
});
Serial
.
println
(
""
);
time_t
now
=
time
(
nullptr
);
struct
tm
timeinfo
;
gmtime_r
(
&
now
,
&
timeinfo
);
Serial
.
print
(
"Current time: "
);
...
...
libraries/WiFi/examples/BearSSL_Validation/BearSSL_Validation.ino
View file @
c889a3c1
...
...
@@ -22,16 +22,14 @@ const char *path = "/";
// Set time via NTP, as required for x.509 validation
void
setClock
()
{
configTime
(
3
*
3600
,
0
,
"pool.ntp.org"
,
"time.nist.gov"
);
NTP
.
begin
(
"pool.ntp.org"
,
"time.nist.gov"
);
Serial
.
print
(
"Waiting for NTP time sync: "
);
time_t
now
=
time
(
nullptr
);
while
(
now
<
8
*
3600
*
2
)
{
delay
(
500
);
NTP
.
waitSet
([]()
{
Serial
.
print
(
"."
);
now
=
time
(
nullptr
);
}
});
Serial
.
println
(
""
);
time_t
now
=
time
(
nullptr
);
struct
tm
timeinfo
;
gmtime_r
(
&
now
,
&
timeinfo
);
Serial
.
print
(
"Current time: "
);
...
...
libraries/WiFi/src/WiFiNTP.h
View file @
c889a3c1
...
...
@@ -77,12 +77,19 @@ public:
}
bool
waitSet
(
uint32_t
timeout
=
10000
)
{
return
waitSet
(
nullptr
,
timeout
);
}
bool
waitSet
(
void
(
*
cb
)(),
uint32_t
timeout
=
10000
)
{
if
(
!
running
())
{
begin
(
"pool.ntp.org"
);
}
uint32_t
start
=
millis
();
while
((
time
(
nullptr
)
<
10000000
)
&&
(
millis
()
-
start
<
timeout
))
{
delay
(
10
);
delay
(
100
);
if
(
cb
)
{
cb
();
}
}
return
time
(
nullptr
)
<
10000000
;
}
...
...
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