heavy WIP - EEPROM Stuff now working in principal
This commit is contained in:
parent
031c09e8da
commit
56d988153d
1 changed files with 43 additions and 25 deletions
|
@ -29,8 +29,9 @@
|
||||||
#include "DHT.h"
|
#include "DHT.h"
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
#include <ArduinoJson.h>
|
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
@ -48,7 +49,7 @@ bool WIPE;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Size of EEPROM
|
// Size of EEPROM
|
||||||
const uint8_t EEPROMsize = 512;
|
//const uint8_t EEPROMsize = 512;
|
||||||
bool configured;
|
bool configured;
|
||||||
char WIFIssid[32];
|
char WIFIssid[32];
|
||||||
char WIFIpassword[64];
|
char WIFIpassword[64];
|
||||||
|
@ -341,13 +342,15 @@ int getLightchirp() {
|
||||||
|
|
||||||
|
|
||||||
void wipeEEPROM() {
|
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 < EEPROMsize; i++) { EEPROM.write(i, 0); }
|
for (int i = 0; i < 512; i++) { EEPROM.write(i, 0); }
|
||||||
Serial.println("DONE");
|
EEPROM.commit();
|
||||||
pinMode(PIN_WIPE, OUTPUT);
|
Serial.println("DONE");
|
||||||
digitalWrite(PIN_WIPE, LOW);
|
pinMode(PIN_WIPE, OUTPUT);
|
||||||
delay(5000);
|
digitalWrite(PIN_WIPE, LOW);
|
||||||
|
Serial.println("Please restart the device.");
|
||||||
|
delay(5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -366,11 +369,12 @@ bool loadEEPROM() {
|
||||||
EEPROM.get(128, WIFInetmask);
|
EEPROM.get(128, WIFInetmask);
|
||||||
// read var gateway, 16 byte long
|
// read var gateway, 16 byte long
|
||||||
EEPROM.get(144, WIFIgateway);
|
EEPROM.get(144, WIFIgateway);
|
||||||
*/
|
|
||||||
Serial.println(":: EEPROM loaded ::");
|
|
||||||
Serial.print("configured: ");
|
Serial.print("configured: ");
|
||||||
Serial.println(configured);
|
Serial.println(configured);
|
||||||
|
*/
|
||||||
|
Serial.println(":: EEPROM loaded ::");
|
||||||
Serial.print("WIFIssid: ");
|
Serial.print("WIFIssid: ");
|
||||||
Serial.println(WIFIssid);
|
Serial.println(WIFIssid);
|
||||||
Serial.print("WIFIpassword: ");
|
Serial.print("WIFIpassword: ");
|
||||||
|
@ -393,6 +397,9 @@ bool loadEEPROM() {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void setup() {
|
void setup() {
|
||||||
|
// Start EEPROM
|
||||||
|
EEPROM.begin(512);
|
||||||
|
|
||||||
// setup pins
|
// setup pins
|
||||||
pinMode(PINfan, OUTPUT);
|
pinMode(PINfan, OUTPUT);
|
||||||
pinMode(PINdht, INPUT);
|
pinMode(PINdht, INPUT);
|
||||||
|
@ -411,9 +418,13 @@ void setup() {
|
||||||
|
|
||||||
// Start Serial
|
// Start Serial
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
// Write an empty line, because before there is some garbage in serial
|
||||||
|
// output
|
||||||
|
Serial.println("");
|
||||||
|
Serial.println(".:: CanGrow Start ::.");
|
||||||
|
|
||||||
// Start EEPROM
|
// load stored values from EEPROM
|
||||||
EEPROM.begin(EEPROMsize);
|
loadEEPROM();
|
||||||
|
|
||||||
// initialise Wire for I2C
|
// initialise Wire for I2C
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
@ -442,8 +453,7 @@ void setup() {
|
||||||
Serial.print("AP IP address: ");
|
Serial.print("AP IP address: ");
|
||||||
Serial.println(WiFi.softAPIP());
|
Serial.println(WiFi.softAPIP());
|
||||||
|
|
||||||
// load stored values from EEPROM
|
|
||||||
loadEEPROM();
|
|
||||||
|
|
||||||
// wait a few seconds to let the user pull D4 down to wipe EEPROM
|
// wait a few seconds to let the user pull D4 down to wipe EEPROM
|
||||||
// and we can enjoy the boot screen meanwhile :p
|
// and we can enjoy the boot screen meanwhile :p
|
||||||
|
@ -555,35 +565,43 @@ 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 = 1;
|
||||||
EEPROM.put(0, configured);
|
|
||||||
EEPROM.put(1, WIFIssid_new);
|
|
||||||
|
|
||||||
|
EEPROM.put(0, WIFIssid);
|
||||||
|
EEPROM.put(32, WIFIpassword);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
|
|
||||||
|
|
||||||
Serial.println(":: POSTwifiConfig ::");
|
Serial.println(":: POSTwifiConfig ::");
|
||||||
Serial.print("configured: ");
|
//Serial.print("configured: ");
|
||||||
Serial.println(configured);
|
//Serial.println(configured);
|
||||||
|
|
||||||
Serial.print("WIFIssid: ");
|
Serial.print("WIFIssid: ");
|
||||||
Serial.println(WIFIssid_new);
|
Serial.println(WIFIssid_new);
|
||||||
|
Serial.println(WIFIssid);
|
||||||
Serial.print("WIFIpassword: ");
|
Serial.print("WIFIpassword: ");
|
||||||
Serial.println(WIFIpassword_new);
|
Serial.println(WIFIpassword_new);
|
||||||
|
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];
|
char rofl[32];
|
||||||
EEPROM.get(1, rofl);
|
EEPROM.get(0, rofl);
|
||||||
Serial.println("READ EEPROM WIFIssid");
|
Serial.println("READ EEPROM WIFIssid");
|
||||||
Serial.println(rofl);
|
Serial.println(rofl);
|
||||||
|
|
||||||
Serial.println("READ EEPROM configured");
|
Serial.println("READ EEPROM WIFIpassword");
|
||||||
bool lol;
|
char lol[64];
|
||||||
EEPROM.get(0, lol);
|
EEPROM.get(32, lol);
|
||||||
Serial.println(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