WiFi sections hiding, STA auto enable on scan click, Terminal colors preview, better explanations, CONFIGURABLE UART
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
#ifndef CGIAPPCFG_H
|
||||
#define CGIAPPCFG_H
|
||||
|
||||
#include "httpd.h"
|
||||
|
||||
httpd_cgi_state cgiAppCfgSetParams(HttpdConnData *connData);
|
||||
httpd_cgi_state tplAppCfg(HttpdConnData *connData, char *token, void **arg);
|
||||
|
||||
#endif
|
||||
@@ -1,20 +0,0 @@
|
||||
#include <esp8266.h>
|
||||
#include <httpd.h>
|
||||
|
||||
#include "cgi_ping.h"
|
||||
|
||||
httpd_cgi_state ICACHE_FLASH_ATTR cgiPing(HttpdConnData *connData)
|
||||
{
|
||||
if (connData->conn==NULL) {
|
||||
//Connection aborted. Clean up.
|
||||
return HTTPD_CGI_DONE;
|
||||
}
|
||||
|
||||
httpdStartResponse(connData, 200);
|
||||
httpdHeader(connData, "Content-Type", "text/plain");
|
||||
httpdEndHeaders(connData);
|
||||
|
||||
httpdSend(connData, "pong\n", -1);
|
||||
|
||||
return HTTPD_CGI_DONE;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
#ifndef CGI_PING_H
|
||||
#define CGI_PING_H
|
||||
|
||||
#include <esp8266.h>
|
||||
#include <httpd.h>
|
||||
|
||||
// this is used by the UI to check if server is already restarted and working again.
|
||||
|
||||
httpd_cgi_state cgiPing(HttpdConnData *connData);
|
||||
|
||||
#endif // CGI_PING_H
|
||||
@@ -1,31 +0,0 @@
|
||||
#include <esp8266.h>
|
||||
#include <httpd.h>
|
||||
|
||||
#include "cgi_reset.h"
|
||||
|
||||
static ETSTimer tmr;
|
||||
|
||||
static void ICACHE_FLASH_ATTR tmrCb(void *arg)
|
||||
{
|
||||
system_restart();
|
||||
}
|
||||
|
||||
httpd_cgi_state ICACHE_FLASH_ATTR cgiResetDevice(HttpdConnData *connData)
|
||||
{
|
||||
if (connData->conn==NULL) {
|
||||
//Connection aborted. Clean up.
|
||||
return HTTPD_CGI_DONE;
|
||||
}
|
||||
|
||||
httpdStartResponse(connData, 200);
|
||||
httpdHeader(connData, "Content-Type", "text/plain");
|
||||
httpdEndHeaders(connData);
|
||||
|
||||
os_timer_disarm(&tmr);
|
||||
os_timer_setfn(&tmr, tmrCb, NULL);
|
||||
os_timer_arm(&tmr, 100, false);
|
||||
|
||||
httpdSend(connData, "system reset\n", -1);
|
||||
|
||||
return HTTPD_CGI_DONE;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#ifndef CGI_RESET_H
|
||||
#define CGI_RESET_H
|
||||
|
||||
#include <esp8266.h>
|
||||
#include <httpd.h>
|
||||
|
||||
httpd_cgi_state cgiResetDevice(HttpdConnData *connData);
|
||||
|
||||
#endif // CGI_RESET_H
|
||||
Executable
+164
@@ -0,0 +1,164 @@
|
||||
#include <esp8266.h>
|
||||
#include <httpd.h>
|
||||
#include <helpers.h>
|
||||
|
||||
#include "cgi_system.h"
|
||||
#include "persist.h"
|
||||
#include "syscfg.h"
|
||||
#include "uart_driver.h"
|
||||
|
||||
#define SET_REDIR_SUC "/cfg/system"
|
||||
#define SET_REDIR_ERR SET_REDIR_SUC"?err="
|
||||
|
||||
static ETSTimer tmr;
|
||||
|
||||
static void ICACHE_FLASH_ATTR tmrCb(void *arg)
|
||||
{
|
||||
system_restart();
|
||||
}
|
||||
|
||||
httpd_cgi_state ICACHE_FLASH_ATTR cgiResetDevice(HttpdConnData *connData)
|
||||
{
|
||||
if (connData->conn==NULL) {
|
||||
//Connection aborted. Clean up.
|
||||
return HTTPD_CGI_DONE;
|
||||
}
|
||||
|
||||
httpdStartResponse(connData, 200);
|
||||
httpdHeader(connData, "Content-Type", "text/plain");
|
||||
httpdEndHeaders(connData);
|
||||
|
||||
os_timer_disarm(&tmr);
|
||||
os_timer_setfn(&tmr, tmrCb, NULL);
|
||||
os_timer_arm(&tmr, 100, false);
|
||||
|
||||
httpdSend(connData, "system reset\n", -1);
|
||||
|
||||
return HTTPD_CGI_DONE;
|
||||
}
|
||||
|
||||
httpd_cgi_state ICACHE_FLASH_ATTR cgiPing(HttpdConnData *connData)
|
||||
{
|
||||
if (connData->conn==NULL) {
|
||||
//Connection aborted. Clean up.
|
||||
return HTTPD_CGI_DONE;
|
||||
}
|
||||
|
||||
httpdStartResponse(connData, 200);
|
||||
httpdHeader(connData, "Content-Type", "text/plain");
|
||||
httpdEndHeaders(connData);
|
||||
|
||||
httpdSend(connData, "pong\n", -1);
|
||||
|
||||
return HTTPD_CGI_DONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Universal CGI endpoint to set Terminal params.
|
||||
*/
|
||||
httpd_cgi_state ICACHE_FLASH_ATTR
|
||||
cgiSystemCfgSetParams(HttpdConnData *connData)
|
||||
{
|
||||
char buff[50];
|
||||
|
||||
char redir_url_buf[300];
|
||||
char *redir_url = redir_url_buf;
|
||||
redir_url += sprintf(redir_url, SET_REDIR_ERR);
|
||||
// we'll test if anything was printed by looking for \0 in failed_keys_buf
|
||||
|
||||
if (connData->conn == NULL) {
|
||||
//Connection aborted. Clean up.
|
||||
return HTTPD_CGI_DONE;
|
||||
}
|
||||
|
||||
if (GET_ARG("uart_baud")) {
|
||||
dbg("Baud rate: %s", buff);
|
||||
int baud = atoi(buff);
|
||||
if (baud == BIT_RATE_300 ||
|
||||
baud == BIT_RATE_600 ||
|
||||
baud == BIT_RATE_1200 ||
|
||||
baud == BIT_RATE_2400 ||
|
||||
baud == BIT_RATE_4800 ||
|
||||
baud == BIT_RATE_9600 ||
|
||||
baud == BIT_RATE_19200 ||
|
||||
baud == BIT_RATE_38400 ||
|
||||
baud == BIT_RATE_57600 ||
|
||||
baud == BIT_RATE_74880 ||
|
||||
baud == BIT_RATE_115200 ||
|
||||
baud == BIT_RATE_230400 ||
|
||||
baud == BIT_RATE_460800 ||
|
||||
baud == BIT_RATE_921600 ||
|
||||
baud == BIT_RATE_1843200 ||
|
||||
baud == BIT_RATE_3686400) {
|
||||
sysconf->uart_baudrate = (u32) baud;
|
||||
} else {
|
||||
warn("Bad baud rate %s", buff);
|
||||
redir_url += sprintf(redir_url, "uart_baud,");
|
||||
}
|
||||
}
|
||||
|
||||
if (GET_ARG("uart_parity")) {
|
||||
dbg("Parity: %s", buff);
|
||||
int parity = atoi(buff);
|
||||
if (parity >= 0 && parity <= 2) {
|
||||
sysconf->uart_parity = (UartParityMode) parity;
|
||||
} else {
|
||||
warn("Bad parity %s", buff);
|
||||
redir_url += sprintf(redir_url, "uart_parity,");
|
||||
}
|
||||
}
|
||||
|
||||
if (GET_ARG("uart_stopbits")) {
|
||||
dbg("Stop bits: %s", buff);
|
||||
int stopbits = atoi(buff);
|
||||
if (stopbits >= 1 && stopbits <= 3) {
|
||||
sysconf->uart_stopbits = (UartStopBitsNum) stopbits;
|
||||
} else {
|
||||
warn("Bad stopbits %s", buff);
|
||||
redir_url += sprintf(redir_url, "uart_stopbits,");
|
||||
}
|
||||
}
|
||||
|
||||
if (redir_url_buf[strlen(SET_REDIR_ERR)] == 0) {
|
||||
// All was OK
|
||||
info("Set system params - success, saving...");
|
||||
|
||||
sysconf_apply_settings();
|
||||
persist_store();
|
||||
|
||||
httpdRedirect(connData, SET_REDIR_SUC);
|
||||
} else {
|
||||
warn("Some settings did not validate, asking for correction");
|
||||
// Some errors, appended to the URL as ?err=
|
||||
httpdRedirect(connData, redir_url_buf);
|
||||
}
|
||||
return HTTPD_CGI_DONE;
|
||||
}
|
||||
|
||||
|
||||
httpd_cgi_state ICACHE_FLASH_ATTR
|
||||
tplSystemCfg(HttpdConnData *connData, char *token, void **arg)
|
||||
{
|
||||
#define BUFLEN 100
|
||||
char buff[BUFLEN];
|
||||
|
||||
if (token == NULL) {
|
||||
// We're done
|
||||
return HTTPD_CGI_DONE;
|
||||
}
|
||||
|
||||
strcpy(buff, ""); // fallback
|
||||
|
||||
if (streq(token, "uart_baud")) {
|
||||
sprintf(buff, "%d", sysconf->uart_baudrate);
|
||||
}
|
||||
else if (streq(token, "uart_parity")) {
|
||||
sprintf(buff, "%d", sysconf->uart_parity);
|
||||
}
|
||||
else if (streq(token, "uart_stopbits")) {
|
||||
sprintf(buff, "%d", sysconf->uart_stopbits);
|
||||
}
|
||||
|
||||
httpdSend(connData, buff, -1);
|
||||
return HTTPD_CGI_DONE;
|
||||
}
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
#ifndef CGI_PING_H
|
||||
#define CGI_PING_H
|
||||
|
||||
#include <esp8266.h>
|
||||
#include <httpd.h>
|
||||
|
||||
httpd_cgi_state cgiPing(HttpdConnData *connData);
|
||||
httpd_cgi_state cgiResetDevice(HttpdConnData *connData);
|
||||
httpd_cgi_state cgiSystemCfgSetParams(HttpdConnData *connData);
|
||||
httpd_cgi_state tplSystemCfg(HttpdConnData *connData, char *token, void **arg);
|
||||
|
||||
#endif // CGI_PING_H
|
||||
@@ -3,19 +3,19 @@ Cgi/template routines for configuring non-wifi settings
|
||||
*/
|
||||
|
||||
#include <esp8266.h>
|
||||
#include "cgi_appcfg.h"
|
||||
#include "cgi_term_cfg.h"
|
||||
#include "persist.h"
|
||||
#include "screen.h"
|
||||
#include "helpers.h"
|
||||
|
||||
#define SET_REDIR_SUC "/cfg/app"
|
||||
#define SET_REDIR_SUC "/cfg/term"
|
||||
#define SET_REDIR_ERR SET_REDIR_SUC"?err="
|
||||
|
||||
/**
|
||||
* Universal CGI endpoint to set Terminal params.
|
||||
*/
|
||||
httpd_cgi_state ICACHE_FLASH_ATTR
|
||||
cgiAppCfgSetParams(HttpdConnData *connData)
|
||||
cgiTermCfgSetParams(HttpdConnData *connData)
|
||||
{
|
||||
char buff[50];
|
||||
|
||||
@@ -114,7 +114,7 @@ cgiAppCfgSetParams(HttpdConnData *connData)
|
||||
|
||||
if (redir_url_buf[strlen(SET_REDIR_ERR)] == 0) {
|
||||
// All was OK
|
||||
info("Set app params - success, saving...");
|
||||
info("Set term params - success, saving...");
|
||||
|
||||
terminal_apply_settings();
|
||||
persist_store();
|
||||
@@ -130,7 +130,7 @@ cgiAppCfgSetParams(HttpdConnData *connData)
|
||||
|
||||
|
||||
httpd_cgi_state ICACHE_FLASH_ATTR
|
||||
tplAppCfg(HttpdConnData *connData, char *token, void **arg)
|
||||
tplTermCfg(HttpdConnData *connData, char *token, void **arg)
|
||||
{
|
||||
#define BUFLEN 100
|
||||
char buff[BUFLEN];
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef CGIAPPCFG_H
|
||||
#define CGIAPPCFG_H
|
||||
|
||||
#include "httpd.h"
|
||||
|
||||
httpd_cgi_state cgiTermCfgSetParams(HttpdConnData *connData);
|
||||
httpd_cgi_state tplTermCfg(HttpdConnData *connData, char *token, void **arg);
|
||||
|
||||
#endif
|
||||
+8
-3
@@ -183,9 +183,8 @@ static void ICACHE_FLASH_ATTR wifiStartScan(void)
|
||||
}
|
||||
|
||||
/**
|
||||
* This CGI is called from the bit of AJAX-code in wifi.tpl. It will initiate a
|
||||
* scan for access points and if available will return the result of an earlier scan.
|
||||
* The result is embedded in a bit of JSON parsed by the javascript in wifi.tpl.
|
||||
* Start a scan and return a result of an earlier scan, if available.
|
||||
* The STA is switched ON if disabled.
|
||||
*/
|
||||
httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiScan(HttpdConnData *connData)
|
||||
{
|
||||
@@ -193,6 +192,12 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiScan(HttpdConnData *connData)
|
||||
int len;
|
||||
char buff[256];
|
||||
|
||||
// auto-turn on STA
|
||||
if ((wificonf->opmode & STATION_MODE) == 0) {
|
||||
wificonf->opmode |= STATION_MODE;
|
||||
wifimgr_apply_settings();
|
||||
}
|
||||
|
||||
// 2nd and following runs of the function via MORE:
|
||||
if (!cgiWifiAps.scanInProgress && pos != 0) {
|
||||
// Fill in json code for an access point
|
||||
|
||||
+12
-6
@@ -19,6 +19,7 @@ apply_live_settings(void)
|
||||
dbg("[Persist] Applying live settings...");
|
||||
terminal_apply_settings();
|
||||
wifimgr_apply_settings();
|
||||
sysconf_apply_settings();
|
||||
// ...
|
||||
}
|
||||
|
||||
@@ -27,6 +28,7 @@ restore_live_settings_to_hard_defaults(void)
|
||||
{
|
||||
wifimgr_restore_defaults();
|
||||
terminal_restore_defaults();
|
||||
sysconf_restore_defaults();
|
||||
// ...
|
||||
}
|
||||
|
||||
@@ -41,7 +43,7 @@ restore_live_settings_to_hard_defaults(void)
|
||||
static uint32_t ICACHE_FLASH_ATTR
|
||||
calculateCRC32(const uint8_t *data, size_t length)
|
||||
{
|
||||
uint32_t crc = 0xffffffff;
|
||||
uint32_t crc = 0xffffffff + CHECKSUM_SALT;
|
||||
while (length--) {
|
||||
uint8_t c = *data++;
|
||||
for (uint32_t i = 0x80; i > 0; i >>= 1) {
|
||||
@@ -67,7 +69,8 @@ calculateCRC32(const uint8_t *data, size_t length)
|
||||
static uint32_t ICACHE_FLASH_ATTR
|
||||
compute_checksum(AppConfigBundle *bundle)
|
||||
{
|
||||
return calculateCRC32((uint8_t *) bundle, sizeof(AppConfigBundle) - 4) ^ CHECKSUM_SALT;
|
||||
// this should be the bundle without the checksum
|
||||
return calculateCRC32((uint8_t *) bundle, sizeof(AppConfigBundle) - 4);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,10 +81,13 @@ persist_load(void)
|
||||
{
|
||||
info("[Persist] Loading stored settings from FLASH...");
|
||||
|
||||
dbg("sizeof(AppConfigBundle) = %d bytes", sizeof(AppConfigBundle));
|
||||
dbg("sizeof(PersistBlock) = %d bytes", sizeof(PersistBlock));
|
||||
dbg("sizeof(WiFiConfigBundle) = %d bytes", sizeof(WiFiConfigBundle));
|
||||
dbg("sizeof(TerminalConfigBundle) = %d bytes", sizeof(TerminalConfigBundle));
|
||||
dbg("sizeof(AppConfigBundle) = %d bytes", sizeof(AppConfigBundle));
|
||||
dbg("> sizeof(WiFiConfigBundle) = %d bytes", sizeof(WiFiConfigBundle));
|
||||
dbg("> sizeof(TerminalConfigBundle) = %d bytes", sizeof(TerminalConfigBundle));
|
||||
dbg("> sizeof(SystemConfigBundle) = %d bytes", sizeof(SystemConfigBundle));
|
||||
dbg("> sizeof(checksum) = %d bytes", sizeof(uint32_t));
|
||||
dbg("> filler = %d bytes",
|
||||
sizeof(AppConfigBundle) - (sizeof(WiFiConfigBundle) + sizeof(TerminalConfigBundle) + sizeof(SystemConfigBundle)));
|
||||
|
||||
bool hard_reset = false;
|
||||
|
||||
|
||||
+13
-5
@@ -12,19 +12,21 @@
|
||||
|
||||
#include "wifimgr.h"
|
||||
#include "screen.h"
|
||||
#include "syscfg.h"
|
||||
|
||||
// Changing this could be used to force-erase the config area
|
||||
// after a firmware upgrade
|
||||
#define CHECKSUM_SALT 0x5F5F5F5F
|
||||
#define CHECKSUM_SALT 1
|
||||
|
||||
#define APPCONF_SIZE 2048
|
||||
|
||||
/** Struct for current or default settings */
|
||||
typedef struct {
|
||||
typedef struct { // the entire block should be 1024 bytes long (for compatibility across upgrades)
|
||||
WiFiConfigBundle wificonf;
|
||||
TerminalConfigBundle termconf;
|
||||
SystemConfigBundle sysconf;
|
||||
|
||||
// --- Space for future settings ---
|
||||
// Original size: 1024
|
||||
//
|
||||
// The size must be appropriately reduced each time something is added,
|
||||
// and boolean flags defaulting to 0 should be used to detect unpopulated
|
||||
// sections that must be restored to defaults on load.
|
||||
@@ -32,7 +34,13 @@ typedef struct {
|
||||
// This ensures user settings are not lost each time they upgrade the firmware,
|
||||
// which would lead to a checksum mismatch if the structure was changed and
|
||||
// it grew to a different memory area.
|
||||
uint8_t filler[1024];
|
||||
uint8_t filler[
|
||||
APPCONF_SIZE
|
||||
- sizeof(uint32_t) // checksum
|
||||
- sizeof(WiFiConfigBundle)
|
||||
- sizeof(TerminalConfigBundle)
|
||||
- sizeof(SystemConfigBundle)
|
||||
];
|
||||
|
||||
uint32_t checksum; // computed before write and tested on load. If it doesn't match, values are reset to hard defaults.
|
||||
} AppConfigBundle;
|
||||
|
||||
+9
-9
@@ -6,12 +6,11 @@
|
||||
|
||||
#include "routes.h"
|
||||
#include "cgi_wifi.h"
|
||||
#include "cgi_reset.h"
|
||||
#include "cgi_ping.h"
|
||||
#include "cgi_system.h"
|
||||
#include "cgi_main.h"
|
||||
#include "cgi_sockets.h"
|
||||
#include "cgi_network.h"
|
||||
#include "cgi_appcfg.h"
|
||||
#include "cgi_term_cfg.h"
|
||||
#include "cgi_persist.h"
|
||||
|
||||
#define WIFI_PROTECT 0
|
||||
@@ -54,13 +53,14 @@ HttpdBuiltInUrl routes[] = {
|
||||
ROUTE_TPL_FILE("/cfg/network/?", tplNetwork, "/cfg_network.tpl"),
|
||||
ROUTE_CGI("/cfg/network/set", cgiNetworkSetParams),
|
||||
|
||||
ROUTE_TPL_FILE("/cfg/app/?", tplAppCfg, "/cfg_app.tpl"),
|
||||
ROUTE_CGI("/cfg/app/set", cgiAppCfgSetParams),
|
||||
ROUTE_TPL_FILE("/cfg/term/?", tplTermCfg, "/cfg_term.tpl"),
|
||||
ROUTE_CGI("/cfg/term/set", cgiTermCfgSetParams),
|
||||
|
||||
ROUTE_FILE("/cfg/admin/?", "/cfg_admin.tpl"),
|
||||
ROUTE_CGI("/cfg/admin/write_defaults", cgiPersistWriteDefaults),
|
||||
ROUTE_CGI("/cfg/admin/restore_defaults", cgiPersistRestoreDefaults),
|
||||
ROUTE_CGI("/cfg/admin/restore_hard", cgiPersistRestoreHard),
|
||||
ROUTE_TPL_FILE("/cfg/system/?", tplSystemCfg, "/cfg_system.tpl"),
|
||||
ROUTE_CGI("/cfg/system/set", cgiSystemCfgSetParams),
|
||||
ROUTE_CGI("/cfg/system/write_defaults", cgiPersistWriteDefaults),
|
||||
ROUTE_CGI("/cfg/system/restore_defaults", cgiPersistRestoreDefaults),
|
||||
ROUTE_CGI("/cfg/system/restore_hard", cgiPersistRestoreHard),
|
||||
|
||||
ROUTE_FILESYSTEM(),
|
||||
ROUTE_END(),
|
||||
|
||||
+24
-6
@@ -34,17 +34,35 @@
|
||||
*
|
||||
*/
|
||||
|
||||
// Size designed for the wifi config structure
|
||||
// Must be constant to avoid corrupting user config after upgrade
|
||||
#define TERMCONF_SIZE 200
|
||||
|
||||
#define TERM_BTN_LEN 10
|
||||
#define TERM_TITLE_LEN 64
|
||||
|
||||
typedef struct {
|
||||
u32 width;
|
||||
u32 height;
|
||||
u8 default_bg;
|
||||
u8 default_fg;
|
||||
char title[64];
|
||||
char btn1[10];
|
||||
char btn2[10];
|
||||
char btn3[10];
|
||||
char btn4[10];
|
||||
char btn5[10];
|
||||
char title[TERM_TITLE_LEN];
|
||||
char btn1[TERM_BTN_LEN];
|
||||
char btn2[TERM_BTN_LEN];
|
||||
char btn3[TERM_BTN_LEN];
|
||||
char btn4[TERM_BTN_LEN];
|
||||
char btn5[TERM_BTN_LEN];
|
||||
|
||||
u8 _filler[
|
||||
TERMCONF_SIZE
|
||||
- 4
|
||||
- 4
|
||||
- 1
|
||||
- 1
|
||||
- TERM_TITLE_LEN
|
||||
- TERM_BTN_LEN * 5
|
||||
];
|
||||
|
||||
} TerminalConfigBundle;
|
||||
|
||||
// Live config
|
||||
|
||||
+23
-6
@@ -2,19 +2,36 @@
|
||||
#include "uart_driver.h"
|
||||
#include "uart_handler.h"
|
||||
#include "ansi_parser.h"
|
||||
#include "syscfg.h"
|
||||
|
||||
// Here the bitrates are defined
|
||||
#define UART0_BAUD BIT_RATE_115200
|
||||
#define UART1_BAUD BIT_RATE_115200
|
||||
/**
|
||||
* Init the serial ports
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR serialInitBase(void)
|
||||
{
|
||||
UART_Init();
|
||||
// debug port
|
||||
UART_SetParity(UART1, PARITY_NONE);
|
||||
UART_SetStopBits(UART1, ONE_STOP_BIT);
|
||||
UART_SetBaudrate(UART1, BIT_RATE_115200);
|
||||
UART_SetPrintPort(UART1);
|
||||
UART_SetupAsyncReceiver();
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the serial ports
|
||||
*/
|
||||
void ICACHE_FLASH_ATTR serialInit(void)
|
||||
{
|
||||
UART_Init(UART0_BAUD, UART1_BAUD);
|
||||
UART_SetPrintPort(UART1);
|
||||
UART_SetupAsyncReceiver();
|
||||
UART_SetParity(UART0, (UartParityMode) sysconf->uart_parity);
|
||||
UART_SetStopBits(UART0, (UartStopBitsNum) sysconf->uart_stopbits);
|
||||
UART_SetBaudrate(UART0, sysconf->uart_baudrate);
|
||||
|
||||
info("COM SERIAL: %d baud, %s parity, %s stopbit(s)",
|
||||
sysconf->uart_baudrate,
|
||||
(sysconf->uart_parity == PARITY_NONE ? "NONE" : (sysconf->uart_parity == PARITY_ODD ? "ODD" : "EVEN")),
|
||||
(sysconf->uart_stopbits == ONE_STOP_BIT ? "1" : (sysconf->uart_stopbits == ONE_HALF_STOP_BIT ? "1.5" : "2"))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#ifndef SERIAL_H
|
||||
#define SERIAL_H
|
||||
|
||||
/** Initial uart init (before sysconf is loaded) */
|
||||
void serialInitBase(void);
|
||||
|
||||
/** Init the uarts */
|
||||
void serialInit(void);
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by MightyPork on 2017/07/29.
|
||||
//
|
||||
|
||||
#include "syscfg.h"
|
||||
#include "persist.h"
|
||||
#include "uart_driver.h"
|
||||
#include "serial.h"
|
||||
|
||||
SystemConfigBundle * const sysconf = &persist.current.sysconf;
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
sysconf_apply_settings(void)
|
||||
{
|
||||
serialInit();
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
sysconf_restore_defaults(void)
|
||||
{
|
||||
sysconf->uart_parity = PARITY_NONE;
|
||||
sysconf->uart_baudrate = BIT_RATE_115200;
|
||||
sysconf->uart_stopbits = ONE_STOP_BIT;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// Created by MightyPork on 2017/07/29.
|
||||
//
|
||||
|
||||
#ifndef ESP_VT100_FIRMWARE_SYSCFG_H
|
||||
#define ESP_VT100_FIRMWARE_SYSCFG_H
|
||||
|
||||
#include <esp8266.h>
|
||||
|
||||
// Size designed for the wifi config structure
|
||||
// Must be constant to avoid corrupting user config after upgrade
|
||||
#define SYSCONF_SIZE 200
|
||||
|
||||
typedef struct {
|
||||
u32 uart_baudrate;
|
||||
u8 uart_parity;
|
||||
u8 uart_stopbits;
|
||||
|
||||
u8 _filler[
|
||||
SYSCONF_SIZE
|
||||
- 4
|
||||
- 1
|
||||
- 1
|
||||
];
|
||||
} SystemConfigBundle;
|
||||
|
||||
extern SystemConfigBundle * const sysconf;
|
||||
|
||||
void sysconf_apply_settings(void);
|
||||
|
||||
void sysconf_restore_defaults(void);
|
||||
|
||||
#endif //ESP_VT100_FIRMWARE_SYSCFG_H
|
||||
+5
-17
@@ -32,22 +32,8 @@ void ICACHE_FLASH_ATTR clear_rxtx(int uart_no)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Configure UART 115200-8-N-1
|
||||
* @param uart_no
|
||||
*/
|
||||
static void ICACHE_FLASH_ATTR my_uart_init(UARTn uart_no, uint32 baud)
|
||||
{
|
||||
UART_SetParity(uart_no, PARITY_NONE);
|
||||
UART_SetStopBits(uart_no, ONE_STOP_BIT);
|
||||
UART_SetWordLength(uart_no, EIGHT_BITS);
|
||||
UART_SetBaudrate(uart_no, baud);
|
||||
UART_ResetFifo(uart_no);
|
||||
}
|
||||
|
||||
|
||||
/** Configure basic UART func and pins */
|
||||
void ICACHE_FLASH_ATTR UART_Init(uint32_t baud0, uint32_t baud1)
|
||||
void ICACHE_FLASH_ATTR UART_Init(void)
|
||||
{
|
||||
// U0TXD
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD);
|
||||
@@ -60,8 +46,10 @@ void ICACHE_FLASH_ATTR UART_Init(uint32_t baud0, uint32_t baud1)
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
|
||||
|
||||
// Configure the UART peripherals
|
||||
my_uart_init(UART0, baud0); // main
|
||||
my_uart_init(UART1, baud1); // debug (output only)
|
||||
UART_SetWordLength(UART0, EIGHT_BITS); // main
|
||||
UART_ResetFifo(UART0);
|
||||
UART_SetWordLength(UART1, EIGHT_BITS); // debug (output only)
|
||||
UART_ResetFifo(UART1);
|
||||
}
|
||||
|
||||
/** Configure Rx on UART0 */
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@
|
||||
|
||||
#include <esp8266.h>
|
||||
|
||||
/** Configure UART periphs and enable pins */
|
||||
void UART_Init(uint32_t baud0, uint32_t baud1);
|
||||
/** Configure UART periphs and enable pins - does not set baud rate, parity and stopbits */
|
||||
void UART_Init(void);
|
||||
|
||||
/** Configure async Rx on UART0 */
|
||||
void UART_SetupAsyncReceiver(void);
|
||||
|
||||
+4
-18
@@ -86,12 +86,12 @@ void ICACHE_FLASH_ATTR user_init(void)
|
||||
static ETSTimer userStartTimer;
|
||||
static ETSTimer prHeapTimer;
|
||||
|
||||
serialInit();
|
||||
serialInitBase();
|
||||
|
||||
// Prevent WiFi starting and connecting by default
|
||||
// let wifi manager handle it
|
||||
wifi_station_set_auto_connect(false);
|
||||
wifi_set_opmode(NULL_MODE); // save to flash if changed - this might avoid the current spike on startup?
|
||||
wifi_set_opmode(NULL_MODE); // saves to flash if changed - this might avoid the current spike on startup?
|
||||
|
||||
printf("\r\n");
|
||||
banner("====== ESP8266 Remote Terminal ======");
|
||||
@@ -126,30 +126,16 @@ void ICACHE_FLASH_ATTR user_init(void)
|
||||
|
||||
static void user_start(void *unused)
|
||||
{
|
||||
// Change AP name if AI-THINKER found (means un-initialized device)
|
||||
// struct softap_config apconf;
|
||||
// wifi_softap_get_config(&apconf);
|
||||
// if (strstarts((char *) apconf.ssid, "AI-THINKER")) {
|
||||
// warn("Un-initialized device, performing factory reset.");
|
||||
// apars_handle_OSC_FactoryReset();
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Load and apply stored settings, or defaults if stored settings are invalid
|
||||
persist_load();
|
||||
// Captive portal (DNS redirector)
|
||||
captdnsInit();
|
||||
// Server
|
||||
httpdInit(routes, 80);
|
||||
|
||||
// The terminal screen
|
||||
captdnsInit();
|
||||
httpdInit(routes, 80);
|
||||
screen_init();
|
||||
|
||||
// Print the CANCEL character to indicate the module has restarted
|
||||
// Critically important for client application if any kind of screen persistence / content re-use is needed
|
||||
UART_WriteChar(UART0, 24, UART_TIMEOUT_US); // 0x18 - 24 - CAN
|
||||
|
||||
info("Listening on UART0, 115200-8-N-1!");
|
||||
}
|
||||
|
||||
// ---- unused funcs removed from sdk to save space ---
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ wifimgr_restore_defaults(void)
|
||||
u8 mac[6];
|
||||
wifi_get_macaddr(SOFTAP_IF, mac);
|
||||
|
||||
wificonf->opmode = SOFTAP_MODE;
|
||||
wificonf->opmode = STATIONAP_MODE; // Client+AP, so we can scan without having to enable Station
|
||||
wificonf->tpw = 20;
|
||||
wificonf->ap_channel = 1;
|
||||
sprintf((char *) wificonf->ap_ssid, "TERM-%02X%02X%02X", mac[3], mac[4], mac[5]);
|
||||
|
||||
+25
-1
@@ -13,6 +13,10 @@
|
||||
#define SSID_LEN 32
|
||||
#define PASSWORD_LEN 64
|
||||
|
||||
// Size designed for the wifi config structure
|
||||
// Must be constant to avoid corrupting user config after upgrade
|
||||
#define WIFICONF_SIZE 340
|
||||
|
||||
/**
|
||||
* A structure holding all configured WiFi parameters
|
||||
* and the active state.
|
||||
@@ -37,8 +41,28 @@ typedef struct {
|
||||
u8 sta_ssid[SSID_LEN];
|
||||
u8 sta_password[PASSWORD_LEN];
|
||||
bool sta_dhcp_enable;
|
||||
|
||||
struct ip_info sta_addr;
|
||||
|
||||
u8 _filler[
|
||||
WIFICONF_SIZE
|
||||
- 1
|
||||
- 1
|
||||
|
||||
- 1
|
||||
- SSID_LEN
|
||||
- PASSWORD_LEN
|
||||
- 1
|
||||
- 2
|
||||
- sizeof(struct dhcps_lease)
|
||||
|
||||
- sizeof(struct ip_info)
|
||||
|
||||
- SSID_LEN
|
||||
- PASSWORD_LEN
|
||||
- 1
|
||||
- sizeof(struct ip_info)
|
||||
- 8 // padding?
|
||||
];
|
||||
} WiFiConfigBundle;
|
||||
|
||||
typedef struct {
|
||||
|
||||
Reference in New Issue
Block a user