Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructured project to work as library compatible with Arduino-Espressif32 v2.0.x #290

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.gcc-flags.json
*Thumbs.db
/data/www
/lib/framework/WWWData.h
src/WWWData.h
/interface/build
/interface/node_modules
/interface/.eslintcache
Expand Down
5 changes: 5 additions & 0 deletions examples/LightState/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
54 changes: 54 additions & 0 deletions examples/LightState/factory_settings.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
; The indicated settings support placeholder substitution as follows:
;
; #{platform} - The microcontroller platform, e.g. "esp32" or "esp8266"
; #{unique_id} - A unique identifier derived from the MAC address, e.g. "0b0a859d6816"
; #{random} - A random number encoded as a hex string, e.g. "55722f94"

[factory_settings]
build_flags =
; WiFi settings
-D FACTORY_WIFI_SSID=\"\"
-D FACTORY_WIFI_PASSWORD=\"\"
-D FACTORY_WIFI_HOSTNAME=\"#{platform}-#{unique_id}\" ; supports placeholders

; Access point settings
-D FACTORY_AP_PROVISION_MODE=AP_MODE_DISCONNECTED
-D FACTORY_AP_SSID=\"ESP8266-React-#{unique_id}\" ; 1-64 characters, supports placeholders
-D FACTORY_AP_PASSWORD=\"esp-react\" ; 8-64 characters
-D FACTORY_AP_CHANNEL=1
-D FACTORY_AP_SSID_HIDDEN=false
-D FACTORY_AP_MAX_CLIENTS=4
-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\"

; 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=\"\" ; supports placeholders
-D FACTORY_MQTT_PASSWORD=\"\"
-D FACTORY_MQTT_CLIENT_ID=\"#{platform}-#{unique_id}\" ; supports placeholders
-D FACTORY_MQTT_KEEP_ALIVE=60
-D FACTORY_MQTT_CLEAN_SESSION=true
-D FACTORY_MQTT_MAX_TOPIC_LENGTH=128

; JWT Secret
-D FACTORY_JWT_SECRET=\"#{random}-#{random}\" ; supports placeholders
8 changes: 8 additions & 0 deletions examples/LightState/features.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[features]
build_flags =
-D FT_PROJECT=1
-D FT_SECURITY=1
-D FT_MQTT=1
-D FT_NTP=1
-D FT_OTA=1
-D FT_UPLOAD_FIRMWARE=1
64 changes: 64 additions & 0 deletions examples/LightState/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[platformio]
extra_configs =
factory_settings.ini
features.ini
default_envs = esp12e
;default_envs = node32s
;default_envs = esp32dev

[env]
build_flags=
${factory_settings.build_flags}
${features.build_flags}
-D NO_GLOBAL_ARDUINOOTA
; Uncomment PROGMEM_WWW to enable the storage of the WWW data in PROGMEM
-D PROGMEM_WWW
; Uncomment to configure Cross-Origin Resource Sharing
;-D ENABLE_CORS
;-D CORS_ORIGIN=\"*\"

; ensure transitive dependencies are included for correct platforms only
lib_compat_mode = strict

; Uncomment & modify the lines below in order to configure OTA updates
;upload_flags =
; --port=8266
; --auth=esp-react
;upload_port = 192.168.0.11
;upload_protocol = espota

framework = arduino
monitor_speed = 115200

extra_scripts =
pre:$PROJECT_LIBDEPS_DIR/$PIOENV/esp8266-react/scripts/build_interface.py

lib_deps =
ArduinoJson@>=6.0.0,<7.0.0
; The following allows the use of the latest code for ESPAsyncWebServer - there hasn't been a release in a while
; Work around for https://github.com/me-no-dev/ESPAsyncWebServer/issues/1151
https://github.com/me-no-dev/ESPAsyncWebServer
;ESP Async WebServer@>=1.2.0,<2.0.0
AsyncMqttClient@>=0.9.0,<1.0.0
https://github.com/FernandoGarcia/esp8266-react.git

[env:esp12e]
platform = espressif8266
board = esp12e
board_build.f_cpu = 160000000L
board_build.filesystem = littlefs

; Comment out min_spiffs.csv setting if disabling PROGMEM_WWW with ESP32

[env:node32s]
board_build.partitions = min_spiffs.csv
platform = espressif32
board = node32s
board_build.filesystem = littlefs

[env:esp32dev]
; Comment out min_spiffs.csv setting if disabling PROGMEM_WWW with ESP32
board_build.partitions = min_spiffs.csv
platform = espressif32
board = esp32dev
board_build.filesystem = littlefs
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion interface/config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function override(config, env) {
terserPlugin.options.extractComments = false;

// build progmem data files
config.plugins.push(new ProgmemGenerator({ outputPath: "../lib/framework/WWWData.h", bytesPerLine: 20 }));
config.plugins.push(new ProgmemGenerator({ outputPath: "../src/WWWData.h", bytesPerLine: 20 }));
}
return config;
};
36 changes: 0 additions & 36 deletions lib/readme.txt

