This may bring us back to the original submission, if my subversion tricks are right.

pull/206/merge^2
dannybackx 8 years ago
parent a33dc84c05
commit fcced95547
  1. 2
      cmd/cmd.h
  2. 29
      cmd/handlers.c
  3. 97
      esp-link/cgiwifi.c
  4. 2
      esp-link/cgiwifi.h
  5. 4
      esp-link/config.c
  6. 19
      html/ui.js
  7. 64
      html/wifi/wifiSta.html
  8. 62
      html/wifi/wifiSta.js

@ -58,8 +58,6 @@ typedef enum {
CMD_SOCKET_SETUP = 40, // set-up callbacks
CMD_SOCKET_SEND, // send data over UDP socket
CMD_GET_WIFI_INFO = 50,// Query IP address info
} CmdName;
typedef void (*cmdfunc_t)(CmdPacket *cmd);

@ -17,7 +17,6 @@
#ifdef SOCKET
#include <socket.h>
#endif
#include <ip_addr.h>
#ifdef CMD_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
@ -30,7 +29,6 @@ static void cmdSync(CmdPacket *cmd);
static void cmdWifiStatus(CmdPacket *cmd);
static void cmdGetTime(CmdPacket *cmd);
static void cmdAddCallback(CmdPacket *cmd);
static void cmdGetWifiInfo(CmdPacket *cmd);
// keep track of last status sent to uC so we can notify it when it changes
static uint8_t lastWifiStatus = wifiIsDisconnected;
@ -46,7 +44,6 @@ const CmdList commands[] = {
{CMD_WIFI_STATUS, "WIFI_STATUS", cmdWifiStatus},
{CMD_CB_ADD, "ADD_CB", cmdAddCallback},
{CMD_GET_TIME, "GET_TIME", cmdGetTime},
{CMD_GET_WIFI_INFO, "GET_WIFI_INFO", cmdGetWifiInfo},
#ifdef MQTT
{CMD_MQTT_SETUP, "MQTT_SETUP", MQTTCMD_Setup},
{CMD_MQTT_PUBLISH, "MQTT_PUB", MQTTCMD_Publish},
@ -181,32 +178,6 @@ cmdGetTime(CmdPacket *cmd) {
return;
}
// Command handler for IP information
static void ICACHE_FLASH_ATTR
cmdGetWifiInfo(CmdPacket *cmd) {
CmdRequest req;
cmdRequest(&req, cmd);
if(cmd->argc != 0 || cmd->value == 0) {
cmdResponseStart(CMD_RESP_V, 0, 0);
cmdResponseEnd();
return;
}
uint32_t callback = req.cmd->value;
struct ip_info info;
wifi_get_ip_info(0, &info);
cmdResponseStart(CMD_RESP_CB, callback, 3);
cmdResponseBody(&info.ip.addr, sizeof(info.ip.addr));
cmdResponseBody(&info.netmask.addr, sizeof(info.netmask.addr));
cmdResponseBody(&info.gw.addr, sizeof(info.gw.addr));
cmdResponseEnd();
return;
}
// Command handler to add a callback to the named-callbacks list, this is for a callback to the uC
static void ICACHE_FLASH_ATTR
cmdAddCallback(CmdPacket *cmd) {

@ -34,7 +34,7 @@ bool mdns_started = false;
// ===== wifi status change callbacks
static WifiStateChangeCb wifi_state_change_cb[4];
// Temp store for new station config
// Temp store for new staion config
struct station_config stconf;
// Temp store for new ap config
@ -54,8 +54,6 @@ static char *wifiReasons[] = {
static char *wifiMode[] = { 0, "STA", "AP", "AP+STA" };
static char *wifiPhy[] = { 0, "11b", "11g", "11n" };
static char *portMode[] = { "unsecure", "disabled", "secure" };
void (*wifiStatusCb)(uint8_t); // callback when wifi status changes
static char* ICACHE_FLASH_ATTR wifiGetReason(void) {
@ -826,99 +824,6 @@ int ICACHE_FLASH_ATTR cgiWifiInfo(HttpdConnData *connData) {
return HTTPD_CGI_DONE;
}
static char *portMode2string(int8_t m) {
if (m < 0 || m > 2) return "?";
return portMode[m];
}
// print various Wifi information into json buffer
int ICACHE_FLASH_ATTR printWiFiSecurity(char *buff) {
int len;
len = os_sprintf(buff,
"\"port1mode\" : \"%s\", \"port1portnumber\" : \"%d\", \"port1pwd\" : \"%s\", "
"\"port2mode\" : \"%s\", \"port2portnumber\" : \"%d\", \"port2pwd\" : \"%s\" ",
portMode2string(flashConfig.port1_mode), flashConfig.port1_portnumber, "",
portMode2string(flashConfig.port2_mode), flashConfig.port2_portnumber, ""
);
return len;
}
// Cgi to return various Wifi information
int ICACHE_FLASH_ATTR jsonWiFiSecurity(HttpdConnData *connData) {
char buff[1024];
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
os_strcpy(buff, "{");
printWiFiSecurity(buff+1);
os_strcat(buff, "}");
jsonHeader(connData, 200);
httpdSend(connData, buff, -1);
return HTTPD_CGI_DONE;
}
// Change security settings
int ICACHE_FLASH_ATTR cgiWiFiSecurity(HttpdConnData *connData) {
char dhcp[8];
char staticip[20];
char netmask[20];
char gateway[20];
if (connData->conn==NULL) return HTTPD_CGI_DONE;
// get args and their string lengths
int dl = httpdFindArg(connData->getArgs, "dhcp", dhcp, sizeof(dhcp));
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 && sl >= 0 && nl >= 0 && gl >= 0)) {
jsonHeader(connData, 400);
httpdSend(connData, "Request is missing fields", -1);
return HTTPD_CGI_DONE;
}
char url[64]; // redirect URL
if (os_strcmp(dhcp, "off") == 0) {
// parse static IP params
struct ip_info ipi;
bool ok = parse_ip(staticip, &ipi.ip);
if (nl > 0) ok = ok && parse_ip(netmask, &ipi.netmask);
else IP4_ADDR(&ipi.netmask, 255, 255, 255, 0);
if (gl > 0) ok = ok && parse_ip(gateway, &ipi.gw);
else ipi.gw.addr = 0;
if (!ok) {
jsonHeader(connData, 400);
httpdSend(connData, "Cannot parse static IP config", -1);
return HTTPD_CGI_DONE;
}
// save the params in flash
flashConfig.staticip = ipi.ip.addr;
flashConfig.netmask = ipi.netmask.addr;
flashConfig.gateway = ipi.gw.addr;
// construct redirect URL
os_sprintf(url, "{\"url\": \"http://%d.%d.%d.%d\"}", IP2STR(&ipi.ip));
} else {
// dynamic IP
flashConfig.staticip = 0;
os_sprintf(url, "{\"url\": \"http://%s\"}", flashConfig.hostname);
}
configSave(); // ignore error...
// schedule 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
// return redirect info
jsonHeader(connData, 200);
httpdSend(connData, url, -1);
return HTTPD_CGI_DONE;
}
// Check string againt invalid characters
int ICACHE_FLASH_ATTR checkString(char *str){
for(int i=0; i<os_strlen(str); i++) {

@ -13,8 +13,6 @@ int cgiWiFiConnect(HttpdConnData *connData);
int cgiWiFiSetMode(HttpdConnData *connData);
int cgiWiFiConnStatus(HttpdConnData *connData);
int cgiWiFiSpecial(HttpdConnData *connData);
int cgiWiFiSecurity(HttpdConnData *connData);
int jsonWiFiSecurity(HttpdConnData *connData);
int cgiApSettingsChange(HttpdConnData *connData);
int cgiApSettingsInfo(HttpdConnData *connData);
void configWifiIP();

@ -35,10 +35,6 @@ FlashConfig flashDefault = {
.data_bits = EIGHT_BITS,
.parity = NONE_BITS,
.stop_bits = ONE_STOP_BIT,
.port1_mode = PORT1_MODE,
.port2_mode = PORT2_MODE,
.port1_portnumber = PORT1_PORTNUMBER,
.port2_portnumber = PORT2_PORTNUMBER,
};
typedef union {

@ -302,25 +302,6 @@ function getWifiInfo() {
function(s, st) { window.setTimeout(getWifiInfo, 1000); });
}
function showWifiSecurity(data) {
Object.keys(data).forEach(function(v) {
el = $("#secure-" + v);
if (el != null) {
if (el.nodeName === "INPUT") el.value = data[v];
else el.innerHTML = data[v];
}
});
var p1 = $('#secure-port1-r'+data.port1mode);
if (p1) p1.click();
var p2 = $('#secure-port2-r'+data.port1mode);
if (p2) p2.click();
}
function getSecurityInfo() {
ajaxJson('GET', "/wifi/security", showWifiSecurity,
function(s, st) { window.setTimeout(getSecurityInfo, 1000); });
}
//===== System info
function showSystemInfo(data) {

@ -65,60 +65,7 @@
<button id="special-button" type="submit" class="pure-button button-primary">Change!</button>
</form>
</div></div>
<div class="pure-u-1 pure-u-md-1-2"><div class="card">
<h1>Security Settings</h1>
<form action="#" id="securform" class="pure-form">
<legend>Disable or protect station access</legend>
<div class="form-horizontal">
Port 1
<label for="port1-ron" style="margin-right:1em">
<input type="radio" name="port1" value="on" id="secure-port1-ron"/>
Unsecure</label>
<label for="port1-roff" style="margin-right:1em">
<input type="radio" name="port1" value="off" id="secure-port1-roff"/>
Disabled</label>
<label for="port1-rpwd">
<input type="radio" name="port1" value="pwd" id="secure-port1-rpwd"/>
Secure</label>
</div>
<div id="port1-off" class="pure-form-stacked"></div>
<div id="port1-pn" class="pure-form-stacked">
<label>TCP port number</label>
<input id="secure-port1portnumber" type="text" name="port1number"/>
</div>
<div id="port1-pwd" class="pure-form-stacked">
<label>Password</label>
<input id="secure-port1password" type="password" name="port1password"/>
</div>
<div class="form-horizontal">
Port 2
<label for="port2-ron" style="margin-right:1em">
<input type="radio" name="port2" value="on" id="secure-port2-ron"/>
Unsecure</label>
<label for="port2-roff" style="margin-right:1em">
<input type="radio" name="port2" value="off" id="secure-port2-roff"/>
Disabled</label>
<label for="port2-rpwd">
<input type="radio" name="port2" value="pwd" id="secure-port2-rpwd"/>
Secured</label>
</div>
<div id="port2-off" class="pure-form-stacked"></div>
<div id="port2-pn" class="pure-form-stacked">
<label>TCP port number</label>
<input id="secure-port2portnumber" type="text" name="port2number"/>
</div>
<div id="port2-pwd" class="pure-form-stacked">
<label>Password</label>
<input id="secure-port2password" type="password" name="port2password"/>
</div>
<button id="secure-button" type="submit" class="pure-button button-primary">Change!</button>
</form>
</div></div>
</div>
</div>
</div>
</div>
@ -131,17 +78,6 @@ onLoad(function() {
getWifiInfo();
bnd($("#wifiform"), "submit", changeWifiAp);
bnd($("#specform"), "submit", changeSpecial);
getSecurityInfo();
bnd($("#securform"), "submit", changeSecurity);
bnd($("#secure-port1-roff"), "click", doPort1Off);
bnd($("#secure-port1-ron"), "click", doPort1Unsecure);
bnd($("#secure-port1-rpwd"), "click", doPort1Secure);
bnd($("#secure-port2-roff"), "click", doPort2Off);
bnd($("#secure-port2-ron"), "click", doPort2Unsecure);
bnd($("#secure-port2-rpwd"), "click", doPort2Secure);
bnd($("#dhcp-ron"), "click", doDhcp);
bnd($("#dhcp-roff"), "click", doStatic);
scanTimeout = window.setTimeout(scanAPs, 500);

@ -192,68 +192,6 @@ function changeSpecial(e) {
});
}
function changeSecurity(e) {
e.preventDefault();
var url = "security";
url += "?port1=" + document.querySelector('input[name="port1"]:checked').value;
url += "&portnumber=" + encodeURIComponent($("#port1-portnumber").value);
url += "&password=" + encodeURIComponent($("#port1-password").value);
url += "?port2=" + document.querySelector('input[name="port2"]:checked').value;
url += "&portnumber=" + encodeURIComponent($("#port2-portnumber").value);
url += "&password=" + encodeURIComponent($("#port2-password").value);
hideWarning();
var cb = $("#secure-button");
addClass(cb, 'pure-button-disabled');
ajaxSpin("POST", url, function(resp) {
removeClass(cb, 'pure-button-disabled');
getSecurityInfo();
//getWifiInfo(); // it takes 1 second for new settings to be applied
}, function(s, st) {
showWarning("Error: "+st);
removeClass(cb, 'pure-button-disabled');
getSecurityInfo();
});
}
function doPort1Secure() {
$('#port1-off').setAttribute('hidden', '');
$('#port1-pn').removeAttribute('hidden');
$('#port1-pwd').removeAttribute('hidden');
}
function doPort1Off() {
$('#port1-off').removeAttribute('hidden');
$('#port1-pn').setAttribute('hidden', '');
$('#port1-pwd').setAttribute('hidden', '');
}
function doPort1Unsecure() {
$('#port1-off').setAttribute('hidden', '');
$('#port1-pn').removeAttribute('hidden');
$('#port1-pwd').setAttribute('hidden', '');
}
function doPort2Secure() {
$('#port2-off').setAttribute('hidden', '');
$('#port2-pn').removeAttribute('hidden');
$('#port2-pwd').removeAttribute('hidden');
}
function doPort2Off() {
$('#port2-off').removeAttribute('hidden');
$('#port2-pn').setAttribute('hidden', '');
$('#port2-pwd').setAttribute('hidden', '');
}
function doPort2Unsecure() {
$('#port2-off').setAttribute('hidden', '');
$('#port2-pn').removeAttribute('hidden');
$('#port2-pwd').setAttribute('hidden', '');
}
function doDhcp() {
$('#dhcp-on').removeAttribute('hidden');
$('#dhcp-off').setAttribute('hidden', '');

Loading…
Cancel
Save