From 910797adaff49db9d3cd4e6b37046d5a3fac3540 Mon Sep 17 00:00:00 2001 From: lukas Date: Sun, 3 Jan 2021 17:08:05 +0100 Subject: [PATCH] add new feature to make wifi ap invisible --- factory_settings.ini | 1 + interface/src/ap/APSettingsForm.tsx | 13 ++++++++++++- interface/src/ap/types.ts | 1 + lib/framework/APSettingsService.cpp | 2 +- lib/framework/APSettingsService.h | 9 ++++++++- src/Pins.h | 2 +- 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/factory_settings.ini b/factory_settings.ini index 4cbcf5c..e083e7a 100644 --- a/factory_settings.ini +++ b/factory_settings.ini @@ -13,6 +13,7 @@ build_flags = -D FACTORY_AP_LOCAL_IP=\"192.168.4.1\" -D FACTORY_AP_GATEWAY_IP=\"192.168.4.1\" -D FACTORY_AP_SUBNET_MASK=\"255.255.255.0\" + -D FACTORY_AP_VISIBLE=true ; User credentials for admin and guest user -D FACTORY_ADMIN_USERNAME=\"admin\" diff --git a/interface/src/ap/APSettingsForm.tsx b/interface/src/ap/APSettingsForm.tsx index 4828c7b..3e68230 100644 --- a/interface/src/ap/APSettingsForm.tsx +++ b/interface/src/ap/APSettingsForm.tsx @@ -3,8 +3,9 @@ import { TextValidator, ValidatorForm, SelectValidator } from 'react-material-ui import MenuItem from '@material-ui/core/MenuItem'; import SaveIcon from '@material-ui/icons/Save'; +import Checkbox from '@material-ui/core/Checkbox'; -import { PasswordValidator, RestFormProps, FormActions, FormButton } from '../components'; +import {PasswordValidator, RestFormProps, FormActions, FormButton, BlockFormControlLabel} from '../components'; import { isAPEnabled } from './APModes'; import { APSettings, APProvisionMode } from './types'; @@ -91,6 +92,16 @@ class APSettingsForm extends React.Component { onChange={handleValueChange('subnet_mask')} margin="normal" /> + + } + label="Network visible?" + /> } diff --git a/interface/src/ap/types.ts b/interface/src/ap/types.ts index 437d0e6..3c64a9b 100644 --- a/interface/src/ap/types.ts +++ b/interface/src/ap/types.ts @@ -24,4 +24,5 @@ export interface APSettings { local_ip: string; gateway_ip: string; subnet_mask: string; + network_visible: boolean; } diff --git a/lib/framework/APSettingsService.cpp b/lib/framework/APSettingsService.cpp index 42732f0..129b87f 100644 --- a/lib/framework/APSettingsService.cpp +++ b/lib/framework/APSettingsService.cpp @@ -46,7 +46,7 @@ void APSettingsService::manageAP() { void APSettingsService::startAP() { Serial.println(F("Starting software access point")); WiFi.softAPConfig(_state.localIP, _state.gatewayIP, _state.subnetMask); - WiFi.softAP(_state.ssid.c_str(), _state.password.c_str()); + WiFi.softAP(_state.ssid.c_str(), _state.password.c_str(), 1, !_state.networkVisible); if (!_dnsServer) { IPAddress apIp = WiFi.softAPIP(); Serial.print(F("Starting captive portal on ")); diff --git a/lib/framework/APSettingsService.h b/lib/framework/APSettingsService.h index 9104615..4d8977f 100644 --- a/lib/framework/APSettingsService.h +++ b/lib/framework/APSettingsService.h @@ -28,6 +28,10 @@ #define FACTORY_AP_PASSWORD "esp-react" #endif +#ifndef FACTORY_AP_VISIBLE +#define FACTORY_AP_VISIBLE true +#endif + #ifndef FACTORY_AP_LOCAL_IP #define FACTORY_AP_LOCAL_IP "192.168.4.1" #endif @@ -53,10 +57,11 @@ class APSettings { IPAddress localIP; IPAddress gatewayIP; IPAddress subnetMask; + bool networkVisible; bool operator==(const APSettings& settings) const { return provisionMode == settings.provisionMode && ssid == settings.ssid && password == settings.password && - localIP == settings.localIP && gatewayIP == settings.gatewayIP && subnetMask == settings.subnetMask; + localIP == settings.localIP && gatewayIP == settings.gatewayIP && subnetMask == settings.subnetMask && networkVisible == settings.networkVisible; } static void read(APSettings& settings, JsonObject& root) { @@ -66,6 +71,7 @@ class APSettings { root["local_ip"] = settings.localIP.toString(); root["gateway_ip"] = settings.gatewayIP.toString(); root["subnet_mask"] = settings.subnetMask.toString(); + root["network_visible"] = settings.networkVisible; } static StateUpdateResult update(JsonObject& root, APSettings& settings) { @@ -81,6 +87,7 @@ class APSettings { } newSettings.ssid = root["ssid"] | FACTORY_AP_SSID; newSettings.password = root["password"] | FACTORY_AP_PASSWORD; + newSettings.networkVisible = root["network_visible"] | FACTORY_AP_VISIBLE; JsonUtils::readIP(root, "local_ip", newSettings.localIP, FACTORY_AP_LOCAL_IP); JsonUtils::readIP(root, "gateway_ip", newSettings.gatewayIP, FACTORY_AP_GATEWAY_IP); diff --git a/src/Pins.h b/src/Pins.h index 08732a7..a2caefd 100644 --- a/src/Pins.h +++ b/src/Pins.h @@ -16,6 +16,6 @@ #define TempSensorPin D4 // version info -#define VERSION "v1.2.3" +#define VERSION "v1.2.4" #endif //PUMPENSTEUERUNG_PINS_H