Compare commits

..

2 commits

Author SHA1 Message Date
c0a1c4f79e mqtt verbindet
All checks were successful
continuous-integration/drone/push Build is passing
2021-09-12 22:03:11 +02:00
10e11d91b6 stash 2021-09-12 22:03:11 +02:00
18 changed files with 216 additions and 205 deletions

View file

@ -9,19 +9,17 @@ steps:
- name: submodules - name: submodules
image: alpine/git image: alpine/git
commands: commands:
- git submodule update --init --recursive --depth 1 - git submodule update --init --recursive
- 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:ki6 image: setsoft/kicad_auto
commands: commands:
- apt update - apt update
- apt install -y make zip - apt install -y make zip
@ -64,6 +62,6 @@ steps:
checksum: checksum:
- sha512 - sha512
- md5 - md5
title: fiatlux title: buildtest
when: when:
event: tag event: tag

2
.gitmodules vendored
View file

@ -1,6 +1,6 @@
[submodule "modules/rtos"] [submodule "modules/rtos"]
path = modules/rtos path = modules/rtos
url = https://git.neulandlabor.de/j3d1/esp-open-rtos.git url = https://github.com/SuperHouse/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

View file

@ -1,3 +1,4 @@
.PHONY: firmware flash firmware_docker case pcb .PHONY: firmware flash firmware_docker case pcb
all: firmware case pcb all: firmware case pcb
@ -18,11 +19,6 @@ 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 html all" sh -c "docker run --volume "$$(pwd)"/firmware:/app/firmware fiatlux_firmware_env make -C firmware html all"

View file

@ -1,12 +1,13 @@
PROGRAM=fiatlux PROGRAM=fiatlux
EXTRA_CFLAGS=-O3 -Ibuild/gen -DLWIP_NETIF_HOSTNAME=1 EXTRA_CFLAGS=-O3 -Ibuild/gen
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 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 = qio FLASH_MODE = dio
include ../modules/rtos/common.mk include ../modules/rtos/common.mk
@ -15,7 +16,7 @@ html: build/gen/fsdata.c
build/gen/fsdata.c: webdir/index.html webdir/404.html webdir/css/picnic.min.css webdir/css/style.css webdir/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.."
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
@./mkwebfs.py --gzip --minify -o $@ $^ @./mkwebfs.py --gzip -o $@ $^
test: unittest systest test: unittest systest

View file

