CanGrow Firmware WIP
This commit is contained in:
parent
9577788dfa
commit
031c09e8da
1 changed files with 67 additions and 16 deletions
|
@ -339,6 +339,7 @@ int getLightchirp() {
|
|||
return lightchirp;
|
||||
}
|
||||
|
||||
|
||||
void wipeEEPROM() {
|
||||
// write a 0 to all 512 bytes of the EEPROM
|
||||
Serial.print("wiping EEPROM... ");
|
||||
|
@ -349,22 +350,39 @@ void wipeEEPROM() {
|
|||
delay(5000);
|
||||
}
|
||||
|
||||
|
||||
bool loadEEPROM() {
|
||||
// read var configured from Byte 0
|
||||
EEPROM.get(0, configured);
|
||||
// read var WIFIssid, 32 byte long
|
||||
EEPROM.get(1, WIFIssid);
|
||||
// read var WIFIpassword, 64 byte long
|
||||
EEPROM.get(33, WIFIpassword);
|
||||
// read var ip, 16 byte long
|
||||
EEPROM.get(113, WIFIip);
|
||||
// read var netmask, 16 byte long
|
||||
EEPROM.get(129, WIFInetmask);
|
||||
// read var gateway, 16 byte long
|
||||
EEPROM.get(145, WIFIgateway);
|
||||
//EEPROM.get(0, configured);
|
||||
|
||||
Serial.print("EEPROM loaded, CanGrow configured is: ");
|
||||
// read var WIFIssid, 32 byte long
|
||||
EEPROM.get(0, WIFIssid);
|
||||
// read var WIFIpassword, 64 byte long
|
||||
EEPROM.get(32, WIFIpassword);
|
||||
/*
|
||||
// read var ip, 16 byte long
|
||||
EEPROM.get(112, WIFIip);
|
||||
// read var netmask, 16 byte long
|
||||
EEPROM.get(128, WIFInetmask);
|
||||
// read var gateway, 16 byte long
|
||||
EEPROM.get(144, WIFIgateway);
|
||||
*/
|
||||
Serial.println(":: EEPROM loaded ::");
|
||||
Serial.print("configured: ");
|
||||
Serial.println(configured);
|
||||
|
||||
Serial.print("WIFIssid: ");
|
||||
Serial.println(WIFIssid);
|
||||
Serial.print("WIFIpassword: ");
|
||||
Serial.println(WIFIpassword);
|
||||
/*
|
||||
Serial.print("WIFIip: ");
|
||||
Serial.println(WIFIip);
|
||||
Serial.print("WIFInetmask: ");
|
||||
Serial.println(WIFInetmask);
|
||||
Serial.print("WIFIgateway: ");
|
||||
Serial.println(WIFIgateway);
|
||||
*/
|
||||
return(configured);
|
||||
|
||||
}
|
||||
|
@ -431,6 +449,7 @@ void setup() {
|
|||
// and we can enjoy the boot screen meanwhile :p
|
||||
delay(2000);
|
||||
|
||||
|
||||
// read status from PIN_WIPE to WIPE
|
||||
WIPE = digitalRead(PIN_WIPE);
|
||||
Serial.print("WIPE is ");
|
||||
|
@ -439,16 +458,19 @@ void setup() {
|
|||
wipeEEPROM();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Webserver handlers
|
||||
//
|
||||
|
||||
// when not configured, webroot is WEBrootAP
|
||||
// nothing else configured
|
||||
if(configured == true) {
|
||||
webserver.on("/", HTTP_GET, WEBroot);
|
||||
} else {
|
||||
if(configured == 0) {
|
||||
webserver.on("/", HTTP_GET, WEBrootAP);
|
||||
} else {
|
||||
webserver.on("/", HTTP_GET, WEBroot);
|
||||
}
|
||||
|
||||
// generic handler
|
||||
|
@ -533,9 +555,38 @@ void POSTwifiConfig() {
|
|||
WIFIip.fromString(WIFIip_new);
|
||||
WIFInetmask.fromString(WIFInetmask_new);
|
||||
WIFIgateway.fromString(WIFIgateway_new);
|
||||
EEPROM.put(0, 1);
|
||||
configured = 1;
|
||||
EEPROM.put(0, configured);
|
||||
EEPROM.put(1, WIFIssid_new);
|
||||
EEPROM.commit();
|
||||
|
||||
|
||||
Serial.println(":: POSTwifiConfig ::");
|
||||
Serial.print("configured: ");
|
||||
Serial.println(configured);
|
||||
|
||||
Serial.print("WIFIssid: ");
|
||||
Serial.println(WIFIssid_new);
|
||||
Serial.print("WIFIpassword: ");
|
||||
Serial.println(WIFIpassword_new);
|
||||
Serial.print("WIFIip: ");
|
||||
Serial.println(WIFIip_new);
|
||||
Serial.print("WIFInetmask: ");
|
||||
Serial.println(WIFInetmask_new);
|
||||
Serial.print("WIFIgateway: ");
|
||||
Serial.println(WIFIgateway_new);
|
||||
|
||||
char rofl[32];
|
||||
EEPROM.get(1, rofl);
|
||||
Serial.println("READ EEPROM WIFIssid");
|
||||
Serial.println(rofl);
|
||||
|
||||
Serial.println("READ EEPROM configured");
|
||||
bool lol;
|
||||
EEPROM.get(0, lol);
|
||||
Serial.println(lol);
|
||||
webserver.send(200, "text/html", "wifiConfig saved, please restart");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue