|
|
|
@ -2,10 +2,7 @@
|
|
|
|
|
|
|
|
|
|
// OS Configuration
|
|
|
|
|
// #define FASTBOOT
|
|
|
|
|
|
|
|
|
|
#ifndef ESPMEGA_REV
|
|
|
|
|
#define ESPMEGA_REV "ESPMega PRO R3.3b"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Network Connectivity
|
|
|
|
|
char HOSTNAME[15];
|
|
|
|
@ -15,9 +12,7 @@ IPAddress GATEWAY(0, 0, 0, 0);
|
|
|
|
|
IPAddress DNS(0, 0, 0, 0);
|
|
|
|
|
IPAddress MQTT_SERVER(0, 0, 0, 0);
|
|
|
|
|
uint16_t MQTT_PORT = 0;
|
|
|
|
|
#ifdef ENABLE_WEBUI
|
|
|
|
|
WebServer otaserver(80);
|
|
|
|
|
#endif
|
|
|
|
|
bool standalone = true;
|
|
|
|
|
// #define MQTT_BASE_TOPIC "/espmega/ProR3"
|
|
|
|
|
char MQTT_BASE_TOPIC[20];
|
|
|
|
@ -27,10 +22,8 @@ bool MQTT_USE_AUTH = false;
|
|
|
|
|
char MQTT_USERNAME[32];
|
|
|
|
|
char MQTT_PASSWORD[32];
|
|
|
|
|
uint8_t utc_offset = 7;
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
float current_room_temp = 0;
|
|
|
|
|
float current_room_humid = 0;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Inputs
|
|
|
|
|
#define VINT_COUNT 16
|
|
|
|
@ -54,19 +47,16 @@ const int PWM_CYCLE_VALUES[PWM_CYCLE_VALUES_COUNT] = {50, 125, 255};
|
|
|
|
|
char PWM_SET_STATE_TOPIC[70];
|
|
|
|
|
char PWM_SET_VALUE_TOPIC[70];
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
// LCD
|
|
|
|
|
int lcd_current_page = 1;
|
|
|
|
|
int lcd_pwmAdj_id = 0;
|
|
|
|
|
EasyNex panel(Serial);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Air Conditioner Control
|
|
|
|
|
/*
|
|
|
|
|
Mode 0: Off, 1: Cool, 2: Fan
|
|
|
|
|
Fan Speed 0: Auto, 1: High, 2: Mid, 3: Low
|
|
|
|
|
*/
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
#define DHT22_PIN 32
|
|
|
|
|
uint8_t ac_mode = 0;
|
|
|
|
|
uint8_t ac_fan_speed = 0;
|
|
|
|
@ -79,7 +69,6 @@ char AC_FAN_TOPIC[75];
|
|
|
|
|
char AC_TEMPERATURE_TOPIC[75];
|
|
|
|
|
char AC_ROOM_TEMPERATURE_TOPIC[75];
|
|
|
|
|
char AC_HUMIDITY_TOPIC[75];
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// EEPROM ADDRESS
|
|
|
|
|
#define EEPROM_ADDRESS_AC_MODE 0 // 01bytes
|
|
|
|
@ -107,9 +96,7 @@ WiFiClient eth;
|
|
|
|
|
PubSubClient mqtt_client(MQTT_SERVER, 1883, eth);
|
|
|
|
|
PubSubClientTools mqtt(mqtt_client);
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
DHTNEW env_sensor(DHT22_PIN);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
Thread mqtt_reconnector = Thread();
|
|
|
|
|
Thread environment_reporter = Thread();
|
|
|
|
@ -117,11 +104,9 @@ Thread eeprom_pwm_updater = Thread();
|
|
|
|
|
Thread user_timer_tick = Thread();
|
|
|
|
|
StaticThreadController<4> thread_controller(&mqtt_reconnector, &environment_reporter, &eeprom_pwm_updater, &user_timer_tick);
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
Thread top_bar_updater = Thread();
|
|
|
|
|
Thread page_updater = Thread();
|
|
|
|
|
StaticThreadController<2> lcd_thread_controller(&top_bar_updater, &page_updater);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
|
{
|
|
|
|
@ -129,19 +114,15 @@ void setup()
|
|
|
|
|
#ifdef ENABLE_EXTERNAL_LCD
|
|
|
|
|
Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
panel.begin(115200);
|
|
|
|
|
#endif
|
|
|
|
|
Serial.println("ESPMega R3 Initializing");
|
|
|
|
|
ESPMega_begin();
|
|
|
|
|
io_begin();
|
|
|
|
|
eeprom_retrieve_init();
|
|
|
|
|
user_pre_init();
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
lcd_send_stop_bit();
|
|
|
|
|
lcd_init();
|
|
|
|
|
lcd_begin();
|
|
|
|
|
#endif
|
|
|
|
|
check_boot_reset();
|
|
|
|
|
#ifdef ENABLE_EXTERNAL_LCD
|
|
|
|
|
Serial2.print("rest");
|
|
|
|
@ -151,11 +132,9 @@ void setup()
|
|
|
|
|
#endif
|
|
|
|
|
lcd_send_command("boot_state.txt=\"Core Initializing . . .\"");
|
|
|
|
|
Serial.println("Initializing Infrared . . .");
|
|
|
|
|
#ifdef ENABLE_IR_MODULE
|
|
|
|
|
lcd_send_command("boot_state.txt=\"Infrared Initializing . . .\"");
|
|
|
|
|
IrReceiver.begin(IR_RECIEVE_PIN);
|
|
|
|
|
IrSender.begin(IR_SEND_PIN);
|
|
|
|
|
#endif
|
|
|
|
|
lcd_send_command("boot_state.txt=\"Network Initializing . . .\"");
|
|
|
|
|
network_begin();
|
|
|
|
|
lcd_send_command("boot_state.txt=\"IoT Core Initializing . . .\"");
|
|
|
|
@ -164,9 +143,7 @@ void setup()
|
|
|
|
|
mqtt_connect();
|
|
|
|
|
lcd_send_command("boot_state.txt=\"Threads Initializing . . .\"");
|
|
|
|
|
thread_initialization();
|
|
|
|
|
#ifdef ENABLE_WEBUI
|
|
|
|
|
ota_begin();
|
|
|
|
|
#endif
|
|
|
|
|
Serial.println("Initialization Completed.");
|
|
|
|
|
Serial.println("Jumping to User Code.");
|
|
|
|
|
user_init();
|
|
|
|
@ -178,29 +155,20 @@ void loop()
|
|
|
|
|
virtual_interrupt_loop();
|
|
|
|
|
mqtt_client.loop();
|
|
|
|
|
ESPMega_loop();
|
|
|
|
|
#ifdef ENABLE_IR_MODULE
|
|
|
|
|
ir_loop();
|
|
|
|
|
#endif
|
|
|
|
|
thread_controller.run();
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
lcd_loop();
|
|
|
|
|
#endif
|
|
|
|
|
user_loop();
|
|
|
|
|
#ifdef ENABLE_WEBUI
|
|
|
|
|
otaserver.handleClient();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void eeprom_retrieve_init()
|
|
|
|
|
{
|
|
|
|
|
// EEPROM Data Retrival
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
ac_mode = ESPMega_FRAM.read8(EEPROM_ADDRESS_AC_MODE);
|
|
|
|
|
ac_temperature = ESPMega_FRAM.read8(EEPROM_ADDRESS_AC_TEMPERATURE);
|
|
|
|
|
ac_fan_speed = ESPMega_FRAM.read8(EEPROM_ADDRESS_AC_FAN_SPEED);
|
|
|
|
|
#endif
|
|
|
|
|
// EEPROM Data Retrival Validation
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
if (ac_mode > 2)
|
|
|
|
|
{
|
|
|
|
|
ac_mode = 0;
|
|
|
|
@ -217,7 +185,6 @@ void eeprom_retrieve_init()
|
|
|
|
|
ESPMega_FRAM.write8(EEPROM_ADDRESS_AC_TEMPERATURE, ac_fan_speed);
|
|
|
|
|
}
|
|
|
|
|
ac_set_state(ac_mode, ac_temperature, ac_fan_speed);
|
|
|
|
|
#endif
|
|
|
|
|
ESPMega_FRAM.read(EEPROM_ADDRESS_PWM_STATE, pwm_states_eeprom, 16);
|
|
|
|
|
memcpy(pwm_states, pwm_states_eeprom, 16);
|
|
|
|
|
ESPMega_FRAM.read(EEPROM_ADDRESS_PWM_VALUE, pwm_values_eeprom, 32);
|
|
|
|
@ -252,7 +219,6 @@ void eeprom_retrieve_init()
|
|
|
|
|
strcat(PWM_SET_STATE_TOPIC, "/pwm/00/set/state");
|
|
|
|
|
memcpy(PWM_SET_VALUE_TOPIC, MQTT_BASE_TOPIC, 20);
|
|
|
|
|
strcat(PWM_SET_VALUE_TOPIC, "/pwm/00/set/value");
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
memcpy(AC_SET_MODE_TOPIC, MQTT_BASE_TOPIC, 20);
|
|
|
|
|
strcat(AC_SET_MODE_TOPIC, "/ac/set/mode");
|
|
|
|
|
memcpy(AC_SET_FAN_TOPIC, MQTT_BASE_TOPIC, 20);
|
|
|
|
@ -269,7 +235,6 @@ void eeprom_retrieve_init()
|
|
|
|
|
strcat(AC_ROOM_TEMPERATURE_TOPIC, "/ac/room_temperature");
|
|
|
|
|
memcpy(AC_HUMIDITY_TOPIC, MQTT_BASE_TOPIC, 20);
|
|
|
|
|
strcat(AC_HUMIDITY_TOPIC, "/ac/humidity");
|
|
|
|
|
#endif
|
|
|
|
|
memcpy(PWM_STATE_TOPIC, MQTT_BASE_TOPIC, 20);
|
|
|
|
|
strcat(PWM_STATE_TOPIC, "/pwm/00/state");
|
|
|
|
|
memcpy(PWM_VALUE_TOPIC, MQTT_BASE_TOPIC, 20);
|
|
|
|
@ -278,7 +243,6 @@ void eeprom_retrieve_init()
|
|
|
|
|
strcat(INPUTS_TOPIC, "/input/00");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_WEBUI
|
|
|
|
|
void ota_begin()
|
|
|
|
|
{
|
|
|
|
|
otaserver.on("/", HTTP_GET, []()
|
|
|
|
@ -355,7 +319,9 @@ void ota_begin()
|
|
|
|
|
set_mqtt_useauth(use_auth);
|
|
|
|
|
otaserver.send(200, "text/html", configbuffer);
|
|
|
|
|
delay(500);
|
|
|
|
|
ESP.restart(); });
|
|
|
|
|
ESP.restart();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
otaserver.on(
|
|
|
|
|
"/update", HTTP_POST, []()
|
|
|
|
@ -372,16 +338,12 @@ void ota_begin()
|
|
|
|
|
Serial.println(upload.currentSize);
|
|
|
|
|
|
|
|
|
|
String otafiletxt = "Downloading File : " + upload.filename;
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
lcd_send_stop_bit();
|
|
|
|
|
panel.writeStr("otatxt.txt", otafiletxt);
|
|
|
|
|
#endif
|
|
|
|
|
Serial.printf("Update: %s\n", upload.filename.c_str());
|
|
|
|
|
if (!Update.begin(UPDATE_SIZE_UNKNOWN))
|
|
|
|
|
{
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
panel.writeStr("otatxt.txt", "Update Failed, Rebooting . . .");
|
|
|
|
|
#endif
|
|
|
|
|
Update.printError(Serial);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -389,9 +351,7 @@ void ota_begin()
|
|
|
|
|
{
|
|
|
|
|
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize)
|
|
|
|
|
{
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
panel.writeStr("otatxt.txt", "Update Failed, Rebooting . . .");
|
|
|
|
|
#endif
|
|
|
|
|
Update.printError(Serial);
|
|
|
|
|
}
|
|
|
|
|
if (upload.currentSize != 0 && upload.totalSize != 0)
|
|
|
|
@ -400,41 +360,32 @@ void ota_begin()
|
|
|
|
|
uint32_t totalsize_kb = upload.totalSize / 1000;
|
|
|
|
|
uint32_t upload_pct = 100 * upload.totalSize / 1000000;
|
|
|
|
|
String otafiletxt = "Downloading File : " + upload.filename + " (" + String(totalsize_kb) + "KB)";
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
panel.writeNum("prog.val", upload_pct);
|
|
|
|
|
panel.writeStr("otatxt.txt", otafiletxt);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (upload.status == UPLOAD_FILE_END)
|
|
|
|
|
{
|
|
|
|
|
if (Update.end(true))
|
|
|
|
|
{
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
panel.writeStr("otatxt.txt", "Update Completed, Rebooting . . .");
|
|
|
|
|
#endif
|
|
|
|
|
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
panel.writeStr("otatxt.txt", "Update Failed, Rebooting . . .");
|
|
|
|
|
#endif
|
|
|
|
|
Update.printError(Serial);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
otaserver.begin();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void io_begin()
|
|
|
|
|
{
|
|
|
|
|
Serial.println("Initializing I/O . . .");
|
|
|
|
|
#ifdef ENABLE_IR_MODULE
|
|
|
|
|
pinMode(IR_RECIEVE_PIN, INPUT_PULLUP);
|
|
|
|
|
pinMode(IR_SEND_PIN, OUTPUT);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void network_begin()
|
|
|
|
@ -480,9 +431,7 @@ void mqtt_connect()
|
|
|
|
|
lcd_send_stop_bit();
|
|
|
|
|
publish_pwm_states();
|
|
|
|
|
publish_input_states();
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
publish_ac_state();
|
|
|
|
|
#endif
|
|
|
|
|
mqtt_connected_user_callback();
|
|
|
|
|
standalone = false;
|
|
|
|
|
ESPMega_updateTimeFromNTP();
|
|
|
|
@ -494,10 +443,8 @@ void mqtt_connect()
|
|
|
|
|
lcd_send_stop_bit();
|
|
|
|
|
}
|
|
|
|
|
lcd_send_stop_bit();
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
lcd_refresh();
|
|
|
|
|
lcd_top_bar_update();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -512,11 +459,9 @@ void mqtt_subscribe()
|
|
|
|
|
mqtt.subscribe(PWM_SET_STATE_TOPIC, pwm_state_callback);
|
|
|
|
|
mqtt.subscribe(PWM_SET_VALUE_TOPIC, pwm_value_callback);
|
|
|
|
|
}
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
mqtt.subscribe(AC_SET_FAN_TOPIC, ac_state_callback);
|
|
|
|
|
mqtt.subscribe(AC_SET_TEMPERATURE_TOPIC, ac_state_callback);
|
|
|
|
|
mqtt.subscribe(AC_SET_MODE_TOPIC, ac_state_callback);
|
|
|
|
|
#endif
|
|
|
|
|
mqtt.subscribe(STATE_REQUEST_TOPIC, state_request_callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -526,10 +471,8 @@ void thread_initialization()
|
|
|
|
|
Serial.println("Initializing MQTT Thread . . .");
|
|
|
|
|
mqtt_reconnector.onRun(mqtt_connect);
|
|
|
|
|
mqtt_reconnector.setInterval(15000);
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
environment_reporter.onRun(publish_env_state);
|
|
|
|
|
environment_reporter.setInterval(5000);
|
|
|
|
|
#endif
|
|
|
|
|
eeprom_pwm_updater.onRun(eeprom_pwm_update);
|
|
|
|
|
eeprom_pwm_updater.setInterval(1000);
|
|
|
|
|
user_timer_tick.onRun(timer_tick_callback);
|
|
|
|
@ -564,10 +507,9 @@ void virtual_interrupt_callback(int pin, int state)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
publish_input_state(pin, state);
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
// Serial.printf("Pin %d changed to %d\n", pin, state);
|
|
|
|
|
if (lcd_current_page == 2)
|
|
|
|
|
panel.writeNum("I" + String(pin) + ".val", state);
|
|
|
|
|
#endif
|
|
|
|
|
virtual_interrupt_user_callback(pin, state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -626,12 +568,10 @@ void pwm_set_state(int id, int state)
|
|
|
|
|
pwm_states[id] = state;
|
|
|
|
|
int pwm_value = pwm_values[id];
|
|
|
|
|
ESPMega_analogWrite(pwm_pins[id], state * (int)(pwm_linear_scaling_m[id] * pwm_value + pwm_linear_scaling_c[id]));
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
if (lcd_current_page == 3)
|
|
|
|
|
panel.writeNum("j" + String(id) + ".ppic", pwm_states[id] ? 33 : 48);
|
|
|
|
|
else if (lcd_current_page == 5 && id == lcd_pwmAdj_id)
|
|
|
|
|
panel.writeStr("pwm_state.txt", pwm_states[lcd_pwmAdj_id] ? "ON" : "OFF");
|
|
|
|
|
#endif
|
|
|
|
|
publish_pwm_state(id);
|
|
|
|
|
pwm_changed_user_callback(id);
|
|
|
|
|
}
|
|
|
|
@ -642,12 +582,10 @@ void pwm_set_value(int id, int value)
|
|
|
|
|
pwm_values[id] = value;
|
|
|
|
|
int pwm_state = pwm_states[id];
|
|
|
|
|
ESPMega_analogWrite(pwm_pins[id], pwm_state * (int)(pwm_linear_scaling_m[id] * value + pwm_linear_scaling_c[id]));
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
if (lcd_current_page == 3)
|
|
|
|
|
panel.writeNum("j" + String(id) + ".val", int(value / 4095.0 * 100.0));
|
|
|
|
|
else if (lcd_current_page == 5 && id == lcd_pwmAdj_id)
|
|
|
|
|
panel.writeNum("pwm_value.val", pwm_values[lcd_pwmAdj_id]);
|
|
|
|
|
#endif
|
|
|
|
|
publish_pwm_state(id);
|
|
|
|
|
pwm_changed_user_callback(id);
|
|
|
|
|
}
|
|
|
|
@ -730,23 +668,22 @@ void state_request_callback(String topic, String message)
|
|
|
|
|
{
|
|
|
|
|
publish_input_states();
|
|
|
|
|
publish_pwm_states();
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
publish_ac_state();
|
|
|
|
|
#endif
|
|
|
|
|
user_state_request_callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_IR_MODULE
|
|
|
|
|
void ir_loop()
|
|
|
|
|
{
|
|
|
|
|
if (IrReceiver.decode())
|
|
|
|
|
{
|
|
|
|
|
// Serial.println();
|
|
|
|
|
// IrReceiver.compensateAndPrintIRResultAsCArray(&Serial, false);
|
|
|
|
|
// Serial.println();
|
|
|
|
|
// Serial.println();
|
|
|
|
|
IrReceiver.resume();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
void publish_ac_state()
|
|
|
|
|
{
|
|
|
|
|
String temp = "";
|
|
|
|
@ -839,7 +776,7 @@ void ac_set_state(int mode, int temperature, int fan_speed)
|
|
|
|
|
ac_temperature = AC_MAX_TEMPERATURE;
|
|
|
|
|
ac_fan_speed = fan_speed;
|
|
|
|
|
temperature -= AC_MIN_TEMPERATURE;
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
|
|
|
|
|
if (lcd_current_page == 4)
|
|
|
|
|
{
|
|
|
|
|
lcd_ac_refresh_fan();
|
|
|
|
@ -849,7 +786,6 @@ void ac_set_state(int mode, int temperature, int fan_speed)
|
|
|
|
|
else
|
|
|
|
|
panel.writeStr("temp.txt", "--C");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
publish_ac_state();
|
|
|
|
|
uint8_t ac_datablock[3] = {ac_mode, ac_temperature, ac_fan_speed};
|
|
|
|
|
ESPMega_FRAM.write(0, ac_datablock, 3);
|
|
|
|
@ -881,7 +817,6 @@ void publish_env_state()
|
|
|
|
|
mqtt_client.loop();
|
|
|
|
|
mqtt.publish(String(AC_HUMIDITY_TOPIC), String(current_room_humid));
|
|
|
|
|
mqtt_client.loop();
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
if (lcd_current_page == 4)
|
|
|
|
|
{
|
|
|
|
|
Serial.printf("roomtemp.txt=\"%.01fC\"", current_room_temp);
|
|
|
|
@ -889,7 +824,6 @@ void publish_env_state()
|
|
|
|
|
Serial.printf("roomhumid.txt=\"%d%%\"", (int)current_room_humid);
|
|
|
|
|
lcd_send_stop_bit();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
mqtt.publish(String(AC_ROOM_TEMPERATURE_TOPIC), "ERROR");
|
|
|
|
@ -898,9 +832,7 @@ void publish_env_state()
|
|
|
|
|
mqtt_client.loop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
void lcd_begin()
|
|
|
|
|
{
|
|
|
|
|
top_bar_updater.onRun(lcd_top_bar_update);
|
|
|
|
@ -954,7 +886,6 @@ void lcd_refresh()
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
Serial.printf("roomtemp.txt=\"%.01fC\"", current_room_temp);
|
|
|
|
|
lcd_send_stop_bit();
|
|
|
|
|
Serial.printf("roomhumid.txt=\"%d%%\"", (int)current_room_humid);
|
|
|
|
@ -965,9 +896,6 @@ void lcd_refresh()
|
|
|
|
|
panel.writeStr("temp.txt", "--C");
|
|
|
|
|
lcd_ac_refresh_fan();
|
|
|
|
|
lcd_ac_refresh_mode();
|
|
|
|
|
#else
|
|
|
|
|
lcd_send_command("page climate_nomod");
|
|
|
|
|
#endif
|
|
|
|
|
case 5:
|
|
|
|
|
panel.writeStr("pwm_id.txt", String("P") + String(lcd_pwmAdj_id));
|
|
|
|
|
panel.writeStr("pwm_state.txt", pwm_states[lcd_pwmAdj_id] ? "ON" : "OFF");
|
|
|
|
@ -1001,7 +929,7 @@ void lcd_top_bar_update()
|
|
|
|
|
panel.writeNum("server.pic", standalone ? 4 : 5);
|
|
|
|
|
panel.writeNum("lan.pic", ETH.linkUp() ? 3 : 2);
|
|
|
|
|
}
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
|
|
|
|
|
void lcd_ac_refresh_mode()
|
|
|
|
|
{
|
|
|
|
|
// auto high mid low
|
|
|
|
@ -1017,7 +945,6 @@ void lcd_ac_refresh_fan()
|
|
|
|
|
panel.writeNum("fan_mid.pic", ac_fan_speed == 2 ? 20 : 21);
|
|
|
|
|
panel.writeNum("fan_high.pic", ac_fan_speed == 1 ? 16 : 17);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void trigger0()
|
|
|
|
|
{
|
|
|
|
@ -1048,70 +975,54 @@ void trigger3()
|
|
|
|
|
lcd_send_stop_bit();
|
|
|
|
|
pwm_set_value(lcd_pwmAdj_id, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void trigger4()
|
|
|
|
|
{
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
if (ac_temperature < AC_MAX_TEMPERATURE && ac_mode != 2)
|
|
|
|
|
ac_set_state(ac_mode, ac_temperature + 1, ac_fan_speed);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void trigger5()
|
|
|
|
|
{
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
if (ac_temperature > AC_MIN_TEMPERATURE && ac_mode != 2)
|
|
|
|
|
ac_set_state(ac_mode, ac_temperature - 1, ac_fan_speed);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void trigger6()
|
|
|
|
|
{
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
ac_set_state(ac_mode, ac_temperature, 0);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void trigger7()
|
|
|
|
|
{
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
ac_set_state(ac_mode, ac_temperature, 3);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void trigger8()
|
|
|
|
|
{
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
ac_set_state(ac_mode, ac_temperature, 2);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void trigger9()
|
|
|
|
|
{
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
ac_set_state(ac_mode, ac_temperature, 1);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void trigger10()
|
|
|
|
|
{
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
ac_set_state(1, ac_temperature, ac_fan_speed);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void trigger11()
|
|
|
|
|
{
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
ac_set_state(2, ac_temperature, ac_fan_speed);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void trigger12()
|
|
|
|
|
{
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
ac_set_state(0, ac_temperature, ac_fan_speed);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void trigger13()
|
|
|
|
|
{
|
|
|
|
|
set_ip(panel.readStr("ip_set.txt"));
|
|
|
|
@ -1141,7 +1052,6 @@ void trigger15()
|
|
|
|
|
delay(100);
|
|
|
|
|
ESP.restart();
|
|
|
|
|
}
|
|
|
|
|
#endif // End Internal LCD Code Block
|
|
|
|
|
|
|
|
|
|
void eeprom_pwm_update()
|
|
|
|
|
{
|
|
|
|
@ -1246,7 +1156,6 @@ boolean input_get_state(int id)
|
|
|
|
|
return virtual_interupt_state[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_CLIMATE_MODULE
|
|
|
|
|
uint8_t ac_get_temperature()
|
|
|
|
|
{
|
|
|
|
|
return ac_temperature;
|
|
|
|
@ -1259,7 +1168,6 @@ uint8_t ac_get_fan_speed()
|
|
|
|
|
{
|
|
|
|
|
return ac_fan_speed;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void eeprom_mqtt_username_retrieve()
|
|
|
|
|
{
|
|
|
|
@ -1289,47 +1197,34 @@ void set_mqtt_useauth(bool use_auth)
|
|
|
|
|
ESPMega_FRAM.write8(EEPROM_ADDRESS_MQTT_USEAUTH, MQTT_USE_AUTH);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void factory_reset()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 5; i > 0; i--)
|
|
|
|
|
{
|
|
|
|
|
if (digitalRead(2) == HIGH)
|
|
|
|
|
{
|
|
|
|
|
void factory_reset() {
|
|
|
|
|
for(int i=5;i>0;i--) {
|
|
|
|
|
if(digitalRead(2)==HIGH) {
|
|
|
|
|
lcd_send_command("boot_state.txt=\"Factory Reset Canceled, Restarting\"");
|
|
|
|
|
delay(5000);
|
|
|
|
|
ESP.restart();
|
|
|
|
|
}
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
Serial.printf("boot_state.txt=\"Factory Reset in %d\"",i);
|
|
|
|
|
lcd_send_stop_bit();
|
|
|
|
|
#endif
|
|
|
|
|
delay(1000);
|
|
|
|
|
}
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
lcd_send_command("boot_state.txt=\"Factory Reseting . . .\"");
|
|
|
|
|
#endif
|
|
|
|
|
// Format FRAM
|
|
|
|
|
for (int i = 0; i < 32768; i++)
|
|
|
|
|
{
|
|
|
|
|
for(int i=0;i<32768;i++) {
|
|
|
|
|
ESPMega_FRAM.write8(i,0);
|
|
|
|
|
}
|
|
|
|
|
// Load Default Values
|
|
|
|
|
set_ip("192.168.0.10");
|
|
|
|
|
set_gw("192.168.0.1");
|
|
|
|
|
set_netmask("255.255.255.0");
|
|
|
|
|
// Reboot
|
|
|
|
|
#ifdef ENABLE_INTERNAL_LCD
|
|
|
|
|
lcd_send_stop_bit();
|
|
|
|
|
lcd_send_command("boot_state.txt=\"Factory Reset OK. Release Button.\"");
|
|
|
|
|
delay(3000);
|
|
|
|
|
#endif
|
|
|
|
|
ESP.restart();
|
|
|
|
|
}
|
|
|
|
|
void check_boot_reset()
|
|
|
|
|
{
|
|
|
|
|
void check_boot_reset() {
|
|
|
|
|
pinMode(2, INPUT_PULLUP);
|
|
|
|
|
if (digitalRead(2) == LOW)
|
|
|
|
|
{
|
|
|
|
|
if(digitalRead(2)==LOW) {
|
|
|
|
|
factory_reset();
|
|
|
|
|
}
|
|
|
|
|
}
|