This file was deleted.

24 changes: 24 additions & 0 deletions library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "esp8266-react",
"description": "A framework for ESP8266 & ESP32 microcontrollers with a React UI ",
"keywords": "react,framework,wifimanager,http,async,websocket,webserver",
"authors": {
"name": "rjwats",
"maintainer": true
},
"repository": {
"type": "git",
"url": "https://github.com/rjwats/esp8266-react.git"
},
"build": {

},
"version": "1.0.0",
"license": "LGPL-3.0",
"frameworks": "arduino",
"platforms": [
"espressif8266",
"espressif32"
],
"dependencies": []
}
12 changes: 10 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extra_configs =
features.ini
default_envs = esp12e
;default_envs = node32s
;default_envs = esp32dev

[env]
build_flags=
Expand All @@ -30,7 +31,7 @@ framework = arduino
monitor_speed = 115200

extra_scripts =
pre:scripts/build_interface.py
pre:lib/esp8266-react/scripts/build_interface.py

lib_deps =
ArduinoJson@>=6.0.0,<7.0.0
Expand All @@ -46,9 +47,16 @@ board = esp12e
board_build.f_cpu = 160000000L
board_build.filesystem = littlefs

[env:node32s]
; Comment out min_spiffs.csv setting if disabling PROGMEM_WWW with ESP32

[env:node32s]
board_build.partitions = min_spiffs.csv
platform = espressif32
board = node32s
board_build.filesystem = littlefs

[env:esp32dev]
board_build.partitions = min_spiffs.csv
platform = espressif32
board = esp32dev
board_build.filesystem = littlefs
6 changes: 5 additions & 1 deletion scripts/build_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
from subprocess import check_output, Popen, PIPE, STDOUT, CalledProcessError
import os
import gzip
import inspect

Import("env")

filename = inspect.getframeinfo(inspect.currentframe()).filename
dir_path = os.path.dirname(os.path.abspath(filename))

def gzipFile(file):
with open(file, 'rb') as f_in:
with gzip.open(file + '.gz', 'wb') as f_out:
Expand All @@ -19,7 +23,7 @@ def flagExists(flag):
return True

def buildWeb():
os.chdir("interface")
os.chdir(dir_path + '/../interface')
print("Building interface with npm")
try:
env.Execute("npm install")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions lib/framework/FSPersistence.h → src/FSPersistence.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <StatefulService.h>
#include <FS.h>
#include <FactoryResetService.h>

template <class T>
class FSPersistence {
Expand Down Expand Up @@ -51,13 +52,33 @@ class FSPersistence {
JsonObject jsonObject = jsonDocument.to<JsonObject>();
_statefulService->read(jsonObject, _stateReader);

if(!_fs->exists(FS_CONFIG_DIRECTORY)){
Serial.println(F("Directory doesn't exists."));

if(_fs->mkdir(FS_CONFIG_DIRECTORY)){
Serial.println(F("Directory created."));
}
else{
Serial.println(F("Can't create the directory."));
}
}
else{
Serial.println(F("Directory exists."));
}

// serialize it to filesystem
File settingsFile = _fs->open(_filePath, "w");

// failed to open file, return false
if (!settingsFile) {
Serial.print(F("Can't open the file: "));
Serial.println(_filePath);
return false;
}
else{
Serial.print(_filePath);
Serial.println(F(" was opened."));
}

// serialize the data to the file
serializeJson(jsonDocument, settingsFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ void FactoryResetService::handleRequest(AsyncWebServerRequest* request) {
*/
void FactoryResetService::factoryReset() {
#ifdef ESP32
File root = fs->open(FS_CONFIG_DIRECTORY);
File file;
while (file = root.openNextFile()) {
fs->remove(file.name());
}
fs->rmdir(FS_CONFIG_DIRECTORY);
#elif defined(ESP8266)
Dir configDirectory = fs->openDir(FS_CONFIG_DIRECTORY);
while (configDirectory.next()) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ void WiFiSettingsService::manageSTA() {
} else {
// configure for DHCP
#ifdef ESP32
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
//WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
WiFi.setHostname(_state.hostname.c_str());
#elif defined(ESP8266)
WiFi.config(INADDR_ANY, INADDR_ANY, INADDR_ANY);
//WiFi.config(INADDR_ANY, INADDR_ANY, INADDR_ANY);
WiFi.hostname(_state.hostname);
#endif
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.