Added basic console site generator and web server

This commit is contained in:
Mark Qvist 2023-01-07 23:32:07 +01:00
parent f932c43411
commit 0d59b6b672
20 changed files with 249 additions and 80 deletions

1
.gitignore vendored
View File

@ -5,4 +5,5 @@ TODO
Release/*.hex
Release/*.zip
Release/*.json
Console/build
build/*

View File

@ -15,10 +15,6 @@
#error Target CONFIG_IDF_TARGET is not supported
#endif
// Replace with your network credentials
const char* ssid = "RNode Test";
const char* password = "somepass";
WebServer server(80);
void console_dbg(String msg) {
@ -63,6 +59,8 @@ String console_get_content_type(String filename) {
return "application/x-zip";
} else if (filename.endsWith(".gz")) {
return "application/x-gzip";
} else if (filename.endsWith(".whl")) {
return "application/octet-stream";
}
return "text/plain";
}
@ -83,6 +81,7 @@ bool console_serve_file(String path) {
File file = SPIFFS.open(path, "r");
console_dbg("Serving file to client");
server.streamFile(file, content_type);
console_dbg("Closing file");
file.close();
console_dbg("File serving done");
@ -104,8 +103,7 @@ void console_register_pages() {
void console_start() {
Serial.println("");
console_dbg("Starting Access Point...");
// WiFi.softAP(ssid, password);
WiFi.softAP(bt_devname, password);
WiFi.softAP(bt_devname);
delay(150);
IPAddress ip(10, 0, 0, 1);
IPAddress nm(255, 255, 255, 0);
@ -125,10 +123,9 @@ void console_start() {
void console_loop(){
server.handleClient();
// Internally, this yields the thread and allows
// other tasks to run.
delay(5);
delay(2);
}
// void listDir(fs::FS &fs, const char * dirname, uint8_t levels){

View File

@ -1,16 +1,17 @@
clean:
@echo Cleaning...
@-rm -rf ./build
@echo Cleaning...
@-rm -rf ./build
site:
@mkdir -p ./build
@mkdir -p ./build/css
@mkdir -p ./build/gfx
@mkdir -p ./build/images
python ./build.py
cp assets/css/* build/css/
cp assets/gfx/* build/gfx/
cp assets/images/* build/images/
cp assets/scripts/* build/scripts/
# @cp -r ../../Reticulum/docs/manual/* build/reticulum_manual/
# @cp -r ../../Reticulum/docs/Reticulum\ Manual.pdf build/reticulum_manual/
@mkdir -p ./build
@mkdir -p ./build/css
@mkdir -p ./build/gfx
@mkdir -p ./build/images
# @mkdir -p ./build/pkgs
python ./build.py
@cp assets/css/* build/css/
@cp assets/gfx/* build/gfx/
# @cp assets/images/* build/images/
# @cp assets/scripts/* build/scripts/
# @cp -r ../../Reticulum/docs/manual/* build/reticulum_manual/
# @cp -r ../../Reticulum/docs/Reticulum\ Manual.pdf build/reticulum_manual/

BIN
Console/assets/gfx/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
Console/assets/gfx/nn.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

View File

@ -1,9 +1,17 @@
import markdown
import os
import shutil
packages = {
"rns": "rns-0.4.6-py3-none-any.whl",
"nomadnet": "nomadnet-0.3.1-py3-none-any.whl",
"lxmf": "lxmf-0.2.8-py3-none-any.whl",
}
DEFAULT_TITLE = "RNode Bootstrap Console"
SOURCES_PATH="./source"
BUILD_PATH="./build"
PACKAGES_PATH = "../../dist_archive"
INPUT_ENCODING="utf-8"
OUTPUT_ENCODING="utf-8"
@ -13,7 +21,7 @@ document_start = """
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="water.css?v=5">
<link rel="stylesheet" href="{ASSET_PATH}css/water.css">
<link rel="shortcut icon" type="image/x-icon" href="{ASSET_PATH}gfx/icon.png">
<meta charset="utf-8"/>
<title>{PAGE_TITLE}</title>
@ -26,7 +34,7 @@ document_start = """
document_end = """</body></html>"""
menu_md = """<center><span class="menu">[Start]({CONTENT_PATH}index.html) | [Replicate]({CONTENT_PATH}replicate.html) | [Guides]({CONTENT_PATH}guides.html) | [Software]({CONTENT_PATH}software/index.html)| [Help](help.html) | [Contribute]({CONTENT_PATH}contribute.html)</span></center>"""
menu_md = """<center><span class="menu">[Start]({CONTENT_PATH}index.html) | [Replicate]({CONTENT_PATH}replicate.html) | [Guides]({CONTENT_PATH}guides.html) | [Software]({CONTENT_PATH}software.html) | [Help](help.html) | [Contribute]({CONTENT_PATH}contribute.html)</span></center>"""
url_maps = [
# { "path": "", "target": "/.md"},
@ -125,6 +133,10 @@ def generate_html(f, root_path):
menu_html = markdown.markdown(menu_md.replace("{CONTENT_PATH}", root_path), extensions=["markdown.extensions.fenced_code"]).replace("<p></p>", "")
page_html = markdown.markdown(md, extensions=["markdown.extensions.fenced_code"]).replace("{ASSET_PATH}", root_path)
page_html = page_html.replace("{LXMF_ADDRESS}", LXMF_ADDRESS)
for pkg_name in packages:
page_html = page_html.replace("{PKG_"+pkg_name+"}", pkg_name+".zip")
page_html = page_html.replace("{PKG_NAME_"+pkg_name+"}", packages[pkg_name])
page_date = get_prop(md, "date")
if page_date != None:
page_html = page_html.replace("{DATE}", page_date)
@ -133,6 +145,39 @@ def generate_html(f, root_path):
source_files = scan_pages(SOURCES_PATH)
def fetch_reticulum_site():
r_site_path = BUILD_PATH+"/r"
shutil.copytree(PACKAGES_PATH+"/reticulum.network", r_site_path)
shutil.rmtree(r_site_path+"/manual")
def gz_all():
import gzip
for root, dirs, files in os.walk(BUILD_PATH):
for file in files:
fpath = root+"/"+file
print("Gzipping "+fpath+"...")
f = open(fpath, "rb")
g = gzip.open(fpath+".gz", "wb")
g.writelines(f)
g.close()
f.close()
os.unlink(fpath)
from zipfile import ZipFile
for pkg_name in packages:
pkg_file = packages[pkg_name]
pkg_full_path = PACKAGES_PATH+"/"+pkg_file
if os.path.isfile(pkg_full_path):
print("Including "+pkg_file)
z = ZipFile(BUILD_PATH+"/"+pkg_name+".zip", "w")
z.write(pkg_full_path, pkg_full_path[len(PACKAGES_PATH+"/"):])
z.close()
# shutil.copy(pkg_full_path, BUILD_PATH+"/"+pkg_name)
else:
print("Could not find "+pkg_full_path)