@ -13,6 +13,7 @@
void user_init(void) void user_init(void)
{ {
uart_set_baud(0, 115200); uart_set_baud(0, 115200);
printf("SDK version: %s\n", sdk_system_get_sdk_version()); printf("SDK version: %s\n", sdk_system_get_sdk_version());
@ -22,6 +23,8 @@ void user_init(void)
wifi_available_semaphore = xSemaphoreCreateBinary(); wifi_available_semaphore = xSemaphoreCreateBinary();
xTaskCreate(mqtt_task, "mqtt_task", 1024, NULL, 1, NULL);
xTaskCreate(wifi_task, "wifi_task", 1024, NULL, 1, NULL); xTaskCreate(wifi_task, "wifi_task", 1024, NULL, 1, NULL);
xTaskCreate(&httpd_task, "httpd_task", 1024, NULL, 2, NULL); xTaskCreate(&httpd_task, "httpd_task", 1024, NULL, 2, NULL);

View file

@ -1,49 +0,0 @@
//
// 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--;
}

View file

@ -1,28 +0,0 @@
//
// 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

View file

@ -2,7 +2,6 @@
import os import os
import gzip import gzip
import argparse import argparse
import subprocess
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-o', '--output', help='Output file name', default='stdout') parser.add_argument('-o', '--output', help='Output file name', default='stdout')
@ -10,9 +9,6 @@ parser.add_argument('-W', '--webroot', help='Output file name', default='webdir/
parser.add_argument('--gzip', dest='gzip', action='store_true') parser.add_argument('--gzip', dest='gzip', action='store_true')
parser.add_argument('--no-gzip', dest='gzip', action='store_false') parser.add_argument('--no-gzip', dest='gzip', action='store_false')
parser.set_defaults(gzip=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('--header', dest='header', action='store_true')
parser.add_argument('--no-header', dest='header', action='store_false') parser.add_argument('--no-header', dest='header', action='store_false')
parser.set_defaults(header=True) parser.set_defaults(header=True)
@ -20,31 +16,6 @@ parser.add_argument('input', nargs='+', default=os.getcwd())
args = parser.parse_args() 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): def dumpBin2CHex(f, b):
oStr = "\t" oStr = "\t"
n = 0 n = 0
@ -70,28 +41,40 @@ for file in httpFiles:
webPath = ("/" + file.removeprefix(args.webroot)).replace("//", "/") webPath = ("/" + file.removeprefix(args.webroot)).replace("//", "/")
print("{} > {}".format(file, webPath)) print("{} > {}".format(file, webPath))
mimeType = mimeFromName(file)
if args.header: if args.header:
if ("404" in file): if ("404" in file):
response = b'HTTP/1.0 404 File not found\r\n' response = b'HTTP/1.0 404 File not found\r\n'
else: else:
response = b'HTTP/1.0 200 OK\r\n' 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"lwIP/1.4.1 (http://savannah.nongnu.org/projects/lwip)\r\n"
response += b'Content-type: ' + mimeType.encode() + b'\r\n' fext = file.split('.')[-1]
ctype = b'Content-type: text/plain\r\n'
if (fext.endswith("html") or fext.endswith("htm") or fext.endswith("shtml") or fext.endswith(
"shtm") or fext.endswith("ssi")):
ctype = b'Content-type: text/html\r\n'
if (fext.endswith("js")):
ctype = b'Content-type: application/x-javascript\r\n'
if (fext.endswith("css")):
ctype = b'Content-type: text/css\r\n'
if (fext.endswith("ico")):
ctype = b'Content-type: image/x-icon\r\n'
if (fext.endswith("gif")):
ctype = b'Content-type: image/gif\r\n'
if (fext.endswith("png")):
ctype = b'Content-type: image/png\r\n'
if(fext.endswith("jpg")):
ctype = b'Content-type: image/jpeg\r\n'
if(fext.endswith("bmp")):
ctype = b'Content-type: image/bmp\r\n'
if(fext.endswith("class")):
ctype = b'Content-type: application/octet-stream\r\n'
if(fext.endswith("ram")):
ctype = b'Content-type: audio/x-pn-realaudio\r\n'
response += ctype
binFile = open(file, 'rb') binFile = open(file, 'rb')
binData = binFile.read() binData = binFile.read()
compEff = False 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: if args.gzip:
compData = gzip.compress(binData, 9) compData = gzip.compress(binData, 9)
if len(compData) < len(binData): if len(compData) < len(binData):
@ -120,8 +103,7 @@ for file in httpFiles:
f_fsdata_c.write("};\n\n") f_fsdata_c.write("};\n\n")
f_fsdata_c.write("const struct fsdata_file {}[] = {{{{\n {},\n {}, {} + {}, sizeof({}) - {}, 1 }}}};\n\n" f_fsdata_c.write("const struct fsdata_file {}[] = {{{{\n {},\n {}, {} + {}, sizeof({}) - {}, 1 }}}};\n\n"
.format(escFileFile, lastFileStruct, escFileData, escFileData, len(fnameBin), escFileData, .format(escFileFile, lastFileStruct, escFileData, escFileData, len(fnameBin), escFileData, len(fnameBin)))
len(fnameBin)))
# TODO: The last value is 1 if args.header == True # TODO: The last value is 1 if args.header == True
lastFileStruct = escFileFile lastFileStruct = escFileFile

View file

@ -3,3 +3,158 @@
// //
#include "mqtt.h" #include "mqtt.h"
#include <stdio.h>
#include <string.h>
#include <espressif/esp_common.h>
#include <espressif/user_interface.h>
extern "C" {
#include <paho_mqtt_c/MQTTESP8266.h>
#include <paho_mqtt_c/MQTTClient.h>
}
#include <semphr.h>
/* You can use http://test.mosquitto.org/ to test mqtt_client instead
* of setting up your own MQTT server */
#define MQTT_HOST ("172.16.0.42")
#define MQTT_PORT 1883
#define MQTT_USER NULL
#define MQTT_PASS NULL
QueueHandle_t publish_queue;
#define PUB_MSG_LEN 16
extern "C" void beat_task(void *pvParameters) {
TickType_t xLastWakeTime = xTaskGetTickCount();
char msg[PUB_MSG_LEN];
int count = 0;
while (1) {
vTaskDelayUntil(&xLastWakeTime, 10000 / portTICK_PERIOD_MS);
printf("beat\r\n");
snprintf(msg, PUB_MSG_LEN, "Beat %d\r\n", count++);
if(xQueueSend(publish_queue, (void *) msg, 0) == pdFALSE) {
printf("Publish queue overflow.\r\n");
}
}
}
static void topic_received(mqtt_message_data_t *md) {
int i;
mqtt_message_t *message = md->message;
printf("Received: ");
for (i = 0; i < md->topic->lenstring.len; ++i)
printf("%c", md->topic->lenstring.data[i]);
printf(" = ");
for (i = 0; i < (int) message->payloadlen; ++i)
printf("%c", ((char *) (message->payload))[i]);
printf("\r\n");
}
static const char *get_my_id(void) {
// Use MAC address for Station as unique ID
static char my_id[13];
static bool my_id_done = false;
int8_t i;
uint8_t x;
if(my_id_done)
return my_id;
if(!sdk_wifi_get_macaddr(STATION_IF, (uint8_t *) my_id))
return NULL;
for (i = 5; i >= 0; --i) {
x = my_id[i] & 0x0F;
if(x > 9) x += 7;
my_id[i * 2 + 1] = x + '0';
x = my_id[i] >> 4;
if(x > 9) x += 7;
my_id[i * 2] = x + '0';
}
my_id[12] = '\0';
my_id_done = true;
return my_id;
}
extern "C" void mqtt_task(void *pvParameters) {
int ret = 0;
struct mqtt_network network;
mqtt_client_t client = mqtt_client_default;
char mqtt_client_id[20];
uint8_t mqtt_buf[100];
uint8_t mqtt_readbuf[100];
mqtt_packet_connect_data_t data = mqtt_packet_connect_data_initializer;
mqtt_network_new(&network);
memset(mqtt_client_id, 0, sizeof(mqtt_client_id));
strcpy(mqtt_client_id, "ESP-");
strcat(mqtt_client_id, get_my_id());
while (1) {
printf("%s: started\n\r", __func__);
printf("%s: (Re)connecting to MQTT server %s ... ", __func__,
MQTT_HOST);
ret = mqtt_network_connect(&network, MQTT_HOST, MQTT_PORT);
if(ret) {
printf("error: %d\n\r", ret);
taskYIELD();
continue;
}
printf("done\n\r");
mqtt_client_new(&client, &network, 5000, mqtt_buf, 100,
mqtt_readbuf, 100);
data.willFlag = 0;
data.MQTTVersion = 3;
data.clientID.cstring = mqtt_client_id;
data.username.cstring = MQTT_USER;
data.password.cstring = MQTT_PASS;
data.keepAliveInterval = 10;
data.cleansession = 0;
printf("Send MQTT connect ... ");
ret = mqtt_connect(&client, &data);
if(ret) {
printf("error: %d\n\r", ret);
mqtt_network_disconnect(&network);
taskYIELD();
continue;
}
printf("done\r\n");
mqtt_subscribe(&client, "/esptopic", MQTT_QOS1, topic_received);
xQueueReset(publish_queue);
while (1) {
char msg[PUB_MSG_LEN - 1] = "\0";
while (xQueueReceive(publish_queue, (void *) msg, 0) ==
pdTRUE) {
printf("got message to publish\r\n");
mqtt_message_t message;
message.payload = msg;
message.payloadlen = PUB_MSG_LEN;
message.dup = 0;
message.qos = MQTT_QOS1;
message.retained = 0;
ret = mqtt_publish(&client, "/beat", &message);
if(ret != MQTT_SUCCESS) {
printf("error while publishing message: %d\n", ret);
break;
}
}
ret = mqtt_yield(&client, 1000);
if(ret == MQTT_DISCONNECTED)
break;
}
printf("Connection dropped, request restart\n\r");
mqtt_network_disconnect(&network);
taskYIELD();
}
}

View file

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

View file

@ -8,7 +8,6 @@ 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()
@ -26,7 +25,7 @@ with open(args.binfile, "rb") as f:
try: try:
ws = websocket.WebSocket() ws = websocket.WebSocket()
print("send {}".format(args.binfile)) print("send {}".format(args.binfile))
ws.connect("ws://" + args.address) ws.connect("ws://172.16.0.1")
i = 0 i = 0
bytes = f.read() bytes = f.read()
rolling = zlib.crc32(bytes) rolling = zlib.crc32(bytes)

View file

@ -4,7 +4,6 @@
#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>
@ -40,7 +39,7 @@ 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) {
syslog("Warning: WiFi config, sysparam not initialized\n"); printf("Warning: WiFi config, sysparam not initialized\n");
num_sectors = 0x2000 / sdk_flashchip.sector_size; num_sectors = 0x2000 / 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);
@ -107,13 +106,13 @@ enum return_code system_otaflash_verify_and_switch(uint32_t len, uint32_t hash)
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) {
syslog("OTA failed to verify firmware\r\n"); printf("OTA failed to verify firmware\r\n");
return CHECKSUM_MISMATCH; return CHECKSUM_MISMATCH;
} }
vPortEnterCritical(); vPortEnterCritical();
if(!rboot_set_current_rom(otaflash_context.slot)) { if(!rboot_set_current_rom(otaflash_context.slot)) {
syslog("OTA Update failed to set new rboot slot\r\n"); printf("OTA Update failed to set new rboot slot\r\n");
vPortExitCritical(); vPortExitCritical();
return RBOOT_SWITCH_FAILED; return RBOOT_SWITCH_FAILED;
} }

