From ce05e00bd7cad47b47ef120a8fcff0db385fa3d9 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Sun, 15 Nov 2015 22:08:32 -0800 Subject: [PATCH] fix pin changes and hostname change --- esp-link/cgiwifi.c | 2 +- esp-link/cgiwifi.h | 1 + esp-link/log.c | 2 +- esp-link/main.c | 16 ++++++++++++---- html/ui.js | 7 +++++-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/esp-link/cgiwifi.c b/esp-link/cgiwifi.c index e379b12..a56eee2 100644 --- a/esp-link/cgiwifi.c +++ b/esp-link/cgiwifi.c @@ -403,7 +403,7 @@ static void ICACHE_FLASH_ATTR debugIP() { #endif // configure Wifi, specifically DHCP vs static IP address based on flash config -static void ICACHE_FLASH_ATTR configWifiIP() { +void ICACHE_FLASH_ATTR configWifiIP() { if (flashConfig.staticip == 0) { // let's DHCP! wifi_station_set_hostname(flashConfig.hostname); diff --git a/esp-link/cgiwifi.h b/esp-link/cgiwifi.h index a2782a5..37a02d6 100644 --- a/esp-link/cgiwifi.h +++ b/esp-link/cgiwifi.h @@ -13,6 +13,7 @@ int cgiWiFiConnect(HttpdConnData *connData); int cgiWiFiSetMode(HttpdConnData *connData); int cgiWiFiConnStatus(HttpdConnData *connData); int cgiWiFiSpecial(HttpdConnData *connData); +void configWifiIP(); void wifiInit(void); void wifiAddStateChangeCb(WifiStateChangeCb cb); diff --git a/esp-link/log.c b/esp-link/log.c index d7035c0..d6c245b 100644 --- a/esp-link/log.c +++ b/esp-link/log.c @@ -128,7 +128,7 @@ ajaxLog(HttpdConnData *connData) { return HTTPD_CGI_DONE; } -static char *dbg_mode[] = { "auto", "off", "on u0", "on u1" }; +static char *dbg_mode[] = { "auto", "off", "on0", "on1" }; int ICACHE_FLASH_ATTR ajaxLogDbg(HttpdConnData *connData) { diff --git a/esp-link/main.c b/esp-link/main.c index 46cc080..3719d9c 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -129,14 +129,22 @@ static int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData) { return HTTPD_CGI_DONE; } +static ETSTimer reassTimer; + // Cgi to update system info (name/description) static int ICACHE_FLASH_ATTR cgiSystemSet(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. - int8_t status = 0; - status |= getStringArg(connData, "name", flashConfig.hostname, sizeof(flashConfig.hostname)); - status |= getStringArg(connData, "description", flashConfig.sys_descr, sizeof(flashConfig.sys_descr)); - if (status < 0) return HTTPD_CGI_DONE; // getStringArg has produced an error response + int8_t n = getStringArg(connData, "name", flashConfig.hostname, sizeof(flashConfig.hostname)); + int8_t d = getStringArg(connData, "description", flashConfig.sys_descr, sizeof(flashConfig.sys_descr)); + if (n < 0 || d < 0) return HTTPD_CGI_DONE; // getStringArg has produced an error response + + if (n > 0) { + // schedule hostname change-over + os_timer_disarm(&reassTimer); + os_timer_setfn(&reassTimer, configWifiIP, NULL); + os_timer_arm(&reassTimer, 1000, 0); // 1 second for the response of this request to make it + } if (configSave()) { httpdStartResponse(connData, 204); diff --git a/html/ui.js b/html/ui.js index a9bef1d..cbf3615 100644 --- a/html/ui.js +++ b/html/ui.js @@ -418,10 +418,10 @@ function createPresets(sel) { setPP("ser", pp[3]); setPP("swap", pp[4]); $("#pin-rxpup").checked = !!pp[5]; + sel.value = 0; }; bnd(sel, "change", function(ev) { - console.log("preset change:", sel.value); ev.preventDefault(); applyPreset(sel.value); }); @@ -431,6 +431,7 @@ function displayPins(resp) { function createSelectForPin(name, v) { var sel = $("#pin-"+name); addClass(sel, "pure-button"); + sel.innerHTML = ""; [-1,0,1,2,3,4,5,12,13,14,15].forEach(function(i) { var opt = document.createElement("option"); opt.value = i; @@ -464,7 +465,8 @@ function fetchPins() { }); } -function setPins(v, name) { +function setPins(ev) { + ev.preventDefault(); var url = "/pins"; var sep = "?"; ["reset", "isp", "conn", "ser", "swap"].forEach(function(p) { @@ -472,6 +474,7 @@ function setPins(v, name) { sep = "&"; }); url += "&rxpup=" + ($("#pin-rxpup").selected ? "1" : "0"); + console.log("set pins: " + url); ajaxSpin("POST", url, function() { showNotification("Pin assignment changed"); }, function(status, errMsg) {