mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
fixed bug with set led
This commit is contained in:
@@ -505,7 +505,7 @@ void MyESP::_printSetCommands() {
|
|||||||
myDebug_P(PSTR("* set erase"));
|
myDebug_P(PSTR("* set erase"));
|
||||||
myDebug_P(PSTR("* set wifi [ssid] [password]"));
|
myDebug_P(PSTR("* set wifi [ssid] [password]"));
|
||||||
myDebug_P(PSTR("* set <mqtt_host | mqtt_username | mqtt_password> [value]"));
|
myDebug_P(PSTR("* set <mqtt_host | mqtt_username | mqtt_password> [value]"));
|
||||||
myDebug_P(PSTR("* set serial"));
|
myDebug_P(PSTR("* set serial <on | off>"));
|
||||||
|
|
||||||
// print custom commands if available. Taken from progmem
|
// print custom commands if available. Taken from progmem
|
||||||
if (_telnetcommand_callback) {
|
if (_telnetcommand_callback) {
|
||||||
@@ -679,7 +679,7 @@ void MyESP::_changeSetting(uint8_t wc, const char * setting, const char * value)
|
|||||||
|
|
||||||
myDebug_P(PSTR("")); // newline
|
myDebug_P(PSTR("")); // newline
|
||||||
|
|
||||||
(void)fs_saveConfig();
|
(void)fs_saveConfig(); // always save the values
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyESP::_telnetCommand(char * commandLine) {
|
void MyESP::_telnetCommand(char * commandLine) {
|
||||||
@@ -1244,7 +1244,6 @@ bool MyESP::fs_saveConfig() {
|
|||||||
|
|
||||||
// init the SPIFF file system and load the config
|
// init the SPIFF file system and load the config
|
||||||
// if it doesn't exist try and create it
|
// if it doesn't exist try and create it
|
||||||
// force Serial for debugging, and turn it off afterwards
|
|
||||||
void MyESP::_fs_setup() {
|
void MyESP::_fs_setup() {
|
||||||
if (!SPIFFS.begin()) {
|
if (!SPIFFS.begin()) {
|
||||||
myDebug_P(PSTR("[FS] Failed to mount the file system. Erasing..."));
|
myDebug_P(PSTR("[FS] Failed to mount the file system. Erasing..."));
|
||||||
@@ -1258,7 +1257,7 @@ void MyESP::_fs_setup() {
|
|||||||
fs_saveConfig();
|
fs_saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
//_fs_printConfig(); // enable for debugging
|
// _fs_printConfig(); // enable for debugging
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t MyESP::getSystemLoadAverage() {
|
uint16_t MyESP::getSystemLoadAverage() {
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ typedef struct {
|
|||||||
// custom params
|
// custom params
|
||||||
bool shower_timer; // true if we want to report back on shower times
|
bool shower_timer; // true if we want to report back on shower times
|
||||||
bool shower_alert; // true if we want the alert of cold water
|
bool shower_alert; // true if we want the alert of cold water
|
||||||
bool led_enabled; // LED on/off
|
bool led; // LED on/off
|
||||||
bool silent_mode; // stop automatic Tx on/off
|
bool silent_mode; // stop automatic Tx on/off
|
||||||
uint16_t publish_time; // frequency of MQTT publish in seconds
|
uint16_t publish_time; // frequency of MQTT publish in seconds
|
||||||
uint8_t led_gpio;
|
uint8_t led_gpio;
|
||||||
@@ -276,7 +276,7 @@ void showInfo() {
|
|||||||
myDebug(" System logging set to None");
|
myDebug(" System logging set to None");
|
||||||
}
|
}
|
||||||
|
|
||||||
myDebug(" LED is %s, Silent mode is %s", EMSESP_Status.led_enabled ? "on" : "off", EMSESP_Status.silent_mode ? "on" : "off");
|
myDebug(" LED is %s, Silent mode is %s", EMSESP_Status.led ? "on" : "off", EMSESP_Status.silent_mode ? "on" : "off");
|
||||||
myDebug(" # connected Dallas temperature sensors=%d", EMSESP_Status.dallas_sensors);
|
myDebug(" # connected Dallas temperature sensors=%d", EMSESP_Status.dallas_sensors);
|
||||||
|
|
||||||
myDebug(" Thermostat is %s, Boiler is %s, Shower Timer is %s, Shower Alert is %s",
|
myDebug(" Thermostat is %s, Boiler is %s, Shower Timer is %s, Shower Alert is %s",
|
||||||
@@ -647,77 +647,61 @@ void startThermostatScan(uint8_t start) {
|
|||||||
|
|
||||||
// callback for loading/saving settings to the file system (SPIFFS)
|
// callback for loading/saving settings to the file system (SPIFFS)
|
||||||
bool FSCallback(MYESP_FSACTION action, const JsonObject json) {
|
bool FSCallback(MYESP_FSACTION action, const JsonObject json) {
|
||||||
bool recreate_config = false;
|
bool recreate_config = true;
|
||||||
|
|
||||||
if (action == MYESP_FSACTION_LOAD) {
|
if (action == MYESP_FSACTION_LOAD) {
|
||||||
// led
|
// led
|
||||||
if (!(EMSESP_Status.led_enabled = json["led"])) {
|
EMSESP_Status.led = json["led"];
|
||||||
EMSESP_Status.led_enabled = LED_BUILTIN; // default value
|
|
||||||
recreate_config = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// led_gpio
|
// led_gpio
|
||||||
if (!(EMSESP_Status.led_gpio = json["led_gpio"])) {
|
if (!(EMSESP_Status.led_gpio = json["led_gpio"])) {
|
||||||
EMSESP_Status.led_gpio = EMSESP_LED_GPIO; // default value
|
EMSESP_Status.led_gpio = EMSESP_LED_GPIO; // default value
|
||||||
recreate_config = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// dallas_gpio
|
// dallas_gpio
|
||||||
if (!(EMSESP_Status.dallas_gpio = json["dallas_gpio"])) {
|
if (!(EMSESP_Status.dallas_gpio = json["dallas_gpio"])) {
|
||||||
EMSESP_Status.dallas_gpio = EMSESP_DALLAS_GPIO; // default value
|
EMSESP_Status.dallas_gpio = EMSESP_DALLAS_GPIO; // default value
|
||||||
recreate_config = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// dallas_parasite
|
// dallas_parasite
|
||||||
if (!(EMSESP_Status.dallas_parasite = json["dallas_parasite"])) {
|
if (!(EMSESP_Status.dallas_parasite = json["dallas_parasite"])) {
|
||||||
EMSESP_Status.dallas_parasite = EMSESP_DALLAS_PARASITE; // default value
|
EMSESP_Status.dallas_parasite = EMSESP_DALLAS_PARASITE; // default value
|
||||||
recreate_config = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// thermostat_type
|
// thermostat_type
|
||||||
if (!(EMS_Thermostat.type_id = json["thermostat_type"])) {
|
if (!(EMS_Thermostat.type_id = json["thermostat_type"])) {
|
||||||
EMS_Thermostat.type_id = EMSESP_THERMOSTAT_TYPE; // set default
|
EMS_Thermostat.type_id = EMSESP_THERMOSTAT_TYPE; // set default
|
||||||
recreate_config = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// boiler_type
|
// boiler_type
|
||||||
if (!(EMS_Boiler.type_id = json["boiler_type"])) {
|
if (!(EMS_Boiler.type_id = json["boiler_type"])) {
|
||||||
EMS_Boiler.type_id = EMSESP_BOILER_TYPE; // set default
|
EMS_Boiler.type_id = EMSESP_BOILER_TYPE; // set default
|
||||||
recreate_config = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// test mode
|
// silent mode
|
||||||
if (!(EMSESP_Status.silent_mode = json["silent_mode"])) {
|
EMSESP_Status.silent_mode = json["silent_mode"];
|
||||||
EMSESP_Status.silent_mode = false; // default value
|
ems_setTxDisabled(EMSESP_Status.silent_mode);
|
||||||
ems_setTxDisabled(false);
|
|
||||||
recreate_config = true;
|
|
||||||
} else {
|
|
||||||
ems_setTxDisabled(true); // silent_mpde is on
|
|
||||||
}
|
|
||||||
|
|
||||||
// shower_timer
|
// shower_timer
|
||||||
if (!(EMSESP_Status.shower_timer = json["shower_timer"])) {
|
if (!(EMSESP_Status.shower_timer = json["shower_timer"])) {
|
||||||
EMSESP_Status.shower_timer = false; // default value
|
EMSESP_Status.shower_timer = false; // default value
|
||||||
recreate_config = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// shower_alert
|
// shower_alert
|
||||||
if (!(EMSESP_Status.shower_alert = json["shower_alert"])) {
|
if (!(EMSESP_Status.shower_alert = json["shower_alert"])) {
|
||||||
EMSESP_Status.shower_alert = false; // default value
|
EMSESP_Status.shower_alert = false; // default value
|
||||||
recreate_config = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// publish_time
|
// publish_time
|
||||||
if (!(EMSESP_Status.publish_time = json["publish_time"])) {
|
if (!(EMSESP_Status.publish_time = json["publish_time"])) {
|
||||||
EMSESP_Status.publish_time = DEFAULT_PUBLISHVALUES_TIME; // default value
|
EMSESP_Status.publish_time = DEFAULT_PUBLISHVALUES_TIME; // default value
|
||||||
recreate_config = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return recreate_config; // return false if some settings are missing and we need to rebuild the file
|
return recreate_config; // return false if some settings are missing and we need to rebuild the file
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == MYESP_FSACTION_SAVE) {
|
if (action == MYESP_FSACTION_SAVE) {
|
||||||
json["led"] = EMSESP_Status.led_enabled;
|
json["led"] = EMSESP_Status.led;
|
||||||
json["led_gpio"] = EMSESP_Status.led_gpio;
|
json["led_gpio"] = EMSESP_Status.led_gpio;
|
||||||
json["dallas_gpio"] = EMSESP_Status.dallas_gpio;
|
json["dallas_gpio"] = EMSESP_Status.dallas_gpio;
|
||||||
json["dallas_parasite"] = EMSESP_Status.dallas_parasite;
|
json["dallas_parasite"] = EMSESP_Status.dallas_parasite;
|
||||||
@@ -736,7 +720,7 @@ bool FSCallback(MYESP_FSACTION action, const JsonObject json) {
|
|||||||
|
|
||||||
// callback for custom settings when showing Stored Settings with the 'set' command
|
// callback for custom settings when showing Stored Settings with the 'set' command
|
||||||
// wc is number of arguments after the 'set' command
|
// wc is number of arguments after the 'set' command
|
||||||
// returns true if the setting was recognized and changed
|
// returns true if the setting was recognized and changed and should be saved back to SPIFFs
|
||||||
bool SettingsCallback(MYESP_FSACTION action, uint8_t wc, const char * setting, const char * value) {
|
bool SettingsCallback(MYESP_FSACTION action, uint8_t wc, const char * setting, const char * value) {
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
|
||||||
@@ -744,14 +728,13 @@ bool SettingsCallback(MYESP_FSACTION action, uint8_t wc, const char * setting, c
|
|||||||
// led
|
// led
|
||||||
if ((strcmp(setting, "led") == 0) && (wc == 2)) {
|
if ((strcmp(setting, "led") == 0) && (wc == 2)) {
|
||||||
if (strcmp(value, "on") == 0) {
|
if (strcmp(value, "on") == 0) {
|
||||||
EMSESP_Status.led_enabled = true;
|
EMSESP_Status.led = true;
|
||||||
ok = true;
|
ok = true;
|
||||||
} else if (strcmp(value, "off") == 0) {
|
} else if (strcmp(value, "off") == 0) {
|
||||||
EMSESP_Status.led_enabled = false;
|
EMSESP_Status.led = false;
|
||||||
ok = true;
|
ok = true;
|
||||||
// let's make sure LED is really off
|
// let's make sure LED is really off - For onboard high=off
|
||||||
digitalWrite(EMSESP_Status.led_gpio,
|
digitalWrite(EMSESP_Status.led_gpio, (EMSESP_Status.led_gpio == LED_BUILTIN) ? HIGH : LOW);
|
||||||
(EMSESP_Status.led_gpio == LED_BUILTIN) ? HIGH : LOW); // light off. For onboard high=off
|
|
||||||
} else {
|
} else {
|
||||||
myDebug("Error. Usage: set led <on | off>");
|
myDebug("Error. Usage: set led <on | off>");
|
||||||
}
|
}
|
||||||
@@ -848,7 +831,7 @@ bool SettingsCallback(MYESP_FSACTION action, uint8_t wc, const char * setting, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (action == MYESP_FSACTION_LIST) {
|
if (action == MYESP_FSACTION_LIST) {
|
||||||
myDebug(" led=%s", EMSESP_Status.led_enabled ? "on" : "off");
|
myDebug(" led=%s", EMSESP_Status.led ? "on" : "off");
|
||||||
myDebug(" led_gpio=%d", EMSESP_Status.led_gpio);
|
myDebug(" led_gpio=%d", EMSESP_Status.led_gpio);
|
||||||
myDebug(" dallas_gpio=%d", EMSESP_Status.dallas_gpio);
|
myDebug(" dallas_gpio=%d", EMSESP_Status.dallas_gpio);
|
||||||
myDebug(" dallas_parasite=%s", EMSESP_Status.dallas_parasite ? "on" : "off");
|
myDebug(" dallas_parasite=%s", EMSESP_Status.dallas_parasite ? "on" : "off");
|
||||||
@@ -1166,7 +1149,7 @@ void initEMSESP() {
|
|||||||
// general settings
|
// general settings
|
||||||
EMSESP_Status.shower_timer = false;
|
EMSESP_Status.shower_timer = false;
|
||||||
EMSESP_Status.shower_alert = false;
|
EMSESP_Status.shower_alert = false;
|
||||||
EMSESP_Status.led_enabled = true; // LED is on by default
|
EMSESP_Status.led = true; // LED is on by default
|
||||||
EMSESP_Status.silent_mode = false;
|
EMSESP_Status.silent_mode = false;
|
||||||
EMSESP_Status.publish_time = DEFAULT_PUBLISHVALUES_TIME;
|
EMSESP_Status.publish_time = DEFAULT_PUBLISHVALUES_TIME;
|
||||||
|
|
||||||
@@ -1201,7 +1184,7 @@ void do_publishValues() {
|
|||||||
// callback to light up the LED, called via Ticker every second
|
// callback to light up the LED, called via Ticker every second
|
||||||
// fast way is to use WRITE_PERI_REG(PERIPHS_GPIO_BASEADDR + (state ? 4 : 8), (1 << EMSESP_Status.led_gpio)); // 4 is on, 8 is off
|
// fast way is to use WRITE_PERI_REG(PERIPHS_GPIO_BASEADDR + (state ? 4 : 8), (1 << EMSESP_Status.led_gpio)); // 4 is on, 8 is off
|
||||||
void do_ledcheck() {
|
void do_ledcheck() {
|
||||||
if (EMSESP_Status.led_enabled) {
|
if (EMSESP_Status.led) {
|
||||||
if (ems_getBusConnected()) {
|
if (ems_getBusConnected()) {
|
||||||
digitalWrite(EMSESP_Status.led_gpio, (EMSESP_Status.led_gpio == LED_BUILTIN) ? LOW : HIGH); // light on. For onboard LED high=off
|
digitalWrite(EMSESP_Status.led_gpio, (EMSESP_Status.led_gpio == LED_BUILTIN) ? LOW : HIGH); // light on. For onboard LED high=off
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user