mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
tidy up EMSESP_DEBUG and EMSESP_TEST
This commit is contained in:
@@ -31,14 +31,6 @@ class FSPersistence {
|
|||||||
DeserializationError error = deserializeJson(jsonDocument, settingsFile);
|
DeserializationError error = deserializeJson(jsonDocument, settingsFile);
|
||||||
if (error == DeserializationError::Ok && jsonDocument.is<JsonObject>()) {
|
if (error == DeserializationError::Ok && jsonDocument.is<JsonObject>()) {
|
||||||
JsonObject jsonObject = jsonDocument.as<JsonObject>();
|
JsonObject jsonObject = jsonDocument.as<JsonObject>();
|
||||||
|
|
||||||
// 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);
|
_statefulService->updateWithoutPropagation(jsonObject, _stateUpdater);
|
||||||
settingsFile.close();
|
settingsFile.close();
|
||||||
return;
|
return;
|
||||||
@@ -46,13 +38,8 @@ class FSPersistence {
|
|||||||
settingsFile.close();
|
settingsFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we reach here we have not been successful in loading the config,
|
// If we reach here we have not been successful in loading the config,
|
||||||
// hard-coded emergency defaults are now applied.
|
// hard-coded emergency defaults are now applied.
|
||||||
#if defined(EMSESP_DEBUG)
|
|
||||||
Serial.println();
|
|
||||||
Serial.printf("Applying defaults for %s: ", _filePath);
|
|
||||||
Serial.println();
|
|
||||||
#endif
|
|
||||||
applyDefaults();
|
applyDefaults();
|
||||||
writeToFS(); // added to make sure the initial file is created
|
writeToFS(); // added to make sure the initial file is created
|
||||||
}
|
}
|
||||||
@@ -78,22 +65,9 @@ class FSPersistence {
|
|||||||
|
|
||||||
// failed to open file, return false
|
// failed to open file, return false
|
||||||
if (!settingsFile || !jsonObject.size()) {
|
if (!settingsFile || !jsonObject.size()) {
|
||||||
#if defined(EMSESP_DEBUG)
|
|
||||||
Serial.println();
|
|
||||||
Serial.printf("Cannot write to file system.");
|
|
||||||
Serial.println();
|
|
||||||
#endif
|
|
||||||
return false;
|
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
|
// serialize the data to the file
|
||||||
serializeJson(jsonDocument, settingsFile);
|
serializeJson(jsonDocument, settingsFile);
|
||||||
settingsFile.close();
|
settingsFile.close();
|
||||||
|
|||||||
@@ -39,11 +39,10 @@ void OTASettingsService::configureArduinoOTA() {
|
|||||||
_arduinoOTA->onEnd([]() { emsesp::EMSESP::system_.upload_status(false); });
|
_arduinoOTA->onEnd([]() { emsesp::EMSESP::system_.upload_status(false); });
|
||||||
|
|
||||||
_arduinoOTA->onProgress([](unsigned int progress, unsigned int total) {
|
_arduinoOTA->onProgress([](unsigned int progress, unsigned int total) {
|
||||||
#if defined(EMSESP_DEBUG)
|
// Serial.printf("Progress: %u%%\r\n", (progress / (total / 100)));
|
||||||
Serial.printf("Progress: %u%%\r\n", (progress / (total / 100)));
|
|
||||||
#endif
|
|
||||||
});
|
});
|
||||||
_arduinoOTA->onError([](ota_error_t error) {
|
_arduinoOTA->onError([](ota_error_t error) {
|
||||||
|
/*
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_DEBUG)
|
||||||
Serial.printf("Error[%u]: ", error);
|
Serial.printf("Error[%u]: ", error);
|
||||||
if (error == OTA_AUTH_ERROR)
|
if (error == OTA_AUTH_ERROR)
|
||||||
@@ -57,6 +56,7 @@ void OTASettingsService::configureArduinoOTA() {
|
|||||||
else if (error == OTA_END_ERROR)
|
else if (error == OTA_END_ERROR)
|
||||||
Serial.println("End Failed");
|
Serial.println("End Failed");
|
||||||
#endif
|
#endif
|
||||||
|
*/
|
||||||
});
|
});
|
||||||
|
|
||||||
_arduinoOTA->setMdnsEnabled(false); // disable as handled in NetworkSettingsService.cpp. https://github.com/emsesp/EMS-ESP32/issues/161
|
_arduinoOTA->setMdnsEnabled(false); // disable as handled in NetworkSettingsService.cpp. https://github.com/emsesp/EMS-ESP32/issues/161
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ unbuild_flags =
|
|||||||
|
|
||||||
[espressi32_base]
|
[espressi32_base]
|
||||||
; platform = espressif32@6.0.1
|
; platform = espressif32@6.0.1
|
||||||
platform = espressif32@5.2.0
|
|
||||||
; platform = espressif32@5.3.0
|
; platform = espressif32@5.3.0
|
||||||
|
platform = espressif32@5.2.0
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
|
|||||||
@@ -699,7 +699,7 @@ bool AnalogSensor::command_commands(const char * value, const int8_t id, JsonObj
|
|||||||
}
|
}
|
||||||
|
|
||||||
// hard coded tests
|
// hard coded tests
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_TEST)
|
||||||
void AnalogSensor::test() {
|
void AnalogSensor::test() {
|
||||||
sensors_.emplace_back(36, "test12", 0, 0.1, 17, AnalogType::ADC);
|
sensors_.emplace_back(36, "test12", 0, 0.1, 17, AnalogType::ADC);
|
||||||
sensors_.back().set_value(12.4);
|
sensors_.back().set_value(12.4);
|
||||||
|
|||||||
@@ -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 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;
|
bool get_value_info(JsonObject & output, const char * cmd, const int8_t id) const;
|
||||||
|
|
||||||
#ifdef EMSESP_DEBUG
|
#if defined(EMSESP_TEST)
|
||||||
void test();
|
void test();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
// re-calculate new path
|
||||||
// if there is only a path (URL) and no body then error!
|
// if there is only a path (URL) and no body then error!
|
||||||
size_t num_paths = p.paths().size();
|
size_t num_paths = p.paths().size();
|
||||||
|
|||||||
@@ -19,10 +19,10 @@
|
|||||||
#ifndef EMSESP_COMMON_H
|
#ifndef EMSESP_COMMON_H
|
||||||
#define EMSESP_COMMON_H
|
#define EMSESP_COMMON_H
|
||||||
|
|
||||||
// logging
|
|
||||||
#include <uuid/log.h>
|
#include <uuid/log.h>
|
||||||
|
|
||||||
using uuid::log::Level;
|
using uuid::log::Level;
|
||||||
|
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_DEBUG)
|
||||||
#define LOG_DEBUG(...) logger_.debug(__VA_ARGS__)
|
#define LOG_DEBUG(...) logger_.debug(__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
@@ -52,8 +52,8 @@ using string_vector = std::vector<const char *>;
|
|||||||
#define F_(string_name) (__pstr__##string_name)
|
#define F_(string_name) (__pstr__##string_name)
|
||||||
#define FL_(list_name) (__pstr__L_##list_name)
|
#define FL_(list_name) (__pstr__L_##list_name)
|
||||||
|
|
||||||
#ifdef EMSESP_DEBUG
|
#if defined(EMSESP_TEST)
|
||||||
// In debug mode just take one language (en) to save on Flash space
|
// 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};
|
#define MAKE_TRANSLATION(list_name, shortname, en, ...) static const char * const __pstr__L_##list_name[] = {shortname, en, nullptr};
|
||||||
#else
|
#else
|
||||||
#define MAKE_TRANSLATION(list_name, ...) static const char * const __pstr__L_##list_name[] = {__VA_ARGS__, nullptr};
|
#define MAKE_TRANSLATION(list_name, ...) static const char * const __pstr__L_##list_name[] = {__VA_ARGS__, nullptr};
|
||||||
|
|||||||
@@ -219,47 +219,6 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
|||||||
//
|
//
|
||||||
// SET 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<std::string> & 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<std::string> & 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<std::string> & current_arguments, const std::string & next_argument) -> std::vector<std::string> {
|
|
||||||
return std::vector<std::string>{"on", "off"};
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
|
|
||||||
commands->add_command(ShellContext::MAIN,
|
commands->add_command(ShellContext::MAIN,
|
||||||
CommandFlags::ADMIN,
|
CommandFlags::ADMIN,
|
||||||
string_vector{F_(set), F_(wifi), F_(password)},
|
string_vector{F_(set), F_(wifi), F_(password)},
|
||||||
|
|||||||
@@ -613,7 +613,7 @@ bool DallasSensor::Sensor::apply_customization() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// hard coded tests
|
// hard coded tests
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_TEST)
|
||||||
void DallasSensor::test() {
|
void DallasSensor::test() {
|
||||||
// add 2 dallas sensors
|
// add 2 dallas sensors
|
||||||
uint8_t addr[ADDR_LEN] = {1, 2, 3, 4, 5, 6, 7, 8};
|
uint8_t addr[ADDR_LEN] = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ class DallasSensor {
|
|||||||
|
|
||||||
bool update(const std::string & id, const std::string & name, int16_t offset);
|
bool update(const std::string & id, const std::string & name, int16_t offset);
|
||||||
|
|
||||||
#ifdef EMSESP_DEBUG
|
#if defined(EMSESP_TEST)
|
||||||
void test();
|
void test();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1442,10 +1442,7 @@ void EMSESP::start() {
|
|||||||
esp8266React.begin(); // loads core system services settings (network, mqtt, ap, ntp etc)
|
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
|
webLogService.begin(); // start web log service. now we can start capturing logs to the web log
|
||||||
|
|
||||||
#if defined(EMSESP_DEBUG)
|
LOG_DEBUG("System is running in Debug mode");
|
||||||
LOG_NOTICE("System is running in Debug mode");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
LOG_INFO("Last system reset reason Core0: %s, Core1: %s", system_.reset_reason(0).c_str(), system_.reset_reason(1).c_str());
|
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
|
// see if we're restoring a settings file
|
||||||
|
|||||||
12
src/mqtt.cpp
12
src/mqtt.cpp
@@ -249,7 +249,7 @@ void Mqtt::show_mqtt(uuid::console::Shell & shell) {
|
|||||||
shell.println();
|
shell.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_TEST)
|
||||||
// simulate receiving a MQTT message, used only for testing
|
// simulate receiving a MQTT message, used only for testing
|
||||||
void Mqtt::incoming(const char * topic, const char * payload) {
|
void Mqtt::incoming(const char * topic, const char * payload) {
|
||||||
if (payload != nullptr) {
|
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 {
|
void Mqtt::on_publish(uint16_t packetId) const {
|
||||||
// find the MQTT message in the queue and remove it
|
// find the MQTT message in the queue and remove it
|
||||||
if (mqtt_messages_.empty()) {
|
if (mqtt_messages_.empty()) {
|
||||||
#if defined(EMSESP_DEBUG)
|
|
||||||
LOG_DEBUG("No message stored for ACK pid %d", packetId);
|
LOG_DEBUG("No message stored for ACK pid %d", packetId);
|
||||||
#endif
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,9 +390,7 @@ void Mqtt::on_publish(uint16_t packetId) const {
|
|||||||
mqtt_publish_fails_++; // increment error count
|
mqtt_publish_fails_++; // increment error count
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(EMSESP_DEBUG)
|
|
||||||
LOG_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
|
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;
|
std::string fulltopic = Mqtt::discovery_prefix() + topic;
|
||||||
#if defined(EMSESP_DEBUG)
|
|
||||||
LOG_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
|
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
|
serializeJson(payload, payload_text); // convert json to string
|
||||||
|
|
||||||
std::string fulltopic = Mqtt::discovery_prefix() + topic;
|
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());
|
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 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
|
queue_publish_message(fulltopic, payload_text, true); // with retain true
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ class Mqtt {
|
|||||||
|
|
||||||
static void ha_status();
|
static void ha_status();
|
||||||
|
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_TEST)
|
||||||
void incoming(const char * topic, const char * payload = ""); // for testing only
|
void incoming(const char * topic, const char * payload = ""); // for testing only
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -417,7 +417,7 @@ void System::start() {
|
|||||||
void System::button_OnClick(PButton & b) {
|
void System::button_OnClick(PButton & b) {
|
||||||
LOG_DEBUG("Button pressed - single click");
|
LOG_DEBUG("Button pressed - single click");
|
||||||
|
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_TEST)
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
Test::listDir(LittleFS, FS_CONFIG_DIRECTORY, 3);
|
Test::listDir(LittleFS, FS_CONFIG_DIRECTORY, 3);
|
||||||
#endif
|
#endif
|
||||||
@@ -521,21 +521,6 @@ void System::loop() {
|
|||||||
|
|
||||||
led_monitor(); // check status and report back using the LED
|
led_monitor(); // check status and report back using the LED
|
||||||
system_check(); // check system health
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ class System {
|
|||||||
return test_set_all_active_;
|
return test_set_all_active_;
|
||||||
}
|
}
|
||||||
static void test_set_all_active(bool n) {
|
static void test_set_all_active(bool n) {
|
||||||
#if defined(EMSESP_DEBUG)
|
#if defined(EMSESP_TEST)
|
||||||
if (n) {
|
if (n) {
|
||||||
logger_.debug("Using dummy entity values");
|
logger_.debug("Using dummy entity values");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user