Browse Source
Factory reset feature (#114)
Factory reset feature (#114)
Implemented factory-reset feature Extract factory settings into separate ini file Hide reset/factory reset from guest user Co-authored-by: kasedy <kasedy@gmail.com>master
rjwats
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 410 additions and 1592 deletions
-
42README.md
-
5data/config/apSettings.json
-
11data/config/mqttSettings.json
-
6data/config/ntpSettings.json
-
5data/config/otaSettings.json
-
15data/config/securitySettings.json
-
6data/config/wifiSettings.json
-
44factory_settings.ini
-
1452interface/package-lock.json
-
1interface/src/api/Endpoints.ts
-
11interface/src/components/ErrorButton.tsx
-
1interface/src/components/index.ts
-
93interface/src/system/SystemStatusForm.tsx
-
19lib/framework/APSettingsService.h
-
1lib/framework/ESP8266React.cpp
-
6lib/framework/ESP8266React.h
-
17lib/framework/ESPUtils.h
-
34lib/framework/FactoryResetService.cpp
-
31lib/framework/FactoryResetService.h
-
5lib/framework/JsonUtils.h
-
6lib/framework/MqttPubSub.h
-
67lib/framework/MqttSettingsService.h
-
28lib/framework/NTPSettingsService.h
-
21lib/framework/OTASettingsService.h
-
8lib/framework/RestartService.cpp
-
5lib/framework/SecurityManager.h
-
25lib/framework/SecuritySettingsService.h
-
18lib/framework/WiFiSettingsService.h
-
2platformio.ini
-
15src/LightMqttSettingsService.h
-
2src/LightStateService.cpp
@ -1,5 +0,0 @@ |
|||
{ |
|||
"provision_mode": 0, |
|||
"ssid": "ESP8266-React", |
|||
"password": "esp-react" |
|||
} |
@ -1,11 +0,0 @@ |
|||
{ |
|||
"enabled": false, |
|||
"host": "test.mosquitto.org", |
|||
"port": 1883, |
|||
"authenticated": false, |
|||
"username": "mqttuser", |
|||
"password": "mqttpassword", |
|||
"keepAlive": 16, |
|||
"cleanSession": true, |
|||
"maxTopicLength": 128 |
|||
} |
@ -1,6 +0,0 @@ |
|||
{ |
|||
"enabled": true, |
|||
"server": "time.google.com", |
|||
"tz_label": "Europe/London", |
|||
"tz_format": "GMT0BST,M3.5.0/1,M10.5.0" |
|||
} |
@ -1,5 +0,0 @@ |
|||
{ |
|||
"enabled": true, |
|||
"port": 8266, |
|||
"password": "esp-react" |
|||
} |
@ -1,15 +0,0 @@ |
|||
{ |
|||
"jwt_secret": "esp8266-react", |
|||
"users": [ |
|||
{ |
|||
"username": "admin", |
|||
"password": "admin", |
|||
"admin": true |
|||
}, |
|||
{ |
|||
"username": "guest", |
|||
"password": "guest", |
|||
"admin": false |
|||
} |
|||
] |
|||
} |
@ -1,6 +0,0 @@ |
|||
{ |
|||
"ssid": "", |
|||
"password": "password", |
|||
"hostname": "esp8266-react", |
|||
"static_ip_config": false |
|||
} |
@ -0,0 +1,44 @@ |
|||
[factory_settings] |
|||
build_flags = |
|||
; WiFi settings |
|||
-D FACTORY_WIFI_SSID=\"\" |
|||
-D FACTORY_WIFI_PASSWORD=\"\" |
|||
-D FACTORY_WIFI_HOSTNAME=\"esp-react\" |
|||
|
|||
; Access point settings |
|||
-D FACTORY_AP_SSID=\"ESP8266-React\" |
|||
-D FACTORY_AP_PASSWORD=\"esp-react\" |
|||
-D FACTORY_AP_PROVISION_MODE=AP_MODE_DISCONNECTED |
|||
|
|||
; User credentials for admin and guest user |
|||
-D FACTORY_ADMIN_USERNAME=\"admin\" |
|||
-D FACTORY_ADMIN_PASSWORD=\"admin\" |
|||
-D FACTORY_GUEST_USERNAME=\"guest\" |
|||
-D FACTORY_GUEST_PASSWORD=\"guest\" |
|||
|
|||
; NTP settings |
|||
-D FACTORY_NTP_ENABLED=true |
|||
-D FACTORY_NTP_TIME_ZONE_LABEL=\"Europe/London\" |
|||
-D FACTORY_NTP_TIME_ZONE_FORMAT=\"GMT0BST,M3.5.0/1,M10.5.0\" |
|||
-D FACTORY_NTP_SERVER=\"time.google.com\" |
|||
|
|||
; OTA settings |
|||
-D FACTORY_OTA_PORT=8266 |
|||
-D FACTORY_OTA_PASSWORD=\"esp-react\" |
|||
-D FACTORY_OTA_ENABLED=true |
|||
|
|||
; MQTT settings |
|||
-D FACTORY_MQTT_ENABLED=false |
|||
-D FACTORY_MQTT_HOST=\"test.mosquitto.org\" |
|||
-D FACTORY_MQTT_PORT=1883 |
|||
-D FACTORY_MQTT_USERNAME=\"\" |
|||
-D FACTORY_MQTT_PASSWORD=\"\" |
|||
; if unspecified the devices hardware ID will be used |
|||
;-D FACTORY_MQTT_CLIENT_ID=\"esp-react\" |
|||
-D FACTORY_MQTT_KEEP_ALIVE=16 |
|||
-D FACTORY_MQTT_CLEAN_SESSION=true |
|||
-D FACTORY_MQTT_MAX_TOPIC_LENGTH=128 |
|||
|
|||
; JWT Secret |
|||
; if unspecified the devices hardware ID will be used |
|||
; -D FACTORY_JWT_SECRET=\"esp8266-react\" |
1452
interface/package-lock.json
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,11 @@ |
|||
import { Button, styled } from "@material-ui/core"; |
|||
|
|||
const ErrorButton = styled(Button)(({ theme }) => ({ |
|||
color: theme.palette.getContrastText(theme.palette.error.main), |
|||
backgroundColor: theme.palette.error.main, |
|||
'&:hover': { |
|||
backgroundColor: theme.palette.error.dark, |
|||
} |
|||
})); |
|||
|
|||
export default ErrorButton; |
@ -0,0 +1,17 @@ |
|||
#ifndef ESPUtils_h |
|||
#define ESPUtils_h |
|||
|
|||
#include <Arduino.h> |
|||
|
|||
class ESPUtils { |
|||
public: |
|||
static String defaultDeviceValue(String prefix = "") { |
|||
#ifdef ESP32 |
|||
return prefix + String((unsigned long)ESP.getEfuseMac(), HEX); |
|||
#elif defined(ESP8266) |
|||
return prefix + String(ESP.getChipId(), HEX); |
|||
#endif |
|||
} |
|||
}; |
|||
|
|||
#endif // end ESPUtils |
@ -0,0 +1,34 @@ |
|||
#include <FactoryResetService.h>
|
|||
|
|||
using namespace std::placeholders; |
|||
|
|||
FactoryResetService::FactoryResetService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : fs(fs) { |
|||
server->on(FACTORY_RESET_SERVICE_PATH, |
|||
HTTP_POST, |
|||
securityManager->wrapRequest(std::bind(&FactoryResetService::handleRequest, this, _1), |
|||
AuthenticationPredicates::IS_ADMIN)); |
|||
} |
|||
|
|||
void FactoryResetService::handleRequest(AsyncWebServerRequest* request) { |
|||
request->onDisconnect(std::bind(&FactoryResetService::factoryReset, this)); |
|||
request->send(200); |
|||
} |
|||
|
|||
/**
|
|||
* Delete function assumes that all files are stored flat, within the config directory |
|||
*/ |
|||
void FactoryResetService::factoryReset() { |
|||
#ifdef ESP32
|
|||
File root = fs->open(FS_CONFIG_DIRECTORY); |
|||
File file; |
|||
while (file = root.openNextFile()) { |
|||
fs->remove(file.name()); |
|||
} |
|||
#elif defined(ESP8266)
|
|||
Dir configDirectory = fs->openDir(FS_CONFIG_DIRECTORY); |
|||
while (configDirectory.next()) { |
|||
fs->remove(configDirectory.fileName()); |
|||
} |
|||
#endif
|
|||
ESP.restart(); |
|||
} |
@ -0,0 +1,31 @@ |
|||
#ifndef FactoryResetService_h |
|||
#define FactoryResetService_h |
|||
|
|||
#ifdef ESP32 |
|||
#include <WiFi.h> |
|||
#include <AsyncTCP.h> |
|||
#elif defined(ESP8266) |
|||
#include <ESP8266WiFi.h> |
|||
#include <ESPAsyncTCP.h> |
|||
#endif |
|||
|
|||
#include <ESPAsyncWebServer.h> |
|||
#include <SecurityManager.h> |
|||
#include <FS.h> |
|||
|
|||
#define FS_CONFIG_DIRECTORY "/config" |
|||
#define FACTORY_RESET_SERVICE_PATH "/rest/factoryReset" |
|||
|
|||
class FactoryResetService { |
|||
FS* fs; |
|||
|
|||
public: |
|||
FactoryResetService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager); |
|||
|
|||
void factoryReset(); |
|||
|
|||
private: |
|||
void handleRequest(AsyncWebServerRequest* request); |
|||
}; |
|||
|
|||
#endif // end FactoryResetService_h |
Write
Preview
Loading…
Cancel
Save
Reference in new issue