Add simple static webserver
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
j3d1 2021-07-19 01:25:27 +02:00
parent 3dffd0f0d2
commit 23cb4a558b
12 changed files with 271 additions and 4 deletions

View file

@ -4,7 +4,7 @@
all: firmware case pcb all: firmware case pcb
firmware: firmware:
+@make -C firmware all +@make -C firmware html all
clean: clean:
+@make -C firmware clean +@make -C firmware clean

1
firmware/.gitignore vendored
View file

@ -142,4 +142,5 @@ dkms.conf
*.remove *.remove
firmware/ firmware/
fsdata/fsdata.c
compile_commands.json compile_commands.json

View file

@ -1,11 +1,11 @@
PROGRAM=fiatlux PROGRAM=fiatlux
EXTRA_CFLAGS=-O3 EXTRA_CFLAGS=-O3 -Ifsdata
#Enable debugging #Enable debugging
#EXTRA_CFLAGS+=-DLWIP_DEBUG=1 -DHTTPD_DEBUG=LWIP_DBG_ON #EXTRA_CFLAGS+=-DLWIP_DEBUG=1 -DHTTPD_DEBUG=LWIP_DBG_ON
EXTRA_COMPONENTS=extras/i2s_dma extras/ws2812_i2s extras/dhcpserver extras/mbedtls extras/sntp extras/cpp_support EXTRA_COMPONENTS=extras/i2s_dma extras/ws2812_i2s extras/dhcpserver extras/mbedtls extras/httpd extras/sntp extras/cpp_support
LIBS = hal m LIBS = hal m
@ -24,3 +24,5 @@ unittest:
systest: systest:
true true
.NOTPARALLEL: html all

View file

@ -24,4 +24,5 @@ void user_init(void)
xTaskCreate(wifi_task, "wifi_task", 512, NULL, 2, NULL); xTaskCreate(wifi_task, "wifi_task", 512, NULL, 2, NULL);
xTaskCreate(&httpd_task, "httpd_task", 512, NULL, 2, NULL);
} }

View file

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<link rel="shortcut icon" href="img/favicon.png">
<title>HTTP Server</title>
</head>
<body>
<ul class="navbar">
<li><a href="/">Home</a></li>
<li><a href="websockets">WebSockets</a></li>
<li><a href="about">About</a></li>
</ul>
<div class="grid main">
<h1>404 - Page not found</h1>
<div class="alert alert-error">Sorry, the page you are requesting was not found on this server.</div>
</div>
</body>
</html>

1
firmware/fsdata/fs/css/picnic.min.css vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,62 @@
main {
padding: 4em 2em 2em 2em;
max-width: 960px;
width: 100%;
margin-left: auto;
margin-right: auto;
}
section {
display: none;
}
canvas{
width: 100%;
}
main[data-page="dashboard"] section[id="dashboard"] {
display: block;
}
main[data-page="ota"] section[id="ota"] {
display: block;
}
main[data-page="wifi"] section[id="wifi"] {
display: block;
}
main[data-page="io"] section[id="io"] {
display: block;
}
.table {
width: 100%;
display: table;
}
.table>.row{
display: table-row;
}
.table>.row:nth-child(2n) {
background: rgba(17,17,17,0.05);
}
.table>.row>*{
display: table-cell;
padding: .3em 2.4em .3em .6em;
}
.table>header.row>*{
text-align: left;
font-weight: 900;
color: #fff;
background-color: #0074d9;
}
.table>.row>input{
border: none;
background: none;
font-weight: 900;
}
.plain{
opacity: initial;
width: initial;
}

View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>fiatlux v0.2</title>
<link rel="stylesheet" href="css/picnic.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<main>
<h2>static web page</h2>
</main>
<script type="text/javascript" src="js/smoothie_min.js"></script>
</body>
</html>

File diff suppressed because one or more lines are too long

114
firmware/fsdata/makefsdata Executable file
View file

@ -0,0 +1,114 @@
#!/usr/bin/perl
$incHttpHeader = 1;
open(OUTPUT, "> fsdata.c");
print(OUTPUT "#include \"httpd/fsdata.h\"\n\n");
chdir("fs");
open(FILES, "find . -type f |");
while($file = <FILES>) {
# Do not include files in CVS directories nor backup files.
if($file =~ /(CVS|~)/) {
next;
}
chop($file);
if($incHttpHeader == 1) {
open(HEADER, "> /tmp/header") || die $!;
if($file =~ /404/) {
print(HEADER "HTTP/1.0 404 File not found\r\n");
} else {
print(HEADER "HTTP/1.0 200 OK\r\n");
}
print(HEADER "lwIP/1.4.1 (http://savannah.nongnu.org/projects/lwip)\r\n");
if($file =~ /\.html$/ || $file =~ /\.htm$/ || $file =~ /\.shtml$/ || $file =~ /\.shtm$/ || $file =~ /\.ssi$/) {
print(HEADER "Content-type: text/html\r\n");
} elsif($file =~ /\.js$/) {
print(HEADER "Content-type: application/x-javascript\r\n\r\n");
} elsif($file =~ /\.css$/) {
print(HEADER "Content-type: text/css\r\n\r\n");
} elsif($file =~ /\.ico$/) {
print(HEADER "Content-type: image/x-icon\r\n\r\n");
} elsif($file =~ /\.gif$/) {
print(HEADER "Content-type: image/gif\r\n");
} elsif($file =~ /\.png$/) {
print(HEADER "Content-type: image/png\r\n");
} elsif($file =~ /\.jpg$/) {
print(HEADER "Content-type: image/jpeg\r\n");
} elsif($file =~ /\.bmp$/) {
print(HEADER "Content-type: image/bmp\r\n\r\n");
} elsif($file =~ /\.class$/) {
print(HEADER "Content-type: application/octet-stream\r\n");
} elsif($file =~ /\.ram$/) {
print(HEADER "Content-type: audio/x-pn-realaudio\r\n");
} else {
print(HEADER "Content-type: text/plain\r\n");
}
print(HEADER "\r\n");
close(HEADER);
unless($file =~ /\.plain$/ || $file =~ /cgi/) {
system("cat /tmp/header $file > /tmp/file");
} else {
system("cp $file /tmp/file");
}
} else {
system("cp $file /tmp/file");
}
open(FILE, "/tmp/file");
unlink("/tmp/file");
unlink("/tmp/header");
$file =~ s/\.//;
$fvar = $file;
$fvar =~ s-/-_-g;
$fvar =~ s-\.-_-g;
print(OUTPUT "static const unsigned char data".$fvar."[] = {\n");
print(OUTPUT "\t/* $file */\n\t");
for($j = 0; $j < length($file); $j++) {
printf(OUTPUT "0x%02X, ", unpack("C", substr($file, $j, 1)));
}
printf(OUTPUT "0,\n");
$i = 0;
while(read(FILE, $data, 1)) {
if($i == 0) {
print(OUTPUT "\t");
}
printf(OUTPUT "0x%02X, ", unpack("C", $data));
$i++;
if($i == 10) {
print(OUTPUT "\n");
$i = 0;
}
}
print(OUTPUT "};\n\n");
close(FILE);
push(@fvars, $fvar);
push(@files, $file);
}
for($i = 0; $i < @fvars; $i++) {
$file = $files[$i];
$fvar = $fvars[$i];
if($i == 0) {
$prevfile = "NULL";
} else {
$prevfile = "file" . $fvars[$i - 1];
}
print(OUTPUT "const struct fsdata_file file".$fvar."[] = {{\n$prevfile,\ndata$fvar, ");
print(OUTPUT "data$fvar + ". (length($file) + 1) .",\n");
print(OUTPUT "sizeof(data$fvar) - ". (length($file) + 1) .",\n");
print(OUTPUT $incHttpHeader."\n}};\n\n");
}
print(OUTPUT "#define FS_ROOT file$fvars[$i - 1]\n\n");
print(OUTPUT "#define FS_NUMFILES $i\n");

View file

@ -1,3 +1,35 @@
// //
// Created by jedi on 25.06.21. // Created by jedi on 25.06.21.
// //
#include "web.h"
#include "system.h"
#include "lux.h"
#include "wifi.h"
#include <cstring>
#include <FreeRTOS.h>
#include <task.h>
extern "C" {
#include <sysparam.h>
#include <lwipopts.h>
}
#include <espressif/esp_common.h>
#include <lwip/tcp.h>
extern "C" {
#include <httpd/httpd.h>
}
extern "C" [[noreturn]] void httpd_task(void *pvParameters) {
while(!uxSemaphoreGetCount( wifi_available_semaphore ))
vTaskDelay(500 / portTICK_PERIOD_MS);
httpd_init();
for (;;)
vTaskDelay(500 / portTICK_PERIOD_MS);
}

View file

@ -9,6 +9,8 @@
extern "C" { extern "C" {
#endif #endif
void httpd_task(void *pvParameters);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif