fix pin changes and hostname change

v2.1
Thorsten von Eicken 9 years ago
parent 5bb517353a
commit ce05e00bd7
  1. 2
      esp-link/cgiwifi.c
  2. 1
      esp-link/cgiwifi.h
  3. 2
      esp-link/log.c
  4. 16
      esp-link/main.c
  5. 7
      html/ui.js

@ -403,7 +403,7 @@ static void ICACHE_FLASH_ATTR debugIP() {
#endif #endif
// configure Wifi, specifically DHCP vs static IP address based on flash config // 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) { if (flashConfig.staticip == 0) {
// let's DHCP! // let's DHCP!
wifi_station_set_hostname(flashConfig.hostname); wifi_station_set_hostname(flashConfig.hostname);

@ -13,6 +13,7 @@ int cgiWiFiConnect(HttpdConnData *connData);
int cgiWiFiSetMode(HttpdConnData *connData); int cgiWiFiSetMode(HttpdConnData *connData);
int cgiWiFiConnStatus(HttpdConnData *connData); int cgiWiFiConnStatus(HttpdConnData *connData);
int cgiWiFiSpecial(HttpdConnData *connData); int cgiWiFiSpecial(HttpdConnData *connData);
void configWifiIP();
void wifiInit(void); void wifiInit(void);
void wifiAddStateChangeCb(WifiStateChangeCb cb); void wifiAddStateChangeCb(WifiStateChangeCb cb);

@ -128,7 +128,7 @@ ajaxLog(HttpdConnData *connData) {
return HTTPD_CGI_DONE; 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 int ICACHE_FLASH_ATTR
ajaxLogDbg(HttpdConnData *connData) { ajaxLogDbg(HttpdConnData *connData) {

@ -129,14 +129,22 @@ static int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData) {
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;
} }
static ETSTimer reassTimer;
// Cgi to update system info (name/description) // Cgi to update system info (name/description)
static int ICACHE_FLASH_ATTR cgiSystemSet(HttpdConnData *connData) { static int ICACHE_FLASH_ATTR cgiSystemSet(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
int8_t status = 0; int8_t n = getStringArg(connData, "name", flashConfig.hostname, sizeof(flashConfig.hostname));
status |= getStringArg(connData, "name", flashConfig.hostname, sizeof(flashConfig.hostname)); int8_t d = getStringArg(connData, "description", flashConfig.sys_descr, sizeof(flashConfig.sys_descr));
status |= 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 (status < 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()) { if (configSave()) {
httpdStartResponse(connData, 204); httpdStartResponse(connData, 204);

@ -418,10 +418,10 @@ function createPresets(sel) {
setPP("ser", pp[3]); setPP("ser", pp[3]);
setPP("swap", pp[4]); setPP("swap", pp[4]);
$("#pin-rxpup").checked = !!pp[5]; $("#pin-rxpup").checked = !!pp[5];
sel.value = 0;
}; };
bnd(sel, "change", function(ev) { bnd(sel, "change", function(ev) {
console.log("preset change:", sel.value);
ev.preventDefault(); ev.preventDefault();
applyPreset(sel.value); applyPreset(sel.value);
}); });
@ -431,6 +431,7 @@ function displayPins(resp) {
function createSelectForPin(name, v) { function createSelectForPin(name, v) {
var sel = $("#pin-"+name); var sel = $("#pin-"+name);
addClass(sel, "pure-button"); addClass(sel, "pure-button");
sel.innerHTML = "";
[-1,0,1,2,3,4,5,12,13,14,15].forEach(function(i) { [-1,0,1,2,3,4,5,12,13,14,15].forEach(function(i) {
var opt = document.createElement("option"); var opt = document.createElement("option");
opt.value = i; opt.value = i;
@ -464,7 +465,8 @@ function fetchPins() {
}); });
} }
function setPins(v, name) { function setPins(ev) {
ev.preventDefault();
var url = "/pins"; var url = "/pins";
var sep = "?"; var sep = "?";
["reset", "isp", "conn", "ser", "swap"].forEach(function(p) { ["reset", "isp", "conn", "ser", "swap"].forEach(function(p) {
@ -472,6 +474,7 @@ function setPins(v, name) {
sep = "&"; sep = "&";
}); });
url += "&rxpup=" + ($("#pin-rxpup").selected ? "1" : "0"); url += "&rxpup=" + ($("#pin-rxpup").selected ? "1" : "0");
console.log("set pins: " + url);
ajaxSpin("POST", url, function() { ajaxSpin("POST", url, function() {
showNotification("Pin assignment changed"); showNotification("Pin assignment changed");
}, function(status, errMsg) { }, function(status, errMsg) {

Loading…
Cancel
Save