View file

@ -6,7 +6,6 @@
#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>
@ -37,34 +36,16 @@ 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) {
syslog("Connection closed, deleting task\n"); printf("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;
@ -76,7 +57,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[192]; char response[160];
size_t len = snprintf(response, sizeof(response), size_t len = snprintf(response, sizeof(response),
"{\"walltime\" : \"%d\"," "{\"walltime\" : \"%d\","
"\"uptime\" : \"%d\"," "\"uptime\" : \"%d\","
@ -90,22 +71,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
syslog("buffer too small 0\n"); printf("buffer too small 1");
vTaskDelayMs(1000); vTaskDelayMs(2000);
} }
//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[192]; char response[160];
size_t len = snprintf(response, sizeof(response), size_t len = snprintf(response, sizeof(response),
"{\"connage\" : \"%d\"," "{\"connage\" : \"%d\","
"\"clientip\" : \"" IPSTR "\"" "\"clientip\" : \"" IPSTR "\""
@ -113,11 +94,10 @@ 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
syslog("buffer too small 1\n"); printf("buffer too small 1");
vTaskDelayMs(1000); vTaskDelayMs(2000);
} }
if(has_changed.wifi) { if(has_changed.wifi) {
@ -172,10 +152,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
syslog("buffer too small 2\n"); printf("buffer too small 2");
} }
vTaskDelayMs(1000); vTaskDelayMs(2000);
if(opmode == STATION_MODE || opmode == STATIONAP_MODE) { if(opmode == STATION_MODE || opmode == STATIONAP_MODE) {
uint8_t hwaddr[6]; uint8_t hwaddr[6];
@ -199,7 +179,7 @@ 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
syslog("buffer too small 3\n"); printf("buffer too small 3");
} }
} }
@ -207,8 +187,6 @@ void websocket_task(void *pvParameter) {
vTaskDelayMs(500); vTaskDelayMs(500);
} }
syslog_detach();
vTaskDelete(nullptr); vTaskDelete(nullptr);
} }
@ -257,14 +235,12 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
ret = OK; ret = OK;
break; break;
case 'D': // Disable LED case 'D': // Disable LED
syslog("G\n");
signal_led(false); signal_led(false);
cmd = 'G'; cmd = 'G';
ret = OK; ret = OK;
val = 1; val = 1;
break; break;
case 'E': // Enable LED case 'E': // Enable LED
syslog("E\n");
signal_led(true); signal_led(true);
cmd = 'G'; cmd = 'G';
ret = OK; ret = OK;

