Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a59f32c

Browse files
rjwatskasedy
andauthored
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 <[email protected]>
1 parent 51dabb7 commit a59f32c

31 files changed

+410
-1592
lines changed

README.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,40 +149,50 @@ You can enable CORS on the back end by uncommenting the -D ENABLE_CORS build fla
149149
-D CORS_ORIGIN=\"http://localhost:3000\"
150150
```
151151

152-
## Device configuration & default settings
152+
## Factory settings
153153

154-
The SPIFFS image (in the ['data'](data) folder) contains a JSON settings file for each of the configurable features.
154+
The firmware has built-in factory settings which act as default values for the various configurable services where settings are not saved on the file system. These settings can be overridden using the build flags defined in [factory_settings.ini](factory_settings.ini).
155155

156-
The config files can be found in the ['data/config'](data/config) directory:
156+
Customize the settings as you see fit, for example you might configure your home WiFi network as the factory default:
157157

158-
File | Description
159-
---- | -----------
160-
[apSettings.json](data/config/apSettings.json) | Access point settings
161-
[mqttSettings.json](data/config/mqttSettings.json) | MQTT connection settings
162-
[ntpSettings.json](data/config/ntpSettings.json) | NTP synchronization settings
163-
[otaSettings.json](data/config/otaSettings.json) | OTA update configuration
164-
[securitySettings.json](data/config/securitySettings.json) | Security settings and user credentials
165-
[wifiSettings.json](data/config/wifiSettings.json) | WiFi connection settings
166-
167-
These files can be pre-loaded with default configuration and [uploaded to the device](#uploading-the-file-system-image) if required. There are sensible defaults provided by the firmware, so this is optional.
158+
```ini
159+
-D FACTORY_WIFI_SSID=\"My Awesome WiFi Network\"
160+
-D FACTORY_WIFI_PASSWORD=\"secret\"
161+
-D FACTORY_WIFI_HOSTNAME=\"awesome_light_controller\"
162+
```
168163

169164
### Default access point settings
170165

171-
The default settings configure the device to bring up an access point on start up which can be used to configure the device:
166+
By default, the factory settings configure the device to bring up an access point on start up which can be used to configure the device:
172167

173168
* SSID: ESP8266-React
174169
* Password: esp-react
175170

176171
### Security settings and user credentials
177172

178-
The security settings and user credentials provide the following users by default:
173+
By default, the factory settings configure two user accounts with the following credentials:
179174

180175
Username | Password
181176
-------- | --------
182177
admin | admin
183178
guest | guest
184179

185-
It is recommended that you change the JWT secret and user credentials from their defaults protect your device. You can do this in the user interface, or by modifying [securitySettings.json](data/config/securitySettings.json) before [uploading the file system image](#uploading-the-file-system-image).
180+
It is recommended that you change the user credentials from their defaults better protect your device. You can do this in the user interface, or by modifying [factory_settings.ini](factory_settings.ini) as mentioned above.
181+
182+
### Customizing the factory time zone setting
183+
184+
Changing factory time zone setting is a common requirement. This requires a little effort because the time zone name and POSIX format are stored as separate values for the moment. The time zone names and POSIX formats are contained in the UI code in [TZ.ts](interface/src/ntp/TZ.ts). Take the appropriate pair of values from there, for example, for Los Angeles you would use:
185+
186+
```ini
187+
-D FACTORY_NTP_TIME_ZONE_LABEL=\"America/Los_Angeles\"
188+
-D FACTORY_NTP_TIME_ZONE_FORMAT=\"PST8PDT,M3.2.0,M11.1.0\"
189+
```
190+
191+
### Device ID factory defaults
192+
193+
If not overridden with a build flag, the firmware will use the device ID to generate factory defaults for settings such as the JWT secret and MQTT client ID.
194+
195+
> **Tip**: Random values are generally better defaults for these settings, so it is recommended you leave these flags undefined.
186196
187197
## Building for different devices
188198

data/config/apSettings.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

data/config/mqttSettings.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

data/config/ntpSettings.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

data/config/otaSettings.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

data/config/securitySettings.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

data/config/wifiSettings.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

factory_settings.ini

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[factory_settings]
2+
build_flags =
3+
; WiFi settings
4+
-D FACTORY_WIFI_SSID=\"\"
5+
-D FACTORY_WIFI_PASSWORD=\"\"
6+
-D FACTORY_WIFI_HOSTNAME=\"esp-react\"
7+
8+
; Access point settings
9+
-D FACTORY_AP_SSID=\"ESP8266-React\"
10+
-D FACTORY_AP_PASSWORD=\"esp-react\"
11+
-D FACTORY_AP_PROVISION_MODE=AP_MODE_DISCONNECTED
12+
13+
; User credentials for admin and guest user
14+
-D FACTORY_ADMIN_USERNAME=\"admin\"
15+
-D FACTORY_ADMIN_PASSWORD=\"admin\"
16+
-D FACTORY_GUEST_USERNAME=\"guest\"
17+
-D FACTORY_GUEST_PASSWORD=\"guest\"
18+
19+
; NTP settings
20+
-D FACTORY_NTP_ENABLED=true
21+
-D FACTORY_NTP_TIME_ZONE_LABEL=\"Europe/London\"
22+
-D FACTORY_NTP_TIME_ZONE_FORMAT=\"GMT0BST,M3.5.0/1,M10.5.0\"
23+
-D FACTORY_NTP_SERVER=\"time.google.com\"
24+
25+
; OTA settings
26+
-D FACTORY_OTA_PORT=8266
27+
-D FACTORY_OTA_PASSWORD=\"esp-react\"
28+
-D FACTORY_OTA_ENABLED=true
29+
30+
; MQTT settings
31+
-D FACTORY_MQTT_ENABLED=false
32+
-D FACTORY_MQTT_HOST=\"test.mosquitto.org\"
33+
-D FACTORY_MQTT_PORT=1883
34+
-D FACTORY_MQTT_USERNAME=\"\"
35+
-D FACTORY_MQTT_PASSWORD=\"\"
36+
; if unspecified the devices hardware ID will be used
37+
;-D FACTORY_MQTT_CLIENT_ID=\"esp-react\"
38+
-D FACTORY_MQTT_KEEP_ALIVE=16
39+
-D FACTORY_MQTT_CLEAN_SESSION=true
40+
-D FACTORY_MQTT_MAX_TOPIC_LENGTH=128
41+
42+
; JWT Secret
43+
; if unspecified the devices hardware ID will be used
44+
; -D FACTORY_JWT_SECRET=\"esp8266-react\"

0 commit comments

Comments
 (0)