heavy WIP - EEPROM Stuff now working in principal

This commit is contained in:
Marcus 2024-04-13 14:39:16 +02:00
parent 031c09e8da
commit 56d988153d

View file

@ -29,8 +29,9 @@
#include "DHT.h"
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ArduinoJson.h>
#include <EEPROM.h>
#include <ArduinoJson.h>
/*
*
@ -48,7 +49,7 @@ bool WIPE;
*/
// Size of EEPROM
const uint8_t EEPROMsize = 512;
//const uint8_t EEPROMsize = 512;
bool configured;
char WIFIssid[32];
char WIFIpassword[64];
@ -343,10 +344,12 @@ int getLightchirp() {
void wipeEEPROM() {
// write a 0 to all 512 bytes of the EEPROM
Serial.print("wiping EEPROM... ");
for (int i = 0; i < EEPROMsize; i++) { EEPROM.write(i, 0); }
for (int i = 0; i < 512; i++) { EEPROM.write(i, 0); }
EEPROM.commit();
Serial.println("DONE");
pinMode(PIN_WIPE, OUTPUT);
digitalWrite(PIN_WIPE, LOW);
Serial.println("Please restart the device.");
delay(5000);
}
@ -366,11 +369,12 @@ bool loadEEPROM() {
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.println(":: EEPROM loaded ::");
Serial.print("WIFIssid: ");
Serial.println(WIFIssid);
Serial.print("WIFIpassword: ");
@ -393,6 +397,9 @@ bool loadEEPROM() {
*
*/
void setup() {
// Start EEPROM
EEPROM.begin(512);
// setup pins
pinMode(PINfan, OUTPUT);
pinMode(PINdht, INPUT);
@ -411,9 +418,13 @@ void setup() {
// Start Serial
Serial.begin(115200);
// Write an empty line, because before there is some garbage in serial
// output
Serial.println("");
Serial.println(".:: CanGrow Start ::.");
// Start EEPROM
EEPROM.begin(EEPROMsize);
// load stored values from EEPROM
loadEEPROM();
// initialise Wire for I2C
Wire.begin();
@ -442,8 +453,7 @@ void setup() {
Serial.print("AP IP address: ");
Serial.println(WiFi.softAPIP());
// load stored values from EEPROM
loadEEPROM();
// wait a few seconds to let the user pull D4 down to wipe EEPROM
// and we can enjoy the boot screen meanwhile :p
@ -555,35 +565,43 @@ void POSTwifiConfig() {
WIFIip.fromString(WIFIip_new);
WIFInetmask.fromString(WIFInetmask_new);
WIFIgateway.fromString(WIFIgateway_new);
configured = 1;
EEPROM.put(0, configured);
EEPROM.put(1, WIFIssid_new);
//configured = 1;
EEPROM.put(0, WIFIssid);
EEPROM.put(32, WIFIpassword);
EEPROM.commit();
Serial.println(":: POSTwifiConfig ::");
Serial.print("configured: ");
Serial.println(configured);
//Serial.print("configured: ");
//Serial.println(configured);
Serial.print("WIFIssid: ");
Serial.println(WIFIssid_new);
Serial.println(WIFIssid);
Serial.print("WIFIpassword: ");
Serial.println(WIFIpassword_new);
Serial.println(WIFIpassword);
/*
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);
EEPROM.get(0, rofl);
Serial.println("READ EEPROM WIFIssid");
Serial.println(rofl);
Serial.println("READ EEPROM configured");
bool lol;
EEPROM.get(0, lol);
Serial.println("READ EEPROM WIFIpassword");
char lol[64];
EEPROM.get(32, lol);
Serial.println(lol);
webserver.send(200, "text/html", "wifiConfig saved, please restart");