Skip to content

Commit

Permalink
fix dhcp/static ip switch-over
Browse files Browse the repository at this point in the history
  • Loading branch information
tve committed Nov 19, 2015
1 parent df8afa8 commit 72118a7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
10 changes: 3 additions & 7 deletions esp-link/cgiwifi.c
Expand Up @@ -428,7 +428,6 @@ void ICACHE_FLASH_ATTR configWifiIP() {
// Change special settings
int ICACHE_FLASH_ATTR cgiWiFiSpecial(HttpdConnData *connData) {
char dhcp[8];
char hostname[32];
char staticip[20];
char netmask[20];
char gateway[20];
Expand All @@ -437,12 +436,11 @@ int ICACHE_FLASH_ATTR cgiWiFiSpecial(HttpdConnData *connData) {

// get args and their string lengths
int dl = httpdFindArg(connData->getArgs, "dhcp", dhcp, sizeof(dhcp));
int hl = httpdFindArg(connData->getArgs, "hostname", hostname, sizeof(hostname));
int sl = httpdFindArg(connData->getArgs, "staticip", staticip, sizeof(staticip));
int nl = httpdFindArg(connData->getArgs, "netmask", netmask, sizeof(netmask));
int gl = httpdFindArg(connData->getArgs, "gateway", gateway, sizeof(gateway));

if (!(dl > 0 && hl >= 0 && sl >= 0 && nl >= 0 && gl >= 0)) {
if (!(dl > 0 && sl >= 0 && nl >= 0 && gl >= 0)) {
jsonHeader(connData, 400);
httpdSend(connData, "Request is missing fields", -1);
return HTTPD_CGI_DONE;
Expand Down Expand Up @@ -470,11 +468,9 @@ int ICACHE_FLASH_ATTR cgiWiFiSpecial(HttpdConnData *connData) {
os_sprintf(url, "{\"url\": \"http://%d.%d.%d.%d\"}", IP2STR(&ipi.ip));

} else {
// no static IP, set hostname
if (hl == 0) os_strcpy(hostname, "esp-link");
// dynamic IP
flashConfig.staticip = 0;
os_strcpy(flashConfig.hostname, hostname);
os_sprintf(url, "{\"url\": \"http://%s\"}", hostname);
os_sprintf(url, "{\"url\": \"http://%s\"}", flashConfig.hostname);
}

configSave(); // ignore error...
Expand Down
1 change: 0 additions & 1 deletion html/wifi/wifi.js
Expand Up @@ -175,7 +175,6 @@ function changeSpecial(e) {
e.preventDefault();
var url = "special";
url += "?dhcp=" + document.querySelector('input[name="dhcp"]:checked').value;
url += "&hostname=" + encodeURIComponent($("#wifi-hostname").value);
url += "&staticip=" + encodeURIComponent($("#wifi-staticip").value);
url += "&netmask=" + encodeURIComponent($("#wifi-netmask").value);
url += "&gateway=" + encodeURIComponent($("#wifi-gateway").value);
Expand Down

0 comments on commit 72118a7

Please sign in to comment.