View file

@ -63,16 +63,6 @@
</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="dashboard"> <section id="dashboard">
@ -191,7 +181,6 @@
<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 = {};
@ -220,7 +209,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.info(text); console.log(text);
} }
function startPolling() { function startPolling() {
@ -264,13 +253,6 @@
} 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);
} }

View file

@ -3,7 +3,6 @@
// //
#include "wifi.h" #include "wifi.h"
#include "log.h"
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
@ -37,7 +36,7 @@ SemaphoreHandle_t wifi_available_semaphore = nullptr;
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) {
syslog("dns: no ip address\n"); printf("dns: no ip address\n");
vTaskDelete(nullptr); vTaskDelete(nullptr);
} }
ip4_addr_t server_addr; ip4_addr_t server_addr;
@ -195,7 +194,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) {
syslog("len err\n"); printf("len err\n");
wifi_ap_enable = 0; wifi_ap_enable = 0;
} }
} }

@ -1 +1 @@
Subproject commit 7faa16b07ce0d606f9525a316990da5b58e61314 Subproject commit 503e66a500419e8863998b7ea784c5e26a7a5f7c

4
pcb/.gitignore vendored
View file

@ -31,8 +31,6 @@ fp-info-cache
*.wrl *.wrl
*.step *.step
*-backups/ *-bak
gen/ gen/
pcb.zip pcb.zip
report.txt

3
webapp/.gitignore vendored
View file

@ -1,3 +0,0 @@
node_modules/
src/gen/
package-lock.json