|
|
@ -32,16 +32,11 @@ WebServer otaserver(80);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
bool standalone = true;
|
|
|
|
bool standalone = true;
|
|
|
|
char MQTT_BASE_TOPIC[20];
|
|
|
|
char MQTT_BASE_TOPIC[20];
|
|
|
|
char AVAILABILITY_TOPIC[40];
|
|
|
|
|
|
|
|
uint8_t base_topic_length = 0;
|
|
|
|
uint8_t base_topic_length = 0;
|
|
|
|
char STATE_REQUEST_TOPIC[40];
|
|
|
|
char STATE_REQUEST_TOPIC[40];
|
|
|
|
bool MQTT_USE_AUTH = false;
|
|
|
|
bool MQTT_USE_AUTH = false;
|
|
|
|
char MQTT_USERNAME[32];
|
|
|
|
char MQTT_USERNAME[32];
|
|
|
|
char MQTT_PASSWORD[32];
|
|
|
|
char MQTT_PASSWORD[32];
|
|
|
|
#ifdef ENABLE_WEBUI
|
|
|
|
|
|
|
|
char WEBUI_USERNAME[32];
|
|
|
|
|
|
|
|
char WEBUI_PASSWORD[32];
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
uint8_t utc_offset = 7;
|
|
|
|
uint8_t utc_offset = 7;
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
float current_room_temp = 0;
|
|
|
|
float current_room_temp = 0;
|
|
|
@ -138,8 +133,6 @@ char DAC_VALUE_TOPIC[75];
|
|
|
|
#define EEPROM_ADDRESS_ADC_REPORT_STATE 187 // 8bytes, thru 194
|
|
|
|
#define EEPROM_ADDRESS_ADC_REPORT_STATE 187 // 8bytes, thru 194
|
|
|
|
#define EEPROM_ADDRESS_DAC_STATE 195 // 4bytes, thru 198
|
|
|
|
#define EEPROM_ADDRESS_DAC_STATE 195 // 4bytes, thru 198
|
|
|
|
#define EEPROM_ADDRESS_DAC_VALUE 199 // 8bytes, thru 206
|
|
|
|
#define EEPROM_ADDRESS_DAC_VALUE 199 // 8bytes, thru 206
|
|
|
|
#define EEPROM_ADDRESS_WEBUI_USERNAME 207 // 32bytes, thru 238
|
|
|
|
|
|
|
|
#define EEPROM_ADDRESS_WEBUI_PASSWORD 239 // 32bytes, thru 270
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char PWM_STATE_TOPIC[75];
|
|
|
|
char PWM_STATE_TOPIC[75];
|
|
|
|
char PWM_VALUE_TOPIC[75];
|
|
|
|
char PWM_VALUE_TOPIC[75];
|
|
|
@ -183,9 +176,6 @@ void setup()
|
|
|
|
Wire.setClock(400000);
|
|
|
|
Wire.setClock(400000);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
io_begin();
|
|
|
|
io_begin();
|
|
|
|
#ifdef VIRTUAL_INTERRUPT_PRELOAD
|
|
|
|
|
|
|
|
virtual_interrupt_preload();
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
eeprom_retrieve_init();
|
|
|
|
eeprom_retrieve_init();
|
|
|
|
user_pre_init();
|
|
|
|
user_pre_init();
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
@ -249,18 +239,6 @@ void loop()
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void eeprom_retrieve_init()
|
|
|
|
void eeprom_retrieve_init()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_WEBUI
|
|
|
|
|
|
|
|
ESPMega_FRAM.read(EEPROM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32);
|
|
|
|
|
|
|
|
ESPMega_FRAM.read(EEPROM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
|
|
|
|
|
|
|
|
if(strlen(WEBUI_USERNAME)==0) {
|
|
|
|
|
|
|
|
strcpy(WEBUI_USERNAME,"admin");
|
|
|
|
|
|
|
|
ESPMega_FRAM.write(EEPROM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strlen(WEBUI_PASSWORD)==0) {
|
|
|
|
|
|
|
|
strcpy(WEBUI_PASSWORD,"admin");
|
|
|
|
|
|
|
|
ESPMega_FRAM.write(EEPROM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// EEPROM Data Retrival
|
|
|
|
// EEPROM Data Retrival
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
ac_mode = ESPMega_FRAM.read8(EEPROM_ADDRESS_AC_MODE);
|
|
|
|
ac_mode = ESPMega_FRAM.read8(EEPROM_ADDRESS_AC_MODE);
|
|
|
@ -344,8 +322,6 @@ void eeprom_retrieve_init()
|
|
|
|
strcat(PWM_VALUE_TOPIC, "/pwm/00/value");
|
|
|
|
strcat(PWM_VALUE_TOPIC, "/pwm/00/value");
|
|
|
|
memcpy(INPUTS_TOPIC, MQTT_BASE_TOPIC, 20);
|
|
|
|
memcpy(INPUTS_TOPIC, MQTT_BASE_TOPIC, 20);
|
|
|
|
strcat(INPUTS_TOPIC, "/input/00");
|
|
|
|
strcat(INPUTS_TOPIC, "/input/00");
|
|
|
|
memcpy(AVAILABILITY_TOPIC, MQTT_BASE_TOPIC, 20);
|
|
|
|
|
|
|
|
strcat(AVAILABILITY_TOPIC, "/availability");
|
|
|
|
|
|
|
|
#ifdef ENABLE_ANALOG_MODULE
|
|
|
|
#ifdef ENABLE_ANALOG_MODULE
|
|
|
|
memcpy(ADC_COMMAND_TOPIC, MQTT_BASE_TOPIC, 20);
|
|
|
|
memcpy(ADC_COMMAND_TOPIC, MQTT_BASE_TOPIC, 20);
|
|
|
|
strcat(ADC_COMMAND_TOPIC, "/adc/00/set/state");
|
|
|
|
strcat(ADC_COMMAND_TOPIC, "/adc/00/set/state");
|
|
|
@ -387,8 +363,6 @@ void ota_begin()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
otaserver.on("/", HTTP_GET, []()
|
|
|
|
otaserver.on("/", HTTP_GET, []()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!otaserver.authenticate(WEBUI_USERNAME, WEBUI_PASSWORD))
|
|
|
|
|
|
|
|
return otaserver.requestAuthentication();
|
|
|
|
|
|
|
|
otaserver.sendHeader("Connection", "close");
|
|
|
|
otaserver.sendHeader("Connection", "close");
|
|
|
|
String otabuffer = ota_part1;
|
|
|
|
String otabuffer = ota_part1;
|
|
|
|
otabuffer+=ota_part2_1+"Hostname"+ota_part2_2+String(HOSTNAME)+ota_part2_3;
|
|
|
|
otabuffer+=ota_part2_1+"Hostname"+ota_part2_2+String(HOSTNAME)+ota_part2_3;
|
|
|
@ -406,8 +380,6 @@ void ota_begin()
|
|
|
|
otaserver.send(200, "text/html", otabuffer); });
|
|
|
|
otaserver.send(200, "text/html", otabuffer); });
|
|
|
|
otaserver.on("/config", HTTP_GET, []()
|
|
|
|
otaserver.on("/config", HTTP_GET, []()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!otaserver.authenticate(WEBUI_USERNAME, WEBUI_PASSWORD))
|
|
|
|
|
|
|
|
return otaserver.requestAuthentication();
|
|
|
|
|
|
|
|
otaserver.sendHeader("Connection", "close");
|
|
|
|
otaserver.sendHeader("Connection", "close");
|
|
|
|
String configbuffer = config_part1;
|
|
|
|
String configbuffer = config_part1;
|
|
|
|
configbuffer+=config_txt_part1+"IP Address"+config_txt_part2+"text"+config_txt_part3+"dev_ip"+config_txt_part4+"dev_ip"+config_txt_part5+IP.toString()+config_txt_part6;
|
|
|
|
configbuffer+=config_txt_part1+"IP Address"+config_txt_part2+"text"+config_txt_part3+"dev_ip"+config_txt_part4+"dev_ip"+config_txt_part5+IP.toString()+config_txt_part6;
|
|
|
@ -421,15 +393,11 @@ void ota_begin()
|
|
|
|
configbuffer+=config_txt_part1+"BMS Server - Username"+config_txt_part2+"text"+config_txt_part3+"bms_username"+config_txt_part4+"bms_username"+config_txt_part5+String(MQTT_USERNAME)+config_txt_part6;
|
|
|
|
configbuffer+=config_txt_part1+"BMS Server - Username"+config_txt_part2+"text"+config_txt_part3+"bms_username"+config_txt_part4+"bms_username"+config_txt_part5+String(MQTT_USERNAME)+config_txt_part6;
|
|
|
|
configbuffer+=config_txt_part1+"BMS Server - Password"+config_txt_part2+"password"+config_txt_part3+"bms_password"+config_txt_part4+"bms_password"+config_txt_part5+String(MQTT_PASSWORD)+config_txt_part6;
|
|
|
|
configbuffer+=config_txt_part1+"BMS Server - Password"+config_txt_part2+"password"+config_txt_part3+"bms_password"+config_txt_part4+"bms_password"+config_txt_part5+String(MQTT_PASSWORD)+config_txt_part6;
|
|
|
|
configbuffer+=config_txt_part1+"BMS Server - Endpoint"+config_txt_part2+"text"+config_txt_part3+"bms_endpoint"+config_txt_part4+"bms_endpoint"+config_txt_part5+String(MQTT_BASE_TOPIC)+config_txt_part6;
|
|
|
|
configbuffer+=config_txt_part1+"BMS Server - Endpoint"+config_txt_part2+"text"+config_txt_part3+"bms_endpoint"+config_txt_part4+"bms_endpoint"+config_txt_part5+String(MQTT_BASE_TOPIC)+config_txt_part6;
|
|
|
|
configbuffer+=config_txt_part1+"WebUI Username"+config_txt_part2+"text"+config_txt_part3+"webui_username"+config_txt_part4+"webui_username"+config_txt_part5+String(WEBUI_USERNAME)+config_txt_part6;
|
|
|
|
|
|
|
|
configbuffer+=config_txt_part1+"WebUI Password"+config_txt_part2+"password"+config_txt_part3+"webui_password"+config_txt_part4+"webui_password"+config_txt_part5+String(WEBUI_PASSWORD)+config_txt_part6;
|
|
|
|
|
|
|
|
configbuffer+=config_part2;
|
|
|
|
configbuffer+=config_part2;
|
|
|
|
otaserver.send(200, "text/html", configbuffer); });
|
|
|
|
otaserver.send(200, "text/html", configbuffer); });
|
|
|
|
|
|
|
|
|
|
|
|
otaserver.on("/save_config", HTTP_GET, []()
|
|
|
|
otaserver.on("/save_config", HTTP_GET, []()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!otaserver.authenticate(WEBUI_USERNAME, WEBUI_PASSWORD))
|
|
|
|
|
|
|
|
return otaserver.requestAuthentication();
|
|
|
|
|
|
|
|
otaserver.sendHeader("Connection", "close");
|
|
|
|
otaserver.sendHeader("Connection", "close");
|
|
|
|
String configbuffer = "Configuration Saved. Rebooting . . .";
|
|
|
|
String configbuffer = "Configuration Saved. Rebooting . . .";
|
|
|
|
otaserver.send(200, "text/html", configbuffer);
|
|
|
|
otaserver.send(200, "text/html", configbuffer);
|
|
|
@ -462,10 +430,6 @@ void ota_begin()
|
|
|
|
} else if(!arg.compareTo("bms_useauth")) {
|
|
|
|
} else if(!arg.compareTo("bms_useauth")) {
|
|
|
|
if(!value.compareTo("yes"))
|
|
|
|
if(!value.compareTo("yes"))
|
|
|
|
use_auth = true;
|
|
|
|
use_auth = true;
|
|
|
|
} else if(!arg.compareTo("webui_username")) {
|
|
|
|
|
|
|
|
ESPMega_FRAM.write(EEPROM_ADDRESS_WEBUI_USERNAME, (uint8_t *)value.c_str(), value.length()+1);
|
|
|
|
|
|
|
|
} else if(!arg.compareTo("webui_password")) {
|
|
|
|
|
|
|
|
ESPMega_FRAM.write(EEPROM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)value.c_str(), value.length()+1);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set_mqtt_useauth(use_auth);
|
|
|
|
set_mqtt_useauth(use_auth);
|
|
|
@ -476,8 +440,6 @@ void ota_begin()
|
|
|
|
otaserver.on(
|
|
|
|
otaserver.on(
|
|
|
|
"/update", HTTP_POST, []()
|
|
|
|
"/update", HTTP_POST, []()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!otaserver.authenticate(WEBUI_USERNAME, WEBUI_PASSWORD))
|
|
|
|
|
|
|
|
return otaserver.requestAuthentication();
|
|
|
|
|
|
|
|
otaserver.sendHeader("Connection", "close");
|
|
|
|
otaserver.sendHeader("Connection", "close");
|
|
|
|
otaserver.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
|
|
|
|
otaserver.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
|
|
|
|
ESP.restart(); },
|
|
|
|
ESP.restart(); },
|
|
|
@ -607,14 +569,13 @@ void mqtt_connect()
|
|
|
|
Serial.print("MQTT not connected, connecting . . .\n");
|
|
|
|
Serial.print("MQTT not connected, connecting . . .\n");
|
|
|
|
lcd_send_stop_bit();
|
|
|
|
lcd_send_stop_bit();
|
|
|
|
if (MQTT_USE_AUTH)
|
|
|
|
if (MQTT_USE_AUTH)
|
|
|
|
mqtt.connect(HOSTNAME, MQTT_USERNAME, MQTT_PASSWORD, AVAILABILITY_TOPIC, 0, true, "offline");
|
|
|
|
mqtt.connect(HOSTNAME, MQTT_USERNAME, MQTT_PASSWORD);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
mqtt.connect(HOSTNAME, AVAILABILITY_TOPIC, 0, true, "offline");
|
|
|
|
mqtt.connect(HOSTNAME);
|
|
|
|
if (mqtt.connected())
|
|
|
|
if (mqtt.connected())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mqtt_subscribe();
|
|
|
|
mqtt_subscribe();
|
|
|
|
Serial.print("MQTT connected\n");
|
|
|
|
Serial.print("MQTT connected\n");
|
|
|
|
mqtt.publish(AVAILABILITY_TOPIC, "online", true);
|
|
|
|
|
|
|
|
lcd_send_stop_bit();
|
|
|
|
lcd_send_stop_bit();
|
|
|
|
publish_pwm_states();
|
|
|
|
publish_pwm_states();
|
|
|
|
publish_input_states();
|
|
|
|
publish_input_states();
|
|
|
@ -1837,18 +1798,6 @@ void set_mqtt_useauth(bool use_auth)
|
|
|
|
ESPMega_FRAM.write8(EEPROM_ADDRESS_MQTT_USEAUTH, MQTT_USE_AUTH);
|
|
|
|
ESPMega_FRAM.write8(EEPROM_ADDRESS_MQTT_USEAUTH, MQTT_USE_AUTH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void set_webui_username(String username)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
username.toCharArray(WEBUI_USERNAME, 32);
|
|
|
|
|
|
|
|
ESPMega_FRAM.write(EEPROM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void set_webui_password(String password)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
password.toCharArray(WEBUI_PASSWORD, 32);
|
|
|
|
|
|
|
|
ESPMega_FRAM.write(EEPROM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Resets the device to factory default settings.
|
|
|
|
* @brief Resets the device to factory default settings.
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -1884,9 +1833,6 @@ void factory_reset()
|
|
|
|
set_ip("192.168.0.10");
|
|
|
|
set_ip("192.168.0.10");
|
|
|
|
set_gw("192.168.0.1");
|
|
|
|
set_gw("192.168.0.1");
|
|
|
|
set_netmask("255.255.255.0");
|
|
|
|
set_netmask("255.255.255.0");
|
|
|
|
set_webui_username("admin");
|
|
|
|
|
|
|
|
set_webui_password("admin");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Reboot
|
|
|
|
// Reboot
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
lcd_send_stop_bit();
|
|
|
|
lcd_send_stop_bit();
|
|
|
@ -2257,9 +2203,3 @@ bool dac_get_state(int id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void virtual_interrupt_preload() {
|
|
|
|
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
|
|
|
|
virtual_interupt_state[i] = ESPMega_digitalRead(virtual_interrupt_pins[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|