forked from j3d1/fiatlux
Compare commits
9 commits
jedi/dev/o
...
stable
Author | SHA1 | Date | |
---|---|---|---|
8209a9a936 | |||
b10103377d | |||
d5c10e441d | |||
5466bceb0e | |||
7a627ee1f1 | |||
24f5e4398d | |||
|
8f052ecb37 | ||
|
c0228cdf49 | ||
5fa1ec14e2 |
27 changed files with 484 additions and 520 deletions
|
@ -9,17 +9,19 @@ steps:
|
||||||
- name: submodules
|
- name: submodules
|
||||||
image: alpine/git
|
image: alpine/git
|
||||||
commands:
|
commands:
|
||||||
- git submodule update --init --recursive
|
- git submodule update --init --recursive --depth 1
|
||||||
|
|
||||||
- name: firmware
|
- name: firmware
|
||||||
image: docker-repo.service.intern.lab.or.it:5000/fiatlux-build-env
|
image: docker-repo.service.intern.lab.or.it:5000/fiatlux-build-env
|
||||||
depends_on: [ submodules ]
|
depends_on: [ submodules ]
|
||||||
commands:
|
commands:
|
||||||
- export PATH=$(pwd)/modules/sdk/xtensa-lx106-elf/bin:$PATH
|
- export PATH=$(pwd)/modules/sdk/xtensa-lx106-elf/bin:$PATH
|
||||||
|
- apt update
|
||||||
|
- apt install -y minify
|
||||||
- make firmware -j$(nproc)
|
- make firmware -j$(nproc)
|
||||||
|
|
||||||
- name: pcb
|
- name: pcb
|
||||||
image: setsoft/kicad_auto
|
image: setsoft/kicad_auto:ki6
|
||||||
commands:
|
commands:
|
||||||
- apt update
|
- apt update
|
||||||
- apt install -y make zip
|
- apt install -y make zip
|
||||||
|
@ -62,6 +64,6 @@ steps:
|
||||||
checksum:
|
checksum:
|
||||||
- sha512
|
- sha512
|
||||||
- md5
|
- md5
|
||||||
title: buildtest
|
title: fiatlux
|
||||||
when:
|
when:
|
||||||
event: tag
|
event: tag
|
||||||
|
|
2
.gitmodules
vendored
2
.gitmodules
vendored
|
@ -1,6 +1,6 @@
|
||||||
[submodule "modules/rtos"]
|
[submodule "modules/rtos"]
|
||||||
path = modules/rtos
|
path = modules/rtos
|
||||||
url = https://github.com/SuperHouse/esp-open-rtos.git
|
url = https://git.neulandlabor.de/j3d1/esp-open-rtos.git
|
||||||
[submodule "modules/sdk"]
|
[submodule "modules/sdk"]
|
||||||
path = modules/sdk
|
path = modules/sdk
|
||||||
url = https://github.com/pfalcon/esp-open-sdk.git
|
url = https://github.com/pfalcon/esp-open-sdk.git
|
||||||
|
|
8
Makefile
8
Makefile
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
.PHONY: firmware flash firmware_docker case pcb
|
.PHONY: firmware flash firmware_docker case pcb
|
||||||
|
|
||||||
all: firmware case pcb
|
all: firmware case pcb
|
||||||
|
@ -19,9 +18,14 @@ clean:
|
||||||
+@make -C firmware clean
|
+@make -C firmware clean
|
||||||
+@make -C pcb clean
|
+@make -C pcb clean
|
||||||
|
|
||||||
|
flash_docker:
|
||||||
|
sh -c "docker build -t fiatlux_firmware_env docker/firmware"
|
||||||
|
sh -c "docker run --volume "$$(pwd)"/firmware:/app/firmware --device=/dev/ttyUSB0 fiatlux_firmware_env make -C firmware flash"
|
||||||
|
|
||||||
|
|
||||||
firmware_docker:
|
firmware_docker:
|
||||||
sh -c "docker build -t fiatlux_firmware_env docker/firmware"
|
sh -c "docker build -t fiatlux_firmware_env docker/firmware"
|
||||||
sh -c "docker run --volume "$$(pwd)"/firmware:/app/firmware fiatlux_firmware_env make -C firmware all"
|
sh -c "docker run --volume "$$(pwd)"/firmware:/app/firmware fiatlux_firmware_env make -C firmware html all"
|
||||||
|
|
||||||
pcb_docker:
|
pcb_docker:
|
||||||
sh -c "docker build -t fiatlux_pcb_env docker/pcb"
|
sh -c "docker build -t fiatlux_pcb_env docker/pcb"
|
||||||
|
|
|
@ -13,7 +13,7 @@ git submodule update --init --recursive
|
||||||
### Build Requirements
|
### Build Requirements
|
||||||
|
|
||||||
- make
|
- make
|
||||||
- bash gawk perl
|
- bash gawk
|
||||||
- g++ gcc
|
- g++ gcc
|
||||||
- libc6-dev
|
- libc6-dev
|
||||||
- flex bison
|
- flex bison
|
||||||
|
|
|
@ -6,7 +6,7 @@ RUN cd app; git clone --recursive https://github.com/SuperHouse/esp-open-rtos.gi
|
||||||
RUN cd app; sed -i 's/GNU bash, version (3\\\.\[1-9\]|4)/GNU bash, version (3.[1-9]|4|5)/g' modules/sdk/crosstool-NG/configure.ac; mkdir -p modules/sdk/crosstool-NG/.build/tarballs; wget https://github.com/libexpat/libexpat/releases/download/R_2_1_0/expat-2.1.0.tar.gz -O modules/sdk/crosstool-NG/.build/tarballs/expat-2.1.0.tar.gz
|
RUN cd app; sed -i 's/GNU bash, version (3\\\.\[1-9\]|4)/GNU bash, version (3.[1-9]|4|5)/g' modules/sdk/crosstool-NG/configure.ac; mkdir -p modules/sdk/crosstool-NG/.build/tarballs; wget https://github.com/libexpat/libexpat/releases/download/R_2_1_0/expat-2.1.0.tar.gz -O modules/sdk/crosstool-NG/.build/tarballs/expat-2.1.0.tar.gz
|
||||||
RUN cd app/modules/sdk; export CT_EXPERIMENTAL=y; export CT_ALLOW_BUILD_AS_ROOT=y; export CT_ALLOW_BUILD_AS_ROOT_SURE=y; make standalone=y -j$(nproc); wget -N https://raw.githubusercontent.com/espressif/esptool/master/esptool.py -O xtensa-lx106-elf/bin/esptool.py
|
RUN cd app/modules/sdk; export CT_EXPERIMENTAL=y; export CT_ALLOW_BUILD_AS_ROOT=y; export CT_ALLOW_BUILD_AS_ROOT_SURE=y; make standalone=y -j$(nproc); wget -N https://raw.githubusercontent.com/espressif/esptool/master/esptool.py -O xtensa-lx106-elf/bin/esptool.py
|
||||||
USER 0
|
USER 0
|
||||||
RUN apt remove --purge -y python2 && apt autoremove --purge -y && apt install -y python3 python3-serial perl
|
RUN apt remove --purge -y python2 && apt autoremove --purge -y && apt install -y python3 python3-serial
|
||||||
RUN apt install -y --reinstall python-is-python3
|
RUN apt install -y --reinstall python-is-python3
|
||||||
USER 1000
|
USER 1000
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
2
firmware/.gitignore
vendored
2
firmware/.gitignore
vendored
|
@ -142,5 +142,5 @@ dkms.conf
|
||||||
|
|
||||||
*.remove
|
*.remove
|
||||||
firmware/
|
firmware/
|
||||||
fsdata/fsdata.c
|
build/
|
||||||
compile_commands.json
|
compile_commands.json
|
|
@ -1,20 +1,21 @@
|
||||||
PROGRAM=fiatlux
|
PROGRAM=fiatlux
|
||||||
|
|
||||||
EXTRA_CFLAGS=-O3 -Ifsdata
|
EXTRA_CFLAGS=-O3 -Ibuild/gen -DLWIP_NETIF_HOSTNAME=1
|
||||||
|
|
||||||
EXTRA_COMPONENTS=extras/i2s_dma extras/ws2812_i2s extras/dhcpserver extras/rboot-ota extras/mbedtls extras/httpd extras/sntp extras/cpp_support
|
EXTRA_COMPONENTS=extras/i2s_dma extras/ws2812_i2s extras/dhcpserver extras/rboot-ota extras/mbedtls extras/httpd extras/sntp extras/cpp_support extras/paho_mqtt_c
|
||||||
|
|
||||||
LIBS = hal m
|
LIBS = hal m
|
||||||
|
|
||||||
FLASH_MODE = dio
|
FLASH_MODE = qio
|
||||||
|
|
||||||
include ../modules/rtos/common.mk
|
include ../modules/rtos/common.mk
|
||||||
|
|
||||||
html: fsdata/fsdata.c
|
html: build/gen/fsdata.c
|
||||||
|
|
||||||
fsdata/fsdata.c: fsdata/fs/index.html fsdata/fs/404.html fsdata/fs/css/picnic.min.css fsdata/fs/css/style.css fsdata/fs/js/smoothie_min.js
|
build/gen/fsdata.c: webdir/index.html webdir/404.html webdir/css/picnic.min.css webdir/css/style.css webdir/js/smoothie_min.js
|
||||||
@echo "Generating fsdata.."
|
@echo "Generating fsdata.."
|
||||||
cd fsdata && ./makefsdata
|
@mkdir -p $(dir $@)
|
||||||
|
@./mkwebfs.py --gzip --minify -o $@ $^
|
||||||
|
|
||||||
test: unittest systest
|
test: unittest systest
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
#include <espressif/esp_common.h>
|
#include <espressif/esp_common.h>
|
||||||
#include <esp/uart.h>
|
#include <esp/uart.h>
|
||||||
|
|
||||||
#include "rboot-api.h"
|
|
||||||
|
|
||||||
void user_init(void)
|
void user_init(void)
|
||||||
{
|
{
|
||||||
uart_set_baud(0, 115200);
|
uart_set_baud(0, 115200);
|
||||||
|
@ -29,15 +27,4 @@ void user_init(void)
|
||||||
xTaskCreate(&httpd_task, "httpd_task", 1024, NULL, 2, NULL);
|
xTaskCreate(&httpd_task, "httpd_task", 1024, NULL, 2, NULL);
|
||||||
|
|
||||||
xTaskCreate(&lux_task, "lux_task", 512, NULL, 1, NULL);
|
xTaskCreate(&lux_task, "lux_task", 512, NULL, 1, NULL);
|
||||||
|
|
||||||
rboot_config conf = rboot_get_config();
|
|
||||||
printf("\r\n\r\nOTA Basic demo.\r\nCurrently running on flash slot %d / %d.\r\n\r\n",
|
|
||||||
conf.current_rom, conf.count);
|
|
||||||
|
|
||||||
printf("Image addresses in flash:\r\n");
|
|
||||||
for(int i = 0; i <conf.count; i++) {
|
|
||||||
printf("%c%d: offset 0x%08x\r\n", i == conf.current_rom ? '*':' ', i, conf.roms[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("profit!\n");
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
<!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,114 +0,0 @@
|
||||||
#!/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");
|
|
49
firmware/log.cpp
Normal file
49
firmware/log.cpp
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
//
|
||||||
|
// Created by jedi on 18.11.21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
#include <espressif/esp_common.h>
|
||||||
|
|
||||||
|
constexpr unsigned syslog_buffer_size = 1024;
|
||||||
|
char syslog_buf[syslog_buffer_size];
|
||||||
|
volatile unsigned head = 0;
|
||||||
|
volatile unsigned streams = 0;
|
||||||
|
|
||||||
|
extern "C" void syslog(const char *msg) {
|
||||||
|
printf("syslog> %s", msg);
|
||||||
|
while (char c = *msg++) {
|
||||||
|
syslog_buf[head++ % syslog_buffer_size] = c;
|
||||||
|
}
|
||||||
|
syslog_buf[head] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned syslog_current_tail() {
|
||||||
|
if(head < syslog_buffer_size)
|
||||||
|
return 0;
|
||||||
|
return head + 1 - syslog_buffer_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned syslog_data_after(unsigned local_tail) {
|
||||||
|
if(local_tail > head)
|
||||||
|
return 0;
|
||||||
|
return (head % syslog_buffer_size) - (local_tail % syslog_buffer_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" int syslog_copy_out(char *out, int len, unsigned local_tail) {
|
||||||
|
unsigned cnt = 0;
|
||||||
|
while (cnt < syslog_data_after(local_tail) && cnt < len) {
|
||||||
|
out[cnt] = syslog_buf[local_tail % syslog_buffer_size + cnt];
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void syslog_attach() {
|
||||||
|
streams++;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void syslog_detach() {
|
||||||
|
streams--;
|
||||||
|
}
|
28
firmware/log.h
Normal file
28
firmware/log.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
//
|
||||||
|
// Created by jedi on 18.11.21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef FIRMWARE_LOG_H
|
||||||
|
#define FIRMWARE_LOG_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void syslog(const char *);
|
||||||
|
|
||||||
|
unsigned syslog_current_tail();
|
||||||
|
|
||||||
|
unsigned syslog_data_after(unsigned);
|
||||||
|
|
||||||
|
int syslog_copy_out(char *, int, unsigned);
|
||||||
|
|
||||||
|
void syslog_attach();
|
||||||
|
|
||||||
|
void syslog_detach();
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif //FIRMWARE_LOG_H
|
130
firmware/mkwebfs.py
Executable file
130
firmware/mkwebfs.py
Executable file
|
@ -0,0 +1,130 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import os
|
||||||
|
import gzip
|
||||||
|
import argparse
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('-o', '--output', help='Output file name', default='stdout')
|
||||||
|
parser.add_argument('-W', '--webroot', help='Output file name', default='webdir/')
|
||||||
|
parser.add_argument('--gzip', dest='gzip', action='store_true')
|
||||||
|
parser.add_argument('--no-gzip', dest='gzip', action='store_false')
|
||||||
|
parser.set_defaults(gzip=False)
|
||||||
|
parser.add_argument('--minify', dest='minify', action='store_true')
|
||||||
|
parser.add_argument('--no-minify', dest='minify', action='store_false')
|
||||||
|
parser.set_defaults(minify=False)
|
||||||
|
parser.add_argument('--header', dest='header', action='store_true')
|
||||||
|
parser.add_argument('--no-header', dest='header', action='store_false')
|
||||||
|
parser.set_defaults(header=True)
|
||||||
|
parser.add_argument('input', nargs='+', default=os.getcwd())
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def mimeFromName(name):
|
||||||
|
if name.endswith(".html") or name.endswith(".htm") or name.endswith(".shtml") or name.endswith(
|
||||||
|
".shtm") or name.endswith(".ssi"):
|
||||||
|
return "text/html"
|
||||||
|
if name.endswith(".js"):
|
||||||
|
return "application/x-javascript"
|
||||||
|
if name.endswith(".css"):
|
||||||
|
return "text/css"
|
||||||
|
if name.endswith(".ico"):
|
||||||
|
return "image/x-icon"
|
||||||
|
if name.endswith(".gif"):
|
||||||
|
return "image/gif"
|
||||||
|
if name.endswith(".png"):
|
||||||
|
return "image/png"
|
||||||
|
if name.endswith(".jpg"):
|
||||||
|
return "image/jpeg"
|
||||||
|
if name.endswith(".bmp"):
|
||||||
|
return "image/bmp"
|
||||||
|
if name.endswith(".class"):
|
||||||
|
return "application/octet-stream"
|
||||||
|
if name.endswith(".ram"):
|
||||||
|
return "audio/x-pn-realaudio"
|
||||||
|
return "text/plain"
|
||||||
|
|
||||||
|
|
||||||
|
def dumpBin2CHex(f, b):
|
||||||
|
oStr = "\t"
|
||||||
|
n = 0
|
||||||
|
for val in b:
|
||||||
|
oStr += hex(val) + ", "
|
||||||
|
n += 1
|
||||||
|
if n % 8 == 0:
|
||||||
|
oStr += "\n\t"
|
||||||
|
oStr += "\n"
|
||||||
|
f.write(oStr)
|
||||||
|
|
||||||
|
|
||||||
|
f_fsdata_c = open(args.output, 'w')
|
||||||
|
f_fsdata_c.write('#include "httpd/fsdata.h"\n\n')
|
||||||
|
|
||||||
|
httpFiles = [file for file in args.input if (args.webroot in file)]
|
||||||
|
|
||||||
|
lastFileStruct = "NULL"
|
||||||
|
|
||||||
|
for file in httpFiles:
|
||||||
|
response = b''
|
||||||
|
|
||||||
|
webPath = ("/" + file.removeprefix(args.webroot)).replace("//", "/")
|
||||||
|
print("{} > {}".format(file, webPath))
|
||||||
|
|
||||||
|
mimeType = mimeFromName(file)
|
||||||
|
|
||||||
|
if args.header:
|
||||||
|
if ("404" in file):
|
||||||
|
response = b'HTTP/1.0 404 File not found\r\n'
|
||||||
|
else:
|
||||||
|
response = b'HTTP/1.0 200 OK\r\n'
|
||||||
|
response += b"lwIP/1.4.1 (http://savannah.nongnu.org/projects/lwip)\r\n"
|
||||||
|
response += b'Content-type: ' + mimeType.encode() + b'\r\n'
|
||||||
|
|
||||||
|
binFile = open(file, 'rb')
|
||||||
|
binData = binFile.read()
|
||||||
|
compEff = False
|
||||||
|
if args.minify:
|
||||||
|
p = subprocess.Popen(["minify", "--html-keep-document-tags", "--mime", mimeType], stdin=subprocess.PIPE,
|
||||||
|
stdout=subprocess.PIPE)
|
||||||
|
minData = p.communicate(binData)[0]
|
||||||
|
if len(minData) < len(binData):
|
||||||
|
print("- Minify: {} -> {}".format(len(binData), len(minData)))
|
||||||
|
compEff = True
|
||||||
|
binData = minData
|
||||||
|
|
||||||
|
if args.gzip:
|
||||||
|
compData = gzip.compress(binData, 9)
|
||||||
|
if len(compData) < len(binData):
|
||||||
|
compEff = True
|
||||||
|
print("- Compressed from {} to {}".format(len(binData), len(compData)))
|
||||||
|
binData = compData
|
||||||
|
else:
|
||||||
|
print("- Compression skipped Orig: {} Comp: {}".format(len(binData), len(compData)))
|
||||||
|
binFile.close()
|
||||||
|
|
||||||
|
if compEff:
|
||||||
|
response += b'Content-Encoding: gzip\r\n'
|
||||||
|
response += b"\r\n"
|
||||||
|
response += binData
|
||||||
|
binFile.close()
|
||||||
|
escFile = file.replace("/", "_").replace(".", "_")
|
||||||
|
escFileData = "data_" + escFile
|
||||||
|
escFileFile = "file_" + escFile
|
||||||
|
|
||||||
|
f_fsdata_c.write('static const unsigned char {}[] = {{\n'.format(escFileData))
|
||||||
|
f_fsdata_c.write('\t/* LOCAL:{} */\n'.format(file))
|
||||||
|
f_fsdata_c.write('\t/* WEB: {} */\n'.format(webPath))
|
||||||
|
fnameBin = webPath.encode("ascii") + b'\0'
|
||||||
|
dumpBin2CHex(f_fsdata_c, fnameBin)
|
||||||
|
dumpBin2CHex(f_fsdata_c, response)
|
||||||
|
f_fsdata_c.write("};\n\n")
|
||||||
|
|
||||||
|
f_fsdata_c.write("const struct fsdata_file {}[] = {{{{\n {},\n {}, {} + {}, sizeof({}) - {}, 1 }}}};\n\n"
|
||||||
|
.format(escFileFile, lastFileStruct, escFileData, escFileData, len(fnameBin), escFileData,
|
||||||
|
len(fnameBin)))
|
||||||
|
# TODO: The last value is 1 if args.header == True
|
||||||
|
lastFileStruct = escFileFile
|
||||||
|
|
||||||
|
f_fsdata_c.write("\n")
|
||||||
|
f_fsdata_c.write("#define FS_ROOT {}\n\n".format(lastFileStruct))
|
||||||
|
f_fsdata_c.write("#define FS_NUMFILES {}\n\n".format(len(httpFiles)))
|
|
@ -4,42 +4,69 @@ import time
|
||||||
import websocket
|
import websocket
|
||||||
import argparse
|
import argparse
|
||||||
import zlib
|
import zlib
|
||||||
|
from websocket import WebSocketTimeoutException
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Update fiatlux firmware via websocket.')
|
parser = argparse.ArgumentParser(description='Update fiatlux firmware via websocket.')
|
||||||
parser.add_argument("binfile")
|
parser.add_argument("binfile")
|
||||||
|
parser.add_argument("address")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
bs = 1024
|
||||||
|
|
||||||
|
|
||||||
|
def parse_reply(bytes):
|
||||||
|
cmd = bytes[0:1].decode("utf-8")
|
||||||
|
ret = int.from_bytes(bytes[1:2], "big")
|
||||||
|
val = int.from_bytes(bytes[2:4], "big")
|
||||||
|
return {'cmd': cmd, 'ret': ret, 'val': val}
|
||||||
|
|
||||||
|
|
||||||
with open(args.binfile, "rb") as f:
|
with open(args.binfile, "rb") as f:
|
||||||
try:
|
try:
|
||||||
ws = websocket.WebSocket()
|
ws = websocket.WebSocket()
|
||||||
ws.connect("ws://172.16.0.1")
|
print("send {}".format(args.binfile))
|
||||||
|
ws.connect("ws://" + args.address)
|
||||||
i = 0
|
i = 0
|
||||||
rolling = 0
|
bytes = f.read()
|
||||||
total = 0
|
rolling = zlib.crc32(bytes)
|
||||||
|
total = len(bytes)
|
||||||
while True:
|
while True:
|
||||||
print(i)
|
chunk = bytes[bs * i:bs * i + bs]
|
||||||
bytes = f.read(512)
|
|
||||||
rolling = zlib.crc32(bytes, rolling)
|
|
||||||
total += len(bytes)
|
|
||||||
msg = b'F\x00\x00\x00'
|
msg = b'F\x00\x00\x00'
|
||||||
msg += i.to_bytes(2, 'big')
|
msg += i.to_bytes(2, 'big')
|
||||||
msg += len(bytes).to_bytes(2, 'big')
|
msg += len(chunk).to_bytes(2, 'big')
|
||||||
msg += (zlib.crc32(bytes) & 0xffffffff).to_bytes(4, 'big')
|
msg += (zlib.crc32(chunk) & 0xffffffff).to_bytes(4, 'big')
|
||||||
msg += bytes
|
msg += chunk
|
||||||
ws.send(msg)
|
ws.send(msg)
|
||||||
reply = ws.recv()
|
print("\r{:6.2f}%".format(100 * i * bs / total), end='')
|
||||||
print(reply)
|
reply = parse_reply(ws.recv())
|
||||||
|
if reply['cmd'] == 'F' and reply['ret'] == 0:
|
||||||
|
i += 1
|
||||||
|
elif reply['cmd'] == 'F' and reply['ret'] == 1:
|
||||||
|
print("Error: SEQUENCE_OUT_OF_ORDER")
|
||||||
|
i = reply['val']
|
||||||
|
elif reply['cmd'] == 'F' and reply['ret'] == 2:
|
||||||
|
print("Error: CHECKSUM_MISMATCH")
|
||||||
|
i = reply['val']
|
||||||
|
else:
|
||||||
|
print(reply)
|
||||||
|
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
i += 1
|
if len(chunk) != bs:
|
||||||
if len(bytes) != 512:
|
|
||||||
break
|
break
|
||||||
|
|
||||||
|
print("\rdone ")
|
||||||
msg = b'C\x00\x00\x00'
|
msg = b'C\x00\x00\x00'
|
||||||
msg += total.to_bytes(4, 'big')
|
msg += total.to_bytes(4, 'big')
|
||||||
msg += rolling.to_bytes(4, 'big')
|
msg += (rolling).to_bytes(4, 'big')
|
||||||
|
ws.settimeout(5)
|
||||||
ws.send(msg)
|
ws.send(msg)
|
||||||
print(ws.recv())
|
reply = parse_reply(ws.recv())
|
||||||
|
print(reply)
|
||||||
ws.close()
|
ws.close()
|
||||||
|
except WebSocketTimeoutException:
|
||||||
|
pass
|
||||||
except ConnectionResetError:
|
except ConnectionResetError:
|
||||||
pass
|
pass
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "crc32.h"
|
#include "crc32.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
#include <FreeRTOS.h>
|
#include <FreeRTOS.h>
|
||||||
#include <sysparam.h>
|
#include <sysparam.h>
|
||||||
|
@ -23,7 +24,6 @@
|
||||||
void system_clear_config() {
|
void system_clear_config() {
|
||||||
vPortEnterCritical();
|
vPortEnterCritical();
|
||||||
uint32_t num_sectors = 0x2000 / sdk_flashchip.sector_size;
|
uint32_t num_sectors = 0x2000 / sdk_flashchip.sector_size;
|
||||||
//uint32_t start = sdk_flashchip.chip_size - num_sectors * sdk_flashchip.sector_size;
|
|
||||||
uint32_t start = 0x00100000;
|
uint32_t start = 0x00100000;
|
||||||
for (uint32_t i = 0; i < num_sectors; i++) {
|
for (uint32_t i = 0; i < num_sectors; i++) {
|
||||||
spiflash_erase_sector(start + i * sdk_flashchip.sector_size);
|
spiflash_erase_sector(start + i * sdk_flashchip.sector_size);
|
||||||
|
@ -40,9 +40,8 @@ void system_init_config() {
|
||||||
uint32_t num_sectors;
|
uint32_t num_sectors;
|
||||||
sysparam_init(base_addr, 0);
|
sysparam_init(base_addr, 0);
|
||||||
if(sysparam_get_info(&base_addr, &num_sectors) != SYSPARAM_OK) {
|
if(sysparam_get_info(&base_addr, &num_sectors) != SYSPARAM_OK) {
|
||||||
printf("Warning: WiFi config, sysparam not initialized\n");
|
syslog("Warning: WiFi config, sysparam not initialized\n");
|
||||||
num_sectors = 0x2000 / sdk_flashchip.sector_size;
|
num_sectors = 0x2000 / sdk_flashchip.sector_size;
|
||||||
//base_addr = sdk_flashchip.chip_size - (5 + num_sectors) * sdk_flashchip.sector_size;
|
|
||||||
if(sysparam_create_area(base_addr, num_sectors, true) == SYSPARAM_OK) {
|
if(sysparam_create_area(base_addr, num_sectors, true) == SYSPARAM_OK) {
|
||||||
sysparam_init(base_addr, 0);
|
sysparam_init(base_addr, 0);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +49,7 @@ void system_init_config() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_IMAGE_SIZE 0x100000 /*1MB images max at the moment */
|
#define MAX_IMAGE_SIZE 0x100000
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
rboot_write_status status;
|
rboot_write_status status;
|
||||||
|
@ -68,14 +67,10 @@ void system_otaflash_init() {
|
||||||
otaflash_context.status = rboot_write_init(otaflash_context.base);
|
otaflash_context.status = rboot_write_init(otaflash_context.base);
|
||||||
otaflash_context.head = otaflash_context.base;
|
otaflash_context.head = otaflash_context.base;
|
||||||
otaflash_context.seq = 0;
|
otaflash_context.seq = 0;
|
||||||
|
|
||||||
//printf("slot: %u, base: %x, sector: %u\n", otaflash_context.slot, otaflash_context.base,
|
|
||||||
// otaflash_context.status.start_sector);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int system_otaflash_chunk(uint8_t *data, uint16_t len, uint16_t seq, uint32_t hash) {
|
enum return_code system_otaflash_chunk(uint8_t *data, uint16_t len, uint16_t seq, uint32_t hash, uint16_t *ack) {
|
||||||
uint32_t local_hash = crc32(data, len);
|
uint32_t local_hash = crc32(data, len);
|
||||||
//printf("@%x seq: %u, len: %u, hash: %x =? %x\n", otaflash_context.head, seq, len, hash, local_hash);
|
|
||||||
if(hash == local_hash && otaflash_context.seq == seq) {
|
if(hash == local_hash && otaflash_context.seq == seq) {
|
||||||
if(otaflash_context.head % SECTOR_SIZE == 0) {
|
if(otaflash_context.head % SECTOR_SIZE == 0) {
|
||||||
sdk_spi_flash_erase_sector(otaflash_context.head / SECTOR_SIZE);
|
sdk_spi_flash_erase_sector(otaflash_context.head / SECTOR_SIZE);
|
||||||
|
@ -89,10 +84,13 @@ int system_otaflash_chunk(uint8_t *data, uint16_t len, uint16_t seq, uint32_t ha
|
||||||
}
|
}
|
||||||
otaflash_context.head += len;
|
otaflash_context.head += len;
|
||||||
otaflash_context.seq++;
|
otaflash_context.seq++;
|
||||||
return 0x88;
|
return OK;
|
||||||
|
} else if(hash != local_hash) {
|
||||||
|
return CHECKSUM_MISMATCH;
|
||||||
} else {
|
} else {
|
||||||
//printf("nak: %04x = %04x, %04x = %04x\n", hash, local_hash, seq, otaflash_context.seq);
|
if(ack)
|
||||||
return 0xff;
|
*ack = otaflash_context.seq;
|
||||||
|
return SEQUENCE_OUT_OF_ORDER;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -103,21 +101,22 @@ void system_otaflash_verify_chunk(void *ctx, void *data, size_t len) {
|
||||||
*(uint32_t *) ctx = digest;
|
*(uint32_t *) ctx = digest;
|
||||||
}
|
}
|
||||||
|
|
||||||
int system_otaflash_verify_and_switch(uint32_t len, uint32_t hash) {
|
enum return_code system_otaflash_verify_and_switch(uint32_t len, uint32_t hash) {
|
||||||
|
|
||||||
uint32_t digest = 0;
|
uint32_t digest = 0;
|
||||||
rboot_digest_image(otaflash_context.base, min(len, MAX_IMAGE_SIZE), system_otaflash_verify_chunk, &digest);
|
rboot_digest_image(otaflash_context.base, min(len, MAX_IMAGE_SIZE), system_otaflash_verify_chunk, &digest);
|
||||||
|
|
||||||
if(hash != digest) {
|
if(hash != digest) {
|
||||||
printf("OTA failed to verify firmware\r\n");
|
syslog("OTA failed to verify firmware\r\n");
|
||||||
return 0x99;
|
return CHECKSUM_MISMATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
vPortEnterCritical();
|
vPortEnterCritical();
|
||||||
if(!rboot_set_current_rom(otaflash_context.slot)) {
|
if(!rboot_set_current_rom(otaflash_context.slot)) {
|
||||||
printf("OTA TFTP failed to set new rboot slot\r\n");
|
syslog("OTA Update failed to set new rboot slot\r\n");
|
||||||
|
vPortExitCritical();
|
||||||
|
return RBOOT_SWITCH_FAILED;
|
||||||
}
|
}
|
||||||
sdk_system_restart();
|
vPortExitCritical();
|
||||||
vPortExitCritical(); // | should not be reached
|
return OK;
|
||||||
return 0x77; // |
|
|
||||||
}
|
}
|
|
@ -6,6 +6,7 @@
|
||||||
#define FIRMWARE_SYSTEM_H
|
#define FIRMWARE_SYSTEM_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -17,9 +18,9 @@ void system_init_config();
|
||||||
|
|
||||||
void system_otaflash_init();
|
void system_otaflash_init();
|
||||||
|
|
||||||
int system_otaflash_chunk(uint8_t *data, uint16_t len, uint16_t seq, uint32_t hash);
|
enum return_code system_otaflash_chunk(uint8_t *data, uint16_t len, uint16_t seq, uint32_t hash, uint16_t *ack);
|
||||||
|
|
||||||
int system_otaflash_verify_and_switch(uint32_t len, uint32_t hash);
|
enum return_code system_otaflash_verify_and_switch(uint32_t len, uint32_t hash);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
20
firmware/types.h
Normal file
20
firmware/types.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
//
|
||||||
|
// Created by jedi on 09.09.21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef FIRMWARE_TYPES_H
|
||||||
|
#define FIRMWARE_TYPES_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum return_code {
|
||||||
|
OK = 0, SEQUENCE_OUT_OF_ORDER, CHECKSUM_MISMATCH, RBOOT_SWITCH_FAILED, ERROR = 0xFF
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif //FIRMWARE_TYPES_H
|
185
firmware/web.cpp
185
firmware/web.cpp
|
@ -6,6 +6,7 @@
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "lux.h"
|
#include "lux.h"
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <FreeRTOS.h>
|
#include <FreeRTOS.h>
|
||||||
|
@ -36,16 +37,34 @@ void websocket_task(void *pvParameter) {
|
||||||
|
|
||||||
size_t connstarttime = xTaskGetTickCount();
|
size_t connstarttime = xTaskGetTickCount();
|
||||||
has_changed = {true, true, true};
|
has_changed = {true, true, true};
|
||||||
|
syslog_attach();
|
||||||
|
unsigned local_log_tail = syslog_current_tail();
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if(pcb == nullptr || pcb->state != ESTABLISHED) {
|
if(pcb == nullptr || pcb->state != ESTABLISHED) {
|
||||||
printf("Connection closed, deleting task\n");
|
syslog("Connection closed, deleting task\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Syslog
|
||||||
|
if(syslog_data_after(local_log_tail) != 0) {
|
||||||
|
char response[128];
|
||||||
|
response[0] = 'L';
|
||||||
|
size_t len = syslog_copy_out(&response[4], 124, local_log_tail);
|
||||||
|
response[1] = len;
|
||||||
|
((uint16_t &) response[2]) = local_log_tail & 0xFFFF;
|
||||||
|
if(len < sizeof(response)) {
|
||||||
|
LOCK_TCPIP_CORE();
|
||||||
|
websocket_write(pcb, (unsigned char *) response, len + 4, WS_BIN_MODE);
|
||||||
|
local_log_tail += len;
|
||||||
|
UNLOCK_TCPIP_CORE();
|
||||||
|
} else
|
||||||
|
syslog("buffer too small -1\n");
|
||||||
|
vTaskDelayMs(1000);
|
||||||
|
}
|
||||||
|
|
||||||
//Global Info
|
//Global Info
|
||||||
if(has_changed.global) {
|
if(has_changed.global) {
|
||||||
has_changed.global = false;
|
|
||||||
timeval tv{};
|
timeval tv{};
|
||||||
gettimeofday(&tv, nullptr);
|
gettimeofday(&tv, nullptr);
|
||||||
size_t uptime = xTaskGetTickCount() * portTICK_PERIOD_MS / 1000;
|
size_t uptime = xTaskGetTickCount() * portTICK_PERIOD_MS / 1000;
|
||||||
|
@ -57,7 +76,7 @@ void websocket_task(void *pvParameter) {
|
||||||
|
|
||||||
sysparam_get_string("hostname", &hostname);
|
sysparam_get_string("hostname", &hostname);
|
||||||
/* Generate response in JSON format */
|
/* Generate response in JSON format */
|
||||||
char response[160];
|
char response[192];
|
||||||
size_t len = snprintf(response, sizeof(response),
|
size_t len = snprintf(response, sizeof(response),
|
||||||
"{\"walltime\" : \"%d\","
|
"{\"walltime\" : \"%d\","
|
||||||
"\"uptime\" : \"%d\","
|
"\"uptime\" : \"%d\","
|
||||||
|
@ -71,22 +90,22 @@ void websocket_task(void *pvParameter) {
|
||||||
if(len < sizeof(response)) {
|
if(len < sizeof(response)) {
|
||||||
LOCK_TCPIP_CORE();
|
LOCK_TCPIP_CORE();
|
||||||
websocket_write(pcb, (unsigned char *) response, len, WS_TEXT_MODE);
|
websocket_write(pcb, (unsigned char *) response, len, WS_TEXT_MODE);
|
||||||
|
has_changed.global = false;
|
||||||
UNLOCK_TCPIP_CORE();
|
UNLOCK_TCPIP_CORE();
|
||||||
} else
|
} else
|
||||||
printf("buffer too small 1");
|
syslog("buffer too small 0\n");
|
||||||
vTaskDelayMs(2000);
|
vTaskDelayMs(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Connection Info
|
//Connection Info
|
||||||
if(has_changed.connection) {
|
if(has_changed.connection) {
|
||||||
has_changed.connection = false;
|
|
||||||
timeval tv{};
|
timeval tv{};
|
||||||
gettimeofday(&tv, nullptr);
|
gettimeofday(&tv, nullptr);
|
||||||
size_t connuptime = (xTaskGetTickCount() - connstarttime) * portTICK_PERIOD_MS / 1000;
|
size_t connuptime = (xTaskGetTickCount() - connstarttime) * portTICK_PERIOD_MS / 1000;
|
||||||
|
|
||||||
printf("conn %d: " IPSTR " <-> " IPSTR " \n", pcb->netif_idx, IP2STR(&pcb->local_ip),
|
printf("conn %d: " IPSTR " <-> " IPSTR " \n", pcb->netif_idx, IP2STR(&pcb->local_ip),
|
||||||
IP2STR(&pcb->remote_ip));
|
IP2STR(&pcb->remote_ip));
|
||||||
char response[160];
|
char response[192];
|
||||||
size_t len = snprintf(response, sizeof(response),
|
size_t len = snprintf(response, sizeof(response),
|
||||||
"{\"connage\" : \"%d\","
|
"{\"connage\" : \"%d\","
|
||||||
"\"clientip\" : \"" IPSTR "\""
|
"\"clientip\" : \"" IPSTR "\""
|
||||||
|
@ -94,10 +113,11 @@ void websocket_task(void *pvParameter) {
|
||||||
if(len < sizeof(response)) {
|
if(len < sizeof(response)) {
|
||||||
LOCK_TCPIP_CORE();
|
LOCK_TCPIP_CORE();
|
||||||
websocket_write(pcb, (unsigned char *) response, len, WS_TEXT_MODE);
|
websocket_write(pcb, (unsigned char *) response, len, WS_TEXT_MODE);
|
||||||
|
has_changed.connection = false;
|
||||||
UNLOCK_TCPIP_CORE();
|
UNLOCK_TCPIP_CORE();
|
||||||
} else
|
} else
|
||||||
printf("buffer too small 1");
|
syslog("buffer too small 1\n");
|
||||||
vTaskDelayMs(2000);
|
vTaskDelayMs(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(has_changed.wifi) {
|
if(has_changed.wifi) {
|
||||||
|
@ -152,10 +172,10 @@ void websocket_task(void *pvParameter) {
|
||||||
websocket_write(pcb, (unsigned char *) response, len, WS_TEXT_MODE);
|
websocket_write(pcb, (unsigned char *) response, len, WS_TEXT_MODE);
|
||||||
UNLOCK_TCPIP_CORE();
|
UNLOCK_TCPIP_CORE();
|
||||||
} else
|
} else
|
||||||
printf("buffer too small 2");
|
syslog("buffer too small 2\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
vTaskDelayMs(2000);
|
vTaskDelayMs(1000);
|
||||||
|
|
||||||
if(opmode == STATION_MODE || opmode == STATIONAP_MODE) {
|
if(opmode == STATION_MODE || opmode == STATIONAP_MODE) {
|
||||||
uint8_t hwaddr[6];
|
uint8_t hwaddr[6];
|
||||||
|
@ -179,28 +199,16 @@ void websocket_task(void *pvParameter) {
|
||||||
websocket_write(pcb, (unsigned char *) response, len, WS_TEXT_MODE);
|
websocket_write(pcb, (unsigned char *) response, len, WS_TEXT_MODE);
|
||||||
UNLOCK_TCPIP_CORE();
|
UNLOCK_TCPIP_CORE();
|
||||||
} else
|
} else
|
||||||
printf("buffer too small 3");
|
syslog("buffer too small 3\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*vTaskDelayMs(250);
|
|
||||||
{
|
|
||||||
uint8_t response[3];
|
|
||||||
uint16_t val;
|
|
||||||
val = sdk_system_adc_read();
|
|
||||||
response[2] = (uint8_t) val;
|
|
||||||
response[1] = val >> 8;
|
|
||||||
response[0] = 'V';
|
|
||||||
LOCK_TCPIP_CORE();
|
|
||||||
websocket_write(pcb, response, 3, WS_BIN_MODE);
|
|
||||||
UNLOCK_TCPIP_CORE();
|
|
||||||
}*/
|
|
||||||
vTaskDelayMs(500);
|
vTaskDelayMs(500);
|
||||||
//printf("9: %d\n",gpio_read(9));
|
|
||||||
//printf("10: %d\n",gpio_read(10));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
syslog_detach();
|
||||||
|
|
||||||
vTaskDelete(nullptr);
|
vTaskDelete(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,48 +237,50 @@ struct fw_check {
|
||||||
void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
|
void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
|
||||||
uint8_t /*mode*/) { //mode should be WS_BIN_MODE or WS_TEXT_MODE
|
uint8_t /*mode*/) { //mode should be WS_BIN_MODE or WS_TEXT_MODE
|
||||||
|
|
||||||
uint8_t response[3];
|
uint8_t response[4];
|
||||||
uint16_t val = 0;
|
auto &cmd = (char &) response[0];
|
||||||
char cmd = '0';
|
auto &ret = response[1];
|
||||||
|
auto &val = (uint16_t &) response[2];
|
||||||
|
cmd = '0';
|
||||||
|
ret = ERROR;
|
||||||
|
val = 0;
|
||||||
|
|
||||||
int8_t en = 0;
|
bool togl = false;
|
||||||
/*uint8_t ap_disable_if_sta = 0;
|
|
||||||
uint8_t ssid_hidden = 0;
|
|
||||||
uint8_t dns_enable = 0;
|
|
||||||
uint8_t mdns_enable = 0;*/
|
|
||||||
bool togl = 0;
|
|
||||||
|
|
||||||
switch (data[0]) {
|
switch (data[0]) {
|
||||||
case 'V': // ADC
|
|
||||||
/* This should be done on a separate thread in 'real' applications */
|
|
||||||
val = sdk_system_adc_read();
|
|
||||||
cmd = 'V';
|
|
||||||
break;
|
|
||||||
case 'R': // Restart
|
case 'R': // Restart
|
||||||
cmd = 'R';
|
cmd = 'R';
|
||||||
|
ret = OK;
|
||||||
break;
|
break;
|
||||||
case 'X': // Clear Config
|
case 'X': // Clear Config
|
||||||
cmd = 'X';
|
cmd = 'X';
|
||||||
|
ret = OK;
|
||||||
break;
|
break;
|
||||||
case 'D': // Disable LED
|
case 'D': // Disable LED
|
||||||
|
syslog("G\n");
|
||||||
signal_led(false);
|
signal_led(false);
|
||||||
val = 1;
|
|
||||||
cmd = 'G';
|
cmd = 'G';
|
||||||
|
ret = OK;
|
||||||
|
val = 1;
|
||||||
break;
|
break;
|
||||||
case 'E': // Enable LED
|
case 'E': // Enable LED
|
||||||
|
syslog("E\n");
|
||||||
signal_led(true);
|
signal_led(true);
|
||||||
val = 0;
|
|
||||||
cmd = 'G';
|
cmd = 'G';
|
||||||
|
ret = OK;
|
||||||
|
val = 0;
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
togl = ~togl;
|
togl = !togl;
|
||||||
signal_led(togl);
|
signal_led(togl);
|
||||||
{
|
{
|
||||||
auto *f = (fw_frame *) data;
|
auto *f = (fw_frame *) data;
|
||||||
if(f->seq == 0) {
|
if(f->seq == 0) {
|
||||||
system_otaflash_init();
|
system_otaflash_init();
|
||||||
}
|
}
|
||||||
val = system_otaflash_chunk(f->data, ntohs(f->len), ntohs(f->seq), ntohl(f->hash));
|
uint16_t ack = 0;
|
||||||
|
ret = system_otaflash_chunk(f->data, ntohs(f->len), ntohs(f->seq), ntohl(f->hash), &ack);
|
||||||
|
val = htons(ack);
|
||||||
}
|
}
|
||||||
cmd = 'F';
|
cmd = 'F';
|
||||||
break;
|
break;
|
||||||
|
@ -278,67 +288,31 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
|
||||||
signal_led(false);
|
signal_led(false);
|
||||||
{
|
{
|
||||||
auto *f = (fw_check *) data;
|
auto *f = (fw_check *) data;
|
||||||
val = system_otaflash_verify_and_switch(ntohl(f->len), ntohl(f->hash));
|
ret = system_otaflash_verify_and_switch(ntohl(f->len), ntohl(f->hash));
|
||||||
}
|
}
|
||||||
cmd = 'C';
|
cmd = 'C';
|
||||||
break;
|
break;
|
||||||
case 'S': {
|
|
||||||
if(data[1] == 'E')
|
|
||||||
en = 1;
|
|
||||||
char *ssid = &data[2];
|
|
||||||
size_t ssid_len = strlen(ssid);
|
|
||||||
char *password = &data[3 + ssid_len];
|
|
||||||
size_t password_len = strlen(password);
|
|
||||||
(void) password_len;
|
|
||||||
|
|
||||||
sysparam_set_int8("wifi_sta_enable", en);
|
|
||||||
sysparam_set_string("wifi_sta_ssid", ssid);
|
|
||||||
sysparam_set_string("wifi_sta_password", password);
|
|
||||||
}
|
|
||||||
cmd = 'S';
|
|
||||||
break;
|
|
||||||
case 'A': {
|
|
||||||
if(data[1] == 'E')
|
|
||||||
en = 1;
|
|
||||||
char *ssid = &data[2];
|
|
||||||
size_t ssid_len = strlen(ssid);
|
|
||||||
char *password = &data[3 + ssid_len];
|
|
||||||
size_t password_len = strlen(password);
|
|
||||||
(void) password_len;
|
|
||||||
|
|
||||||
sysparam_set_int8("wifi_ap_enable", en);
|
|
||||||
sysparam_set_string("wifi_ap_ssid", ssid);
|
|
||||||
sysparam_set_string("wifi_ap_password", password);
|
|
||||||
|
|
||||||
//sysparam_set_int8("wifi_ap_disable_if_sta", ap_disable_if_sta);
|
|
||||||
//sysparam_set_int8("wifi_ap_ssid_hidden", ssid_hidden);
|
|
||||||
//sysparam_set_int8("wifi_ap_dns", dns_enable);
|
|
||||||
//sysparam_set_int8("wifi_ap_mdns", mdns_enable);
|
|
||||||
}
|
|
||||||
cmd = 'A';
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
printf("[websocket_callback]:\n%.*s\n", (int) data_len, (char *) data);
|
printf("[websocket_callback]:\n%.*s\n", (int) data_len, (char *) data);
|
||||||
printf("Unknown command %c\n", data[0]);
|
printf("Unknown command %c\n", data[0]);
|
||||||
val = 0;
|
ret = ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
response[2] = (uint8_t) val;
|
|
||||||
response[1] = val >> 8;
|
|
||||||
response[0] = cmd;
|
|
||||||
|
|
||||||
LOCK_TCPIP_CORE();
|
LOCK_TCPIP_CORE();
|
||||||
websocket_write(pcb, response, 3, WS_BIN_MODE);
|
websocket_write(pcb, response, 4, WS_BIN_MODE);
|
||||||
UNLOCK_TCPIP_CORE();
|
UNLOCK_TCPIP_CORE();
|
||||||
|
|
||||||
if(data[0] == 'R') { // Restart
|
if(ret == OK) {
|
||||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
if(cmd == 'R' || cmd == 'C') { // Restart
|
||||||
vPortEnterCritical();
|
printf("rebooting now");
|
||||||
sdk_system_restart();
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
} else if(data[0] == 'X') { // Clear Config
|
vPortEnterCritical();
|
||||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
sdk_system_restart();
|
||||||
system_clear_config();
|
} else if(cmd == 'X') { // Clear Config
|
||||||
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
|
system_clear_config();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,36 +327,11 @@ void websocket_open_cb(struct tcp_pcb *pcb, const char *uri) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*const char *gpio_cgi_handler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]) {
|
|
||||||
for (int i = 0; i < iNumParams; i++) {
|
|
||||||
if(strcmp(pcParam[i], "on") == 0) {
|
|
||||||
uint8_t gpio_num = atoi(pcValue[i]);
|
|
||||||
gpio_enable(gpio_num, GPIO_OUTPUT);
|
|
||||||
gpio_write(gpio_num, true);
|
|
||||||
} else if(strcmp(pcParam[i], "off") == 0) {
|
|
||||||
uint8_t gpio_num = atoi(pcValue[i]);
|
|
||||||
gpio_enable(gpio_num, GPIO_OUTPUT);
|
|
||||||
gpio_write(gpio_num, false);
|
|
||||||
} else if(strcmp(pcParam[i], "toggle") == 0) {
|
|
||||||
uint8_t gpio_num = atoi(pcValue[i]);
|
|
||||||
gpio_enable(gpio_num, GPIO_OUTPUT);
|
|
||||||
gpio_toggle(gpio_num);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "/index.html";
|
|
||||||
}*/
|
|
||||||
|
|
||||||
extern "C" void httpd_task(void *pvParameters) {
|
extern "C" void httpd_task(void *pvParameters) {
|
||||||
(void) pvParameters;
|
(void) pvParameters;
|
||||||
|
|
||||||
while (!uxSemaphoreGetCount(wifi_available_semaphore))
|
while (!uxSemaphoreGetCount(wifi_available_semaphore))
|
||||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||||
/*tCGI pCGIs[] = {
|
|
||||||
{"/gpio", (tCGIHandler) gpio_cgi_handler},
|
|
||||||
};
|
|
||||||
|
|
||||||
// register handlers and start the server
|
|
||||||
http_set_cgi_handlers(pCGIs, sizeof(pCGIs) / sizeof(pCGIs[0]));*/
|
|
||||||
websocket_register_callbacks((tWsOpenHandler) websocket_open_cb, (tWsHandler) websocket_cb);
|
websocket_register_callbacks((tWsOpenHandler) websocket_open_cb, (tWsHandler) websocket_cb);
|
||||||
httpd_init();
|
httpd_init();
|
||||||
|
|
||||||
|
|
22
firmware/webdir/404.html
Normal file
22
firmware/webdir/404.html
Normal 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>
|
||||||
|
|
|
@ -6,15 +6,15 @@ main {
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas{
|
canvas {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
main section:target ~ section, main section#io, main section#wifi, main section#ota {
|
main section:target ~ section, main section#io, main section#wifi, main section#ota {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
main section:target{
|
main section:target {
|
||||||
display: block !important;
|
display: block !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,30 +22,34 @@ main section:target{
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: table;
|
display: table;
|
||||||
}
|
}
|
||||||
.table>.row{
|
|
||||||
|
.table > .row {
|
||||||
display: table-row;
|
display: table-row;
|
||||||
}
|
}
|
||||||
.table>.row:nth-child(2n) {
|
|
||||||
background: rgba(17,17,17,0.05);
|
.table > .row:nth-child(2n) {
|
||||||
|
background: rgba(17, 17, 17, 0.05);
|
||||||
}
|
}
|
||||||
.table>.row>*{
|
|
||||||
display: table-cell;
|
.table > .row > * {
|
||||||
padding: .3em 2.4em .3em .6em;
|
display: table-cell;
|
||||||
|
padding: .3em .6em .3em .6em;
|
||||||
}
|
}
|
||||||
.table>header.row>*{
|
|
||||||
|
.table > header.row > * {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
font-weight: 900;
|
font-weight: 900;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
background-color: #0074d9;
|
background-color: #0074d9;
|
||||||
}
|
}
|
||||||
|
|
||||||
.table>.row>input{
|
.table > .row > input {
|
||||||
border: none;
|
border: none;
|
||||||
background: none;
|
background: none;
|
||||||
font-weight: 900;
|
font-weight: 900;
|
||||||
}
|
}
|
||||||
|
|
||||||
.plain{
|
.plain {
|
||||||
opacity: initial;
|
opacity: initial;
|
||||||
width: initial;
|
width: initial;
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@
|
||||||
<title>fiatlux v0.2</title>
|
<title>fiatlux v0.2</title>
|
||||||
<link rel="stylesheet" href="css/picnic.min.css">
|
<link rel="stylesheet" href="css/picnic.min.css">
|
||||||
<link rel="stylesheet" href="css/style.css">
|
<link rel="stylesheet" href="css/style.css">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav>
|
<nav>
|
||||||
|
@ -16,8 +17,6 @@
|
||||||
<label for="bmenub" class="burger pseudo button">☰</label>
|
<label for="bmenub" class="burger pseudo button">☰</label>
|
||||||
<div class="menu">
|
<div class="menu">
|
||||||
<a href="/#" class="button icon-picture">Dashboard</a>
|
<a href="/#" class="button icon-picture">Dashboard</a>
|
||||||
<a href="/#io" class="button icon-puzzle">I/O</a>
|
|
||||||
<a href="/#wifi" class="button icon-puzzle">Wifi Settings</a>
|
|
||||||
<a href="/#ota" class="button icon-picture">System</a>
|
<a href="/#ota" class="button icon-picture">System</a>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
@ -32,6 +31,12 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<span><input id="firmware_file" type="file" onchange="load_firmware(event)"/></span>
|
<span><input id="firmware_file" type="file" onchange="load_firmware(event)"/></span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="full" id="progress_ct_ota">
|
||||||
|
<div id="progress_bar_ota"
|
||||||
|
style="background:#0074d9; display: block; width:9%; color: #fff"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<span><input id="transmit_firmware" disabled type="submit" value="Upload"
|
<span><input id="transmit_firmware" disabled type="submit" value="Upload"
|
||||||
onclick="transmit_firmware(event)"></span>
|
onclick="transmit_firmware(event)"></span>
|
||||||
|
@ -58,127 +63,18 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
<article class="card">
|
||||||
|
<header>
|
||||||
|
<h3>Syslog</h3>
|
||||||
|
</header>
|
||||||
|
<div class="table">
|
||||||
|
<div class="row">
|
||||||
|
<pre id="syslog"></pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
<section id="io">
|
|
||||||
<h2>I/O</h2>
|
|
||||||
<article class="card">
|
|
||||||
<header>
|
|
||||||
<h3>Protocols</h3>
|
|
||||||
</header>
|
|
||||||
<div class="table">
|
|
||||||
<div class="row">
|
|
||||||
<label>MQTT</label>
|
|
||||||
<span><input type="checkbox" class="plain"/></span>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<span><input type="reset" class="button"/></span>
|
|
||||||
<span><input type="submit" value="Save"></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
<article class="card">
|
|
||||||
<header>
|
|
||||||
<h3>Station Mode <span class="label success">current connection</span></h3>
|
|
||||||
</header>
|
|
||||||
<div class="table">
|
|
||||||
<div class="row">
|
|
||||||
<label>WS2812 via I2S</label>
|
|
||||||
<span><input type="checkbox" class="plain"/></span>
|
|
||||||
<span><input type="color"/></span>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<label>APA102C via SPI</label>
|
|
||||||
<span><input type="checkbox" class="plain"/></span>
|
|
||||||
<span><input type="color"/></span>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<label>6 Channel SPI Dimmer</label>
|
|
||||||
<span><input type="checkbox" class="plain"/></span>
|
|
||||||
<span><input type="color"/></span>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<label>Binary Output on GPIO4</label>
|
|
||||||
<span><input type="checkbox" class="plain"/></span>
|
|
||||||
<span><button class="toggle button">Toggle</button></span>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<label>Binary Output on GPIO5</label>
|
|
||||||
<span><input type="checkbox" class="plain"/></span>
|
|
||||||
<span><button class="toggle button">Toggle</button></span>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<span><input type="reset" class="button"/></span>
|
|
||||||
<span><input type="submit" value="Save"></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
</section>
|
|
||||||
<section id="wifi">
|
|
||||||
<h2>Wifi Settings</h2>
|
|
||||||
<article class="card">
|
|
||||||
<header>
|
|
||||||
<h3>AP Mode</h3>
|
|
||||||
</header>
|
|
||||||
<div class="table">
|
|
||||||
<div class="row">
|
|
||||||
<label>Enable</label>
|
|
||||||
<span><input id="ap_toggle" type="checkbox" class="plain"/></span>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<label>SSID</label>
|
|
||||||
<span><input id="ap_ssid" type="text" placeholder="SSID"/></span>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<label>Password</label>
|
|
||||||
<span><input id="ap_pw" type="password" placeholder="Password"/></span>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<span>AP IP</span>
|
|
||||||
<span><span class="postfill_apip">N/A</span></span>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<span>AP MAC</span>
|
|
||||||
<span><span class="postfill_apmac">N/A</span></span>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<span><input type="reset" class="button"/></span>
|
|
||||||
<span><input onclick="ap_update();" type="submit" value="Save"></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
<article class="card">
|
|
||||||
<header>
|
|
||||||
<h3>Station Mode <span class="label success">current connection</span></h3>
|
|
||||||
</header>
|
|
||||||
<div class="table">
|
|
||||||
<div class="row">
|
|
||||||
<label>Eanable</label>
|
|
||||||
<span><input id="sta_toggle" type="checkbox" class="plain"/></span>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<label>SSID</label>
|
|
||||||
<span><input id="sta_ssid" type="text" placeholder="SSID"/></span>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<label>Password</label>
|
|
||||||
<span><input id="sta_pw" type="password" placeholder="Password"/></span>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<span>Sation IP</span>
|
|
||||||
<span><span class="postfill_staip">N/A</span></span>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<span>Station MAC</span>
|
|
||||||
<span><span class="postfill_stamac">N/A</span></span>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<span><input type="reset" class="button"/></span>
|
|
||||||
<span><input onclick="sta_update();" type="submit" value="Save"></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
</section>
|
|
||||||
<section id="dashboard">
|
<section id="dashboard">
|
||||||
<h2>Status</h2>
|
<h2>Status</h2>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
|
@ -295,6 +191,7 @@
|
||||||
<script>
|
<script>
|
||||||
var menu = document.getElementById("bmenub");
|
var menu = document.getElementById("bmenub");
|
||||||
var voltage = document.getElementById("out_voltage");
|
var voltage = document.getElementById("out_voltage");
|
||||||
|
var syslog = document.getElementById("syslog");
|
||||||
|
|
||||||
var unused_values = {};
|
var unused_values = {};
|
||||||
|
|
||||||
|
@ -303,6 +200,10 @@
|
||||||
return pos;
|
return pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DataView.prototype.getChar = function (pos) {
|
||||||
|
return String.fromCharCode(this.getInt8(pos));
|
||||||
|
};
|
||||||
|
|
||||||
DataView.prototype.setString = function (pos, str) {
|
DataView.prototype.setString = function (pos, str) {
|
||||||
for (var i = 0; i < str.length; i++) {
|
for (var i = 0; i < str.length; i++) {
|
||||||
this.setInt8(pos++, str.charCodeAt(i));
|
this.setInt8(pos++, str.charCodeAt(i));
|
||||||
|
@ -319,7 +220,7 @@
|
||||||
sbox = document.getElementById('status_box');
|
sbox = document.getElementById('status_box');
|
||||||
sbox.className = "label " + cls;
|
sbox.className = "label " + cls;
|
||||||
sbox.innerHTML = text;
|
sbox.innerHTML = text;
|
||||||
console.log(text);
|
console.info(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
function startPolling() {
|
function startPolling() {
|
||||||
|
@ -358,18 +259,25 @@
|
||||||
|
|
||||||
if (cmd === 'G')
|
if (cmd === 'G')
|
||||||
console.log("LED switched", val);
|
console.log("LED switched", val);
|
||||||
else if (cmd === 'F') {
|
else if ((cmd === 'F') || (cmd === "C")) {
|
||||||
receive_chunk_confirmation(dv);
|
receive_chunk_confirmation(dv);
|
||||||
} else if (cmd === 'V') {
|
} else if (cmd === 'V') {
|
||||||
voltage.innerHTML = (val * 13 / 1024).toFixed(2);
|
voltage.innerHTML = (val * 13 / 1024).toFixed(2);
|
||||||
series.append(new Date().getTime(), val);
|
series.append(new Date().getTime(), val);
|
||||||
|
} else if (cmd === 'L') {
|
||||||
|
var len = dv.getUint8(1);
|
||||||
|
var offset = dv.getUint16(2);
|
||||||
|
var str = "";
|
||||||
|
for (var i = 0; i < len; i++)
|
||||||
|
str += dv.getChar(4 + i);
|
||||||
|
syslog.innerHTML = syslog.innerHTML.slice(0, offset) + str;
|
||||||
} else
|
} else
|
||||||
console.log('unknown command', cmd, val);
|
console.log('unknown command', cmd, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function wsOpen() {
|
function wsOpen() {
|
||||||
var uri = "/stream"
|
var uri = "/stream";
|
||||||
if (ws === undefined || ws.readyState !== 0) {
|
if (ws === undefined || ws.readyState !== 0) {
|
||||||
if (retries)
|
if (retries)
|
||||||
setMsg("warning", "WebSocket timeout, retrying..");
|
setMsg("warning", "WebSocket timeout, retrying..");
|
||||||
|
@ -385,6 +293,12 @@
|
||||||
console.error(evt);
|
console.error(evt);
|
||||||
setMsg("error", "WebSocket error!"); /*window.location.reload(true);*/
|
setMsg("error", "WebSocket error!"); /*window.location.reload(true);*/
|
||||||
};
|
};
|
||||||
|
ws.onclose = function (evt) {
|
||||||
|
msgStyle = "warning";
|
||||||
|
if (!evt.wasClean) msgStyle = "error";
|
||||||
|
setMsg(msgStyle, "WebSocket closed!");
|
||||||
|
setTimeout(() => wsOpen(), 0);
|
||||||
|
};
|
||||||
ws.onmessage = function (evt) {
|
ws.onmessage = function (evt) {
|
||||||
onMessage(evt);
|
onMessage(evt);
|
||||||
};
|
};
|
||||||
|
@ -416,46 +330,6 @@
|
||||||
startPolling();
|
startPolling();
|
||||||
}
|
}
|
||||||
|
|
||||||
var sta_toggle = document.getElementById("sta_toggle");
|
|
||||||
var sta_ssid = document.getElementById("sta_ssid");
|
|
||||||
var sta_pw = document.getElementById("sta_pw");
|
|
||||||
|
|
||||||
function sta_update() {
|
|
||||||
var en = sta_toggle.checked;
|
|
||||||
|
|
||||||
const ssid = sta_ssid.value;
|
|
||||||
const password = sta_pw.value;
|
|
||||||
|
|
||||||
const buffer = new ArrayBuffer(ssid.length + password.length + 4);
|
|
||||||
const view1 = new DataView(buffer);
|
|
||||||
var tx_len = 0;
|
|
||||||
view1.setChar(tx_len++, 'S');
|
|
||||||
view1.setChar(tx_len++, (en ? "E" : "D"));
|
|
||||||
tx_len = view1.setString(tx_len, ssid);
|
|
||||||
tx_len = view1.setString(tx_len, password);
|
|
||||||
wsWrite(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
var ap_toggle = document.getElementById("ap_toggle");
|
|
||||||
var ap_ssid = document.getElementById("ap_ssid");
|
|
||||||
var ap_pw = document.getElementById("ap_pw");
|
|
||||||
|
|
||||||
function ap_update() {
|
|
||||||
var en = ap_toggle.checked;
|
|
||||||
|
|
||||||
const ssid = ap_ssid.value;
|
|
||||||
const password = ap_pw.value;
|
|
||||||
|
|
||||||
const buffer = new ArrayBuffer(ssid.length + password.length + 4);
|
|
||||||
const view1 = new DataView(buffer);
|
|
||||||
var tx_len = 0;
|
|
||||||
view1.setChar(tx_len++, 'A');
|
|
||||||
view1.setChar(tx_len++, (en ? "E" : "D"));
|
|
||||||
tx_len = view1.setString(tx_len, ssid);
|
|
||||||
tx_len = view1.setString(tx_len, password);
|
|
||||||
wsWrite(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
var makeCRCTable = function () {
|
var makeCRCTable = function () {
|
||||||
var c;
|
var c;
|
||||||
var crcTable = [];
|
var crcTable = [];
|
||||||
|
@ -484,8 +358,6 @@
|
||||||
var firmware_file;
|
var firmware_file;
|
||||||
|
|
||||||
function load_firmware(evt) {
|
function load_firmware(evt) {
|
||||||
console.log("load_firmware", evt);
|
|
||||||
|
|
||||||
var file = evt.target.files[0];
|
var file = evt.target.files[0];
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return;
|
return;
|
||||||
|
@ -516,53 +388,57 @@
|
||||||
frame.set(new Uint8Array(slice), 12);
|
frame.set(new Uint8Array(slice), 12);
|
||||||
receive_chunk_confirmation = (dv) => {
|
receive_chunk_confirmation = (dv) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
resolve(i);
|
resolve({cmd: dv.getChar(0), ret: dv.getUint8(1), val: dv.getUint16(2)});
|
||||||
}, 50);
|
}, 50);
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
reject(i);
|
reject({frame_error: i});
|
||||||
}, 2000);
|
}, 2000);
|
||||||
wsWrite(frame.buffer);
|
wsWrite(frame.buffer);
|
||||||
//build packet: type, seq, len, hash, data
|
|
||||||
console.log(i, (end - begin), crc32(slice), (100*end/buf.byteLength)+"%");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function transmit_firmware_final(buf, hash) {
|
function transmit_firmware_final(buf, hash) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
console.log("final: ", buf.byteLength, hash.toString(16));
|
|
||||||
var frame = new ArrayBuffer(12);
|
var frame = new ArrayBuffer(12);
|
||||||
var headerview = new DataView(frame);
|
var headerview = new DataView(frame);
|
||||||
headerview.setChar(0, 'C');
|
headerview.setChar(0, 'C');
|
||||||
headerview.setInt32(4, buf.byteLength);
|
headerview.setInt32(4, buf.byteLength);
|
||||||
headerview.setInt32(8, hash);
|
headerview.setInt32(8, hash);
|
||||||
receive_chunk_confirmation = (dv) => {
|
receive_chunk_confirmation = (dv) => {
|
||||||
resolve(i);
|
resolve({cmd: dv.getChar(0), ret: dv.getUint8(1), val: dv.getUint16(2)});
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
reject(i);
|
reject({final_error: 0});
|
||||||
}, 500);
|
}, 500);
|
||||||
wsWrite(frame);
|
wsWrite(frame);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function transmit_firmware(evt) {
|
function transmit_firmware(evt) {
|
||||||
console.log("transmit_firmware", evt);
|
console.log("transmit_firmware begin");
|
||||||
if (firmware_file) {
|
if (firmware_file) {
|
||||||
console.log("len", firmware_file.byteLength);
|
|
||||||
//console.log(crc32(firmware_file));
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const ash = crc32(firmware_file);
|
const ash = crc32(firmware_file);
|
||||||
for (var i = 0; i * chunk_size < firmware_file.byteLength; i++) {
|
for (var i = 0; i * chunk_size < firmware_file.byteLength; i++) {
|
||||||
await transmit_firmware_chunk(firmware_file, i);
|
update_progress("ota", i * chunk_size / firmware_file.byteLength * 100);
|
||||||
|
const reply = await transmit_firmware_chunk(firmware_file, i);
|
||||||
|
console.log("reply", reply)
|
||||||
}
|
}
|
||||||
await transmit_firmware_final(firmware_file, crc32(firmware_file));
|
await transmit_firmware_final(firmware_file, crc32(firmware_file));
|
||||||
|
update_progress("ota", 100);
|
||||||
})().then(() => {
|
})().then(() => {
|
||||||
console.log("transmit_firmware done");
|
console.log("transmit_firmware done");
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function update_progress(progressBar, progress) {
|
||||||
|
var iP = Math.floor(progress);
|
||||||
|
var dBar = document.getElementById("progress_bar_" + progressBar);
|
||||||
|
dBar.innerText = iP + "%";
|
||||||
|
dBar.style.width = progress + "%";
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -3,6 +3,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
@ -33,12 +34,10 @@ char *wifi_ap_password = nullptr;
|
||||||
SemaphoreHandle_t wifi_available_semaphore = nullptr;
|
SemaphoreHandle_t wifi_available_semaphore = nullptr;
|
||||||
|
|
||||||
[[noreturn]] static void dns_task(void *pvParameters) {
|
[[noreturn]] static void dns_task(void *pvParameters) {
|
||||||
printf("run dns task\n");
|
|
||||||
|
|
||||||
char *wifi_ap_ip_addr = nullptr;
|
char *wifi_ap_ip_addr = nullptr;
|
||||||
sysparam_get_string("wifi_ap_ip_addr", &wifi_ap_ip_addr);
|
sysparam_get_string("wifi_ap_ip_addr", &wifi_ap_ip_addr);
|
||||||
if(!wifi_ap_ip_addr) {
|
if(!wifi_ap_ip_addr) {
|
||||||
printf("dns: no ip address\n");
|
syslog("dns: no ip address\n");
|
||||||
vTaskDelete(nullptr);
|
vTaskDelete(nullptr);
|
||||||
}
|
}
|
||||||
ip4_addr_t server_addr;
|
ip4_addr_t server_addr;
|
||||||
|
@ -196,7 +195,7 @@ extern "C" void wifi_task(void *pvParameters) {
|
||||||
/* If the ssid and password are not valid then disable the AP interface. */
|
/* If the ssid and password are not valid then disable the AP interface. */
|
||||||
if(!wifi_ap_ssid || strlen(wifi_ap_ssid) < 1 || strlen(wifi_ap_ssid) >= 32 ||
|
if(!wifi_ap_ssid || strlen(wifi_ap_ssid) < 1 || strlen(wifi_ap_ssid) >= 32 ||
|
||||||
!wifi_ap_password || strlen(wifi_ap_password) < 8 || strlen(wifi_ap_password) >= 64) {
|
!wifi_ap_password || strlen(wifi_ap_password) < 8 || strlen(wifi_ap_password) >= 64) {
|
||||||
printf("len err\n");
|
syslog("len err\n");
|
||||||
wifi_ap_enable = 0;
|
wifi_ap_enable = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -272,7 +271,6 @@ extern "C" void wifi_task(void *pvParameters) {
|
||||||
if(wifi_ap_channel < 1 || wifi_ap_channel > 14) {
|
if(wifi_ap_channel < 1 || wifi_ap_channel > 14) {
|
||||||
wifi_ap_channel = 6;
|
wifi_ap_channel = 6;
|
||||||
}
|
}
|
||||||
wifi_ap_channel = 3;
|
|
||||||
|
|
||||||
int8_t wifi_ap_authmode = AUTH_WPA_WPA2_PSK;
|
int8_t wifi_ap_authmode = AUTH_WPA_WPA2_PSK;
|
||||||
sysparam_get_int8("wifi_ap_authmode", &wifi_ap_authmode);
|
sysparam_get_int8("wifi_ap_authmode", &wifi_ap_authmode);
|
||||||
|
@ -286,7 +284,6 @@ extern "C" void wifi_task(void *pvParameters) {
|
||||||
if(wifi_ap_max_conn < 1 || wifi_ap_max_conn > 8) {
|
if(wifi_ap_max_conn < 1 || wifi_ap_max_conn > 8) {
|
||||||
wifi_ap_max_conn = 3;
|
wifi_ap_max_conn = 3;
|
||||||
}
|
}
|
||||||
wifi_ap_max_conn = 8;
|
|
||||||
|
|
||||||
int32_t wifi_ap_beacon_interval = 100;
|
int32_t wifi_ap_beacon_interval = 100;
|
||||||
sysparam_get_int32("wifi_ap_beacon_interval", &wifi_ap_beacon_interval);
|
sysparam_get_int32("wifi_ap_beacon_interval", &wifi_ap_beacon_interval);
|
||||||
|
@ -360,6 +357,5 @@ extern "C" void wifi_task(void *pvParameters) {
|
||||||
xSemaphoreGive(wifi_available_semaphore);
|
xSemaphoreGive(wifi_available_semaphore);
|
||||||
|
|
||||||
//monitor loop connection here
|
//monitor loop connection here
|
||||||
printf("wifi task done\n");
|
|
||||||
vTaskDelete(nullptr);
|
vTaskDelete(nullptr);
|
||||||
}
|
}
|
|
@ -1 +1 @@
|
||||||
Subproject commit 503e66a500419e8863998b7ea784c5e26a7a5f7c
|
Subproject commit 7faa16b07ce0d606f9525a316990da5b58e61314
|
4
pcb/.gitignore
vendored
4
pcb/.gitignore
vendored
|
@ -31,6 +31,8 @@ fp-info-cache
|
||||||
*.wrl
|
*.wrl
|
||||||
*.step
|
*.step
|
||||||
|
|
||||||
*-bak
|
*-backups/
|
||||||
gen/
|
gen/
|
||||||
pcb.zip
|
pcb.zip
|
||||||
|
|
||||||
|
report.txt
|
3
webapp/.gitignore
vendored
Normal file
3
webapp/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
node_modules/
|
||||||
|
src/gen/
|
||||||
|
package-lock.json
|
Loading…
Reference in a new issue