Compare commits

..
5 Commits
13 changed files with 212 additions and 111 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ LIBS += esphttpd
# compiler flags using during compilation of source files
CFLAGS = -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \
-nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH \
-Wno-address -Wno-unused -DHTTPD_MAX_BACKLOG_SIZE=4096 -DADMIN_PASSWORD=$(ADMIN_PASSWORD) \
-Wno-address -Wno-unused -DHTTPD_MAX_BACKLOG_SIZE=8192 -DADMIN_PASSWORD=$(ADMIN_PASSWORD) \
-DGIT_HASH='"$(shell git rev-parse --short HEAD)"'
# linker flags used to generate the main object file
+17 -2
View File
@@ -16,6 +16,11 @@ return [
'title.term' => 'Terminal',
'term_nav.config' => 'Config',
'term_nav.wifi' => 'WiFi',
'term_nav.help' => 'Help',
'term_nav.about' => 'About',
'net.ap' => 'DHCP Server (AP)',
'net.sta' => 'DHCP Client (Station)',
'net.sta_mac' => 'Station MAC',
@@ -100,10 +105,20 @@ return [
'wifi.conn.status' => 'Status:',
'wifi.conn.back_to_config' => 'Back to WiFi config',
'wifi.conn.telemetry_lost' => 'Telemetry lost, something went wrong. Try again...',
'wifi.conn.telemetry_lost' => 'Telemetry lost; something went wrong, or your device disconnected.',
'wifi.conn.explain_android_sucks' => '
If you\'re configuring ESPTerm via a smartphone, or were connected
from another external network, your device may lose connection and this
progress indicator won\'t work. Please wait a while (~ 15 seconds),
then check if the connection succeeded.',
'wifi.conn.explain_reset' => '
To force enable the built-in AP, hold the BOOT
button until the blue LED starts flashing. Hold the button longer (until the LED
flashes rapidly) for a "factory reset".',
'wifi.conn.disabled' =>"Station mode is disabled.",
'wifi.conn.idle' =>"Idle, not connected and with no IP.",
'wifi.conn.idle' =>"Idle, not connected and has no IP.",
'wifi.conn.success' => "Connected! Received IP ",
'wifi.conn.working' => "Connecting to selected AP",
'wifi.conn.fail' => "Connection failed, check settings & try again. Cause: ",
+1 -1
View File
@@ -42,7 +42,7 @@
</div>
</form>
<form class="Box str mobcol" action="<?= e(url('wifi_set')) ?>" method="GET" id="form-2">
<form class="Box str mobcol expanded" action="<?= e(url('wifi_set')) ?>" method="GET" id="form-2">
<h2 tabindex=0><?= tr('wifi.sta') ?></h2>
<div class="Row checkbox x-sta-toggle">
+42 -6
View File
@@ -5,9 +5,15 @@
<a href="<?= e(url('cfg_wifi')) ?>" id="backbtn" class="button"><?= tr('wifi.conn.back_to_config') ?></a>
</div>
<div class="Box">
<p><?= tr('wifi.conn.explain_android_sucks') ?></p>
<p><?= tr('wifi.conn.explain_reset') ?></p>
</div>
<script>
var xhr = new XMLHttpRequest();
var abortTmeo;
var failCounter = 0;
var messages = <?= json_encode([
'disabled' => tr('wifi.conn.disabled'),
@@ -17,16 +23,32 @@
'fail' => tr('wifi.conn.fail'),
]) ?>;
function onFail() {
$("#status").html(<?= json_encode(tr('wifi.conn.telemetry_lost')) ?>);
$('.anim-dots').addClass('hidden');
}
function getStatus() {
xhr.open("GET", 'http://'+_root+'<?= url('wifi_connstatus', true) ?>');
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status >= 200 && xhr.status < 300) {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
clearTimeout(abortTmeo);
try {
var data = JSON.parse(xhr.responseText);
var done = false;
var msg = messages[data.status] || '...';
if (data.status == 'success') msg += data.ip;
if (data.status == 'fail') msg += data.cause;
if (data.status == 'success') {
msg += data.ip;
done = true;
}
if (data.status == 'fail') {
msg += data.cause;
done = true;
}
$("#status").html(msg);
@@ -34,16 +56,30 @@
// $('#backbtn').removeClass('hidden');
$('.anim-dots').addClass('hidden');
} else {
// ask again after a short delay
window.setTimeout(getStatus, 1000);
}
} catch(e) {
failCounter++;
console.log(e);
// repeat
if (failCounter > 5) {
onFail();
}
else {
window.setTimeout(getStatus, 1000);
}
}
} else {
onFail();
}
}
};
// XHR timeout
abortTmeo = setTimeout(function () {
xhr.abort();
$("#status").html(<?= json_encode(tr('wifi.conn.telemetry_lost')) ?>);
// $('#backbtn').removeClass('hidden');
$('.anim-dots').addClass('hidden');
onFail();
}, 4000);
xhr.send();
+4 -3
View File
@@ -26,9 +26,10 @@
<nav id="botnav">
<a href="#" onclick="toggleSoftKb(true); return false" class="icn-keyboard mq-tablet-max"></a><!--
--><a href="<?= url('cfg_term') ?>"><?= tr('menu.settings') ?></a><!--
--><a href="<?= url('help') ?>">Help</a><!--
--><a href="<?= url('about') ?>">About</a>
--><a href="<?= url('cfg_term') ?>"><?= tr('term_nav.config') ?></a><!--
--><a href="<?= url('cfg_wifi') ?>"><?= tr('term_nav.wifi') ?></a><!--
--><a href="<?= url('help') ?>"><?= tr('term_nav.help') ?></a><!--
--><a href="<?= url('about') ?>"><?= tr('term_nav.about') ?></a>
</nav>
<script>
+1 -1
View File
@@ -17,7 +17,7 @@
/**
* Helper that retrieves an arg from `connData->getArgs` and stores it in `buff`. Returns 1 on success
*/
#define GET_ARG(key) (httpdFindArg(connData->getArgs, key, buff, sizeof(buff)) > 0)
#define GET_ARG(key) (httpdFindArg(connData->getArgs, key, buff, sizeof(buff)) >= 0)
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
+65 -73
View File
@@ -19,11 +19,11 @@ static const char _ansi_eof_actions[] = {
0, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 0, 0, 0, 0, 0
0, 0, 0, 0, 0
};
static const int ansi_start = 1;
static const int ansi_first_final = 26;
static const int ansi_first_final = 24;
static const int ansi_error = 0;
static const int ansi_en_CSI_body = 3;
@@ -123,7 +123,7 @@ case 2:
goto tr2;
case 0:
goto _out;
case 26:
case 24:
if ( (*p) == 27 )
goto tr1;
goto tr0;
@@ -157,7 +157,7 @@ case 4:
} else
goto tr11;
goto tr2;
case 27:
case 25:
goto tr2;
case 5:
switch( (*p) ) {
@@ -183,82 +183,74 @@ case 9:
goto tr18;
goto tr2;
case 10:
if ( (*p) == 27 )
goto tr2;
switch( (*p) ) {
case 7: goto tr20;
case 27: goto tr21;
}
goto tr19;
case 26:
switch( (*p) ) {
case 7: goto tr20;
case 27: goto tr21;
}
goto tr19;
case 11:
switch( (*p) ) {
case 7: goto tr20;
case 27: goto tr21;
}
goto tr19;
case 28:
switch( (*p) ) {
case 7: goto tr20;
case 27: goto tr21;
}
goto tr19;
case 12:
if ( (*p) == 92 )
goto tr22;
goto tr2;
case 29:
case 27:
goto tr2;
case 13:
case 12:
if ( (*p) == 73 )
goto tr23;
goto tr2;
case 14:
case 13:
if ( (*p) == 84 )
goto tr24;
goto tr2;
case 15:
case 14:
if ( (*p) == 76 )
goto tr25;
goto tr2;
case 16:
case 15:
if ( (*p) == 69 )
goto tr26;
goto tr2;
case 17:
case 16:
if ( (*p) == 61 )
goto tr27;
goto tr2;
case 17:
switch( (*p) ) {
case 7: goto tr29;
case 27: goto tr30;
}
goto tr28;
case 28:
switch( (*p) ) {
case 7: goto tr29;
case 27: goto tr30;
}
goto tr28;
case 18:
if ( (*p) == 27 )
goto tr2;
goto tr28;
case 19:
switch( (*p) ) {
case 7: goto tr29;
case 27: goto tr30;
}
goto tr28;
case 30:
switch( (*p) ) {
case 7: goto tr29;
case 27: goto tr30;
}
goto tr28;
case 20:
if ( (*p) == 92 )
goto tr31;
goto tr2;
case 21:
case 19:
if ( 48 <= (*p) && (*p) <= 57 )
goto tr32;
goto tr2;
case 22:
case 20:
if ( (*p) == 59 )
goto tr33;
if ( 48 <= (*p) && (*p) <= 57 )
goto tr32;
goto tr2;
case 23:
case 21:
if ( 48 <= (*p) && (*p) <= 57 )
goto tr34;
goto tr2;
case 24:
case 22:
switch( (*p) ) {
case 7: goto tr35;
case 27: goto tr36;
@@ -266,7 +258,7 @@ case 24:
if ( 48 <= (*p) && (*p) <= 57 )
goto tr34;
goto tr2;
case 25:
case 23:
if ( (*p) == 92 )
goto tr35;
goto tr2;
@@ -283,32 +275,32 @@ case 25:
tr16: cs = 8; goto _again;
tr17: cs = 9; goto f8;
tr18: cs = 10; goto _again;
tr19: cs = 11; goto f11;
tr21: cs = 12; goto _again;
tr13: cs = 13; goto _again;
tr23: cs = 14; goto _again;
tr24: cs = 15; goto _again;
tr25: cs = 16; goto _again;
tr26: cs = 17; goto _again;
tr27: cs = 18; goto _again;
tr28: cs = 19; goto f11;
tr30: cs = 20; goto _again;
tr14: cs = 21; goto _again;
tr32: cs = 22; goto f8;
tr33: cs = 23; goto f9;
tr34: cs = 24; goto f8;
tr36: cs = 25; goto _again;
tr3: cs = 26; goto f2;
tr4: cs = 26; goto f3;
tr5: cs = 26; goto f4;
tr6: cs = 26; goto f5;
tr7: cs = 26; goto f6;
tr11: cs = 27; goto f10;
tr20: cs = 28; goto f12;
tr22: cs = 29; goto f13;
tr31: cs = 29; goto f15;
tr35: cs = 29; goto f16;
tr29: cs = 30; goto f14;
tr19: cs = 10; goto f11;
tr21: cs = 11; goto _again;
tr13: cs = 12; goto _again;
tr23: cs = 13; goto _again;
tr24: cs = 14; goto _again;
tr25: cs = 15; goto _again;
tr26: cs = 16; goto _again;
tr27: cs = 17; goto _again;
tr28: cs = 17; goto f11;
tr30: cs = 18; goto _again;
tr14: cs = 19; goto _again;
tr32: cs = 20; goto f8;
tr33: cs = 21; goto f9;
tr34: cs = 22; goto f8;
tr36: cs = 23; goto _again;
tr3: cs = 24; goto f2;
tr4: cs = 24; goto f3;
tr5: cs = 24; goto f4;
tr6: cs = 24; goto f5;
tr7: cs = 24; goto f6;
tr11: cs = 25; goto f10;
tr20: cs = 26; goto f12;
tr22: cs = 27; goto f13;
tr31: cs = 27; goto f15;
tr35: cs = 27; goto f16;
tr29: cs = 28; goto f14;
f1: _acts = _ansi_actions + 1; goto execFuncs;
f4: _acts = _ansi_actions + 3; goto execFuncs;
@@ -458,7 +450,7 @@ execFuncs:
{cs = 1;goto _again;}
}
break;
/* #line 462 "user/ansi_parser.c" */
/* #line 454 "user/ansi_parser.c" */
}
}
goto _again;
@@ -484,7 +476,7 @@ _again:
goto _again;}
}
break;
/* #line 488 "user/ansi_parser.c" */
/* #line 480 "user/ansi_parser.c" */
}
}
}
+2 -2
View File
@@ -169,8 +169,8 @@ ansi_parser(const char *newdata, size_t len)
}
OSC_body := (
("BTN" digit @CSI_digit '=' (NOESC @OSC_text_char)+ OSC_END @OSC_button) |
("TITLE=" (NOESC @OSC_text_char)+ OSC_END @OSC_title) |
("BTN" digit @CSI_digit '=' (NOESC @OSC_text_char)* OSC_END @OSC_button) |
("TITLE=" (NOESC @OSC_text_char)* OSC_END @OSC_title) |
('W' (digit @CSI_digit)+ ';' @CSI_semi (digit @CSI_digit)+ OSC_END @OSC_resize)
) $!errBadSeq;
+17 -1
View File
@@ -22,6 +22,8 @@ cgiTermCfgSetParams(HttpdConnData *connData)
char redir_url_buf[100];
int n, w, h;
bool shall_clear_screen = false;
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
@@ -41,8 +43,11 @@ cgiTermCfgSetParams(HttpdConnData *connData)
h = atoi(buff);
if (h > 1) {
if (w * h <= MAX_SCREEN_SIZE) {
if (termconf->width != w || termconf->height != h) {
termconf->width = w;
termconf->height = h;
shall_clear_screen = true;
}
} else {
warn("Bad dimensions: %d x %d (total %d)", w, h, w*h);
redir_url += sprintf(redir_url, "term_width,term_height,");
@@ -66,7 +71,10 @@ cgiTermCfgSetParams(HttpdConnData *connData)
dbg("Screen default BG: %s", buff);
n = atoi(buff);
if (n >= 0 && n < 16) {
if (termconf->default_bg != n) {
termconf->default_bg = (u8) n;
shall_clear_screen = true;
}
} else {
warn("Bad color %s", buff);
redir_url += sprintf(redir_url, "default_bg,");
@@ -88,7 +96,10 @@ cgiTermCfgSetParams(HttpdConnData *connData)
dbg("Screen default FG: %s", buff);
n = atoi(buff);
if (n >= 0 && n < 16) {
if (termconf->default_fg != n) {
termconf->default_fg = (u8) n;
shall_clear_screen = true;
}
} else {
warn("Bad color %s", buff);
redir_url += sprintf(redir_url, "default_fg,");
@@ -123,9 +134,14 @@ cgiTermCfgSetParams(HttpdConnData *connData)
// All was OK
info("Set term params - success, saving...");
terminal_apply_settings();
persist_store();
if (shall_clear_screen) {
terminal_apply_settings();
} else {
terminal_apply_settings_noclear();
}
httpdRedirect(connData, SET_REDIR_SUC);
} else {
warn("Some settings did not validate, asking for correction");
+39 -5
View File
@@ -193,6 +193,11 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiScan(HttpdConnData *connData)
int len;
char buff[256];
if (connData->conn == NULL) {
//Connection aborted. Clean up.
return HTTPD_CGI_DONE;
}
// auto-turn on STA
if ((wificonf->opmode & STATION_MODE) == 0) {
wificonf->opmode |= STATION_MODE;
@@ -265,6 +270,13 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData)
char buff[100];
struct ip_info info;
buff[0] = 0; // avoid unitialized read
if (connData->conn == NULL) {
//Connection aborted. Clean up.
return HTTPD_CGI_DONE;
}
httpdStartResponse(connData, 200);
httpdHeader(connData, "Content-Type", "application/json");
httpdEndHeaders(connData);
@@ -276,6 +288,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData)
}
STATION_STATUS st = wifi_station_get_connect_status();
dbg("CONN STATE = %d", st);
switch(st) {
case STATION_IDLE:
sprintf(buff, "{\"status\": \"idle\"}"); // unclear when this is used
@@ -301,9 +314,14 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData)
wifi_get_ip_info(STATION_IF, &info);
sprintf(buff, "{\"status\": \"success\", \"ip\": \""IPSTR"\"}", GOOD_IP2STR(info.ip.addr));
break;
default:
sprintf(buff, "{\"status\": \"working\", \"wtf\": \"state = %d\"}", st);
break;
}
tplSend(connData, buff, -1);
httpdSend(connData, buff, -1);
return HTTPD_CGI_DONE;
}
@@ -336,6 +354,9 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData)
return HTTPD_CGI_DONE;
}
bool sta_turned_on = false;
bool sta_ssid_pw_changed = false;
// ---- WiFi opmode ----
if (GET_ARG("opmode")) {
@@ -366,6 +387,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData)
if (enable) {
wificonf->opmode |= STATION_MODE;
sta_turned_on = true;
} else {
wificonf->opmode &= ~STATION_MODE;
}
@@ -463,6 +485,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData)
info("Setting station SSID to: \"%s\"", buff);
strncpy_safe(wificonf->sta_ssid, buff, SSID_LEN);
wifi_change_flags.sta = true;
sta_ssid_pw_changed = true;
}
}
@@ -474,12 +497,13 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData)
info("Setting station password to: \"%s\"", buff);
strncpy_safe(wificonf->sta_password, buff, PASSWORD_LEN);
wifi_change_flags.sta = true;
sta_ssid_pw_changed = true;
}
}
if (redir_url_buf[strlen(SET_REDIR_ERR)] == 0) {
// All was OK
info("Set WiFi params - success, applying in 1000 ms");
info("Set WiFi params - success, applying in 2000 ms");
// Settings are applied only if all was OK
//
@@ -492,9 +516,19 @@ httpd_cgi_state ICACHE_FLASH_ATTR cgiWiFiSetParams(HttpdConnData *connData)
// If user connects via the Station IF, they may not even notice the connection reset.
os_timer_disarm(&timer);
os_timer_setfn(&timer, applyWifiSettingsLaterCb, NULL);
os_timer_arm(&timer, 1000, false);
os_timer_arm(&timer, 2000, false);
if ((sta_ssid_pw_changed || sta_turned_on)
&& wificonf->opmode != SOFTAP_MODE
&& wificonf->sta_ssid[0] != 0) {
// User wants to connect
info("User wants to connect to SSID, redirecting to ConnStatus page.");
httpdRedirect(connData, "/cfg/wifi/connecting");
}
else {
httpdRedirect(connData, SET_REDIR_SUC);
}
} else {
warn("Some WiFi settings did not validate, asking for correction");
// Some errors, appended to the URL as ?err=
@@ -558,7 +592,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token,
// For display of our current SSID
connectStatus = wifi_station_get_connect_status();
x = wifi_get_opmode();
if (x == SOFTAP_MODE || connectStatus != STATION_GOT_IP) {
if (x == SOFTAP_MODE || connectStatus != STATION_GOT_IP || wificonf->opmode == SOFTAP_MODE) {
strcpy(buff, "");
}
else {
@@ -571,7 +605,7 @@ httpd_cgi_state ICACHE_FLASH_ATTR tplWlan(HttpdConnData *connData, char *token,
x = wifi_get_opmode();
connectStatus = wifi_station_get_connect_status();
if (x == SOFTAP_MODE || connectStatus != STATION_GOT_IP) {
if (x == SOFTAP_MODE || connectStatus != STATION_GOT_IP || wificonf->opmode == SOFTAP_MODE) {
strcpy(buff, "");
}
else {
+7 -1
View File
@@ -31,6 +31,12 @@ void terminal_restore_defaults(void)
* Apply settings after eg. restore from defaults
*/
void terminal_apply_settings(void)
{
terminal_apply_settings_noclear();
screen_init();
}
void terminal_apply_settings_noclear(void)
{
memcpy(&termconf_scratch, termconf, sizeof(TerminalConfigBundle));
if (W*H >= MAX_SCREEN_SIZE) {
@@ -39,9 +45,9 @@ void terminal_apply_settings(void)
terminal_restore_defaults();
persist_store();
memcpy(&termconf_scratch, termconf, sizeof(TerminalConfigBundle));
}
screen_init();
}
}
/**
* Highest permissible value of the color attribute
+1
View File
@@ -70,6 +70,7 @@ extern TerminalConfigBundle termconf_scratch;
void terminal_restore_defaults(void);
void terminal_apply_settings(void);
void terminal_apply_settings_noclear(void); // the same, but with no screen reset / init
/**
* Maximum screen size (determines size of the static data array)
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef USER_MAIN_H_H
#define USER_MAIN_H_H
#define FIRMWARE_VERSION "0.6.1+" GIT_HASH
#define FIRMWARE_VERSION "0.6.3+" GIT_HASH
#define TERMINAL_GITHUB_REPO "https://github.com/MightyPork/esp-vt100-firmware"
#endif //USER_MAIN_H_H