EEPROM have its own header

This commit is contained in:
Mathieu Maret 2016-06-01 15:21:32 +02:00
parent 7e25978455
commit 075ed120aa
4 changed files with 19 additions and 13 deletions

View File

@ -0,0 +1,12 @@
#pragma once
int EepromSaveConfig(uint8_t bootMode, String ssid, String password, String host,
String mqttServer, String mqttUser, String mqttPasswd,
int mqttPort, int ip_config, uint32_t ip, uint32_t gw,
uint32_t mask, uint32_t dns, uint32_t dns2);
int EepromSaveBootMode(uint8_t bootMode);
void EepromReadConfig(uint8_t &bootMode, char **ssid, char **password, char **host,
char **mqttServer, char **mqttUser, char **mqttPasswd,
int &mqttPort, int &ip_config, uint32_t &ip, uint32_t &gw,
uint32_t &mask, uint32_t &dns, uint32_t &dns2);

View File

@ -4,7 +4,9 @@
IP_CONFIG could be 0 for DHCP, 1 for static IP_CONFIG could be 0 for DHCP, 1 for static
Setup mode is trigger by setting GPIO3 to ground or at first boot Setup mode is trigger by setting GPIO3 to ground or at first boot
*/ */
#include "EEPROM.h"
char eeprom[CONFIG_EEPROM_SIZE];
int EepromSaveConfig(uint8_t bootMode, String ssid, String password, String host, int EepromSaveConfig(uint8_t bootMode, String ssid, String password, String host,
String mqttServer, String mqttUser, String mqttPasswd, String mqttServer, String mqttUser, String mqttPasswd,
@ -50,8 +52,10 @@ void readConfElement(char** element, int &i) {
} while (i < CONFIG_EEPROM_SIZE && eeprom[i - 1] != ';'); } while (i < CONFIG_EEPROM_SIZE && eeprom[i - 1] != ';');
eeprom[i - 1] = '\0'; eeprom[i - 1] = '\0';
if (i >= CONFIG_EEPROM_SIZE) if (i >= CONFIG_EEPROM_SIZE){
SKETCH_DEBUG_PRINTLN("Looks like there is a configuration issue (too long)");
**element = '\0'; **element = '\0';
}
} }

View File

@ -45,12 +45,12 @@
#include "MQTT.h" #include "MQTT.h"
#include "Adafruit_MQTT.h" #include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h" #include "Adafruit_MQTT_Client.h"
#include "EEPROM.h"
extern "C" { extern "C" {
#include <user_interface.h> #include <user_interface.h>
} }
char eeprom[CONFIG_EEPROM_SIZE];
#define BOOTMODE_SETUP 0 #define BOOTMODE_SETUP 0
#define BOOTMODE_NORMAL 1 #define BOOTMODE_NORMAL 1
@ -75,17 +75,6 @@ void WebHandleOTA();
void WebHandleNotFound(); void WebHandleNotFound();
void WebSetupServer(int bootmode); void WebSetupServer(int bootmode);
/* EEPROM decl */
int EepromSaveConfig(uint8_t bootMode, String ssid, String password, String host,
String mqttServer, String mqttUser, String mqttPasswd,
int mqttPort, int ip_config, uint32_t ip, uint32_t gw,
uint32_t mask, uint32_t dns, uint32_t dns2);
int EepromSaveBootMode(uint8_t bootMode);
void EepromReadConfig(uint8_t &bootMode, char **ssid, char **password, char **host,
char **mqttServer, char **mqttUser, char **mqttPasswd,
int &mqttPort, int &ip_config, uint32_t &ip, uint32_t &gw,
uint32_t &mask, uint32_t &dns, uint32_t &dns2);
void WifiSetup(int bootmode, char *confSsid, char *confPassword, char *confHost, int ip_config, uint32_t ip, uint32_t gw, uint32_t mask, uint32_t dns, uint32_t dns2) { void WifiSetup(int bootmode, char *confSsid, char *confPassword, char *confHost, int ip_config, uint32_t ip, uint32_t gw, uint32_t mask, uint32_t dns, uint32_t dns2) {
IPAddress myIP; IPAddress myIP;

View File

@ -42,4 +42,5 @@
// EEPROM SIZE // EEPROM SIZE
// Max is 4096, but this amount will be allocated in RAM for reading its content
//#CONFIG_EEPROM_SIZE 256 //#CONFIG_EEPROM_SIZE 256