Added the functionality to rewrite the ip config by the web interface.
This commit is contained in:
parent
c79e15d7a1
commit
5d1ea14e2e
4 changed files with 128 additions and 8 deletions
|
@ -5,7 +5,7 @@
|
|||
|
||||
#define LOCAL_TIMEZONE_STRING "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00" // Berlin, Germany - https://sites.google.com/a/usapiens.com/opnode/time-zones
|
||||
|
||||
//#define DEVELOPMENT
|
||||
#define DEVELOPMENT
|
||||
|
||||
#define LIGHT_NAME_STR "Lumini/Lominie Pixie30/P30 light control" // default light name
|
||||
|
||||
|
@ -17,6 +17,10 @@
|
|||
#define EEPROM_DYNAMIC_IP_ADDRESS 3
|
||||
#define EEPROM_LAST_STATE_ADDRESS 4 // the first "last state" information for the first light
|
||||
#define EEPROM_TIMING_DATA_ADDRESS (EEPROM_LAST_STATE_ADDRESS + LIGHTS_COUNT) // Stored data date per light ELE_USED; HH; MM; CH1; CH2; CH3; CH4;
|
||||
#define EEPROM_IP_ADDRESS (EEPROM_TIMING_DATA_ADDRESS + 60) // 10 blocks of 6 byte per timing control data block = 60 byte EEPROM space
|
||||
#define EEPROM_GW_ADDRESS (EEPROM_IP_ADDRESS + 4) // step 4 byte further IP
|
||||
#define EEPROM_NM_ADDRESS (EEPROM_GW_ADDRESS + 4) // step 4 byte further GW
|
||||
#define EEPROM_DNS_ADDRESS (EEPROM_NM_ADDRESS + 4) // step 4 byte further NM
|
||||
|
||||
#define BRI_MOD_STEPS_PER_SEC 25
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
//********* preprocessor block *********//
|
||||
|
||||
#ifdef DEVELOPMENT
|
||||
#define LIGHT_NAME "Dimmable Hue Light (DEV)"
|
||||
#define LIGHT_NAME "Lumini/Lominie Pixie30/P30 light control (DEV)"
|
||||
#else
|
||||
#define LIGHT_NAME LIGHT_NAME_STR
|
||||
#endif
|
||||
|
@ -103,13 +103,13 @@ void setup()
|
|||
Serial.printf("Datei Name: %s, Größe: %s\n", fileName.c_str(), formatBytes(fileSize).c_str());
|
||||
}
|
||||
|
||||
read_eeprom_config();
|
||||
|
||||
if (EEPROM.read(EEPROM_DYNAMIC_IP_ADDRESS) == 0)
|
||||
{
|
||||
{ // static ip is used
|
||||
WiFi.config(strip_ip, gateway_ip, subnet_mask, dns);
|
||||
}
|
||||
|
||||
read_eeprom_config();
|
||||
|
||||
for (int j = 0; j < 200; j++)
|
||||
{
|
||||
lightEngine();
|
||||
|
@ -260,6 +260,49 @@ void read_eeprom_config()
|
|||
Serial.println("light[" + (String)light + "] = " + (String)light_state[light]);
|
||||
}
|
||||
|
||||
// read IP, NetMask, GateWay and DNS from EEPROM or store default value
|
||||
// only IPv4 is supported
|
||||
if (EEPROM.read(EEPROM_IP_ADDRESS) == 255)
|
||||
{
|
||||
for (uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
EEPROM.write(EEPROM_IP_ADDRESS + i, strip_ip[i]);
|
||||
EEPROM.write(EEPROM_GW_ADDRESS + i, gateway_ip[i]);
|
||||
EEPROM.write(EEPROM_NM_ADDRESS + i, subnet_mask[i]);
|
||||
EEPROM.write(EEPROM_DNS_ADDRESS + i, dns[i]);
|
||||
}
|
||||
} else {
|
||||
if (EEPROM.read(EEPROM_DYNAMIC_IP_ADDRESS) == 0)
|
||||
{
|
||||
for (uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
strip_ip[i] = EEPROM.read(EEPROM_IP_ADDRESS + i);
|
||||
gateway_ip[i] = EEPROM.read(EEPROM_GW_ADDRESS + i);
|
||||
subnet_mask[i] = EEPROM.read(EEPROM_NM_ADDRESS + i);
|
||||
dns[i] = EEPROM.read(EEPROM_DNS_ADDRESS + i);
|
||||
}
|
||||
Serial.println("IP from EEPROM: " +
|
||||
(String)strip_ip[0] + "." +
|
||||
(String)strip_ip[1] + "." +
|
||||
(String)strip_ip[2] + "." +
|
||||
(String)strip_ip[3]);
|
||||
Serial.println("GW from EEPROM: " +
|
||||
(String)gateway_ip[0] + "." +
|
||||
(String)gateway_ip[1] + "." +
|
||||
(String)gateway_ip[2] + "." +
|
||||
(String)gateway_ip[3]);
|
||||
Serial.println("NetMask from EEPROM: " +
|
||||
(String)subnet_mask[0] + "." +
|
||||
(String)subnet_mask[1] + "." +
|
||||
(String)subnet_mask[2] + "." +
|
||||
(String)subnet_mask[3]);
|
||||
Serial.println("DNS from EEPROM: " +
|
||||
(String)dns[0] + "." +
|
||||
(String)dns[1] + "." +
|
||||
(String)dns[2] + "." +
|
||||
(String)dns[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//********************************//
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
|
||||
bool tc_testOngoing = false;
|
||||
|
||||
uint32_t tc_last_check = 60000;
|
||||
uint32_t tc_last_check = TIME_CHECK_INTERVAL_MS; // initially check if new data needs to be read
|
||||
|
||||
uint8_t current_target_data_block = 255;
|
||||
uint8_t current_target_data_block = 255; // no data processed yet
|
||||
|
||||
WiFiUDP ntpUDP;
|
||||
NTPClient timeClient(ntpUDP, MY_NTP_SERVER);
|
||||
|
|
|
@ -286,7 +286,8 @@ void init_webserver()
|
|||
}
|
||||
}
|
||||
|
||||
if (server.hasArg("dip")) {
|
||||
if (server.hasArg("dip"))
|
||||
{
|
||||
uint8_t tmp = EEPROM.read(EEPROM_DYNAMIC_IP_ADDRESS);
|
||||
uint8_t tmp2 = (server.arg("dip") == "true" ? 1 : 0);
|
||||
if (tmp != tmp2)
|
||||
|
@ -298,6 +299,78 @@ void init_webserver()
|
|||
}
|
||||
}
|
||||
|
||||
if (server.hasArg("ip"))
|
||||
{
|
||||
strip_ip.fromString(server.arg("ip"));
|
||||
|
||||
// make it persistent to eeprom
|
||||
EEPROM.write(EEPROM_IP_ADDRESS, strip_ip[0]);
|
||||
EEPROM.write(EEPROM_IP_ADDRESS+1, strip_ip[1]);
|
||||
EEPROM.write(EEPROM_IP_ADDRESS+2, strip_ip[2]);
|
||||
EEPROM.write(EEPROM_IP_ADDRESS+3, strip_ip[3]);
|
||||
EEPROM.commit();
|
||||
|
||||
Serial.println("IP set to: " +
|
||||
(String)EEPROM.read(EEPROM_IP_ADDRESS) + "." +
|
||||
(String)EEPROM.read(EEPROM_IP_ADDRESS+1) + "." +
|
||||
(String)EEPROM.read(EEPROM_IP_ADDRESS+2) + "." +
|
||||
(String)EEPROM.read(EEPROM_IP_ADDRESS+3));
|
||||
}
|
||||
|
||||
if (server.hasArg("gwip"))
|
||||
{
|
||||
gateway_ip.fromString(server.arg("gwip"));
|
||||
|
||||
// make it persistent to eeprom
|
||||
EEPROM.write(EEPROM_GW_ADDRESS, gateway_ip[0]);
|
||||
EEPROM.write(EEPROM_GW_ADDRESS+1, gateway_ip[1]);
|
||||
EEPROM.write(EEPROM_GW_ADDRESS+2, gateway_ip[2]);
|
||||
EEPROM.write(EEPROM_GW_ADDRESS+3, gateway_ip[3]);
|
||||
EEPROM.commit();
|
||||
|
||||
Serial.println("GW set to: " +
|
||||
(String)EEPROM.read(EEPROM_GW_ADDRESS) + "." +
|
||||
(String)EEPROM.read(EEPROM_GW_ADDRESS+1) + "." +
|
||||
(String)EEPROM.read(EEPROM_GW_ADDRESS+2) + "." +
|
||||
(String)EEPROM.read(EEPROM_GW_ADDRESS+3));
|
||||
}
|
||||
|
||||
if (server.hasArg("netmas"))
|
||||
{
|
||||
subnet_mask.fromString(server.arg("netmas"));
|
||||
|
||||
// make it persistent to eeprom
|
||||
EEPROM.write(EEPROM_NM_ADDRESS, subnet_mask[0]);
|
||||
EEPROM.write(EEPROM_NM_ADDRESS+1, subnet_mask[1]);
|
||||
EEPROM.write(EEPROM_NM_ADDRESS+2, subnet_mask[2]);
|
||||
EEPROM.write(EEPROM_NM_ADDRESS+3, subnet_mask[3]);
|
||||
EEPROM.commit();
|
||||
|
||||
Serial.println("NetMask set to: " +
|
||||
(String)EEPROM.read(EEPROM_NM_ADDRESS) + "." +
|
||||
(String)EEPROM.read(EEPROM_NM_ADDRESS+1) + "." +
|
||||
(String)EEPROM.read(EEPROM_NM_ADDRESS+2) + "." +
|
||||
(String)EEPROM.read(EEPROM_NM_ADDRESS+3));
|
||||
}
|
||||
|
||||
if (server.hasArg("dns"))
|
||||
{
|
||||
dns.fromString(server.arg("dns"));
|
||||
|
||||
// make it persistent to eeprom
|
||||
EEPROM.write(EEPROM_DNS_ADDRESS, dns[0]);
|
||||
EEPROM.write(EEPROM_DNS_ADDRESS+1, dns[1]);
|
||||
EEPROM.write(EEPROM_DNS_ADDRESS+2, dns[2]);
|
||||
EEPROM.write(EEPROM_DNS_ADDRESS+3, dns[3]);
|
||||
EEPROM.commit();
|
||||
|
||||
Serial.println("DNS set to: " +
|
||||
(String)EEPROM.read(EEPROM_DNS_ADDRESS) + "." +
|
||||
(String)EEPROM.read(EEPROM_DNS_ADDRESS+1) + "." +
|
||||
(String)EEPROM.read(EEPROM_DNS_ADDRESS+2) + "." +
|
||||
(String)EEPROM.read(EEPROM_DNS_ADDRESS+3));
|
||||
}
|
||||
|
||||
// process the received data for every light
|
||||
for (int light = 0; light < LIGHTS_COUNT; light++)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue