Firmware WIP
This commit is contained in:
parent
56d988153d
commit
b7eb2a4398
1 changed files with 80 additions and 58 deletions
|
@ -48,8 +48,6 @@ bool WIPE;
|
||||||
* EEPROM variables
|
* EEPROM variables
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Size of EEPROM
|
|
||||||
//const uint8_t EEPROMsize = 512;
|
|
||||||
bool configured;
|
bool configured;
|
||||||
char WIFIssid[32];
|
char WIFIssid[32];
|
||||||
char WIFIpassword[64];
|
char WIFIpassword[64];
|
||||||
|
@ -345,48 +343,76 @@ void wipeEEPROM() {
|
||||||
// write a 0 to all 512 bytes of the EEPROM
|
// write a 0 to all 512 bytes of the EEPROM
|
||||||
Serial.print("wiping EEPROM... ");
|
Serial.print("wiping EEPROM... ");
|
||||||
for (int i = 0; i < 512; i++) { EEPROM.write(i, 0); }
|
for (int i = 0; i < 512; i++) { EEPROM.write(i, 0); }
|
||||||
EEPROM.commit();
|
|
||||||
|
// commit everything to EEPROM and end here
|
||||||
|
EEPROM.end();
|
||||||
|
|
||||||
Serial.println("DONE");
|
Serial.println("DONE");
|
||||||
|
|
||||||
|
// set D4 PIN_WIPE internal LED to Output to give feedback WIPE
|
||||||
|
// was done
|
||||||
pinMode(PIN_WIPE, OUTPUT);
|
pinMode(PIN_WIPE, OUTPUT);
|
||||||
|
|
||||||
|
Serial.println("!! Device will restart in 5 seconds !!");
|
||||||
|
|
||||||
|
byte i = 0;
|
||||||
|
while( i <= 10 ) {
|
||||||
|
if( i % 2 ) {
|
||||||
digitalWrite(PIN_WIPE, LOW);
|
digitalWrite(PIN_WIPE, LOW);
|
||||||
Serial.println("Please restart the device.");
|
} else {
|
||||||
delay(5000);
|
digitalWrite(PIN_WIPE, HIGH);
|
||||||
|
}
|
||||||
|
delay(500);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool loadEEPROM() {
|
bool loadEEPROM() {
|
||||||
// read var configured from Byte 0
|
|
||||||
//EEPROM.get(0, configured);
|
|
||||||
|
|
||||||
// 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
|
* WIFI data
|
||||||
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.print("configured: ");
|
|
||||||
Serial.println(configured);
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// read var WIFIssid from address 0, 32 byte long
|
||||||
|
EEPROM.get(0, WIFIssid);
|
||||||
|
// read var WIFIpassword from address 32, 64 byte long
|
||||||
|
EEPROM.get(32, WIFIpassword);
|
||||||
|
|
||||||
|
// read var WIFIip from address 96, 16 byte long
|
||||||
|
EEPROM.get(96, WIFIip);
|
||||||
|
|
||||||
|
// read var WIFInetmask from address 112, 16 byte long
|
||||||
|
EEPROM.get(112, WIFInetmask);
|
||||||
|
// read var WIFIgateway from address 128, 16 byte long
|
||||||
|
EEPROM.get(128, WIFIgateway);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Grow data
|
||||||
|
*/
|
||||||
|
|
||||||
|
//TBD
|
||||||
|
|
||||||
|
/*
|
||||||
|
* configured
|
||||||
|
*
|
||||||
|
* read var configured from address 511 - I put this to the end to
|
||||||
|
* prevent confusion with the 1 byte offset in the address when it
|
||||||
|
* would be at the beginning - more a cosmetic thing
|
||||||
|
*/
|
||||||
|
EEPROM.get(511, configured);
|
||||||
|
|
||||||
|
// print values to Serial output
|
||||||
Serial.println(":: EEPROM loaded ::");
|
Serial.println(":: EEPROM loaded ::");
|
||||||
Serial.print("WIFIssid: ");
|
Serial.print("WIFIssid: ");
|
||||||
Serial.println(WIFIssid);
|
Serial.println(WIFIssid);
|
||||||
Serial.print("WIFIpassword: ");
|
Serial.print("WIFIpassword: ");
|
||||||
Serial.println(WIFIpassword);
|
Serial.println(WIFIpassword);
|
||||||
/*
|
|
||||||
Serial.print("WIFIip: ");
|
Serial.print("configured: ");
|
||||||
Serial.println(WIFIip);
|
Serial.println(configured);
|
||||||
Serial.print("WIFInetmask: ");
|
|
||||||
Serial.println(WIFInetmask);
|
|
||||||
Serial.print("WIFIgateway: ");
|
|
||||||
Serial.println(WIFIgateway);
|
|
||||||
*/
|
|
||||||
return(configured);
|
return(configured);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -418,14 +444,12 @@ void setup() {
|
||||||
|
|
||||||
// Start Serial
|
// Start Serial
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
// Write an empty line, because before there is some garbage in serial
|
// Write an empty line, because before there is some garbage in serial
|
||||||
// output
|
// output
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
Serial.println(".:: CanGrow Start ::.");
|
Serial.println(".:: CanGrow Start ::.");
|
||||||
|
|
||||||
// load stored values from EEPROM
|
|
||||||
loadEEPROM();
|
|
||||||
|
|
||||||
// initialise Wire for I2C
|
// initialise Wire for I2C
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
|
||||||
|
@ -459,21 +483,27 @@ void setup() {
|
||||||
// and we can enjoy the boot screen meanwhile :p
|
// and we can enjoy the boot screen meanwhile :p
|
||||||
delay(2000);
|
delay(2000);
|
||||||
|
|
||||||
|
|
||||||
// read status from PIN_WIPE to WIPE
|
// read status from PIN_WIPE to WIPE
|
||||||
WIPE = digitalRead(PIN_WIPE);
|
WIPE = digitalRead(PIN_WIPE);
|
||||||
Serial.print("WIPE is ");
|
|
||||||
Serial.println(WIPE);
|
// when PIN_WIPE is set to LOW, wipe EEPROM
|
||||||
if( WIPE == 0 ) {
|
if( WIPE == 0 ) {
|
||||||
|
Serial.print("PIN_WIPE (D4) is set to LOW, wiping EEPROM now..");
|
||||||
|
|
||||||
|
// wipe EEPROM
|
||||||
wipeEEPROM();
|
wipeEEPROM();
|
||||||
|
} else {
|
||||||
|
// load stored values from EEPROM
|
||||||
|
loadEEPROM();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
/*
|
||||||
// Webserver handlers
|
* Webserver handlers
|
||||||
//
|
*/
|
||||||
|
|
||||||
// when not configured, webroot is WEBrootAP
|
// when not configured, webroot is WEBrootAP
|
||||||
// nothing else configured
|
// nothing else configured
|
||||||
|
@ -565,18 +595,19 @@ void POSTwifiConfig() {
|
||||||
WIFIip.fromString(WIFIip_new);
|
WIFIip.fromString(WIFIip_new);
|
||||||
WIFInetmask.fromString(WIFInetmask_new);
|
WIFInetmask.fromString(WIFInetmask_new);
|
||||||
WIFIgateway.fromString(WIFIgateway_new);
|
WIFIgateway.fromString(WIFIgateway_new);
|
||||||
//configured = 1;
|
|
||||||
|
|
||||||
|
|
||||||
|
configured = true;
|
||||||
|
|
||||||
EEPROM.put(0, WIFIssid);
|
EEPROM.put(0, WIFIssid);
|
||||||
EEPROM.put(32, WIFIpassword);
|
EEPROM.put(32, WIFIpassword);
|
||||||
|
EEPROM.put(96, WIFIip);
|
||||||
|
EEPROM.put(112, WIFInetmask);
|
||||||
|
EEPROM.put(128, WIFIgateway);
|
||||||
|
EEPROM.put(511, configured);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
|
|
||||||
|
|
||||||
Serial.println(":: POSTwifiConfig ::");
|
Serial.println(":: POSTwifiConfig ::");
|
||||||
//Serial.print("configured: ");
|
|
||||||
//Serial.println(configured);
|
|
||||||
|
|
||||||
Serial.print("WIFIssid: ");
|
Serial.print("WIFIssid: ");
|
||||||
Serial.println(WIFIssid_new);
|
Serial.println(WIFIssid_new);
|
||||||
|
@ -584,25 +615,16 @@ void POSTwifiConfig() {
|
||||||
Serial.print("WIFIpassword: ");
|
Serial.print("WIFIpassword: ");
|
||||||
Serial.println(WIFIpassword_new);
|
Serial.println(WIFIpassword_new);
|
||||||
Serial.println(WIFIpassword);
|
Serial.println(WIFIpassword);
|
||||||
|
|
||||||
/*
|
|
||||||
Serial.print("WIFIip: ");
|
Serial.print("WIFIip: ");
|
||||||
Serial.println(WIFIip_new);
|
Serial.println(WIFIip_new);
|
||||||
Serial.print("WIFInetmask: ");
|
Serial.print("WIFInetmask: ");
|
||||||
Serial.println(WIFInetmask_new);
|
Serial.println(WIFInetmask_new);
|
||||||
Serial.print("WIFIgateway: ");
|
Serial.print("WIFIgateway: ");
|
||||||
Serial.println(WIFIgateway_new);
|
Serial.println(WIFIgateway_new);
|
||||||
*/
|
|
||||||
|
|
||||||
char rofl[32];
|
Serial.print("configured: ");
|
||||||
EEPROM.get(0, rofl);
|
Serial.println(configured);
|
||||||
Serial.println("READ EEPROM WIFIssid");
|
|
||||||
Serial.println(rofl);
|
|
||||||
|
|
||||||
Serial.println("READ EEPROM WIFIpassword");
|
|
||||||
char lol[64];
|
|
||||||
EEPROM.get(32, lol);
|
|
||||||
Serial.println(lol);
|
|
||||||
webserver.send(200, "text/html", "wifiConfig saved, please restart");
|
webserver.send(200, "text/html", "wifiConfig saved, please restart");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue