diff --git a/lib/uuid-console/src/shell.cpp b/lib/uuid-console/src/shell.cpp index 608d485bb..4da3406b8 100644 --- a/lib/uuid-console/src/shell.cpp +++ b/lib/uuid-console/src/shell.cpp @@ -60,7 +60,7 @@ bool Shell::running() const { } void Shell::start() { -#ifdef EMSESP_DEBUG +#if defined(EMSESP_DEBUG) uuid::log::Logger::register_handler(this, uuid::log::Level::DEBUG); // added for EMS-ESP #else uuid::log::Logger::register_handler(this, uuid::log::Level::INFO); diff --git a/src/analogsensor.cpp b/src/analogsensor.cpp index a7c2aad97..625604829 100644 --- a/src/analogsensor.cpp +++ b/src/analogsensor.cpp @@ -395,9 +395,7 @@ void AnalogSensor::remove_ha_topic(const uint8_t gpio) const { return; } -#ifdef EMSESP_DEBUG LOG_DEBUG("Removing HA config for analog sensor GPIO %02d", gpio); -#endif char topic[Mqtt::MQTT_TOPIC_MAX_SIZE]; snprintf(topic, sizeof(topic), "sensor/%s/analogsensor_%02d/config", Mqtt::basename().c_str(), gpio); @@ -701,7 +699,7 @@ bool AnalogSensor::command_commands(const char * value, const int8_t id, JsonObj } // hard coded tests -#ifdef EMSESP_DEBUG +#if defined(EMSESP_DEBUG) void AnalogSensor::test() { sensors_.emplace_back(36, "test12", 0, 0.1, 17, AnalogType::ADC); sensors_.back().set_value(12.4); diff --git a/src/command.cpp b/src/command.cpp index c0edbfa42..448034a31 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -52,10 +52,12 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec } } + /* #ifdef EMSESP_DEBUG - Serial.print("[DEBUG] processing path: "); + 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! @@ -273,9 +275,7 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * // except for system commands as this is a special device without any queryable entities (device values) if ((device_type > EMSdevice::DeviceType::SYSTEM) && (!value || !strlen(value))) { if (!cf || !cf->cmdfunction_json_) { -#if defined(EMSESP_DEBUG) - LOG_DEBUG("[DEBUG] Calling %s command '%s' to retrieve attributes", dname, cmd); -#endif + LOG_DEBUG("Calling %s command '%s' to retrieve attributes", dname, cmd); return EMSESP::get_device_value_info(output, cmd, id, device_type) ? CommandRet::OK : CommandRet::ERROR; // entity = cmd } } diff --git a/src/common.h b/src/common.h index c96c0ec61..9e2ec4fbc 100644 --- a/src/common.h +++ b/src/common.h @@ -23,7 +23,12 @@ #include using uuid::log::Level; +#if defined(EMSESP_DEBUG) #define LOG_DEBUG(...) logger_.debug(__VA_ARGS__) +#else +#define LOG_DEBUG(...) +#endif + #define LOG_INFO(...) logger_.info(__VA_ARGS__) #define LOG_TRACE(...) logger_.trace(__VA_ARGS__) #define LOG_NOTICE(...) logger_.notice(__VA_ARGS__) diff --git a/src/dallassensor.cpp b/src/dallassensor.cpp index 757a390c8..47d5d8351 100644 --- a/src/dallassensor.cpp +++ b/src/dallassensor.cpp @@ -91,7 +91,7 @@ void DallasSensor::loop() { if (state_ == State::IDLE) { if (time_now - last_activity_ >= READ_INTERVAL_MS) { #ifdef EMSESP_DEBUG_SENSOR - LOG_DEBUG("[DEBUG] Read sensor temperature"); + LOG_DEBUG("Read sensor temperature"); #endif if (bus_.reset() || parasite_) { YIELD; @@ -456,9 +456,7 @@ void DallasSensor::remove_ha_topic(const std::string & id) { if (!Mqtt::ha_enabled()) { return; } -#ifdef EMSESP_DEBUG LOG_DEBUG("Removing HA config for temperature sensor ID %s", id.c_str()); -#endif // use '_' as HA doesn't like '-' in the topic name std::string sensorid = id; std::replace(sensorid.begin(), sensorid.end(), '-', '_'); @@ -600,9 +598,7 @@ bool DallasSensor::Sensor::apply_customization() { auto sensors = settings.sensorCustomizations; if (!sensors.empty()) { for (const auto & sensor : sensors) { -#if defined(EMSESP_DEBUG) LOG_DEBUG("Loading customization for dallas sensor %s", sensor.id.c_str()); -#endif if (id_ == sensor.id) { set_name(sensor.name); set_offset(sensor.offset); @@ -617,7 +613,7 @@ bool DallasSensor::Sensor::apply_customization() { } // hard coded tests -#ifdef EMSESP_DEBUG +#if defined(EMSESP_DEBUG) void DallasSensor::test() { // add 2 dallas sensors uint8_t addr[ADDR_LEN] = {1, 2, 3, 4, 5, 6, 7, 8}; diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index 3c8e0429f..f1f2ff018 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -216,9 +216,7 @@ std::shared_ptr Thermostat::heating_circuit(const ui return heating_circuit; } } -#if defined(EMSESP_DEBUG) LOG_DEBUG("Heating circuit not fond on device 0x%02X", device_id()); -#endif return nullptr; // not found } @@ -3299,9 +3297,7 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co write_command(set_typeid, offset, (uint8_t)(temperature * (float)factor), validate_typeid); return true; } -#if defined(EMSESP_DEBUG) LOG_DEBUG("temperature mode %d not found", mode); -#endif return false; } diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 72833697f..fa3cf7ea3 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -283,7 +283,9 @@ const std::string EMSdevice::to_string_short() { // for each telegram that has the fetch value set (true) do a read request void EMSdevice::fetch_values() { +#if defined(EMSESP_DEBUG) EMSESP::logger().debug("Fetching values for deviceID 0x%02X", device_id()); +#endif for (const auto & tf : telegram_functions_) { if (tf.fetch_) { @@ -294,7 +296,9 @@ void EMSdevice::fetch_values() { // toggle on/off automatic fetch for a telegramID void EMSdevice::toggle_fetch(uint16_t telegram_id, bool toggle) { +#if defined(EMSESP_DEBUG) EMSESP::logger().debug("Toggling fetch for deviceID 0x%02X, telegramID 0x%02X to %d", device_id(), telegram_id, toggle); +#endif for (auto & tf : telegram_functions_) { if (tf.telegram_type_id_ == telegram_id) { @@ -1480,7 +1484,7 @@ bool EMSdevice::get_value_info(JsonObject & output, const char * cmd, const int8 // if we're filtering on an attribute, go find it if (attribute_s) { #if defined(EMSESP_DEBUG) - EMSESP::logger().debug("[DEBUG] Attribute '%s'", attribute_s); + EMSESP::logger().debug("Attribute '%s'", attribute_s); #endif if (json.containsKey(attribute_s)) { JsonVariant data = json[attribute_s]; @@ -1765,7 +1769,9 @@ bool EMSdevice::handle_telegram(std::shared_ptr telegram) { // if the data block is empty and we have not received data before, assume that this telegram // is not recognized by the bus master. So remove it from the automatic fetch list if (telegram->message_length == 0 && telegram->offset == 0 && !tf.received_) { +#if defined(EMSESP_DEBUG) EMSESP::logger().debug("This telegram (%s) is not recognized by the EMS bus", tf.telegram_type_name_); +#endif tf.fetch_ = false; return false; } diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 74bb912e4..67f4d9292 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -1430,7 +1430,7 @@ void EMSESP::start() { File root = LittleFS.open("/config"); bool factory_settings = !root; if (!root) { -#ifdef EMSESP_DEBUG +#if defined(EMSESP_DEBUG) Serial.println("No config found, assuming factory settings"); #endif } @@ -1442,7 +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 -#ifdef EMSESP_DEBUG +#if defined(EMSESP_DEBUG) LOG_NOTICE("System is running in Debug mode"); #endif diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 74e2f4a68..497808cba 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -372,7 +372,7 @@ 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("[DEBUG] No message stored for ACK pid %d", packetId); + LOG_DEBUG("No message stored for ACK pid %d", packetId); #endif return; } @@ -382,7 +382,7 @@ void Mqtt::on_publish(uint16_t packetId) const { // if the last published failed, don't bother checking it. wait for the next retry if (mqtt_message.packet_id_ == 0) { #if defined(EMSESP_DEBUG) - LOG_DEBUG("[DEBUG] ACK for failed message pid 0"); + LOG_DEBUG("ACK for failed message pid 0"); #endif return; } @@ -393,7 +393,7 @@ void Mqtt::on_publish(uint16_t packetId) const { } #if defined(EMSESP_DEBUG) - LOG_DEBUG("[DEBUG] ACK pid %d", packetId); + LOG_DEBUG("ACK pid %d", packetId); #endif mqtt_messages_.pop_front(); // always remove from queue, regardless if there was a successful ACK @@ -685,12 +685,12 @@ std::shared_ptr Mqtt::queue_message(const uint8_t operation, #if defined(EMSESP_DEBUG) if (operation == Operation::PUBLISH) { if (message->payload.empty()) { - LOG_INFO("[DEBUG] Adding to queue: (publish) topic='%s' empty payload", message->topic.c_str()); + LOG_INFO("Adding to queue: (publish) topic='%s' empty payload", message->topic.c_str()); } else { - LOG_INFO("[DEBUG] Adding to queue: (publish) topic='%s' payload=%s", message->topic.c_str(), message->payload.c_str()); + LOG_INFO("Adding to queue: (publish) topic='%s' payload=%s", message->topic.c_str(), message->payload.c_str()); } } else { - LOG_INFO("[DEBUG] Adding to queue: (subscribe) topic='%s'", message->topic.c_str()); + LOG_INFO("Adding to queue: (subscribe) topic='%s'", message->topic.c_str()); } #endif @@ -773,7 +773,7 @@ void Mqtt::publish_ha(const char * topic) { std::string fulltopic = Mqtt::discovery_prefix() + topic; #if defined(EMSESP_DEBUG) - LOG_DEBUG("[DEBUG] Publishing empty HA topic=%s", fulltopic.c_str()); + LOG_DEBUG("Publishing empty HA topic=%s", fulltopic.c_str()); #endif queue_publish_message(fulltopic, "", true); // publish with retain to remove from broker @@ -793,7 +793,7 @@ void Mqtt::publish_ha(const char * topic, const JsonObject & payload) { #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("[debug] Publishing HA topic=%s, payload=%s", fulltopic.c_str(), payload_text.c_str()); + 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 @@ -823,7 +823,7 @@ void Mqtt::process_queue() { // it will have a real packet ID if (mqtt_message.packet_id_ > 0) { #if defined(EMSESP_DEBUG) - LOG_DEBUG("[DEBUG] Waiting for QOS-ACK"); + LOG_DEBUG("Waiting for QOS-ACK"); #endif // if we don't get the ack within 10 minutes, republish with new packet_id if (uuid::get_uptime_sec() - last_publish_queue_ < 600) { @@ -870,6 +870,7 @@ void Mqtt::process_queue() { uint16_t packet_id = mqttClient_->publish(topic, mqtt_qos_, message->retain, message->payload.c_str(), message->payload.size(), false, mqtt_message.id_); lasttopic_ = topic; lastpayload_ = message->payload; + LOG_DEBUG("Publishing topic %s (#%02d, retain=%d, retry=%d, size=%d, pid=%d)", topic, mqtt_message.id_, @@ -877,11 +878,11 @@ void Mqtt::process_queue() { mqtt_message.retry_count_ + 1, message->payload.size(), packet_id); -#if defined(EMSESP_DEBUG) + if (!message->payload.empty()) { LOG_DEBUG("Payload:%s", message->payload.c_str()); // extra message for #784 } -#endif + if (packet_id == 0) { // it failed. if we retried n times, give up. remove from queue if (mqtt_message.retry_count_ == (MQTT_PUBLISH_MAX_RETRY - 1)) { @@ -901,9 +902,7 @@ void Mqtt::process_queue() { // but add the packet_id so we can check it later if (mqtt_qos_ != 0) { mqtt_messages_.front().packet_id_ = packet_id; -#if defined(EMSESP_DEBUG) - LOG_DEBUG("[DEBUG] Setting packetID for ACK to %d", packet_id); -#endif + LOG_DEBUG("Setting packetID for ACK to %d", packet_id); return; } diff --git a/src/telegram.cpp b/src/telegram.cpp index 8f23ab03d..f9d35557d 100644 --- a/src/telegram.cpp +++ b/src/telegram.cpp @@ -211,9 +211,7 @@ void RxService::add(uint8_t * data, uint8_t length) { LOG_TRACE("Rx: %s", Helpers::data_to_hex(data, length).c_str()); } -#ifdef EMSESP_DEBUG - LOG_DEBUG("[DEBUG] New Rx telegram, message length %d", message_length); -#endif + LOG_DEBUG("New Rx telegram, message length %d", message_length); // if we don't have a type_id exit, // do not exit on empty message, it is checked for toggle fetch @@ -443,9 +441,7 @@ void TxService::add(const uint8_t operation, const bool front) { auto telegram = std::make_shared(operation, ems_bus_id(), dest, type_id, offset, message_data, message_length); -#ifdef EMSESP_DEBUG - LOG_DEBUG("[DEBUG] New Tx [#%d] telegram, length %d", tx_telegram_id_, message_length); -#endif + LOG_DEBUG("New Tx [#%d] telegram, length %d", tx_telegram_id_, message_length); // if the queue is full, make room by removing the last one if (tx_telegrams_.size() >= MAX_TX_TELEGRAMS) { @@ -507,9 +503,7 @@ void TxService::add(uint8_t operation, const uint8_t * data, const uint8_t lengt // if we don't have a type_id or empty data block, exit if ((type_id == 0) || (message_length == 0)) { -#ifdef EMSESP_DEBUG - LOG_DEBUG("[DEBUG] Tx telegram type %d failed, length %d", type_id, message_length); -#endif + LOG_DEBUG("Tx telegram type %d failed, length %d", type_id, message_length); return; } @@ -537,9 +531,7 @@ void TxService::add(uint8_t operation, const uint8_t * data, const uint8_t lengt tx_telegrams_.pop_front(); } -#ifdef EMSESP_DEBUG - LOG_DEBUG("[DEBUG] New Tx [#%d] telegram, length %d", tx_telegram_id_, message_length); -#endif + LOG_DEBUG("New Tx [#%d] telegram, length %d", tx_telegram_id_, message_length); if (front) { // tx_telegrams_.push_front(qtxt); // add to front of queue @@ -639,13 +631,11 @@ void TxService::retry_tx(const uint8_t operation, const uint8_t * data, const ui return; } -#ifdef EMSESP_DEBUG - LOG_DEBUG("[DEBUG] Last Tx %s operation failed. Retry #%d. sent message: %s, received: %s", + LOG_DEBUG("Last Tx %s operation failed. Retry #%d. sent message: %s, received: %s", (operation == Telegram::Operation::TX_WRITE) ? ("Write") : ("Read"), retry_count_, telegram_last_->to_string().c_str(), Helpers::data_to_hex(data, length - 1).c_str()); -#endif // add to the top of the queue if (tx_telegrams_.size() >= MAX_TX_TELEGRAMS) { diff --git a/src/web/WebAPIService.cpp b/src/web/WebAPIService.cpp index 6e9f94f9f..9fc0b1d5a 100644 --- a/src/web/WebAPIService.cpp +++ b/src/web/WebAPIService.cpp @@ -126,7 +126,6 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject & input) { emsesp::EMSESP::logger().err(error); api_fails_++; } else { - // emsesp::EMSESP::logger().debug("API command called successfully"); // if there was no json output from the call, default to the output message 'OK'. if (!output.size()) { output["message"] = "OK"; diff --git a/src/web/WebDataService.cpp b/src/web/WebDataService.cpp index 703837369..9aace51a5 100644 --- a/src/web/WebDataService.cpp +++ b/src/web/WebDataService.cpp @@ -188,7 +188,7 @@ void WebDataService::device_data(AsyncWebServerRequest * request, JsonVariant & #if defined(EMSESP_DEBUG) size_t length = response->setLength(); - EMSESP::logger().debug("[DEBUG] Dashboard buffer used: %d", length); + EMSESP::logger().debug("Dashboard buffer used: %d", length); #else response->setLength(); #endif @@ -245,7 +245,9 @@ void WebDataService::write_value(AsyncWebServerRequest * request, JsonVariant & if (return_code != CommandRet::OK) { EMSESP::logger().err("Write command failed %s (%s)", (const char *)output["message"], Command::return_code_string(return_code).c_str()); } else { +#if defined(EMSESP_DEBUG) EMSESP::logger().debug("Write command successful"); +#endif } response->setCode((return_code == CommandRet::OK) ? 200 : 204);