From 6aea27e30fe4c91fbeb25983f23e882f3a2f94d7 Mon Sep 17 00:00:00 2001 From: Proddy Date: Tue, 21 Feb 2023 21:49:21 +0100 Subject: [PATCH] tidy up EMSESP_DEBUG and EMSESP_TEST --- lib/framework/FSPersistence.h | 30 ++------------------ lib/framework/OTASettingsService.cpp | 6 ++-- platformio.ini | 2 +- src/analogsensor.cpp | 2 +- src/analogsensor.h | 2 +- src/command.cpp | 7 ----- src/common.h | 6 ++-- src/console.cpp | 41 ---------------------------- src/dallassensor.cpp | 2 +- src/dallassensor.h | 2 +- src/emsesp.cpp | 5 +--- src/mqtt.cpp | 12 +------- src/mqtt.h | 2 +- src/system.cpp | 17 +----------- src/system.h | 2 +- 15 files changed, 18 insertions(+), 120 deletions(-) diff --git a/lib/framework/FSPersistence.h b/lib/framework/FSPersistence.h index 323aec815..41819fc83 100644 --- a/lib/framework/FSPersistence.h +++ b/lib/framework/FSPersistence.h @@ -31,14 +31,6 @@ class FSPersistence { DeserializationError error = deserializeJson(jsonDocument, settingsFile); if (error == DeserializationError::Ok && jsonDocument.is()) { JsonObject jsonObject = jsonDocument.as(); - -// debug added by Proddy -#if defined(EMSESP_DEBUG) - Serial.println(); - Serial.printf("Reading file: %s: ", _filePath); - serializeJson(jsonDocument, Serial); - Serial.println(); -#endif _statefulService->updateWithoutPropagation(jsonObject, _stateUpdater); settingsFile.close(); return; @@ -46,13 +38,8 @@ class FSPersistence { settingsFile.close(); } -// If we reach here we have not been successful in loading the config, -// hard-coded emergency defaults are now applied. -#if defined(EMSESP_DEBUG) - Serial.println(); - Serial.printf("Applying defaults for %s: ", _filePath); - Serial.println(); -#endif + // If we reach here we have not been successful in loading the config, + // hard-coded emergency defaults are now applied. applyDefaults(); writeToFS(); // added to make sure the initial file is created } @@ -78,22 +65,9 @@ class FSPersistence { // failed to open file, return false if (!settingsFile || !jsonObject.size()) { -#if defined(EMSESP_DEBUG) - Serial.println(); - Serial.printf("Cannot write to file system."); - Serial.println(); -#endif return false; } -// debug added by Proddy -#if defined(EMSESP_DEBUG) - Serial.println(); - Serial.printf("Writing to file: %s: ", _filePath); - serializeJson(jsonDocument, Serial); - Serial.println(); -#endif - // serialize the data to the file serializeJson(jsonDocument, settingsFile); settingsFile.close(); diff --git a/lib/framework/OTASettingsService.cpp b/lib/framework/OTASettingsService.cpp index 31d9338d5..3fb20eeee 100644 --- a/lib/framework/OTASettingsService.cpp +++ b/lib/framework/OTASettingsService.cpp @@ -39,11 +39,10 @@ void OTASettingsService::configureArduinoOTA() { _arduinoOTA->onEnd([]() { emsesp::EMSESP::system_.upload_status(false); }); _arduinoOTA->onProgress([](unsigned int progress, unsigned int total) { -#if defined(EMSESP_DEBUG) - Serial.printf("Progress: %u%%\r\n", (progress / (total / 100))); -#endif + // Serial.printf("Progress: %u%%\r\n", (progress / (total / 100))); }); _arduinoOTA->onError([](ota_error_t error) { + /* #if defined(EMSESP_DEBUG) Serial.printf("Error[%u]: ", error); if (error == OTA_AUTH_ERROR) @@ -57,6 +56,7 @@ void OTASettingsService::configureArduinoOTA() { else if (error == OTA_END_ERROR) Serial.println("End Failed"); #endif +*/ }); _arduinoOTA->setMdnsEnabled(false); // disable as handled in NetworkSettingsService.cpp. https://github.com/emsesp/EMS-ESP32/issues/161 diff --git a/platformio.ini b/platformio.ini index d8c4e5c72..beed6ecbe 100644 --- a/platformio.ini +++ b/platformio.ini @@ -41,8 +41,8 @@ unbuild_flags = [espressi32_base] ; platform = espressif32@6.0.1 -platform = espressif32@5.2.0 ; platform = espressif32@5.3.0 +platform = espressif32@5.2.0 framework = arduino [env] diff --git a/src/analogsensor.cpp b/src/analogsensor.cpp index 625604829..158defe6c 100644 --- a/src/analogsensor.cpp +++ b/src/analogsensor.cpp @@ -699,7 +699,7 @@ bool AnalogSensor::command_commands(const char * value, const int8_t id, JsonObj } // hard coded tests -#if defined(EMSESP_DEBUG) +#if defined(EMSESP_TEST) void AnalogSensor::test() { sensors_.emplace_back(36, "test12", 0, 0.1, 17, AnalogType::ADC); sensors_.back().set_value(12.4); diff --git a/src/analogsensor.h b/src/analogsensor.h index a91ceffa6..cf391c394 100644 --- a/src/analogsensor.h +++ b/src/analogsensor.h @@ -160,7 +160,7 @@ class AnalogSensor { bool update(uint8_t gpio, const std::string & name, double offset, double factor, uint8_t uom, int8_t type); bool get_value_info(JsonObject & output, const char * cmd, const int8_t id) const; -#ifdef EMSESP_DEBUG +#if defined(EMSESP_TEST) void test(); #endif diff --git a/src/command.cpp b/src/command.cpp index 448034a31..9d37b21cc 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -52,13 +52,6 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec } } - /* -#ifdef EMSESP_DEBUG - Serial.print("Processing path: "); - Serial.println(p.path().c_str()); // dump paths, for debugging -#endif -*/ - // re-calculate new path // if there is only a path (URL) and no body then error! size_t num_paths = p.paths().size(); diff --git a/src/common.h b/src/common.h index 9e2ec4fbc..a5f59dadc 100644 --- a/src/common.h +++ b/src/common.h @@ -19,10 +19,10 @@ #ifndef EMSESP_COMMON_H #define EMSESP_COMMON_H -// logging #include using uuid::log::Level; + #if defined(EMSESP_DEBUG) #define LOG_DEBUG(...) logger_.debug(__VA_ARGS__) #else @@ -52,8 +52,8 @@ using string_vector = std::vector; #define F_(string_name) (__pstr__##string_name) #define FL_(list_name) (__pstr__L_##list_name) -#ifdef EMSESP_DEBUG -// In debug mode just take one language (en) to save on Flash space +#if defined(EMSESP_TEST) +// In testing just take one language (en) to save on Flash space #define MAKE_TRANSLATION(list_name, shortname, en, ...) static const char * const __pstr__L_##list_name[] = {shortname, en, nullptr}; #else #define MAKE_TRANSLATION(list_name, ...) static const char * const __pstr__L_##list_name[] = {__VA_ARGS__, nullptr}; diff --git a/src/console.cpp b/src/console.cpp index 3be20ad0b..e7e4ff3fc 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -219,47 +219,6 @@ static void setup_commands(std::shared_ptr & commands) { // // SET commands // - - /* -#ifndef EMSESP_STANDALONE - commands->add_command(ShellContext::MAIN, - CommandFlags::USER, - string_vector{F_(set), F_(timeout)}, - string_vector{F_(n_mandatory)}, - [](Shell & shell, const std::vector & arguments) { - uint16_t value = Helpers::atoint(arguments.front().c_str()); - telnet_.initial_idle_timeout(value * 60); - shell.printfln("Console timeout set to %d minutes", value); - }); -#endif -*/ - -#if defined(EMSESP_DEBUG) - // only for debug - commands->add_command( - ShellContext::MAIN, - CommandFlags::ADMIN, - string_vector{F_(set), "mqtt"}, - string_vector{"[on|off]"}, - [](Shell & shell, const std::vector & arguments) { - auto b = arguments.front(); - - if ((b == "on") || (b == "off")) { - to_app(shell).esp8266React.getMqttSettingsService()->updateWithoutPropagation([&](MqttSettings & settings) { - settings.enabled = (b == "on"); - shell.printfln("MQTT %s", settings.enabled ? "enabled" : "disabled"); - return StateUpdateResult::CHANGED; - }); - emsesp::EMSESP::mqtt_.reset_mqtt(); - } else { - shell.println("Must be on or off"); - } - }, - [](Shell & shell, const std::vector & current_arguments, const std::string & next_argument) -> std::vector { - return std::vector{"on", "off"}; - }); -#endif - commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, string_vector{F_(set), F_(wifi), F_(password)}, diff --git a/src/dallassensor.cpp b/src/dallassensor.cpp index 47d5d8351..1bd7d4848 100644 --- a/src/dallassensor.cpp +++ b/src/dallassensor.cpp @@ -613,7 +613,7 @@ bool DallasSensor::Sensor::apply_customization() { } // hard coded tests -#if defined(EMSESP_DEBUG) +#if defined(EMSESP_TEST) void DallasSensor::test() { // add 2 dallas sensors uint8_t addr[ADDR_LEN] = {1, 2, 3, 4, 5, 6, 7, 8}; diff --git a/src/dallassensor.h b/src/dallassensor.h index a1163888b..868b958e1 100644 --- a/src/dallassensor.h +++ b/src/dallassensor.h @@ -111,7 +111,7 @@ class DallasSensor { bool update(const std::string & id, const std::string & name, int16_t offset); -#ifdef EMSESP_DEBUG +#if defined(EMSESP_TEST) void test(); #endif diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 67f4d9292..272b29b23 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -1442,10 +1442,7 @@ void EMSESP::start() { esp8266React.begin(); // loads core system services settings (network, mqtt, ap, ntp etc) webLogService.begin(); // start web log service. now we can start capturing logs to the web log -#if defined(EMSESP_DEBUG) - LOG_NOTICE("System is running in Debug mode"); -#endif - + LOG_DEBUG("System is running in Debug mode"); LOG_INFO("Last system reset reason Core0: %s, Core1: %s", system_.reset_reason(0).c_str(), system_.reset_reason(1).c_str()); // see if we're restoring a settings file diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 497808cba..0aba44e4a 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -249,7 +249,7 @@ void Mqtt::show_mqtt(uuid::console::Shell & shell) { shell.println(); } -#if defined(EMSESP_DEBUG) +#if defined(EMSESP_TEST) // simulate receiving a MQTT message, used only for testing void Mqtt::incoming(const char * topic, const char * payload) { if (payload != nullptr) { @@ -371,9 +371,7 @@ void Mqtt::show_topic_handlers(uuid::console::Shell & shell, const uint8_t devic void Mqtt::on_publish(uint16_t packetId) const { // find the MQTT message in the queue and remove it if (mqtt_messages_.empty()) { -#if defined(EMSESP_DEBUG) LOG_DEBUG("No message stored for ACK pid %d", packetId); -#endif return; } @@ -392,9 +390,7 @@ void Mqtt::on_publish(uint16_t packetId) const { mqtt_publish_fails_++; // increment error count } -#if defined(EMSESP_DEBUG) LOG_DEBUG("ACK pid %d", packetId); -#endif mqtt_messages_.pop_front(); // always remove from queue, regardless if there was a successful ACK } @@ -772,9 +768,7 @@ void Mqtt::publish_ha(const char * topic) { } std::string fulltopic = Mqtt::discovery_prefix() + topic; -#if defined(EMSESP_DEBUG) LOG_DEBUG("Publishing empty HA topic=%s", fulltopic.c_str()); -#endif queue_publish_message(fulltopic, "", true); // publish with retain to remove from broker } @@ -790,11 +784,7 @@ void Mqtt::publish_ha(const char * topic, const JsonObject & payload) { serializeJson(payload, payload_text); // convert json to string std::string fulltopic = Mqtt::discovery_prefix() + topic; -#if defined(EMSESP_STANDALONE) LOG_DEBUG("Publishing HA topic=%s, payload=%s", fulltopic.c_str(), payload_text.c_str()); -#elif defined(EMSESP_DEBUG) - LOG_DEBUG("Publishing HA topic=%s, payload=%s", fulltopic.c_str(), payload_text.c_str()); -#endif // queue messages if the MQTT connection is not yet established. to ensure we don't miss messages queue_publish_message(fulltopic, payload_text, true); // with retain true diff --git a/src/mqtt.h b/src/mqtt.h index 80e5828e6..f1228ec74 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -114,7 +114,7 @@ class Mqtt { static void ha_status(); -#if defined(EMSESP_DEBUG) +#if defined(EMSESP_TEST) void incoming(const char * topic, const char * payload = ""); // for testing only #endif diff --git a/src/system.cpp b/src/system.cpp index 7de595569..1d31a4f40 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -417,7 +417,7 @@ void System::start() { void System::button_OnClick(PButton & b) { LOG_DEBUG("Button pressed - single click"); -#if defined(EMSESP_DEBUG) +#if defined(EMSESP_TEST) #ifndef EMSESP_STANDALONE Test::listDir(LittleFS, FS_CONFIG_DIRECTORY, 3); #endif @@ -521,21 +521,6 @@ void System::loop() { led_monitor(); // check status and report back using the LED system_check(); // check system health - -#ifndef EMSESP_STANDALONE - -#if defined(EMSESP_DEBUG) -/* - static uint32_t last_memcheck_ = 0; - if (currentMillis - last_memcheck_ > 10000) { // 10 seconds - last_memcheck_ = currentMillis; - show_mem("core"); - } - */ -#endif - -#endif - #endif } diff --git a/src/system.h b/src/system.h index dba4d6dde..b2ae9c1ff 100644 --- a/src/system.h +++ b/src/system.h @@ -247,7 +247,7 @@ class System { return test_set_all_active_; } static void test_set_all_active(bool n) { -#if defined(EMSESP_DEBUG) +#if defined(EMSESP_TEST) if (n) { logger_.debug("Using dummy entity values"); }