some improvements
This commit is contained in:
5
dist/main.js
vendored
5
dist/main.js
vendored
@ -25,7 +25,7 @@ function getToc() {
|
|||||||
logger.info("building toc");
|
logger.info("building toc");
|
||||||
let toc = "";
|
let toc = "";
|
||||||
let posts = fs.readdirSync('./docroot/posts');
|
let posts = fs.readdirSync('./docroot/posts');
|
||||||
posts.forEach((v) => {
|
posts.sort().reverse().forEach((v) => {
|
||||||
let content = fs.readFileSync(`./docroot/posts/${v}/article.pag`);
|
let content = fs.readFileSync(`./docroot/posts/${v}/article.pag`);
|
||||||
let contentStr = content.toString();
|
let contentStr = content.toString();
|
||||||
let pageOptions = getPageOptions(contentStr);
|
let pageOptions = getPageOptions(contentStr);
|
||||||
@ -89,7 +89,8 @@ app.get('/reload', (req, res) => {
|
|||||||
cache = {};
|
cache = {};
|
||||||
toc = getToc();
|
toc = getToc();
|
||||||
masterTmpl = fs.readFileSync('./docroot/master.tmpl').toString();
|
masterTmpl = fs.readFileSync('./docroot/master.tmpl').toString();
|
||||||
res.send('reload triggered');
|
let base = req.headers['x-proxy-original-url'] || "/";
|
||||||
|
res.redirect(`${base}index`);
|
||||||
});
|
});
|
||||||
app.use('/files', express.static('files'));
|
app.use('/files', express.static('files'));
|
||||||
masterTmpl = fs.readFileSync('./docroot/master.tmpl').toString();
|
masterTmpl = fs.readFileSync('./docroot/master.tmpl').toString();
|
||||||
|
2
dist/main.js.map
vendored
2
dist/main.js.map
vendored
@ -1 +1 @@
|
|||||||
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;AAAA,yBAAwB;AAExB,mCAAkC;AAClC,gCAA+B;AAE/B,mCAAkC;AAGlC,wBAAwB,UAAkB;IACtC,IAAI,WAAW,GAAS,EAAE,CAAA;IAC1B,2CAA2C;IAC3C,IAAI;QACA,IAAI,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAClC,IAAI,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QAC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C,CAAC,CAAC,CAAA;AAEF,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;AAG1C,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,uBAAuB,CAAC,CAAC,QAAQ,EAAE,CAAA;AAChE,GAAG,GAAG,MAAM,EAAE,CAAA;AAEd,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE;IAClC,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAA;AACxC,CAAC,CAAC,CAAA;AACF,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA"}
|
@ -2,19 +2,25 @@
|
|||||||
|
|
||||||
<h1>So ugly ... why not Wordpress?</h1>
|
<h1>So ugly ... why not Wordpress?</h1>
|
||||||
<p>
|
<p>
|
||||||
I shut down my homepage at wordpress.com since it wasn't absolutely unclear to me which data was collected there. I decided to run the homepage on my own server again, since I know exactly which data is collected here: There is the Apache log with the requesters IP stripped away:
|
I shut down my homepage at wordpress.com since it was absolutely unclear to me which data was collected there. I decided to run the homepage on my own server again, since I know exactly which data is collected here: There is the Apache log with the requesters IP stripped away:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<pre>
|
<pre>
|
||||||
|
<code language="Apache">
|
||||||
CustomLog "logs/access_log" common
|
CustomLog "logs/access_log" common
|
||||||
#LogFormat "%h %l %u %t \"%r\" %>s %b" common
|
#LogFormat "%h %l %u %t \"%r\" %>s %b" common
|
||||||
LogFormat "%l %u %t \"%r\" %>s %b" common
|
LogFormat "%l %u %t \"%r\" %>s %b" common
|
||||||
</pre>
|
</pre>
|
||||||
|
</code>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Nothing else. And since I'm quite bad in CSS, it currently looks so ugly.
|
Nothing else. The homepage engine just logs which post or page is accessed and served, nothing more. If you like to have a look: <a href="https://gitlab.com/wolutator/homepage" target="_blank">https://gitlab.com/wolutator/homepage</a>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
And since I'm quite bad in CSS, it currently looks so ugly.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<a href="pages/impressum">Impressum</a>
|
<a href="pages/impressum">Impressum</a>
|
||||||
|
<a href="reload">Reload</a>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<!-- { "title": "Configuration-Webserver for ESP8266 Projects" } -->
|
<!-- { "title": "Configuration-Webserver for ESP8266 Projects" } -->
|
||||||
|
|
||||||
|
<h1>#title#</h1>
|
||||||
<p>
|
<p>
|
||||||
In my previous ESP8266 based weekend projects I always hardcoded configuration data. For the ESP8266 these are at least the WiFi credentials SSID and WPA key. Moving it into a different WiFi network requires re-flashing it. There must be a better way I thought and found that's a single line of code to run the ESP8266 as an accesspoint, which opens its own WiFi network.
|
In my previous ESP8266 based weekend projects I always hardcoded configuration data. For the ESP8266 these are at least the WiFi credentials SSID and WPA key. Moving it into a different WiFi network requires re-flashing it. There must be a better way I thought and found that's a single line of code to run the ESP8266 as an accesspoint, which opens its own WiFi network.
|
||||||
</p>
|
</p>
|
||||||
@ -41,270 +43,14 @@ open('configuration.cpp','w').write(str(c_file))
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The two templates are:
|
Using the both templates for a <a href="https://gitlab.com/wolutator/EspThermometer2/blob/master/ConfigGenerator/configuration_c.tmpl" target="_blank">C-</a> and a <a href="https://gitlab.com/wolutator/EspThermometer2/blob/master/ConfigGenerator/configuration_h.tmpl" target="_blank">H-</a>file all the code for the configuration web page, the EEPROM handling code and the code to access the configuration variables is generated.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<pre>
|
The functions provided using these templates in turn a call from a rather simple <a href="https://gitlab.com/wolutator/EspThermometer2/blob/master/configurationMode.cpp" target="_blank">configuration mode</a>. In pure configuration mode (when the device is unconfigured or the configuration mode is requested using a pulled-down pin) a new WLAN will be opened using the accesspoint functionality of the ESP8266. In production mode, the configuration accesspoint is not started, however, the configuration mode webserver is started nevertheless.
|
||||||
<code "language"="C">
|
|
||||||
typedef struct {
|
|
||||||
#for $configItem in $configItems
|
|
||||||
#if $configItem.type == 'C'
|
|
||||||
char ${configItem.key}[$configItem.length];
|
|
||||||
#else if $configItem.type == 'I'
|
|
||||||
uint32_t $configItem.key;
|
|
||||||
#end if
|
|
||||||
#end for
|
|
||||||
} tConfigBlock;
|
|
||||||
|
|
||||||
extern const uint32_t MAGIC;
|
|
||||||
extern tConfigBlock configBlock;
|
|
||||||
|
|
||||||
void configServeIndex();
|
|
||||||
void configServeGetConfiguration();
|
|
||||||
void showConfiguration();
|
|
||||||
|
|
||||||
</code>
|
|
||||||
</pre>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
And:
|
This code can be also found embedded in several of my projects. Find them at <a href="https://gitlab.com/wolutator/EspThermometer2" target="_blank">https://gitlab.com/wolutator/EspThermometer2</a>, <a href="https://gitlab.com/wolutator/TouchSwitch" target="_blank">https://gitlab.com/wolutator/TouchSwitch</a>, <a href="https://gitlab.com/wolutator/MySwitch" target="_blank">https://gitlab.com/wolutator/MySwitch</a>, <a href="https://gitlab.com/wolutator/RainSensor" target="_blank">https://gitlab.com/wolutator/RainSensor</a> and <a href="https://gitlab.com/wolutator/TwoLedSignal" target="_blank">https://gitlab.com/wolutator/TwoLedSignal</a>.
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<pre>
|
|
||||||
<code language="C">
|
|
||||||
#raw
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <ESP8266WebServer.h>
|
|
||||||
#include <EEPROM.h>
|
|
||||||
|
|
||||||
#include "defines.h"
|
|
||||||
#include "configuration.h"
|
|
||||||
#end raw
|
|
||||||
|
|
||||||
|
|
||||||
tConfigBlock configBlock;
|
|
||||||
const uint32_t MAGIC = 0xC0DE0001;
|
|
||||||
extern ESP8266WebServer webServer;
|
|
||||||
|
|
||||||
bool configSaved = false;
|
|
||||||
|
|
||||||
void configServeIndex() {
|
|
||||||
bool configValid = (configBlock.magic == MAGIC);
|
|
||||||
|
|
||||||
if (! configValid) {
|
|
||||||
#for $configItem in $configItems
|
|
||||||
#if $configItem.label != "_"
|
|
||||||
#if $configItem.type == "C"
|
|
||||||
strcpy(configBlock.$configItem.key, "$configItem.default");
|
|
||||||
#else if $configItem.type == "I"
|
|
||||||
configBlock.$configItem.key = $configItem.default;
|
|
||||||
#end if
|
|
||||||
#end if
|
|
||||||
#end for
|
|
||||||
}
|
|
||||||
|
|
||||||
String buffer =
|
|
||||||
"<!doctype html"
|
|
||||||
"<html lang=\"en\">"
|
|
||||||
" <head>"
|
|
||||||
" <title>ESP8266 Thermometer Configuration Page</title>"
|
|
||||||
" </head>"
|
|
||||||
" <body>"
|
|
||||||
" <h1>ESP8266 Configuration Page</h1>";
|
|
||||||
|
|
||||||
if (configSaved) {
|
|
||||||
configSaved = false;
|
|
||||||
buffer += "<h2>Configuration saved</h2>";
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer +=
|
|
||||||
" <form action=\"/config\" method=\"GET\">"
|
|
||||||
" <table>"
|
|
||||||
#for $configItem in $configItems
|
|
||||||
#if $configItem.label != "_"
|
|
||||||
" <tr>"
|
|
||||||
" <td>"
|
|
||||||
" <label for\"$configItem.key\">$configItem.label</label>"
|
|
||||||
" </td><td>"
|
|
||||||
" <input type=\"text\" name=\"$configItem.key\" id=\"$configItem.key\" ";
|
|
||||||
|
|
||||||
#if $configItem.type == "C"
|
|
||||||
buffer += " size=\"$configItem.length\" ";
|
|
||||||
buffer += " value=\"";
|
|
||||||
buffer += configBlock.$configItem.key;
|
|
||||||
buffer += "\"";
|
|
||||||
#else if $configItem.type == "I"
|
|
||||||
buffer += " value=\"";
|
|
||||||
buffer += configBlock.$configItem.key;
|
|
||||||
buffer += "\"";
|
|
||||||
#end if
|
|
||||||
|
|
||||||
buffer +=
|
|
||||||
" />"
|
|
||||||
" </td>"
|
|
||||||
" </tr>"
|
|
||||||
#end if
|
|
||||||
#end for
|
|
||||||
" <tr>"
|
|
||||||
" <td colspan=\"2\">"
|
|
||||||
" <button type=\"submit\">Save</button>"
|
|
||||||
" </td>"
|
|
||||||
" </tr>"
|
|
||||||
" </table>"
|
|
||||||
" </form>"
|
|
||||||
" </body>"
|
|
||||||
"</html>";
|
|
||||||
|
|
||||||
webServer.send(200, "text/html", buffer);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.println("indexHtml request served");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void configServeGetConfiguration() {
|
|
||||||
String arg;
|
|
||||||
|
|
||||||
#for $configItem in $configItems
|
|
||||||
#if $configItem.label != "_"
|
|
||||||
arg = webServer.arg("$configItem.key");
|
|
||||||
#if $configItem.type == "C"
|
|
||||||
strcpy(configBlock.$configItem.key, arg.c_str());
|
|
||||||
#else if $configItem.type == "I"
|
|
||||||
configBlock.$configItem.key = atoi(arg.c_str());
|
|
||||||
#end if
|
|
||||||
#end if
|
|
||||||
#end for
|
|
||||||
|
|
||||||
configBlock.magic = MAGIC;
|
|
||||||
|
|
||||||
showConfiguration();
|
|
||||||
|
|
||||||
EEPROM.begin(512);
|
|
||||||
EEPROM.put(EEPROM_ADDR, configBlock);
|
|
||||||
EEPROM.commit();
|
|
||||||
|
|
||||||
Serial.println("EEPROM saved");
|
|
||||||
|
|
||||||
configSaved = true;
|
|
||||||
webServer.sendHeader("Location", String("/"), true);
|
|
||||||
webServer.send(302, "text/plain", "");
|
|
||||||
//webServer.send(200, "text/html", "configuration saved");
|
|
||||||
}
|
|
||||||
|
|
||||||
void showConfiguration() {
|
|
||||||
Serial.println("Configuration is");
|
|
||||||
|
|
||||||
#for $configItem in $configItems
|
|
||||||
Serial.print("$configItem.key = ");
|
|
||||||
Serial.println(configBlock.$configItem.key);
|
|
||||||
|
|
||||||
#end for
|
|
||||||
|
|
||||||
Serial.println("---");
|
|
||||||
}
|
|
||||||
</code>
|
|
||||||
</pre>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Besides these generated files I also needed a framework to distinguish between "configuration mode" and "production mode" and in configuration mode to start the WiFi accesspoint.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Since I'm programming the ESP8266 in an Eclipse-based Arduino-environment, this is all done in the <code>setup()</code> and <code>loop()</code> function:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<pre>
|
|
||||||
<code language="C">
|
|
||||||
// Do not remove the include below
|
|
||||||
#include "EspThermometer2.h"
|
|
||||||
#include "defines.h"
|
|
||||||
|
|
||||||
// #define ESP8266
|
|
||||||
|
|
||||||
|
|
||||||
#include <EEPROM.h>
|
|
||||||
|
|
||||||
#include "configuration.h"
|
|
||||||
#include "productionMode.h"
|
|
||||||
#include "configurationMode.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ADC_MODE(ADC_VCC);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool configMode = false;
|
|
||||||
|
|
||||||
uint32_t startTime = 0;
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
startTime = millis();
|
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.begin(115200);
|
|
||||||
Serial.println("Starting ...");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pinMode(CONFIG_SWITCH, INPUT_PULLUP);
|
|
||||||
pinMode(LED_PIN, OUTPUT);
|
|
||||||
|
|
||||||
|
|
||||||
EEPROM.begin(512);
|
|
||||||
EEPROM.get(EEPROM_ADDR, configBlock);
|
|
||||||
|
|
||||||
|
|
||||||
Serial.print("Magic: ");
|
|
||||||
Serial.println(configBlock.magic);
|
|
||||||
|
|
||||||
configMode = ((LOW == digitalRead(CONFIG_SWITCH)) || (configBlock.magic != MAGIC));
|
|
||||||
|
|
||||||
if (configMode) {
|
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.println("Configuration mode");
|
|
||||||
#endif
|
|
||||||
digitalWrite(LED_PIN, LOW);
|
|
||||||
setupConfigurationNetwork();
|
|
||||||
setupConfigurationServer();
|
|
||||||
} else {
|
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.println("Production mode");
|
|
||||||
Serial.println();
|
|
||||||
Serial.println();
|
|
||||||
showConfiguration();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
digitalWrite(LED_PIN, HIGH);
|
|
||||||
setupProduction();
|
|
||||||
setupConfigurationServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.println("Started.");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
if (configMode) {
|
|
||||||
loopConfiguration();
|
|
||||||
} else {
|
|
||||||
loopProduction();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
</code>
|
|
||||||
</pre>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
This code can be also found embedded into two of my projects. Find them at <a href="https://gitlab.com/wolutator/EspThermometer2" target="_blank">https://gitlab.com/wolutator/EspThermometer2</a> and <a href="https://gitlab.com/wolutator/TouchSwitch" target="_blank">https://gitlab.com/wolutator/TouchSwitch</a>.
|
|
||||||
</p>
|
</p>
|
||||||
|
@ -111,7 +111,8 @@ app.get('/reload', (req, res) => {
|
|||||||
cache = {}
|
cache = {}
|
||||||
toc = getToc()
|
toc = getToc()
|
||||||
masterTmpl = fs.readFileSync('./docroot/master.tmpl').toString()
|
masterTmpl = fs.readFileSync('./docroot/master.tmpl').toString()
|
||||||
res.send('reload triggered')
|
let base = req.headers['x-proxy-original-url'] || "/"
|
||||||
|
res.redirect(`${base}index`)
|
||||||
})
|
})
|
||||||
|
|
||||||
app.use('/files', express.static('files'))
|
app.use('/files', express.static('files'))
|
||||||
|
Reference in New Issue
Block a user