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>
|
||||
|
||||
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) {
|
||||
File dataFile = SPIFFS.open(fileName, "r");
|
||||
char * pch;
|
||||
const char * config_key;
|
||||
char * config_value;
|
||||
while (dataFile.available()) {
|
||||
// Lets read line by line from the file
|
||||
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');
|
||||
pch = strtok(line,"=");
|
||||
Serial.println(line);
|
||||
Serial.println(pch);
|
||||
//pch = strtok(NULL," ");
|
||||
config_key = strtok(char_array,"=");
|
||||
config_value = strtok(NULL,"=");
|
||||
config[0] = config_value;
|
||||
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;
|
||||
|
@ -36,12 +59,11 @@ bool handleFile(String fileName, String dataType) {
|
|||
return true;
|
||||
}
|
||||
|
||||
const char *form-fields[] = {"device-id" "wifi-ssid" "wifi-password"};
|
||||
|
||||
bool handlePayload() {
|
||||
Serial.println(server.args());
|
||||
|
||||
if(server.args()!=3)
|
||||
if(server.args()!=4)
|
||||
server.send(404, "text/plain", "Missing params");
|
||||
|
||||
Serial.println("saving");
|
||||
|
@ -59,7 +81,12 @@ bool handlePayload() {
|
|||
dataFile.print("=");
|
||||
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("=");
|
||||
dataFile.println(server.arg(i));
|
||||
|
@ -91,6 +118,8 @@ bool handleNotFound() {
|
|||
// may handle multiple images
|
||||
if (server.uri().endsWith(".js"))
|
||||
return handleFile("/main.js", "text/javascript");
|
||||
if (server.uri().endsWith(".woff2"))
|
||||
return handleFile("/fa-solid-900.woff2", "text/javascript");
|
||||
if (server.uri().endsWith(".css"))
|
||||
return handleFile("/tachyon.css", "text/css");
|
||||
if (server.uri().endsWith(".html"))
|
||||
|
|
Binary file not shown.
|
@ -1,12 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<html style="height:100%;">
|
||||
<html class="h-100 bg-green" lang="en">
|
||||
<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">
|
||||
<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>
|
||||
<body style="height:100%;">
|
||||
<div id="app" style="height:100%;">Loading</div>
|
||||
<script src="main.js" type="text/javascript"></script>
|
||||
<body class="h-100">
|
||||
<div id="app" class="h-100"><i class="fas fa-spinner"></i>Loading</div>
|
||||
<script src="dev-main.js"></script>
|
||||
</body>
|
||||
</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"
|
||||
:asset-path "app/data/prod",
|
||||
:optimizations :advanced
|
||||
:source-map nil
|
||||
; :source-map none
|
||||
:main DEMOAPP.core}
|
||||
|
|
|
@ -22,3 +22,7 @@ http://localhost:9500/figwheel-extra-main/devcards
|
|||
|
||||
app config
|
||||
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
|
||||
(reitit/router
|
||||
[["/" :index]
|
||||
["/404" :about]]))
|
||||
["/404" :about]]))
|
||||
|
||||
; link builder
|
||||
(defn path-for [route & [params]]
|
||||
|
@ -26,11 +26,12 @@
|
|||
(:path (reitit/match-by-name router route params))
|
||||
(: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
|
||||
[:label.db.fw4.lh-copy.f6 {:for name} title]
|
||||
[: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))
|
||||
:value ((keyword name) @form-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"}
|
||||
[:fieldset#sign_up.ba.b--transparent.ph0.mh0
|
||||
[:legend.ph0.mh0.fw6 "Device Setup"]
|
||||
|
||||
(form-input "server" "Server" "127.0.0.1"
|
||||
form-data "device-id-type"
|
||||
"Invalid server address")
|
||||
(form-input "device-id" "Device Unique ID" "AAAA" form-data
|
||||
"device-id-type" "Invalid identifier, should be alphanumeric and 4 characters long.")
|
||||
(form-input "wifi-ssid" "WIFI SSID" "" form-data "wifi-ssid-type"
|
||||
"Invalid SSID, should be no more than 32 characters and must not start with !, #, or ;.")
|
||||
(form-input "wifi-key" "WIFI Password" "" form-data "wifi-key-type" "No password set.")
|
||||
|
||||
]
|
||||
(form-input-map {:name "server" :title "Server" :placeholder "127.0.0.1"
|
||||
:data form-data :validator "device-id-type"
|
||||
:error "Invalid server address"})
|
||||
(form-input-map {:name "device-id" :title "Device Unique ID" :placeholder "AAAA"
|
||||
:data form-data :validator "device-id-type"
|
||||
:error "Invalid identifier" :focus "true"})
|
||||
(form-input-map {:name "wifi-ssid" :title "WIFI SSID"
|
||||
:data form-data :validator "wifi-ssid-type"
|
||||
: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
|
||||
[:input.b.ph3.pv2.input-reset.ba.b--black.bg-transparent.grow.pointer.f6.br2
|
||||
{:type "submit" :value "Save"}]]]])
|
||||
|
||||
(defn home-page []
|
||||
[:div.w-25
|
||||
[:div.w-35
|
||||
[:a.athelas.f3.link.white-70.hover-white.no-underline.flex.items-center.pa3
|
||||
{:href "/"}
|
||||
[:h2
|
||||
|
|
Loading…
Reference in New Issue