Skip to content

Commit

Permalink
fix pin changes and hostname change
Browse files Browse the repository at this point in the history
  • Loading branch information
tve committed Nov 16, 2015
1 parent 5bb5173 commit ce05e00
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion esp-link/cgiwifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions esp-link/cgiwifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion esp-link/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 12 additions & 4 deletions esp-link/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions html/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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;
Expand Down Expand Up @@ -464,14 +465,16 @@ function fetchPins() {
});
}

function setPins(v, name) {
function setPins(ev) {
ev.preventDefault();
var url = "/pins";
var sep = "?";
["reset", "isp", "conn", "ser", "swap"].forEach(function(p) {
url += sep + p + "=" + $("#pin-"+p).value;
sep = "&";
});
url += "&rxpup=" + ($("#pin-rxpup").selected ? "1" : "0");
console.log("set pins: " + url);
ajaxSpin("POST", url, function() {
showNotification("Pin assignment changed");
}, function(status, errMsg) {
Expand Down

0 comments on commit ce05e00

Please sign in to comment.