mostly working
AP off bug WLAN settings work
This commit is contained in:
parent
57c42facd5
commit
a58ff54d5b
3
TODO.txt
3
TODO.txt
@ -15,5 +15,6 @@ implement LED Control (NeoPixelBus?) -- vip
|
|||||||
implement HSB slider option
|
implement HSB slider option
|
||||||
implement default color on boot
|
implement default color on boot
|
||||||
|
|
||||||
|
Bugs:
|
||||||
FAILURE SOURCE?? --> non-null String
|
FAILURE SOURCE?? --> non-null String
|
||||||
|
post req doesnt send checkboxes
|
||||||
|
@ -13,34 +13,34 @@
|
|||||||
if (this.readyState == 4) {
|
if (this.readyState == 4) {
|
||||||
if (this.status == 200) {
|
if (this.status == 200) {
|
||||||
if (this.responseXML != null) {
|
if (this.responseXML != null) {
|
||||||
document.Settings_form.CSSID.value = this.responseXML.getElementsByTagName('cssid')[0].childNodes[0].nodeValue;
|
document.Settings_form.CSSID.value = this.responseXML.getElementsByTagName('cssid')[0].innerHTML;
|
||||||
document.Settings_form.CPASS.value = this.responseXML.getElementsByTagName('cpass')[0].childNodes[0].nodeValue; //fake pass like ******
|
document.Settings_form.CPASS.value = this.responseXML.getElementsByTagName('cpass')[0].innerHTML; //fake pass like ******
|
||||||
document.Settings_form.CSIP0.value = this.responseXML.getElementsByTagName('csips')[0].childNodes[0].nodeValue;
|
document.Settings_form.CSIP0.value = this.responseXML.getElementsByTagName('csips')[0].innerHTML;
|
||||||
document.Settings_form.CSIP1.value = this.responseXML.getElementsByTagName('csips')[1].childNodes[0].nodeValue;
|
document.Settings_form.CSIP1.value = this.responseXML.getElementsByTagName('csips')[1].innerHTML;
|
||||||
document.Settings_form.CSIP2.value = this.responseXML.getElementsByTagName('csips')[2].childNodes[0].nodeValue;
|
document.Settings_form.CSIP2.value = this.responseXML.getElementsByTagName('csips')[2].innerHTML;
|
||||||
document.Settings_form.CSIP3.value = this.responseXML.getElementsByTagName('csips')[3].childNodes[0].nodeValue;
|
document.Settings_form.CSIP3.value = this.responseXML.getElementsByTagName('csips')[3].innerHTML;
|
||||||
document.Settings_form.CSGW0.value = this.responseXML.getElementsByTagName('csgws')[0].childNodes[0].nodeValue;
|
document.Settings_form.CSGW0.value = this.responseXML.getElementsByTagName('csgws')[0].innerHTML;
|
||||||
document.Settings_form.CSGW1.value = this.responseXML.getElementsByTagName('csgws')[1].childNodes[0].nodeValue;
|
document.Settings_form.CSGW1.value = this.responseXML.getElementsByTagName('csgws')[1].innerHTML;
|
||||||
document.Settings_form.CSGW2.value = this.responseXML.getElementsByTagName('csgws')[2].childNodes[0].nodeValue;
|
document.Settings_form.CSGW2.value = this.responseXML.getElementsByTagName('csgws')[2].innerHTML;
|
||||||
document.Settings_form.CSGW3.value = this.responseXML.getElementsByTagName('csgws')[3].childNodes[0].nodeValue;
|
document.Settings_form.CSGW3.value = this.responseXML.getElementsByTagName('csgws')[3].innerHTML;
|
||||||
document.Settings_form.CSSN0.value = this.responseXML.getElementsByTagName('cssns')[0].childNodes[0].nodeValue;
|
document.Settings_form.CSSN0.value = this.responseXML.getElementsByTagName('cssns')[0].innerHTML;
|
||||||
document.Settings_form.CSSN1.value = this.responseXML.getElementsByTagName('cssns')[1].childNodes[0].nodeValue;
|
document.Settings_form.CSSN1.value = this.responseXML.getElementsByTagName('cssns')[1].innerHTML;
|
||||||
document.Settings_form.CSSN2.value = this.responseXML.getElementsByTagName('cssns')[2].childNodes[0].nodeValue;
|
document.Settings_form.CSSN2.value = this.responseXML.getElementsByTagName('cssns')[2].innerHTML;
|
||||||
document.Settings_form.CSSN3.value = this.responseXML.getElementsByTagName('cssns')[3].childNodes[0].nodeValue;
|
document.Settings_form.CSSN3.value = this.responseXML.getElementsByTagName('cssns')[3].innerHTML;
|
||||||
document.Settings_form.CMDNS.value = this.responseXML.getElementsByTagName('cmdns')[0].childNodes[0].nodeValue;
|
document.Settings_form.CMDNS.value = this.responseXML.getElementsByTagName('cmdns')[0].innerHTML;
|
||||||
document.Settings_form.APSSID.value = this.responseXML.getElementsByTagName('apssid')[0].childNodes[0].nodeValue;
|
document.Settings_form.APSSID.value = this.responseXML.getElementsByTagName('apssid')[0].innerHTML;
|
||||||
document.Settings_form.APHSSID.checked = (this.responseXML.getElementsByTagName('aphssid')[0].childNodes[0].nodeValue)!=0?true:false;
|
document.Settings_form.APHSSID.checked = (this.responseXML.getElementsByTagName('aphssid')[0].innerHTML)!=0?true:false;
|
||||||
document.Settings_form.APPASS.value = this.responseXML.getElementsByTagName('appass')[0].childNodes[0].nodeValue; //fake pass like ******
|
document.Settings_form.APPASS.value = this.responseXML.getElementsByTagName('appass')[0].innerHTML; //fake pass like ******
|
||||||
document.Settings_form.APCHAN.value = this.responseXML.getElementsByTagName('apchan')[0].childNodes[0].nodeValue;
|
document.Settings_form.APCHAN.value = this.responseXML.getElementsByTagName('apchan')[0].innerHTML;
|
||||||
document.Settings_form.LEDS.value = this.responseXML.getElementsByTagName('leds')[0].childNodes[0].nodeValue;
|
document.Settings_form.LEDS.value = this.responseXML.getElementsByTagName('leds')[0].innerHTML;
|
||||||
document.Settings_form.PWRLED.checked = (this.responseXML.getElementsByTagName('pwrled')[0].childNodes[0].nodeValue)!=0?true:false;
|
document.Settings_form.PWRLED.checked = (this.responseXML.getElementsByTagName('pwrled')[0].innerHTML)!=0?true:false;
|
||||||
document.Settings_form.BTNP.value = this.responseXML.getElementsByTagName('btnp')[0].childNodes[0].nodeValue;
|
document.Settings_form.BTNP.value = this.responseXML.getElementsByTagName('btnp')[0].innerHTML;
|
||||||
document.Settings_form.NOOTA.checked = (this.responseXML.getElementsByTagName('noota')[0].childNodes[0].nodeValue)!=0?true:false;
|
document.Settings_form.NOOTA.checked = (this.responseXML.getElementsByTagName('noota')[0].innerHTML)!=0?true:false;
|
||||||
document.Settings_form.NORAP.checked = (this.responseXML.getElementsByTagName('norap')[0].childNodes[0].nodeValue)!=0?true:false;
|
document.Settings_form.NORAP.checked = (this.responseXML.getElementsByTagName('norap')[0].innerHTML)!=0?true:false;
|
||||||
document.getElementsByClassName("sip")[0].innerHTML = this.responseXML.getElementsByTagName('sip')[0].childNodes[0].nodeValue;
|
document.getElementsByClassName("sip")[0].innerHTML = this.responseXML.getElementsByTagName('sip')[0].innerHTML;
|
||||||
document.getElementsByClassName("sip")[1].innerHTML = this.responseXML.getElementsByTagName('sip')[1].childNodes[0].nodeValue;
|
document.getElementsByClassName("sip")[1].innerHTML = this.responseXML.getElementsByTagName('sip')[1].innerHTML;
|
||||||
document.getElementsByClassName("otastat")[0].innerHTML = this.responseXML.getElementsByTagName('otastat')[0].childNodes[0].nodeValue;
|
document.getElementsByClassName("otastat")[0].innerHTML = this.responseXML.getElementsByTagName('otastat')[0].innerHTML;
|
||||||
document.getElementsByClassName("msg")[0].innerHTML = this.responseXML.getElementsByTagName('msg')[0].childNodes[0].nodeValue;
|
document.getElementsByClassName("msg")[0].innerHTML = this.responseXML.getElementsByTagName('msg')[0].innerHTML;
|
||||||
if (Settings_form.NOOTA.checked) {document.Settings_form.NOOTA.disabled="disabled";}
|
if (Settings_form.NOOTA.checked) {document.Settings_form.NOOTA.disabled="disabled";}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ boolean ota_lock = false;
|
|||||||
int led_amount = 16;
|
int led_amount = 16;
|
||||||
int nopwrled = 1;
|
int nopwrled = 1;
|
||||||
|
|
||||||
char HTTP_req[350];
|
char HTTP_req[150];
|
||||||
|
|
||||||
ESP8266WebServer server(80);
|
ESP8266WebServer server(80);
|
||||||
File fsUploadFile;
|
File fsUploadFile;
|
||||||
@ -53,12 +53,14 @@ void clearEEPROM()
|
|||||||
{
|
{
|
||||||
EEPROM.write(i, 0);
|
EEPROM.write(i, 0);
|
||||||
}
|
}
|
||||||
|
EEPROM.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveSettingsToEEPROM()
|
void saveSettingsToEEPROM()
|
||||||
{
|
{
|
||||||
if (EEPROM.read(233) != 233) //set no first boot flag
|
if (EEPROM.read(233) != 233) //set no first boot flag
|
||||||
{
|
{
|
||||||
|
clearEEPROM();
|
||||||
EEPROM.write(233, 233);
|
EEPROM.write(233, 233);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 32; ++i)
|
for (int i = 0; i < 32; ++i)
|
||||||
@ -67,19 +69,19 @@ void saveSettingsToEEPROM()
|
|||||||
}
|
}
|
||||||
for (int i = 32; i < 96; ++i)
|
for (int i = 32; i < 96; ++i)
|
||||||
{
|
{
|
||||||
EEPROM.write(i, clientpass.charAt(i));
|
EEPROM.write(i, clientpass.charAt(i-32));
|
||||||
}
|
}
|
||||||
for (int i = 96; i < 128; ++i)
|
for (int i = 96; i < 128; ++i)
|
||||||
{
|
{
|
||||||
EEPROM.write(i, cmdns.charAt(i));
|
EEPROM.write(i, cmdns.charAt(i-96));
|
||||||
}
|
}
|
||||||
for (int i = 128; i < 160; ++i)
|
for (int i = 128; i < 160; ++i)
|
||||||
{
|
{
|
||||||
EEPROM.write(i, apssid.charAt(i));
|
EEPROM.write(i, apssid.charAt(i-128));
|
||||||
}
|
}
|
||||||
for (int i = 160; i < 224; ++i)
|
for (int i = 160; i < 224; ++i)
|
||||||
{
|
{
|
||||||
EEPROM.write(i, appass.charAt(i));
|
EEPROM.write(i, appass.charAt(i-160));
|
||||||
}
|
}
|
||||||
EEPROM.write(228, aphide);
|
EEPROM.write(228, aphide);
|
||||||
EEPROM.write(227, apchannel);
|
EEPROM.write(227, apchannel);
|
||||||
@ -97,6 +99,8 @@ void saveSettingsToEEPROM()
|
|||||||
EEPROM.write(243, staticsubnet[1]);
|
EEPROM.write(243, staticsubnet[1]);
|
||||||
EEPROM.write(244, staticsubnet[2]);
|
EEPROM.write(244, staticsubnet[2]);
|
||||||
EEPROM.write(245, staticsubnet[3]);
|
EEPROM.write(245, staticsubnet[3]);
|
||||||
|
|
||||||
|
EEPROM.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadSettingsFromEEPROM()
|
void loadSettingsFromEEPROM()
|
||||||
@ -109,26 +113,31 @@ void loadSettingsFromEEPROM()
|
|||||||
clientssid = "";
|
clientssid = "";
|
||||||
for (int i = 0; i < 32; ++i)
|
for (int i = 0; i < 32; ++i)
|
||||||
{
|
{
|
||||||
|
if (EEPROM.read(i) == 0) break;
|
||||||
clientssid += char(EEPROM.read(i));
|
clientssid += char(EEPROM.read(i));
|
||||||
}
|
}
|
||||||
clientpass = "";
|
clientpass = "";
|
||||||
for (int i = 32; i < 96; ++i)
|
for (int i = 32; i < 96; ++i)
|
||||||
{
|
{
|
||||||
|
if (EEPROM.read(i) == 0) break;
|
||||||
clientpass += char(EEPROM.read(i));
|
clientpass += char(EEPROM.read(i));
|
||||||
}
|
}
|
||||||
cmdns = "";
|
cmdns = "";
|
||||||
for (int i = 96; i < 128; ++i)
|
for (int i = 96; i < 128; ++i)
|
||||||
{
|
{
|
||||||
|
if (EEPROM.read(i) == 0) break;
|
||||||
cmdns += char(EEPROM.read(i));
|
cmdns += char(EEPROM.read(i));
|
||||||
}
|
}
|
||||||
apssid = "";
|
apssid = "";
|
||||||
for (int i = 128; i < 160; ++i)
|
for (int i = 128; i < 160; ++i)
|
||||||
{
|
{
|
||||||
|
if (EEPROM.read(i) == 0) break;
|
||||||
apssid += char(EEPROM.read(i));
|
apssid += char(EEPROM.read(i));
|
||||||
}
|
}
|
||||||
appass = "";
|
appass = "";
|
||||||
for (int i = 160; i < 224; ++i)
|
for (int i = 160; i < 224; ++i)
|
||||||
{
|
{
|
||||||
|
if (EEPROM.read(i) == 0) break;
|
||||||
appass += char(EEPROM.read(i));
|
appass += char(EEPROM.read(i));
|
||||||
}
|
}
|
||||||
aphide = EEPROM.read(228);
|
aphide = EEPROM.read(228);
|
||||||
@ -174,6 +183,7 @@ void XML_response()
|
|||||||
|
|
||||||
void XML_response_settings()
|
void XML_response_settings()
|
||||||
{
|
{
|
||||||
|
Serial.println("XML settings response");
|
||||||
String resp;
|
String resp;
|
||||||
resp = resp + "<?xml version = \"1.0\" ?>";
|
resp = resp + "<?xml version = \"1.0\" ?>";
|
||||||
resp = resp + "<vs>";
|
resp = resp + "<vs>";
|
||||||
@ -264,6 +274,7 @@ void XML_response_settings()
|
|||||||
resp = resp + "<otastat>Not implemented</otastat>";
|
resp = resp + "<otastat>Not implemented</otastat>";
|
||||||
resp = resp + "<msg>WLED 0.1c OK</msg>";
|
resp = resp + "<msg>WLED 0.1c OK</msg>";
|
||||||
resp = resp + "</vs>";
|
resp = resp + "</vs>";
|
||||||
|
Serial.println(resp);
|
||||||
server.send(200, "text/xml", resp);
|
server.send(200, "text/xml", resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,6 +323,19 @@ uint8_t getNumberAfterStringPos(char str[], char spos)
|
|||||||
void handleSettingsSet()
|
void handleSettingsSet()
|
||||||
{
|
{
|
||||||
if (server.hasArg("CSSID")) clientssid = server.arg("CSSID");
|
if (server.hasArg("CSSID")) clientssid = server.arg("CSSID");
|
||||||
|
if (server.hasArg("CPASS"))
|
||||||
|
{
|
||||||
|
if (!server.arg("CPASS").indexOf('*') == 0)
|
||||||
|
{
|
||||||
|
Serial.println("Setting pass");
|
||||||
|
clientpass = server.arg("CPASS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (server.hasArg("APSSID")) apssid = server.arg("APSSID");
|
||||||
|
if (server.hasArg("APPASS"))
|
||||||
|
{
|
||||||
|
if (!server.arg("APPASS").indexOf('*') == 0) appass = server.arg("APPASS");
|
||||||
|
}
|
||||||
|
|
||||||
saveSettingsToEEPROM();
|
saveSettingsToEEPROM();
|
||||||
}
|
}
|
||||||
@ -320,7 +344,7 @@ boolean handleSet(String req)
|
|||||||
{
|
{
|
||||||
Serial.println("handleSet:");
|
Serial.println("handleSet:");
|
||||||
Serial.println(req);
|
Serial.println(req);
|
||||||
req.toCharArray(HTTP_req, 350, 0);
|
req.toCharArray(HTTP_req, 150, 0);
|
||||||
if (!StrContains(HTTP_req, "ajax_in")) {
|
if (!StrContains(HTTP_req, "ajax_in")) {
|
||||||
if (StrContains(HTTP_req, "get-settings"))
|
if (StrContains(HTTP_req, "get-settings"))
|
||||||
{
|
{
|
||||||
@ -485,7 +509,6 @@ void setLeds() {
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("T123");
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
for(uint8_t t = 4; t > 0; t--) {
|
for(uint8_t t = 4; t > 0; t--) {
|
||||||
@ -508,6 +531,13 @@ void setup() {
|
|||||||
EEPROM.begin(256);
|
EEPROM.begin(256);
|
||||||
loadSettingsFromEEPROM();
|
loadSettingsFromEEPROM();
|
||||||
|
|
||||||
|
Serial.print("CC: SSID: ");
|
||||||
|
Serial.print(clientssid);
|
||||||
|
Serial.print(" PASS: ");
|
||||||
|
Serial.println(clientpass);
|
||||||
|
|
||||||
|
WiFi.disconnect(); //close old connections
|
||||||
|
|
||||||
if (staticip[0] != 0)
|
if (staticip[0] != 0)
|
||||||
{
|
{
|
||||||
WiFi.config(staticip, staticgateway, staticsubnet);
|
WiFi.config(staticip, staticgateway, staticsubnet);
|
||||||
@ -516,8 +546,9 @@ void setup() {
|
|||||||
WiFi.config(0U, 0U, 0U);
|
WiFi.config(0U, 0U, 0U);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useap)
|
if (apssid.length()>0)
|
||||||
{
|
{
|
||||||
|
Serial.println(apssid.length());
|
||||||
initAP();
|
initAP();
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
@ -531,7 +562,7 @@ void setup() {
|
|||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
// Set up mDNS responder:
|
// Set up mDNS responder:
|
||||||
if (cmdns != NULL && !WL_CONNECTED && !MDNS.begin(cmdns.c_str())) {
|
if (cmdns != NULL && WL_CONNECTED && !MDNS.begin(cmdns.c_str())) {
|
||||||
Serial.println("Error setting up MDNS responder!");
|
Serial.println("Error setting up MDNS responder!");
|
||||||
down();
|
down();
|
||||||
}
|
}
|
||||||
@ -554,7 +585,7 @@ void setup() {
|
|||||||
server.on("/reset", HTTP_GET, reset);
|
server.on("/reset", HTTP_GET, reset);
|
||||||
server.on("/set-settings", HTTP_POST, [](){
|
server.on("/set-settings", HTTP_POST, [](){
|
||||||
handleSettingsSet();
|
handleSettingsSet();
|
||||||
server.send(200, "text/plain", "Settings saved. Please wait a minute for module to reset...");
|
server.send(200, "text/html", "<html><head><script>alert(Settings saved. Please power cycle module to apply changes...);</script></head></html>");
|
||||||
reset();
|
reset();
|
||||||
});
|
});
|
||||||
if (!ota_lock){
|
if (!ota_lock){
|
||||||
@ -573,6 +604,8 @@ void setup() {
|
|||||||
server.on("/list", HTTP_GET, handleFileList);
|
server.on("/list", HTTP_GET, handleFileList);
|
||||||
//kill module
|
//kill module
|
||||||
server.on("/down", HTTP_GET, down);
|
server.on("/down", HTTP_GET, down);
|
||||||
|
//clear eeprom
|
||||||
|
server.on("/cleareeprom", HTTP_GET, clearEEPROM);
|
||||||
}
|
}
|
||||||
//called when the url is not defined here, ajax-in; get-settings
|
//called when the url is not defined here, ajax-in; get-settings
|
||||||
server.onNotFound([](){
|
server.onNotFound([](){
|
||||||
@ -597,10 +630,6 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
server.handleClient();
|
server.handleClient();
|
||||||
/*if (wasConnected && !WL_CONNECTED)
|
|
||||||
{
|
|
||||||
initCon();
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void initAP(){
|
void initAP(){
|
||||||
@ -623,7 +652,6 @@ void initCon()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//wasConnected = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user