Skip to content

Commit

Permalink
Started adding updated web code
Browse files Browse the repository at this point in the history
  • Loading branch information
forkineye committed Nov 16, 2019
1 parent 2a86765 commit 854c946
Show file tree
Hide file tree
Showing 20 changed files with 717 additions and 224 deletions.
3 changes: 2 additions & 1 deletion .doxygen/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
43 changes: 43 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
72 changes: 37 additions & 35 deletions ESPixelStick.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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"
Expand Down Expand Up @@ -80,12 +81,14 @@ static void _u0_putc(char c){

/// Map of input modules
std::map<const String, _Input*>::const_iterator itInput;
const String strddp="ddp";
const std::map<const String, _Input*> INPUT_MODES = {
{ E131Input::KEY, new E131Input() }
};

/// Map of output modules
std::map<const String, _Output*>::const_iterator itOutput;
const String strdmx="dmx";
const std::map<const String, _Output*> OUTPUT_MODES = {
{ WS2811::KEY, new WS2811() }
};
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -213,8 +215,6 @@ void setup() {
WiFi.hostname(config.hostname);

// Configure inputs and outputs
// setInput(input);
// setOutput(output);
setMode(input, output);

// Setup WiFi Handlers
Expand Down Expand Up @@ -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"));
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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");
Expand Down Expand Up @@ -447,35 +449,38 @@ 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());
} else {
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());
} else {
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<String>();
config.inputmode = json["device"]["inputmode"].as<String>();
config.outputmode = json["device"]["outputmode"].as<String>();
config.input = json["device"]["input"].as<String>();
config.output = json["device"]["output"].as<String>();
} else {
LOG_PORT.println("No device settings found.");
}
Expand All @@ -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<String>();
config.netmask = networkJson["netmask"].as<String>();
config.gateway = networkJson["gateway"].as<String>();

config.dhcp = networkJson["dhcp"];
config.sta_timeout = networkJson["sta_timeout"] | CLIENT_TIMEOUT;
if (config.sta_timeout < 5) {
Expand Down Expand Up @@ -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
Expand All @@ -543,28 +547,26 @@ 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");
network["ssid"] = config.ssid.c_str();
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;

Expand All @@ -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);
Expand Down
25 changes: 5 additions & 20 deletions data/config.json
Original file line number Diff line number Diff line change
@@ -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
},
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions html/e131.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div id="e131">
<legend class="esps-legend">E1.31 Configuration</legend>
<div class="form-group">
<label class="control-label col-sm-2" for="universe">Universe</label>
<div class="col-sm-10"><input type="text" class="form-control" id="universe" name="universe" title="DMX Universe to listen for. Consecutive DMX Universes will be monitored as needed."></div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="channel_start">Start Channel</label>
<div class="col-sm-10"><input type="text" class="form-control" id="channel_start" name="channel_start" title="Start listening for data at this DMX channel."></div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="universe_limit">Universe Boundary</label>
<div class="col-sm-10"><input type="text" class="form-control" id="universe_limit" name="universe_limit" title="The number of DMX channels you are using per Universe. This must match the configuration of your sequencer. Most common values are 510 and 512."></div>
</div>

<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox"><label><input type="checkbox" id="multicast" name="multicast"> Enable Multicast</label></div>
</div>
</div>
</div>
Loading

0 comments on commit 854c946

Please sign in to comment.