diff --git a/.doxygen/Doxyfile b/.doxygen/Doxyfile index 21014f452..435be1bff 100644 --- a/.doxygen/Doxyfile +++ b/.doxygen/Doxyfile @@ -917,7 +917,8 @@ RECURSIVE = YES EXCLUDE = ../node_modules \ ../travis \ ../dist \ - ../data + ../data \ + ../secrets.h # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 07664b9ff..c814cca06 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -6,7 +6,9 @@ "${workspaceFolder}/**", "${workspaceFolder}/../libraries/**", "${workspaceFolder}/../tools/**", - "${workspaceFolder}/../hardware/esp8266com/esp8266/**" + "${workspaceFolder}/../hardware/esp8266com/esp8266/**", + "C:\\Users\\sporadic\\Documents\\Arduino\\hardware\\esp8266com\\esp8266\\**", + "C:\\Users\\sporadic\\Documents\\Arduino\\tools\\**" ], "defines": [ "_DEBUG", diff --git a/.vscode/settings.json b/.vscode/settings.json index d17c273c0..ed9996ef7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,48 @@ "search.exclude": { "**/node_modules": true, "**/.doxygen": true + }, + "javascript.implicitProjectConfig.checkJs": true, + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "fstream": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "ostream": "cpp", + "numeric": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "regex": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "typeinfo": "cpp" } } \ No newline at end of file diff --git a/ESPixelStick.ino b/ESPixelStick.ino index c8b340465..b739ccbaa 100644 --- a/ESPixelStick.ino +++ b/ESPixelStick.ino @@ -21,7 +21,7 @@ /* BEGIN - Configuration */ /*****************************************/ // Create secrets.h with a #define for SECRETS_SSID and SECRETS_PASS -// or delete the #include and enter them directly below. +// or delete the #include and enter the strings directly below. #include "secrets.h" /* Fallback configuration if config.json is empty or fails */ @@ -39,7 +39,8 @@ const char passphrase[] = SECRETS_PASS; #include "src/ESPixelStick.h" #include "src/EFUpdate.h" #include "src/FileIO.h" -#include "src/wshandler.h" +#include "src/WebIO.h" +//#include "src/wshandler.h" // Inputs #include "src/input/_Input.h" @@ -80,12 +81,14 @@ static void _u0_putc(char c){ /// Map of input modules std::map::const_iterator itInput; +const String strddp="ddp"; const std::map INPUT_MODES = { { E131Input::KEY, new E131Input() } }; /// Map of output modules std::map::const_iterator itOutput; +const String strdmx="dmx"; const std::map OUTPUT_MODES = { { WS2811::KEY, new WS2811() } }; @@ -133,7 +136,6 @@ void initWifi(); void initWeb(); void setInput(); void setOutput(); -void serializeConfig(String &jsonString, bool pretty = false, bool creds = false); /// Radio configuration /** ESP8266 radio configuration routines that are executed at startup. */ @@ -213,8 +215,6 @@ void setup() { WiFi.hostname(config.hostname); // Configure inputs and outputs -// setInput(input); -// setOutput(output); setMode(input, output); // Setup WiFi Handlers @@ -293,11 +293,10 @@ void connectWifi() { LOG_PORT.print(F("Connecting with DHCP")); } else { // We don't use DNS, so just set it to our gateway - WiFi.config(IPAddress(config.ip[0], config.ip[1], config.ip[2], config.ip[3]), - IPAddress(config.gateway[0], config.gateway[1], config.gateway[2], config.gateway[3]), - IPAddress(config.netmask[0], config.netmask[1], config.netmask[2], config.netmask[3]), - IPAddress(config.gateway[0], config.gateway[1], config.gateway[2], config.gateway[3]) - ); + IPAddress ip = ip.fromString(config.ip); + IPAddress gateway = gateway.fromString(config.gateway); + IPAddress netmask = netmask.fromString(config.netmask); + WiFi.config(ip, gateway, netmask, gateway); LOG_PORT.print(F("Connecting with Static IP")); } } @@ -349,7 +348,7 @@ void initWeb() { DefaultHeaders::Instance().addHeader(F("Access-Control-Allow-Origin"), "*"); // Setup WebSockets - ws.onEvent(wsEvent); + ws.onEvent(WebIO::onEvent); web.addHandler(&ws); // Heap status handler @@ -360,14 +359,17 @@ void initWeb() { // JSON Config Handler web.on("/conf", HTTP_GET, [](AsyncWebServerRequest *request) { String jsonString; - serializeConfig(jsonString, true); + serializeCore(jsonString, true); request->send(200, "text/json", jsonString); }); // Firmware upload handler - only in station mode web.on("/updatefw", HTTP_POST, [](AsyncWebServerRequest *request) { ws.textAll("X6"); - }, handle_fw_upload).setFilter(ON_STA_FILTER); + }, WebIO::onFirmwareUpload).setFilter(ON_STA_FILTER); + + // Root access for testing + web.serveStatic("/root", SPIFFS, "/"); // Static Handler web.serveStatic("/", SPIFFS, "/www/").setDefaultFile("index.html"); @@ -447,8 +449,8 @@ void validateConfig() { if (!config.hostname.length()) config.hostname = "esps-" + String(chipId); - - itInput = INPUT_MODES.find(config.inputmode); +//TODO: Update this to set to ws2811 and e131 if no config found + itInput = INPUT_MODES.find(config.input); if (itInput != INPUT_MODES.end()) { input = itInput->second; LOG_PORT.printf("- Input mode set to %s\n", input->getKey().c_str()); @@ -456,10 +458,11 @@ void validateConfig() { itInput = INPUT_MODES.begin(); LOG_PORT.printf("* Input mode from core config invalid, setting to %s.\n", itInput->first.c_str()); + config.input = itInput->first; input = itInput->second; } - itOutput = OUTPUT_MODES.find(config.outputmode); + itOutput = OUTPUT_MODES.find(config.output); if (itOutput != OUTPUT_MODES.end()) { output = itOutput->second; LOG_PORT.printf("- Output mode set to %s\n", output->getKey().c_str()); @@ -467,15 +470,17 @@ void validateConfig() { itOutput = OUTPUT_MODES.begin(); LOG_PORT.printf("* Input mode from core config invalid, setting to %s.\n", itOutput->first.c_str()); + config.output = itOutput->first; output = itOutput->second; } } -void deserialize(DynamicJsonDocument &json) { + +void deserializeCore(DynamicJsonDocument &json) { // Device if (json.containsKey("device")) { config.id = json["device"]["id"].as(); - config.inputmode = json["device"]["inputmode"].as(); - config.outputmode = json["device"]["outputmode"].as(); + config.input = json["device"]["input"].as(); + config.output = json["device"]["output"].as(); } else { LOG_PORT.println("No device settings found."); } @@ -494,11 +499,10 @@ void deserialize(DynamicJsonDocument &json) { config.passphrase = passphrase; // Network - for (int i = 0; i < 4; i++) { - config.ip[i] = networkJson["ip"][i]; - config.netmask[i] = networkJson["netmask"][i]; - config.gateway[i] = networkJson["gateway"][i]; - } + config.ip = networkJson["ip"].as(); + config.netmask = networkJson["netmask"].as(); + config.gateway = networkJson["gateway"].as(); + config.dhcp = networkJson["dhcp"]; config.sta_timeout = networkJson["sta_timeout"] | CLIENT_TIMEOUT; if (config.sta_timeout < 5) { @@ -532,7 +536,7 @@ void loadConfig() { // Zeroize Config struct memset(&config, 0, sizeof(config)); - if (FileIO::loadConfig(CONFIG_FILE, &deserialize)) { + if (FileIO::loadConfig(CONFIG_FILE, &deserializeCore)) { validateConfig(); } else { // Load failed, create a new config file and save it @@ -543,13 +547,15 @@ void loadConfig() { } // Serialize the current config into a JSON string -void serializeConfig(String &jsonString, bool pretty, bool creds) { +void serializeCore(String &jsonString, boolean pretty, boolean creds) { // Create buffer and root object DynamicJsonDocument json(1024); // Device JsonObject device = json.createNestedObject("device"); device["id"] = config.id.c_str(); + device["input"] = config.input.c_str(); + device["output"] = config.output.c_str(); // Network JsonObject network = json.createNestedObject("network"); @@ -557,14 +563,10 @@ void serializeConfig(String &jsonString, bool pretty, bool creds) { if (creds) network["passphrase"] = config.passphrase.c_str(); network["hostname"] = config.hostname.c_str(); - JsonArray ip = network.createNestedArray("ip"); - JsonArray netmask = network.createNestedArray("netmask"); - JsonArray gateway = network.createNestedArray("gateway"); - for (int i = 0; i < 4; i++) { - ip.add(config.ip[i]); - netmask.add(config.netmask[i]); - gateway.add(config.gateway[i]); - } + network["ip"] = config.ip.c_str(); + network["netmask"] = config.netmask.c_str(); + network["gateway"] = config.gateway.c_str(); + network["dhcp"] = config.dhcp; network["sta_timeout"] = config.sta_timeout; @@ -584,7 +586,7 @@ void saveConfig() { // Serialize Config String jsonString; - serializeConfig(jsonString, true, true); + serializeCore(jsonString, false, true); // Save Config FileIO::saveConfig(CONFIG_FILE, jsonString); diff --git a/data/config.json b/data/config.json index f175bbab8..3976d8ee0 100644 --- a/data/config.json +++ b/data/config.json @@ -1,31 +1,16 @@ { "device": { "id": "ESPixelStick", - "inputmode": "e131", - "outputmode": "ws2811" + "input": "e131", + "output": "ws2811" }, "network": { "ssid": "", "passphrase": "", - "ip": [ - 192, - 168, - 1, - 10 - ], - "netmask": [ - 255, - 255, - 255, - 0 - ], - "gateway": [ - 192, - 168, - 1, - 1 - ], + "ip": "192.168.1.10", + "netmask": "255.255.255.0", + "gateway": "192.168.1.1", "dhcp": true, "ap_fallback": false }, diff --git a/gulpfile.js b/gulpfile.js index ab61fb38f..56b7c11c3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -12,7 +12,7 @@ var rename = require('gulp-rename'); /* HTML Task */ gulp.task('html', function() { - return gulp.src(['html/*.html', 'html/*.htm']) + return gulp.src(['html/*.html']) .pipe(plumber()) .pipe(htmlmin({ collapseWhitespace: true, diff --git a/html/e131.html b/html/e131.html new file mode 100644 index 000000000..bee0000aa --- /dev/null +++ b/html/e131.html @@ -0,0 +1,21 @@ +
+ E1.31 Configuration +
+ +
+
+
+ +
+
+
+ +
+
+ +
+
+
+
+
+
\ No newline at end of file diff --git a/html/index.html b/html/index.html index b1d8957eb..8bf2e4c6f 100644 --- a/html/index.html +++ b/html/index.html @@ -6,8 +6,10 @@ + + @@ -29,7 +31,7 @@ +
+
+
+
+

+
+
MQTT Configuration
@@ -280,15 +225,15 @@
+
- -
-
- -
+ +
+
+
- - +
+
@@ -486,11 +431,11 @@