Skip to content
Snippets Groups Projects
Commit dd25b333 authored by francois's avatar francois
Browse files

save WiFi credentials typed by the user even if unable to connect to the GW

parent 96418e28
Branches
Tags
No related merge requests found
(c) F.Thiebolt Université Toulouse3, Laboratoire IRIT
=== Release 220328
- save WiFi credentials even if wrongly typed or end device has not been able
to connect to WiFi gateway
(c) F.Thiebolt Université Toulouse3, Laboratoire IRIT
=== (upcoming) HW Release neOSensorV5.2
- add 0805 cap for those ESP32 that miss it on EN pin
- test DAC detect on ESP8266 (check no interference with SCD4x autodetect)
- switch to ESP32 layout featuring unaligned pins
......@@ -42,7 +42,7 @@
*/
#define BOARD_NAME "neOSensor"
#define BOARD_REVISION 1.2
#define BOARD_FWREV 220316 // Firmware revision <year><month><day> in 2 digits each
#define BOARD_FWREV 220328 // Firmware revision <year><month><day> in 2 digits each
/* #############################################################################
......
......@@ -308,11 +308,12 @@ bool setupWiFi( wifiParametersMgt *wp ) {
// Getting posted form values and overriding local variables parameters
// Config file is written regardless the connection state
// TODO: find a way to parse ALL parameters added in wifi manager
// save wifi settings to wifi parameters object
wp->setWIFIsettings( wifiManager.getWiFiSSID().c_str(), wifiManager.getWiFiPass().c_str() );
if( _WMsaveAddonConfigFlag ) {
// save wifi settings to wifi parameters object
wp->_getWIFIsettings();
// save OPTIONS to parameters object
wp->_setopt_sandboxMode( strncmp(p_sandbox.getValue(),"T",1)==0 ? true : false );
wp->_setopt_7segTM1637( strncmp(p_sevenSegTM1637.getValue(),"T",1)==0 ? true : false );
......@@ -327,11 +328,11 @@ bool setupWiFi( wifiParametersMgt *wp ) {
// Dangerous option !!
wp->_setopt_eraseALL( strncmp(p_eraseALL.getValue(),"T",1)==0 ? true : false );
// Writing JSON config file to flash for next boot
wp->saveConfigFile();
}
// Writing JSON config file to flash for next boot ... if something has been updated :)
wp->saveConfigFile();
if( WiFi.status() != WL_CONNECTED ) {
log_error(F("\n[WiFi] failed to connect and hit timeout ... restart"));
// reboot our sensor
......
......@@ -201,46 +201,33 @@ bool wifiParametersMgt::saveConfigFile( void ) {
/*
* Grab WIFI settings from struct station_config
* Grab WIFI settings through Wifi global var or from parameters
* and set within private attributes
*/
bool wifiParametersMgt::_getWIFIsettings( void ) {
// grab WIFI station connexion parameters from current connexion ...
bool wifiParametersMgt::setWIFIsettings( const char* ssid, const char* pass ) {
/*
* [sep.20] ESP8266 DEPRECATED CODE
*
struct station_config _conf;
if( wifi_station_get_config(&_conf) and strlen(reinterpret_cast<const char*>(_conf.ssid)) ) {
const char *tmpSSID = ssid;
const char *tmpPASS = pass;
if( !tmpSSID ) tmpSSID = WiFi.SSID().c_str();
log_debug(F("\n[wifiParams] retrieved current ssid = ")); log_debug(tmpSSID);
if( !tmpPASS ) tmpPASS = WiFi.psk().c_str();
log_debug(F("\n[wifiParams] retrieved current pass = ")); log_debug(tmpPASS);
log_flush();
log_debug(F("\n[wifiParams] retrieved current ssid = ")); log_debug(reinterpret_cast<const char*>(_conf.ssid));
log_debug(F("\n[wifiParams] retrieved current pass = ")); log_debug(reinterpret_cast<const char*>(_conf.password));
log_flush();
if( strncmp(_ssid, reinterpret_cast<const char*>(_conf.ssid), sizeof(_ssid)) or
strncmp(_pass, reinterpret_cast<const char*>(_conf.password)), sizeof(_pass) ) {
log_debug(F("\n[wifiParams] new credentials detected ... update!")); log_flush();
strncpy( _ssid, reinterpret_cast<const char*>(_conf.ssid), sizeof(_ssid) );
strncpy( _pass, reinterpret_cast<const char*>(_conf.password), sizeof(_pass) );
_updated = true;
}
}
else {
log_debug(F("\n[wifiParams] no SSID / PASS found neither in config file nor struct station ... probably first time connect ...")); log_flush();
if( !strlen(tmpSSID) ) {
log_debug(F("\n[wifiParams] empty SSID ...")); log_flush();
return false;
}
*/
log_debug(F("\n[wifiParams] retrieved current ssid = ")); log_debug(WiFi.SSID());
log_debug(F("\n[wifiParams] retrieved current pass = ")); log_debug(WiFi.psk());
log_flush();
if( strncmp(_ssid, WiFi.SSID().c_str(), sizeof(_ssid)) or
strncmp(_pass, WiFi.psk().c_str(), sizeof(_pass)) ) {
if( strncmp(_ssid, tmpSSID, sizeof(_ssid)) or
strncmp(_pass, tmpPASS, sizeof(_pass)) ) {
log_debug(F("\n[wifiParams] new credentials detected ... update!")); log_flush();
strncpy( _ssid, WiFi.SSID().c_str(), sizeof(_ssid) );
strncpy( _pass, WiFi.psk().c_str(), sizeof(_pass) );
strncpy( _ssid, tmpSSID, sizeof(_ssid) );
strncpy( _pass, tmpPASS, sizeof(_pass) );
_updated = true;
}
else {
......@@ -503,8 +490,8 @@ for (JsonObject::iterator it=root.begin(); it!=root.end(); ++it) {
*/
if( _wifiSet ) return true;
// grab from previous settings ...
_getWIFIsettings();
// grab WiFi from previous settings (Wifi global var)
setWIFIsettings();
// over :)
return true;
......
......@@ -44,7 +44,8 @@ class wifiParametersMgt {
const char * getWIFIssid( void );
const char * getWIFIpass( void );
bool _getWIFIsettings( void ); // read struct station to extract WIFI parameters
bool setWIFIsettings( const char* ssid=nullptr, const char* pass=nullptr ); // extract WIFI parameters through Wifi global var
// or parameters and set our private attributes
// wrapper for options querries
bool isEnabledSandbox( void ) { return _opt_sandboxMode; }; // tell if neOCampus sandbox apply or if sensocampus is enabled (default)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment