Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
neOCampus-arduino
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GIS-neOCampus
neOSensor
neOCampus-arduino
Commits
19485916
Commit
19485916
authored
2 years ago
by
thiebolt
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
519e117b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/nvs_namespace/nvs_namespace.ino
+27
-6
27 additions, 6 deletions
tests/nvs_namespace/nvs_namespace.ino
with
27 additions
and
6 deletions
tests/nvs_namespace/nvs_namespace.ino
+
27
−
6
View file @
19485916
...
...
@@ -88,7 +88,7 @@ void setup() {
/*
* Open NVS-WiFi namespace to retrieve SSID / PSK
*/
if
(
not
nvs_wifi
.
begin
(
WIFI_NVS_NAMESPACE
,
tru
e
)
)
{
//
readonly
mode
if
(
not
nvs_wifi
.
begin
(
WIFI_NVS_NAMESPACE
,
fals
e
)
)
{
//
R/Wf
mode
Serial
.
print
(
F
(
"
\n
[NVS-WiFi] unable to open NVS namespace '"
));
Serial
.
print
(
WIFI_NVS_NAMESPACE
);
Serial
.
print
(
F
(
"' ... reboot !"
));
Serial
.
flush
();
delay
(
2000
);
ESP
.
restart
();
...
...
@@ -113,7 +113,7 @@ void setup() {
Serial
.
print
(
_tmp
);
Serial
.
flush
();
delay
(
1000
);
// do we need to change them ?
Serial
.
setTimeout
(
3
000
);
Serial
.
setTimeout
(
10
000
);
Serial
.
print
(
F
(
"
\n
"
));
Serial
.
print
(
F
(
"
\n
Do we need to change them (Y/n) ? "
));
Serial
.
flush
();
_answer
=
'\0'
;
...
...
@@ -122,6 +122,7 @@ void setup() {
delay
(
1000
);
return
;
}
Serial
.
begin
(
115200
);
// flush input buffer
}
/*
...
...
@@ -130,7 +131,7 @@ void setup() {
Serial
.
print
(
F
(
"
\n
[NVS-WiFi] now setting WiFi credentials (15s timeout) ... "
));
Serial
.
flush
();
Serial
.
print
(
F
(
"
\n\t
SSID --> "
));
Serial
.
flush
();
Serial
.
setTimeout
(
15000
);
_str
=
Serial
.
readString
(
);
//read until timeout
_str
=
Serial
.
readString
Until
(
'\n'
);
//read until timeout
_str
.
trim
();
// remove any \r \n whitespace at the end of the String
if
(
not
_str
.
length
()
)
{
Serial
.
print
(
F
(
"
\n\t
no input detected ... reboot !"
));
Serial
.
flush
();
...
...
@@ -139,10 +140,11 @@ void setup() {
delay
(
5000
);
}
strncpy
(
mySSID
,
_str
.
c_str
(),
sizeof
(
mySSID
));
mySSID
[
sizeof
(
mySSID
)
-
1
]
=
'\0'
;
Serial
.
print
(
mySSID
);
Serial
.
flush
();
Serial
.
print
(
F
(
"
\n\t
PASS --> "
));
Serial
.
flush
();
Serial
.
setTimeout
(
15000
);
_str
=
Serial
.
readString
(
);
//read until timeout
_str
=
Serial
.
readString
Until
(
'\n'
);
//read until timeout
_str
.
trim
();
// remove any \r \n whitespace at the end of the String
if
(
not
_str
.
length
()
)
{
Serial
.
print
(
F
(
"
\n\t
no input detected ... reboot !"
));
Serial
.
flush
();
...
...
@@ -151,14 +153,15 @@ void setup() {
delay
(
5000
);
}
strncpy
(
myPSK
,
_str
.
c_str
(),
sizeof
(
myPSK
));
myPSK
[
sizeof
(
myPSK
)
-
1
]
=
'\0'
;
Serial
.
print
(
myPSK
);
Serial
.
flush
();
// save it to NVS ?
Serial
.
print
(
F
(
"
\n
"
));
Serial
.
print
(
F
(
"
\n
[NVS-WiFi] entered crdentials :)"
));
Serial
.
flush
();
Serial
.
print
(
F
(
"
\n
[NVS-WiFi] entered cr
e
dentials :)"
));
Serial
.
flush
();
snprintf
(
_tmp
,
sizeof
(
_tmp
),
"
\n\t
SSID : %s
\n\t
PASS : %s"
,
mySSID
,
myPSK
);
Serial
.
print
(
_tmp
);
Serial
.
flush
();
delay
(
1000
);
Serial
.
setTimeout
(
3
000
);
Serial
.
setTimeout
(
10
000
);
Serial
.
print
(
F
(
"
\n
Save it to NVS (Y/n) ? "
));
Serial
.
flush
();
_answer
=
'\0'
;
if
(
not
Serial
.
readBytes
(
&
_answer
,
1
)
or
(
_answer
!=
'Y'
and
_answer
!=
'y'
)
)
{
...
...
@@ -167,6 +170,7 @@ void setup() {
ESP
.
restart
();
delay
(
5000
);
}
Serial
.
begin
(
115200
);
// flush input buffer
// saving to namespace :)
if
(
not
nvs_wifi
.
begin
(
WIFI_NVS_NAMESPACE
,
false
)
)
{
// R/W mode
...
...
@@ -208,8 +212,25 @@ void setup() {
// --- LOOP --------------------------------------------------------------------
void
loop
()
{
static
unsigned
long
_lastMsg
=
0
;
// elapsed ms since last check
// do we want to reboot ?
if
(
((
millis
()
-
_lastMsg
)
>=
(
unsigned
long
)
45000UL
)
==
true
)
{
_lastMsg
=
millis
();
Serial
.
begin
(
115200
);
// flush input buffer
Serial
.
print
(
F
(
"
\n\t
Do you want to REBOOT (Y/n) ?"
));
Serial
.
setTimeout
(
5000
);
char
_answer
=
'\0'
;
Serial
.
readBytes
(
&
_answer
,
1
);
if
(
_answer
==
'Y'
or
_answer
==
'y'
)
{
Serial
.
print
(
F
(
"
\n\t
... OK, reboot is on way ... "
));
Serial
.
flush
();
_need2reboot
=
true
;
}
Serial
.
begin
(
115200
);
// flush input buffer
}
/*
* do something here ...
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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