Work in progress config loading.
This commit is contained in:
parent
daa5652abe
commit
e966e2f952
43
app/app.ino
43
app/app.ino
|
@ -6,18 +6,41 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
ESP8266WebServer server(80);
|
ESP8266WebServer server(80);
|
||||||
|
// define your expected field names here
|
||||||
|
#define cfg_device_id 0
|
||||||
|
#define cfg_wifi_ssid 1
|
||||||
|
#define cfg_wifi_key 2
|
||||||
|
#define cfg_server 3
|
||||||
|
const char *form_fields[] = {"device-id" "wifi-ssid" "wifi-key" "server"};
|
||||||
|
int number_of_fields = sizeof(form_fields);
|
||||||
|
const char *config[4] = {};
|
||||||
|
|
||||||
bool loadConfig(String fileName) {
|
bool loadConfig(String fileName) {
|
||||||
File dataFile = SPIFFS.open(fileName, "r");
|
File dataFile = SPIFFS.open(fileName, "r");
|
||||||
char * pch;
|
char * pch;
|
||||||
|
const char * config_key;
|
||||||
|
char * config_value;
|
||||||
while (dataFile.available()) {
|
while (dataFile.available()) {
|
||||||
// Lets read line by line from the file
|
// Lets read line by line from the file
|
||||||
String line = dataFile.readStringUntil('\n');
|
String line = dataFile.readStringUntil('\n');
|
||||||
|
int str_len = line.length() + 1;
|
||||||
|
char char_array[str_len];
|
||||||
|
line.toCharArray(char_array, str_len);
|
||||||
//char line[] = dataFile.readStringUntil('\n');
|
//char line[] = dataFile.readStringUntil('\n');
|
||||||
pch = strtok(line,"=");
|
config_key = strtok(char_array,"=");
|
||||||
Serial.println(line);
|
config_value = strtok(NULL,"=");
|
||||||
Serial.println(pch);
|
config[0] = config_value;
|
||||||
//pch = strtok(NULL," ");
|
Serial.println(config_key);
|
||||||
|
Serial.println(config_value);
|
||||||
|
|
||||||
|
for (int i=0; i<3;i++){
|
||||||
|
if(strcmp(form_fields[i],config_key)==0){
|
||||||
|
config[i] = config_value;
|
||||||
|
Serial.println("------");
|
||||||
|
Serial.println(config[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Serial.println(config[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -36,12 +59,11 @@ bool handleFile(String fileName, String dataType) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *form-fields[] = {"device-id" "wifi-ssid" "wifi-password"};
|
|
||||||
|
|
||||||
bool handlePayload() {
|
bool handlePayload() {
|
||||||
Serial.println(server.args());
|
Serial.println(server.args());
|
||||||
|
|
||||||
if(server.args()!=3)
|
if(server.args()!=4)
|
||||||
server.send(404, "text/plain", "Missing params");
|
server.send(404, "text/plain", "Missing params");
|
||||||
|
|
||||||
Serial.println("saving");
|
Serial.println("saving");
|
||||||
|
@ -59,7 +81,12 @@ bool handlePayload() {
|
||||||
dataFile.print("=");
|
dataFile.print("=");
|
||||||
dataFile.println(server.arg(i));
|
dataFile.println(server.arg(i));
|
||||||
}
|
}
|
||||||
if(server.argName(i) == "wifi-password") {
|
if(server.argName(i) == "wifi-key") {
|
||||||
|
dataFile.print(server.argName(i));
|
||||||
|
dataFile.print("=");
|
||||||
|
dataFile.println(server.arg(i));
|
||||||
|
}
|
||||||
|
if(server.argName(i) == "server") {
|
||||||
dataFile.print(server.argName(i));
|
dataFile.print(server.argName(i));
|
||||||
dataFile.print("=");
|
dataFile.print("=");
|
||||||
dataFile.println(server.arg(i));
|
dataFile.println(server.arg(i));
|
||||||
|
@ -91,6 +118,8 @@ bool handleNotFound() {
|
||||||
// may handle multiple images
|
// may handle multiple images
|
||||||
if (server.uri().endsWith(".js"))
|
if (server.uri().endsWith(".js"))
|
||||||
return handleFile("/main.js", "text/javascript");
|
return handleFile("/main.js", "text/javascript");
|
||||||
|
if (server.uri().endsWith(".woff2"))
|
||||||
|
return handleFile("/fa-solid-900.woff2", "text/javascript");
|
||||||
if (server.uri().endsWith(".css"))
|
if (server.uri().endsWith(".css"))
|
||||||
return handleFile("/tachyon.css", "text/css");
|
return handleFile("/tachyon.css", "text/css");
|
||||||
if (server.uri().endsWith(".html"))
|
if (server.uri().endsWith(".html"))
|
||||||
|
|
Binary file not shown.
|
@ -1,12 +1,14 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html style="height:100%;">
|
<html class="h-100 bg-green" lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
<title>Device setup</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<link rel="stylesheet" href="tachyon.css"/>
|
<link rel="stylesheet" href="tachyon.css" type="text/css"/>
|
||||||
|
<link rel="stylesheet" href="all.min.css" type="text/css"/>
|
||||||
</head>
|
</head>
|
||||||
<body style="height:100%;">
|
<body class="h-100">
|
||||||
<div id="app" style="height:100%;">Loading</div>
|
<div id="app" class="h-100"><i class="fas fa-spinner"></i>Loading</div>
|
||||||
<script src="main.js" type="text/javascript"></script>
|
<script src="dev-main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
1429
app/data/main.js
1429
app/data/main.js
File diff suppressed because it is too large
Load Diff
|
@ -2,5 +2,5 @@
|
||||||
:output-dir "app/data/prod"
|
:output-dir "app/data/prod"
|
||||||
:asset-path "app/data/prod",
|
:asset-path "app/data/prod",
|
||||||
:optimizations :advanced
|
:optimizations :advanced
|
||||||
:source-map nil
|
; :source-map none
|
||||||
:main DEMOAPP.core}
|
:main DEMOAPP.core}
|
||||||
|
|
|
@ -22,3 +22,7 @@ http://localhost:9500/figwheel-extra-main/devcards
|
||||||
|
|
||||||
app config
|
app config
|
||||||
clojure -m figwheel.main --print-config --build dev
|
clojure -m figwheel.main --print-config --build dev
|
||||||
|
|
||||||
|
#+BEGIN_SRC sh
|
||||||
|
clojure -m figwheel.main --build prod --repl
|
||||||
|
#+END_SRC
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
(def router
|
(def router
|
||||||
(reitit/router
|
(reitit/router
|
||||||
[["/" :index]
|
[["/" :index]
|
||||||
["/404" :about]]))
|
["/404" :about]]))
|
||||||
|
|
||||||
; link builder
|
; link builder
|
||||||
(defn path-for [route & [params]]
|
(defn path-for [route & [params]]
|
||||||
|
@ -26,11 +26,12 @@
|
||||||
(:path (reitit/match-by-name router route params))
|
(:path (reitit/match-by-name router route params))
|
||||||
(:path (reitit/match-by-name router route))))
|
(:path (reitit/match-by-name router route))))
|
||||||
|
|
||||||
(defn form-input [name title placeholder data validator error]
|
|
||||||
|
(defn form-input-map [{:keys [name title placeholder data validator error focus type]}]
|
||||||
[:div.mt3.dim
|
[:div.mt3.dim
|
||||||
[:label.db.fw4.lh-copy.f6 {:for name} title]
|
[:label.db.fw4.lh-copy.f6 {:for name} title]
|
||||||
[:input#wifi-ssid.pa2.input-reset.ba.bg-near-white.w-100.measure.b--silver
|
[:input#wifi-ssid.pa2.input-reset.ba.bg-near-white.w-100.measure.b--silver
|
||||||
{:type "text" :name name :placeholder placeholder :autoFocus "true"
|
{:type (or type "text") :name name :placeholder placeholder :autoFocus (or focus nil)
|
||||||
:on-change #(swap! data assoc (keyword name) (-> % .-target .-value))
|
:on-change #(swap! data assoc (keyword name) (-> % .-target .-value))
|
||||||
:value ((keyword name) @form-data)}]
|
:value ((keyword name) @form-data)}]
|
||||||
[:p (if (and (not-empty ((keyword name) @data))
|
[:p (if (and (not-empty ((keyword name) @data))
|
||||||
|
@ -46,23 +47,27 @@
|
||||||
[:form.ma3 {:action "sign-up_submit" :method "get" :accept-charset "utf-8"}
|
[:form.ma3 {:action "sign-up_submit" :method "get" :accept-charset "utf-8"}
|
||||||
[:fieldset#sign_up.ba.b--transparent.ph0.mh0
|
[:fieldset#sign_up.ba.b--transparent.ph0.mh0
|
||||||
[:legend.ph0.mh0.fw6 "Device Setup"]
|
[:legend.ph0.mh0.fw6 "Device Setup"]
|
||||||
|
(form-input-map {:name "server" :title "Server" :placeholder "127.0.0.1"
|
||||||
(form-input "server" "Server" "127.0.0.1"
|
:data form-data :validator "device-id-type"
|
||||||
form-data "device-id-type"
|
:error "Invalid server address"})
|
||||||
"Invalid server address")
|
(form-input-map {:name "device-id" :title "Device Unique ID" :placeholder "AAAA"
|
||||||
(form-input "device-id" "Device Unique ID" "AAAA" form-data
|
:data form-data :validator "device-id-type"
|
||||||
"device-id-type" "Invalid identifier, should be alphanumeric and 4 characters long.")
|
:error "Invalid identifier" :focus "true"})
|
||||||
(form-input "wifi-ssid" "WIFI SSID" "" form-data "wifi-ssid-type"
|
(form-input-map {:name "wifi-ssid" :title "WIFI SSID"
|
||||||
"Invalid SSID, should be no more than 32 characters and must not start with !, #, or ;.")
|
:data form-data :validator "wifi-ssid-type"
|
||||||
(form-input "wifi-key" "WIFI Password" "" form-data "wifi-key-type" "No password set.")
|
:error "Invalid SSID"})
|
||||||
|
(form-input-map {:name "wifi-ssid2" :title "WIFI SSID"
|
||||||
]
|
:data form-data :validator "wifi-ssid-type"
|
||||||
|
:error "Invalid SSID"})
|
||||||
|
(form-input-map {:name "wifi-key" :title "WIFI Password"
|
||||||
|
:data form-data :validator "wifi-key-type"
|
||||||
|
:error "Invalid wifi password" :type "password"})]
|
||||||
[:div.mt3
|
[:div.mt3
|
||||||
[:input.b.ph3.pv2.input-reset.ba.b--black.bg-transparent.grow.pointer.f6.br2
|
[:input.b.ph3.pv2.input-reset.ba.b--black.bg-transparent.grow.pointer.f6.br2
|
||||||
{:type "submit" :value "Save"}]]]])
|
{:type "submit" :value "Save"}]]]])
|
||||||
|
|
||||||
(defn home-page []
|
(defn home-page []
|
||||||
[:div.w-25
|
[:div.w-35
|
||||||
[:a.athelas.f3.link.white-70.hover-white.no-underline.flex.items-center.pa3
|
[:a.athelas.f3.link.white-70.hover-white.no-underline.flex.items-center.pa3
|
||||||
{:href "/"}
|
{:href "/"}
|
||||||
[:h2
|
[:h2
|
||||||
|
|
Loading…
Reference in New Issue