add wifi settings tab in web frontend
This commit is contained in:
parent
8209a9a936
commit
6a7babcaf7
3 changed files with 238 additions and 64 deletions
|
@ -204,6 +204,18 @@ void websocket_task(void *pvParameter) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vTaskDelayMs(250);
|
||||||
|
{
|
||||||
|
uint8_t response[3];
|
||||||
|
uint16_t val;
|
||||||
|
val = sdk_system_adc_read();
|
||||||
|
response[2] = (uint8_t) val;
|
||||||
|
response[1] = val >> 8;
|
||||||
|
response[0] = 'V';
|
||||||
|
LOCK_TCPIP_CORE();
|
||||||
|
websocket_write(pcb, response, 3, WS_BIN_MODE);
|
||||||
|
UNLOCK_TCPIP_CORE();
|
||||||
|
}
|
||||||
vTaskDelayMs(500);
|
vTaskDelayMs(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,33 +259,35 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
|
||||||
|
|
||||||
bool togl = false;
|
bool togl = false;
|
||||||
|
|
||||||
switch (data[0]) {
|
if(data[0] == 'V') {
|
||||||
case 'R': // Restart
|
/* This should be done on a separate thread in 'real' applications */
|
||||||
|
val = sdk_system_adc_read();
|
||||||
|
cmd = 'V';
|
||||||
|
} else if(data[0] == 'R') {
|
||||||
|
// Restart
|
||||||
cmd = 'R';
|
cmd = 'R';
|
||||||
ret = OK;
|
ret = OK;
|
||||||
break;
|
} else if(data[0] == 'X') {
|
||||||
case 'X': // Clear Config
|
// Clear Config
|
||||||
cmd = 'X';
|
cmd = 'X';
|
||||||
ret = OK;
|
ret = OK;
|
||||||
break;
|
} else if(data[0] == 'D') {
|
||||||
case 'D': // Disable LED
|
// Disable LED
|
||||||
syslog("G\n");
|
syslog("G\n");
|
||||||
signal_led(false);
|
signal_led(false);
|
||||||
cmd = 'G';
|
cmd = 'G';
|
||||||
ret = OK;
|
ret = OK;
|
||||||
val = 1;
|
val = 1;
|
||||||
break;
|
} else if(data[0] == 'E') {
|
||||||
case 'E': // Enable LED
|
// Enable LED
|
||||||
syslog("E\n");
|
syslog("E\n");
|
||||||
signal_led(true);
|
signal_led(true);
|
||||||
cmd = 'G';
|
cmd = 'G';
|
||||||
ret = OK;
|
ret = OK;
|
||||||
val = 0;
|
val = 0;
|
||||||
break;
|
} else if(data[0] == 'F') {
|
||||||
case 'F':
|
|
||||||
togl = !togl;
|
togl = !togl;
|
||||||
signal_led(togl);
|
signal_led(togl);
|
||||||
{
|
|
||||||
auto *f = (fw_frame *) data;
|
auto *f = (fw_frame *) data;
|
||||||
if(f->seq == 0) {
|
if(f->seq == 0) {
|
||||||
system_otaflash_init();
|
system_otaflash_init();
|
||||||
|
@ -281,22 +295,56 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
|
||||||
uint16_t ack = 0;
|
uint16_t ack = 0;
|
||||||
ret = system_otaflash_chunk(f->data, ntohs(f->len), ntohs(f->seq), ntohl(f->hash), &ack);
|
ret = system_otaflash_chunk(f->data, ntohs(f->len), ntohs(f->seq), ntohl(f->hash), &ack);
|
||||||
val = htons(ack);
|
val = htons(ack);
|
||||||
}
|
|
||||||
cmd = 'F';
|
cmd = 'F';
|
||||||
break;
|
} else if(data[0] == 'C') {
|
||||||
case 'C':
|
|
||||||
signal_led(false);
|
signal_led(false);
|
||||||
{
|
|
||||||
auto *f = (fw_check *) data;
|
auto *f = (fw_check *) data;
|
||||||
ret = system_otaflash_verify_and_switch(ntohl(f->len), ntohl(f->hash));
|
ret = system_otaflash_verify_and_switch(ntohl(f->len), ntohl(f->hash));
|
||||||
}
|
|
||||||
cmd = 'C';
|
cmd = 'C';
|
||||||
break;
|
} else if(data[0] == 'S') {
|
||||||
default:
|
int8_t en = 0;
|
||||||
|
if(data[1] == 'E')
|
||||||
|
en = 1;
|
||||||
|
char *ssid = &data[2];
|
||||||
|
size_t ssid_len = strlen(ssid);
|
||||||
|
char *password = &data[3 + ssid_len];
|
||||||
|
size_t password_len = strlen(password);
|
||||||
|
(void) password_len;
|
||||||
|
|
||||||
|
sysparam_set_int8("wifi_sta_enable", en);
|
||||||
|
sysparam_set_string("wifi_sta_ssid", ssid);
|
||||||
|
sysparam_set_string("wifi_sta_password", password);
|
||||||
|
|
||||||
|
//sysparam_get_int8("wifi_sta_dhcp", wifi_sta_dhcp);
|
||||||
|
//sysparam_get_int32("wifi_sta_ip_addr", wifi_sta_ip_addr);
|
||||||
|
//sysparam_get_int32("wifi_sta_netmask", wifi_sta_netmask);
|
||||||
|
//sysparam_get_int32("wifi_sta_gateway", wifi_sta_gateway);
|
||||||
|
cmd = 'S';
|
||||||
|
} else if(data[0] == 'A') {
|
||||||
|
int8_t en = 0;
|
||||||
|
uint8_t dns_enable = 0;
|
||||||
|
uint8_t mdns_enable = 0;
|
||||||
|
if(data[1] == 'E')
|
||||||
|
en = 1;
|
||||||
|
char *ssid = &data[2];
|
||||||
|
size_t ssid_len = strlen(ssid);
|
||||||
|
char *password = &data[3 + ssid_len];
|
||||||
|
size_t password_len = strlen(password);
|
||||||
|
(void) password_len;
|
||||||
|
|
||||||
|
sysparam_set_int8("wifi_ap_enable", en);
|
||||||
|
sysparam_set_string("wifi_ap_ssid", ssid);
|
||||||
|
sysparam_set_string("wifi_ap_password", password);
|
||||||
|
|
||||||
|
//sysparam_get_int32("wifi_ap_ip_addr", "172.16.0.1");
|
||||||
|
//sysparam_get_int32("wifi_ap_netmask", "255.255.0.0");
|
||||||
|
//sysparam_set_int8("wifi_ap_dns", dns_enable);
|
||||||
|
//sysparam_set_int8("wifi_ap_mdns", mdns_enable);
|
||||||
|
cmd = 'A';
|
||||||
|
} else {
|
||||||
printf("[websocket_callback]:\n%.*s\n", (int) data_len, (char *) data);
|
printf("[websocket_callback]:\n%.*s\n", (int) data_len, (char *) data);
|
||||||
printf("Unknown command %c\n", data[0]);
|
printf("Unknown command %c\n", data[0]);
|
||||||
ret = ERROR;
|
ret = ERROR;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCK_TCPIP_CORE();
|
LOCK_TCPIP_CORE();
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
<label for="bmenub" class="burger pseudo button">☰</label>
|
<label for="bmenub" class="burger pseudo button">☰</label>
|
||||||
<div class="menu">
|
<div class="menu">
|
||||||
<a href="/#" class="button icon-picture">Dashboard</a>
|
<a href="/#" class="button icon-picture">Dashboard</a>
|
||||||
|
<a href="/#wifi" class="button icon-puzzle">Wifi Settings</a>
|
||||||
<a href="/#ota" class="button icon-picture">System</a>
|
<a href="/#ota" class="button icon-picture">System</a>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
@ -75,6 +76,87 @@
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
<section id="wifi">
|
||||||
|
<h2>Wifi Settings</h2>
|
||||||
|
<article class="card">
|
||||||
|
<header>
|
||||||
|
<h3>AP Mode</h3>
|
||||||
|
</header>
|
||||||
|
<div class="table">
|
||||||
|
<div class="row">
|
||||||
|
<label>Enable</label>
|
||||||
|
<span><input id="ap_toggle" type="checkbox" class="plain"/></span>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<label>SSID</label>
|
||||||
|
<span><input id="ap_ssid" type="text" placeholder="SSID"/></span>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<label>Password</label>
|
||||||
|
<span><input id="ap_pw" type="password" placeholder="Password"/></span>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<span>AP IP</span>
|
||||||
|
<span><span class="postfill_apip">N/A</span></span>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<span>AP MAC</span>
|
||||||
|
<span><span class="postfill_apmac">N/A</span></span>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<span><input type="reset" class="button"/></span>
|
||||||
|
<span><input onclick="ap_update();" type="submit" value="Save"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
<article class="card">
|
||||||
|
<header>
|
||||||
|
<h3>Station Mode <span class="label success">current connection</span></h3>
|
||||||
|
</header>
|
||||||
|
<div class="table">
|
||||||
|
<div class="row">
|
||||||
|
<label>Eanable</label>
|
||||||
|
<span><input id="sta_toggle" type="checkbox" class="plain"/></span>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<label>SSID</label>
|
||||||
|
<span><input id="sta_ssid" type="text" placeholder="SSID"/></span>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<label>Password</label>
|
||||||
|
<span><input id="sta_pw" type="password" placeholder="Password"/></span>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<label>Use DHCP</label>
|
||||||
|
<span><input id="sta_shcp" type="checkbox" class="plain"/></span>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<label>Static IP</label>
|
||||||
|
<span><input id="sta_static_ip" type="text" placeholder="192.168.1.2"/></span>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<label>Static Netmask</label>
|
||||||
|
<span><input id="sta_static_netmask" type="text" placeholder="255.255.255.0"/></span>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<label>Static Gateway</label>
|
||||||
|
<span><input id="sta_static_gateway" type="text" placeholder="192.168.1.1"/></span>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<span>Sation IP</span>
|
||||||
|
<span><span class="postfill_staip">N/A</span></span>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<span>Station MAC</span>
|
||||||
|
<span><span class="postfill_stamac">N/A</span></span>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<span><input type="reset" class="button"/></span>
|
||||||
|
<span><input onclick="sta_update();" type="submit" value="Save"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</section>
|
||||||
<section id="dashboard">
|
<section id="dashboard">
|
||||||
<h2>Status</h2>
|
<h2>Status</h2>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
|
@ -212,6 +294,18 @@
|
||||||
return pos;
|
return pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DataView.prototype.setInt8Vec = function (pos, vec) {
|
||||||
|
for (var i = 0; i < vec.length; i++) {
|
||||||
|
this.setInt8(pos++, vec[i]);
|
||||||
|
}
|
||||||
|
return pos;
|
||||||
|
};
|
||||||
|
|
||||||
|
function colorStringToVec(hex) {
|
||||||
|
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||||
|
return result ? [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)] : null;
|
||||||
|
}
|
||||||
|
|
||||||
var ws;
|
var ws;
|
||||||
var retries;
|
var retries;
|
||||||
var series = new TimeSeries();
|
var series = new TimeSeries();
|
||||||
|
@ -433,6 +527,48 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sta_toggle = document.getElementById("sta_toggle");
|
||||||
|
var sta_ssid = document.getElementById("sta_ssid");
|
||||||
|
var sta_pw = document.getElementById("sta_pw");
|
||||||
|
|
||||||
|
function sta_update() {
|
||||||
|
var en = sta_toggle.checked;
|
||||||
|
|
||||||
|
const ssid = sta_ssid.value;
|
||||||
|
const password = sta_pw.value;
|
||||||
|
|
||||||
|
const buffer = new ArrayBuffer(ssid.length + password.length + 4);
|
||||||
|
const view1 = new DataView(buffer);
|
||||||
|
var tx_len = 0;
|
||||||
|
view1.setChar(tx_len++, 'S');
|
||||||
|
view1.setChar(tx_len++, (en ? "E" : "D"));
|
||||||
|
tx_len = view1.setString(tx_len, ssid);
|
||||||
|
tx_len = view1.setString(tx_len, password);
|
||||||
|
wsWrite(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
var ap_toggle = document.getElementById("ap_toggle");
|
||||||
|
var ap_ssid = document.getElementById("ap_ssid");
|
||||||
|
var ap_pw = document.getElementById("ap_pw");
|
||||||
|
|
||||||
|
function ap_update() {
|
||||||
|
var en = ap_toggle.checked;
|
||||||
|
|
||||||
|
const ssid = ap_ssid.value;
|
||||||
|
const password = ap_pw.value;
|
||||||
|
|
||||||
|
const buffer = new ArrayBuffer(ssid.length + password.length + 4 + 8);
|
||||||
|
const view1 = new DataView(buffer);
|
||||||
|
var tx_len = 0;
|
||||||
|
view1.setChar(tx_len++, 'A');
|
||||||
|
view1.setChar(tx_len++, (en ? "E" : "D"));
|
||||||
|
tx_len = view1.setString(tx_len, ssid);
|
||||||
|
tx_len = view1.setString(tx_len, password);
|
||||||
|
tx_len = view1.setInt8Vec(tx_len, [192, 168, 111, 1]);
|
||||||
|
tx_len = view1.setInt8Vec(tx_len, [255, 255, 255, 0]);
|
||||||
|
wsWrite(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
function update_progress(progressBar, progress) {
|
function update_progress(progressBar, progress) {
|
||||||
var iP = Math.floor(progress);
|
var iP = Math.floor(progress);
|
||||||
var dBar = document.getElementById("progress_bar_" + progressBar);
|
var dBar = document.getElementById("progress_bar_" + progressBar);
|
||||||
|
|
|
@ -211,7 +211,7 @@ extern "C" void wifi_task(void *pvParameters) {
|
||||||
|
|
||||||
if(wifi_sta_enable) {
|
if(wifi_sta_enable) {
|
||||||
printf("try STA Mode: %s %s\n", wifi_sta_ssid, wifi_sta_password);
|
printf("try STA Mode: %s %s\n", wifi_sta_ssid, wifi_sta_password);
|
||||||
sdk_station_config config;
|
sdk_station_config config{};
|
||||||
strcpy((char *) config.ssid, wifi_sta_ssid);
|
strcpy((char *) config.ssid, wifi_sta_ssid);
|
||||||
strcpy((char *) config.password, wifi_sta_password);
|
strcpy((char *) config.password, wifi_sta_password);
|
||||||
config.bssid_set = 0;
|
config.bssid_set = 0;
|
||||||
|
@ -231,7 +231,7 @@ extern "C" void wifi_task(void *pvParameters) {
|
||||||
wifi_sta_netmask && strlen(wifi_sta_netmask) > 4 &&
|
wifi_sta_netmask && strlen(wifi_sta_netmask) > 4 &&
|
||||||
wifi_sta_gateway && strlen(wifi_sta_gateway) > 4) {
|
wifi_sta_gateway && strlen(wifi_sta_gateway) > 4) {
|
||||||
sdk_wifi_station_dhcpc_stop();
|
sdk_wifi_station_dhcpc_stop();
|
||||||
ip_info info;
|
ip_info info{};
|
||||||
memset(&info, 0x0, sizeof(info));
|
memset(&info, 0x0, sizeof(info));
|
||||||
info.ip.addr = ipaddr_addr(wifi_sta_ip_addr);
|
info.ip.addr = ipaddr_addr(wifi_sta_ip_addr);
|
||||||
info.netmask.addr = ipaddr_addr(wifi_sta_netmask);
|
info.netmask.addr = ipaddr_addr(wifi_sta_netmask);
|
||||||
|
@ -258,16 +258,6 @@ extern "C" void wifi_task(void *pvParameters) {
|
||||||
int8_t wifi_ap_channel = 6;
|
int8_t wifi_ap_channel = 6;
|
||||||
sysparam_get_int8("wifi_ap_channel", &wifi_ap_channel);
|
sysparam_get_int8("wifi_ap_channel", &wifi_ap_channel);
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* AU does not allow channels above 13, although 14 works. */
|
|
||||||
if(wifi_ap_channel > 13) {
|
|
||||||
wifi_ap_channel = 13;
|
|
||||||
}
|
|
||||||
/* US does not allow channels above 11, although they work. */
|
|
||||||
if (wifi_ap_channel > 11) {
|
|
||||||
wifi_ap_channel = 11;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if(wifi_ap_channel < 1 || wifi_ap_channel > 14) {
|
if(wifi_ap_channel < 1 || wifi_ap_channel > 14) {
|
||||||
wifi_ap_channel = 6;
|
wifi_ap_channel = 6;
|
||||||
}
|
}
|
||||||
|
@ -306,13 +296,13 @@ extern "C" void wifi_task(void *pvParameters) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strlen(wifi_ap_ip_addr) >= 7 && strlen(wifi_ap_netmask) >= 7) {
|
if(strlen(wifi_ap_ip_addr) >= 7 && strlen(wifi_ap_netmask) >= 7) {
|
||||||
ip_info ap_ip;
|
ip_info ap_ip{};
|
||||||
ap_ip.ip.addr = ipaddr_addr(wifi_ap_ip_addr);
|
ap_ip.ip.addr = ipaddr_addr(wifi_ap_ip_addr);
|
||||||
ap_ip.netmask.addr = ipaddr_addr(wifi_ap_netmask);
|
ap_ip.netmask.addr = ipaddr_addr(wifi_ap_netmask);
|
||||||
IP4_ADDR(&ap_ip.gw, 0, 0, 0, 0);
|
IP4_ADDR(&ap_ip.gw, 0, 0, 0, 0);
|
||||||
sdk_wifi_set_ip_info(1, &ap_ip);
|
sdk_wifi_set_ip_info(1, &ap_ip);
|
||||||
|
|
||||||
sdk_softap_config ap_config;
|
sdk_softap_config ap_config{};
|
||||||
strcpy((char *) ap_config.ssid, wifi_ap_ssid);
|
strcpy((char *) ap_config.ssid, wifi_ap_ssid);
|
||||||
ap_config.ssid_len = strlen(wifi_ap_ssid);
|
ap_config.ssid_len = strlen(wifi_ap_ssid);
|
||||||
strcpy((char *) ap_config.password, wifi_ap_password);
|
strcpy((char *) ap_config.password, wifi_ap_password);
|
||||||
|
|
Loading…
Reference in a new issue