allow to set the AP password if we can do hardware reset
This commit is contained in:
parent
5ec4dbcecf
commit
436dd3632b
|
@ -14,8 +14,9 @@ class GwWifi{
|
||||||
unsigned long lastApAccess=0;
|
unsigned long lastApAccess=0;
|
||||||
unsigned long apShutdownTime=0;
|
unsigned long apShutdownTime=0;
|
||||||
bool apActive=false;
|
bool apActive=false;
|
||||||
|
bool fixedApPass=true;
|
||||||
public:
|
public:
|
||||||
GwWifi(const GwConfigHandler *config,GwLog *log);
|
GwWifi(const GwConfigHandler *config,GwLog *log, bool fixedApPass=true);
|
||||||
void setup();
|
void setup();
|
||||||
void loop();
|
void loop();
|
||||||
bool clientConnected();
|
bool clientConnected();
|
||||||
|
|
|
@ -2,12 +2,13 @@
|
||||||
|
|
||||||
const char *AP_password = "esp32nmea2k";
|
const char *AP_password = "esp32nmea2k";
|
||||||
|
|
||||||
GwWifi::GwWifi(const GwConfigHandler *config,GwLog *log){
|
GwWifi::GwWifi(const GwConfigHandler *config,GwLog *log, bool fixedApPass){
|
||||||
this->config=config;
|
this->config=config;
|
||||||
this->logger=log;
|
this->logger=log;
|
||||||
wifiClient=config->getConfigItem(config->wifiClient,true);
|
wifiClient=config->getConfigItem(config->wifiClient,true);
|
||||||
wifiSSID=config->getConfigItem(config->wifiSSID,true);
|
wifiSSID=config->getConfigItem(config->wifiSSID,true);
|
||||||
wifiPass=config->getConfigItem(config->wifiPass,true);
|
wifiPass=config->getConfigItem(config->wifiPass,true);
|
||||||
|
this->fixedApPass=fixedApPass;
|
||||||
}
|
}
|
||||||
void GwWifi::setup(){
|
void GwWifi::setup(){
|
||||||
logger->logString("Wifi setup");
|
logger->logString("Wifi setup");
|
||||||
|
@ -17,7 +18,12 @@ void GwWifi::setup(){
|
||||||
IPAddress AP_subnet(255, 255, 255, 0);
|
IPAddress AP_subnet(255, 255, 255, 0);
|
||||||
WiFi.mode(WIFI_MODE_APSTA); //enable both AP and client
|
WiFi.mode(WIFI_MODE_APSTA); //enable both AP and client
|
||||||
const char *ssid=config->getConfigItem(config->systemName)->asCString();
|
const char *ssid=config->getConfigItem(config->systemName)->asCString();
|
||||||
|
if (fixedApPass){
|
||||||
WiFi.softAP(ssid,AP_password);
|
WiFi.softAP(ssid,AP_password);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
WiFi.softAP(ssid,config->getConfigItem(config->apPassword)->asCString());
|
||||||
|
}
|
||||||
delay(100);
|
delay(100);
|
||||||
WiFi.softAPConfig(AP_local_ip, AP_gateway, AP_subnet);
|
WiFi.softAPConfig(AP_local_ip, AP_gateway, AP_subnet);
|
||||||
logger->logString("WifiAP created: ssid=%s,adress=%s",
|
logger->logString("WifiAP created: ssid=%s,adress=%s",
|
||||||
|
|
12
src/main.cpp
12
src/main.cpp
|
@ -62,7 +62,12 @@ typedef std::map<String,String> StringMap;
|
||||||
|
|
||||||
GwLog logger(GwLog::DEBUG,NULL);
|
GwLog logger(GwLog::DEBUG,NULL);
|
||||||
GwConfigHandler config(&logger);
|
GwConfigHandler config(&logger);
|
||||||
GwWifi gwWifi(&config,&logger);
|
#ifdef GWBUTTON_PIN
|
||||||
|
bool fixedApPass=false;
|
||||||
|
#else
|
||||||
|
bool fixedApPass=true;
|
||||||
|
#endif
|
||||||
|
GwWifi gwWifi(&config,&logger,fixedApPass);
|
||||||
GwSocketServer socketServer(&config,&logger,MIN_TCP_CHANNEL_ID);
|
GwSocketServer socketServer(&config,&logger,MIN_TCP_CHANNEL_ID);
|
||||||
GwBoatData boatData(&logger);
|
GwBoatData boatData(&logger);
|
||||||
|
|
||||||
|
@ -223,13 +228,16 @@ class CapabilitiesRequest : public GwRequestMessage{
|
||||||
CapabilitiesRequest() : GwRequestMessage(F("application/json"),F("capabilities")){};
|
CapabilitiesRequest() : GwRequestMessage(F("application/json"),F("capabilities")){};
|
||||||
protected:
|
protected:
|
||||||
virtual void processRequest(){
|
virtual void processRequest(){
|
||||||
DynamicJsonDocument json(JSON_OBJECT_SIZE(2));
|
DynamicJsonDocument json(JSON_OBJECT_SIZE(6));
|
||||||
#ifdef GWSERIAL_MODE
|
#ifdef GWSERIAL_MODE
|
||||||
String serial(F(GWSERIAL_MODE));
|
String serial(F(GWSERIAL_MODE));
|
||||||
#else
|
#else
|
||||||
String serial(F("NONE"));
|
String serial(F("NONE"));
|
||||||
#endif
|
#endif
|
||||||
json["serialmode"]=serial;
|
json["serialmode"]=serial;
|
||||||
|
#ifdef GWBUTTON_PIN
|
||||||
|
json["hardwareReset"]="true";
|
||||||
|
#endif
|
||||||
serializeJson(json,result);
|
serializeJson(json,result);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,6 +25,15 @@
|
||||||
"description": "stop the access point after that many minutes if not used",
|
"description": "stop the access point after that many minutes if not used",
|
||||||
"category":"system"
|
"category":"system"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "apPassword",
|
||||||
|
"type": "password",
|
||||||
|
"default": "esp32nmea2k",
|
||||||
|
"check": "checkApPass",
|
||||||
|
"description": "set the password for the Wifi access point",
|
||||||
|
"category":"system",
|
||||||
|
"capabilities":{"hardwareReset":["true"]}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "usbBaud",
|
"name": "usbBaud",
|
||||||
"label": "USB baud rate",
|
"label": "USB baud rate",
|
||||||
|
|
|
@ -83,6 +83,12 @@
|
||||||
if (allowed != v) return "contains invalid characters, only a-z, A-Z, 0-9";
|
if (allowed != v) return "contains invalid characters, only a-z, A-Z, 0-9";
|
||||||
if (v.length < 2 || v.length > 32) return "invalid length (2...32)";
|
if (v.length < 2 || v.length > 32) return "invalid length (2...32)";
|
||||||
}
|
}
|
||||||
|
function checkApPass(v){
|
||||||
|
//min 8 characters
|
||||||
|
if (v.length < 8){
|
||||||
|
return "password must be at least 8 characters";
|
||||||
|
}
|
||||||
|
}
|
||||||
function changeConfig(){
|
function changeConfig(){
|
||||||
let url="/api/setConfig?";
|
let url="/api/setConfig?";
|
||||||
let values=document.querySelectorAll('.configForm select , .configForm input');
|
let values=document.querySelectorAll('.configForm select , .configForm input');
|
||||||
|
@ -96,7 +102,9 @@
|
||||||
if (typeof(self[check]) === 'function'){
|
if (typeof(self[check]) === 'function'){
|
||||||
let res=self[check](v.value);
|
let res=self[check](v.value);
|
||||||
if (res){
|
if (res){
|
||||||
alert("invalid config for "+v.getAttribute('name')+"("+v.value+"):\n"+res);
|
let value=v.value;
|
||||||
|
if (v.type === 'password') value="******";
|
||||||
|
alert("invalid config for "+v.getAttribute('name')+"("+value+"):\n"+res);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -254,8 +262,18 @@
|
||||||
}
|
}
|
||||||
el=document.createElement('input');
|
el=document.createElement('input');
|
||||||
el.setAttribute('name',configItem.name)
|
el.setAttribute('name',configItem.name)
|
||||||
|
frame.appendChild(el);
|
||||||
if (configItem.type === 'password'){
|
if (configItem.type === 'password'){
|
||||||
el.setAttribute('type','password');
|
el.setAttribute('type','password');
|
||||||
|
let vis=addEl('span','icon-eye',frame);
|
||||||
|
vis.addEventListener('click',function(v){
|
||||||
|
if (vis.classList.toggle('active')){
|
||||||
|
el.setAttribute('type','text');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
el.setAttribute('type','password');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else if (configItem.type === 'number'){
|
else if (configItem.type === 'number'){
|
||||||
el.setAttribute('type','number');
|
el.setAttribute('type','number');
|
||||||
|
@ -263,7 +281,6 @@
|
||||||
else{
|
else{
|
||||||
el.setAttribute('type','text');
|
el.setAttribute('type','text');
|
||||||
}
|
}
|
||||||
frame.appendChild(el);
|
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
let configDefinitions;
|
let configDefinitions;
|
||||||
|
@ -488,7 +505,7 @@ div#overlayContent {
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
}
|
}
|
||||||
div#overlayContent.text{
|
div#overlayContent.text{
|
||||||
white-space: pre;
|
white-space: pre-line;
|
||||||
}
|
}
|
||||||
.overlayButtons {
|
.overlayButtons {
|
||||||
border-top: 1px solid grey;
|
border-top: 1px solid grey;
|
||||||
|
@ -525,6 +542,17 @@ button#reset{
|
||||||
h1{
|
h1{
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
.icon-eye{
|
||||||
|
background-image: url("data:image/svg+xml;utf-8,<svg width='24' height='24' xmlns='http://www.w3.org/2000/svg' xmlns:svg='http://www.w3.org/2000/svg'> <g class='layer'> <title>Layer 1</title> <path d='m0,0l24,0l0,24l-24,0l0,-24z' fill='none' id='svg_1'/> <path d='m12,6c3.79,0 7.17,2.13 8.82,5.5c-1.65,3.37 -5.03,5.5 -8.82,5.5s-7.17,-2.13 -8.82,-5.5c1.65,-3.37 5.03,-5.5 8.82,-5.5m0,-2c-5,0 -9.27,3.11 -11,7.5c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zm0,5c1.38,0 2.5,1.12 2.5,2.5s-1.12,2.5 -2.5,2.5s-2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5m0,-2c-2.48,0 -4.5,2.02 -4.5,4.5s2.02,4.5 4.5,4.5s4.5,-2.02 4.5,-4.5s-2.02,-4.5 -4.5,-4.5z' id='svg_2'/> </g> </svg>");
|
||||||
|
height: 1.5em;
|
||||||
|
width: 1.5em;
|
||||||
|
margin-left: 0.5em;
|
||||||
|
opacity: 0.3;
|
||||||
|
}
|
||||||
|
.icon-eye.active{
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
Loading…
Reference in New Issue