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
ba3614f8
Commit
ba3614f8
authored
2 years ago
by
thiebolt
Browse files
Options
Downloads
Patches
Plain Diff
improved WiFi connection and no more WiFiManager mods required
parent
0e266671
No related branches found
No related tags found
1 merge request
!3
Feature SDK upgrade
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
neosensor/libraries/neocampus/neocampus_utils.cpp
+48
-46
48 additions, 46 deletions
neosensor/libraries/neocampus/neocampus_utils.cpp
with
48 additions
and
46 deletions
neosensor/libraries/neocampus/neocampus_utils.cpp
+
48
−
46
View file @
ba3614f8
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
* - ...
* - ...
*
*
* ---
* ---
* F.Thiebolt aug.22 removed WiFiparameters hack :) ... by means of dynamic allocation :|
* F.Thiebolt aug.21 extended checkCLEAR to 5000ms (some ESP32 have huge
* F.Thiebolt aug.21 extended checkCLEAR to 5000ms (some ESP32 have huge
* internal capacitor enabled@starup ?!?!)
* internal capacitor enabled@starup ?!?!)
* F.Thiebolt apr.21 removed DNS related includes
* F.Thiebolt apr.21 removed DNS related includes
...
@@ -157,9 +158,15 @@ void cb_enterConfigMode( WiFiManager *myWiFiManager ) {
...
@@ -157,9 +158,15 @@ void cb_enterConfigMode( WiFiManager *myWiFiManager ) {
bool
setupWiFi
(
wifiParametersMgt
*
wp
)
{
bool
setupWiFi
(
wifiParametersMgt
*
wp
)
{
if
(
_need2reboot
)
return
false
;
if
(
_need2reboot
)
return
false
;
log_info
(
F
(
"
\n
[WiFi] start WiFiManager ..."
));
log_info
(
F
(
"
\n
[WiFi] start WiFiManager ..."
));
// WiFiManager local instance ... no need to keep it once business is done :)
WiFiManager
wifiManager
;
// debug messages
wifiManager
.
setDebugOutput
(
true
);
// reload config file
// reload config file
if
(
wp
)
{
if
(
wp
)
{
// load WiFi parameters and options
// load WiFi parameters and options
...
@@ -186,13 +193,19 @@ bool setupWiFi( wifiParametersMgt *wp ) {
...
@@ -186,13 +193,19 @@ bool setupWiFi( wifiParametersMgt *wp ) {
log_debug
(
F
(
"+"
));
log_flush
();
log_debug
(
F
(
"+"
));
log_flush
();
}
}
}
}
// WiFiManager local instance ... no need to keep once business is done
WiFiManager
wifiManager
;
// debug messages
wifiManager
.
setDebugOutput
(
true
);
// set timeouts
if
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
log_debug
(
F
(
"
\n
[WiFi] AP will get open for "
));
log_debug
(
WM_CONFIG_PORTAL_TIMEOUT
,
DEC
);
log_debug
(
F
(
" seconds"
));
wifiManager
.
setConfigPortalTimeout
(
WM_CONFIG_PORTAL_TIMEOUT
);
}
else
{
// [aug.22] if we get connected ... then activate autoreconnect :)
WiFi
.
setAutoReconnect
(
true
);
log_debug
(
F
(
"
\n
[WiFi] AP opened in CONFIG MODE for "
));
log_debug
(
WM_CONFIG_PORTAL_TIMEOUT
/
6
,
DEC
);
log_debug
(
F
(
" seconds"
));
wifiManager
.
setConfigPortalTimeout
(
WM_CONFIG_PORTAL_TIMEOUT
/
6
);
}
// set enter config mode callback
// set enter config mode callback
wifiManager
.
setAPCallback
(
cb_enterConfigMode
);
wifiManager
.
setAPCallback
(
cb_enterConfigMode
);
...
@@ -233,33 +246,30 @@ bool setupWiFi( wifiParametersMgt *wp ) {
...
@@ -233,33 +246,30 @@ bool setupWiFi( wifiParametersMgt *wp ) {
const
char
_customHtml_checkbox_checked
[]
=
"type=
\"
checkbox
\"
checked"
;
const
char
_customHtml_checkbox_checked
[]
=
"type=
\"
checkbox
\"
checked"
;
// enable / disable sensOCampus sandbox
// enable / disable sensOCampus sandbox
WiFiManagerParameter
p_sandbox
(
"sandbox"
,
"neOCampus sandbox"
,
"T"
,
2
,
_customHtml_checkbox
,
WFM_LABEL_AFTER
)
;
WiFiManagerParameter
*
p_sandbox
=
nullptr
;
if
(
wp
->
isEnabledSandbox
()
)
{
if
(
wp
->
isEnabledSandbox
()
)
{
WiFiManagerParameter
p_sandbox
(
"sandbox"
,
"neOCampus sandbox"
,
"T"
,
2
,
_customHtml_checkbox_checked
,
WFM_LABEL_AFTER
);
p_sandbox
=
new
WiFiManagerParameter
(
"sandbox"
,
"neOCampus sandbox"
,
"T"
,
2
,
_customHtml_checkbox_checked
,
WFM_LABEL_AFTER
);
#warning "REMOVE HACK below !"
/* [Jun.18] HACK that requires modification in WiFiManager
p_sandbox._customHTML = _customHtml_checkbox_checked;
*/
}
}
else
{
p_sandbox
=
new
WiFiManagerParameter
(
"sandbox"
,
"neOCampus sandbox"
,
"T"
,
2
,
_customHtml_checkbox
,
WFM_LABEL_AFTER
);
}
// TM1637 7 segment display parameters
// TM1637 7 segment display parameters
WiFiManagerParameter
p_sevenSegTM1637
(
"sevenSegTM1637"
,
"TM1637 7-seg (DIO=2,CLK=SCL)"
,
"T"
,
2
,
_customHtml_checkbox
,
WFM_LABEL_AFTER
)
;
WiFiManagerParameter
*
p_sevenSegTM1637
=
nullptr
;
if
(
wp
->
isEnabled7segTM1637
()
)
{
if
(
wp
->
isEnabled7segTM1637
()
)
{
WiFiManagerParameter
p_sevenSegTM1637
(
"sevenSegTM1637"
,
"TM1637 7-seg (DIO=2,CLK=SCL)"
,
"T"
,
2
,
_customHtml_checkbox_checked
,
WFM_LABEL_AFTER
);
p_sevenSegTM1637
=
new
WiFiManagerParameter
(
"sevenSegTM1637"
,
"TM1637 7-seg (DIO=2,CLK=SCL)"
,
"T"
,
2
,
_customHtml_checkbox_checked
,
WFM_LABEL_AFTER
);
#warning "REMOVE HACK below !"
}
/* [Jun.18] HACK that requires modification in WiFiManager
else
{
p_sevenSegTM1637._customHTML = _customHtml_checkbox_checked;
p_sevenSegTM1637
=
new
WiFiManagerParameter
(
"sevenSegTM1637"
,
"TM1637 7-seg (DIO=2,CLK=SCL)"
,
"T"
,
2
,
_customHtml_checkbox
,
WFM_LABEL_AFTER
);
*/
}
}
// PIR sensor
// PIR sensor
WiFiManagerParameter
p_PIRsensor
(
"PIRsensor"
,
"PIR sensor (pin=5)"
,
"T"
,
2
,
_customHtml_checkbox
,
WFM_LABEL_AFTER
)
;
WiFiManagerParameter
*
p_PIRsensor
=
nullptr
;
if
(
wp
->
isEnabledPIR
()
)
{
if
(
wp
->
isEnabledPIR
()
)
{
WiFiManagerParameter
p_PIRsensor
(
"PIRsensor"
,
"PIR sensor (pin=5)"
,
"T"
,
2
,
_customHtml_checkbox_checked
,
WFM_LABEL_AFTER
);
p_PIRsensor
=
new
WiFiManagerParameter
(
"PIRsensor"
,
"PIR sensor (pin=5)"
,
"T"
,
2
,
_customHtml_checkbox_checked
,
WFM_LABEL_AFTER
);
#warning "REMOVE HACK below !"
}
/* [Jun.18] HACK that requires modification in WiFiManager
else
{
p_PIRsensor._customHTML = _customHtml_checkbox_checked;
p_PIRsensor
=
new
WiFiManagerParameter
(
"PIRsensor"
,
"PIR sensor (pin=5)"
,
"T"
,
2
,
_customHtml_checkbox
,
WFM_LABEL_AFTER
);
*/
}
}
...
@@ -273,27 +283,14 @@ bool setupWiFi( wifiParametersMgt *wp ) {
...
@@ -273,27 +283,14 @@ bool setupWiFi( wifiParametersMgt *wp ) {
* add all parameters to wifiManager
* add all parameters to wifiManager
*/
*/
wifiManager
.
addParameter
(
&
p_hint
);
wifiManager
.
addParameter
(
&
p_hint
);
wifiManager
.
addParameter
(
&
p_sandbox
);
wifiManager
.
addParameter
(
p_sandbox
);
wifiManager
.
addParameter
(
&
p_sevenSegTM1637
);
wifiManager
.
addParameter
(
p_sevenSegTM1637
);
/*
wifiManager
.
addParameter
(
p_PIRsensor
);
wifiManager.addParameter(&p_pinTM1637dio);
wifiManager.addParameter(&p_pinTM1637clk);
*/
wifiManager
.
addParameter
(
&
p_PIRsensor
);
wifiManager
.
addParameter
(
&
p_eraseALL
);
wifiManager
.
addParameter
(
&
p_eraseALL
);
//
// set timeouts
if
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
log_debug
(
F
(
"
\n
[WiFi] AP will get open for "
));
log_debug
(
WM_CONFIG_PORTAL_TIMEOUT
,
DEC
);
log_debug
(
F
(
" seconds"
));
wifiManager
.
setConfigPortalTimeout
(
WM_CONFIG_PORTAL_TIMEOUT
);
}
else
{
log_debug
(
F
(
"
\n
[WiFi] AP opened in CONFIG MODE for "
));
log_debug
(
WM_CONFIG_PORTAL_TIMEOUT
/
6
,
DEC
);
log_debug
(
F
(
" seconds"
));
wifiManager
.
setConfigPortalTimeout
(
WM_CONFIG_PORTAL_TIMEOUT
/
6
);
}
// set a timeout trying to connect to a specified AP
// set a timeout trying to connect to a specified AP
// Note: isn't it useless since we manage connection ahead of WiFiManager ??
log_debug
(
F
(
"
\n
[WiFi] will try a connexion for maximum "
));
log_debug
(
WM_CONNECTION_ATTEMPT_TIMEOUT
,
DEC
);
log_debug
(
F
(
" seconds"
));
log_debug
(
F
(
"
\n
[WiFi] will try a connexion for maximum "
));
log_debug
(
WM_CONNECTION_ATTEMPT_TIMEOUT
,
DEC
);
log_debug
(
F
(
" seconds"
));
wifiManager
.
setConnectTimeout
(
WM_CONNECTION_ATTEMPT_TIMEOUT
);
wifiManager
.
setConnectTimeout
(
WM_CONNECTION_ATTEMPT_TIMEOUT
);
...
@@ -321,9 +318,9 @@ bool setupWiFi( wifiParametersMgt *wp ) {
...
@@ -321,9 +318,9 @@ bool setupWiFi( wifiParametersMgt *wp ) {
if
(
_WMsaveAddonConfigFlag
)
{
if
(
_WMsaveAddonConfigFlag
)
{
// save OPTIONS to parameters object
// save OPTIONS to parameters object
wp
->
_setopt_sandboxMode
(
strncmp
(
p_sandbox
.
getValue
(),
"T"
,
1
)
==
0
?
true
:
false
);
wp
->
_setopt_sandboxMode
(
strncmp
(
p_sandbox
->
getValue
(),
"T"
,
1
)
==
0
?
true
:
false
);
wp
->
_setopt_7segTM1637
(
strncmp
(
p_sevenSegTM1637
.
getValue
(),
"T"
,
1
)
==
0
?
true
:
false
);
wp
->
_setopt_7segTM1637
(
strncmp
(
p_sevenSegTM1637
->
getValue
(),
"T"
,
1
)
==
0
?
true
:
false
);
wp
->
_setopt_PIRsensor
(
strncmp
(
p_PIRsensor
.
getValue
(),
"T"
,
1
)
==
0
?
true
:
false
);
wp
->
_setopt_PIRsensor
(
strncmp
(
p_PIRsensor
->
getValue
(),
"T"
,
1
)
==
0
?
true
:
false
);
/*
/*
strcpy(thingspeakApiKey, p_thingspeakApiKey.getValue());
strcpy(thingspeakApiKey, p_thingspeakApiKey.getValue());
...
@@ -336,6 +333,11 @@ bool setupWiFi( wifiParametersMgt *wp ) {
...
@@ -336,6 +333,11 @@ bool setupWiFi( wifiParametersMgt *wp ) {
wp
->
_setopt_eraseALL
(
strncmp
(
p_eraseALL
.
getValue
(),
"T"
,
1
)
==
0
?
true
:
false
);
wp
->
_setopt_eraseALL
(
strncmp
(
p_eraseALL
.
getValue
(),
"T"
,
1
)
==
0
?
true
:
false
);
}
}
// freeing allocated ressources :s
free
(
p_sandbox
);
p_sandbox
=
nullptr
;
free
(
p_sevenSegTM1637
);
p_sevenSegTM1637
=
nullptr
;
free
(
p_PIRsensor
);
p_PIRsensor
=
nullptr
;
// Writing JSON config file to flash for next boot ... if something has been updated :)
// Writing JSON config file to flash for next boot ... if something has been updated :)
wp
->
saveConfigFile
();
wp
->
saveConfigFile
();
...
...
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