From 697da4f10986f324038c634662eb49499c79e093 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sat, 25 May 2024 20:27:28 +0300 Subject: [PATCH 01/12] Ensure that the local logging libraries are at front --- .clang-format | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.clang-format b/.clang-format index a544b807f..eecc5652d 100644 --- a/.clang-format +++ b/.clang-format @@ -1,3 +1,9 @@ --- BasedOnStyle: Google IndentWidth: 2 +IncludeBlocksStyle: Regroup +IncludeCategories: + - Regex: '"sensesp\.h"' + Priority: -1000 + - Regex: '"esp32-hal-log\.h"' + Priority: -900 From 7bfae343c524180d856606e0a4b0cb711c2cadd6 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sat, 25 May 2024 20:28:00 +0300 Subject: [PATCH 02/12] Remove crud --- src/sensesp/net/debug_output.cpp | 24 ------------------------ src/sensesp/net/debug_output.h | 28 ---------------------------- 2 files changed, 52 deletions(-) delete mode 100644 src/sensesp/net/debug_output.cpp delete mode 100644 src/sensesp/net/debug_output.h diff --git a/src/sensesp/net/debug_output.cpp b/src/sensesp/net/debug_output.cpp deleted file mode 100644 index 653817112..000000000 --- a/src/sensesp/net/debug_output.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "debug_output.h" - -#include "sensesp/system/local_debug.h" -#include "sensesp_app.h" - -namespace sensesp { - -#ifndef DEBUG_DISABLED -DEBUG_CLASS Debug; -#endif - -DebugOutput::DebugOutput() { -#ifndef DEBUG_DISABLED - Debug.begin(); - Debug.setResetCmdEnabled(true); -// serial port debugging happens synchronously -#ifdef REMOTE_DEBUG - // serial port debugging happens synchronously - ReactESP::app->onRepeat(1, []() { Debug.handle(); }); -#endif -#endif -} - -} // namespace sensesp diff --git a/src/sensesp/net/debug_output.h b/src/sensesp/net/debug_output.h deleted file mode 100644 index b6da3d295..000000000 --- a/src/sensesp/net/debug_output.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _remote_debug_H_ -#define _remote_debug_H_ - -#include - -namespace sensesp { - -void SetupSerialDebug(uint32_t baudrate); - -/** - * @brief Initialize logging/debug output. - * - * The actual output mechanism is controlled by preprocessor macros defined - * in platformio.ini. - * - * If DEBUG_DISABLED is defined, all output is disabled. - * If REMOTE_DEBUG is defined, output is enabled both over the serial interface - * and over telnet on port 23. - * By default, output is enabled only on the serial interface. - **/ -class DebugOutput { - public: - DebugOutput(); -}; - -} // namespace sensesp - -#endif From be7b248566a113469280b55bf6cfe57f616dda8b Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sat, 25 May 2024 20:31:14 +0300 Subject: [PATCH 03/12] Migrate to ESP-IDF logging facilities --- src/sensesp.h | 10 +--- .../controllers/system_status_controller.h | 5 +- src/sensesp/system/hash.cpp | 3 - src/sensesp/system/local_debug.h | 55 +++++-------------- src/sensesp/transforms/enable.h | 6 +- src/sensesp/transforms/time_counter.h | 12 ++-- src/sensesp/ui/ui_controls.h | 8 +-- src/sensesp_base_app.cpp | 19 +++---- src/sensesp_base_app.h | 6 +- 9 files changed, 41 insertions(+), 83 deletions(-) diff --git a/src/sensesp.h b/src/sensesp.h index fb6f1bc74..1d32cb289 100644 --- a/src/sensesp.h +++ b/src/sensesp.h @@ -4,12 +4,10 @@ #include #include "sensesp/system/local_debug.h" -#ifndef DEBUG_DISABLED -#define DEBUG_CLASS LocalDebug -#endif // DEBUG_DISABLED #if ESP8266 -#error "ESP8266 isn't supported by SensESP version 2. To compile an existing project, add @^1.0.0 to the SensESP depdenency in platformio.ini." +#error \ + "ESP8266 isn't supported by SensESP version 2. To compile an existing project, add @^1.0.0 to the SensESP depdenency in platformio.ini." #endif namespace sensesp { @@ -21,10 +19,6 @@ using namespace reactesp; typedef std::function void_cb_func; -#ifndef DEBUG_DISABLED -extern DEBUG_CLASS Debug; -#endif - } // namespace sensesp #endif diff --git a/src/sensesp/controllers/system_status_controller.h b/src/sensesp/controllers/system_status_controller.h index 0f7e8de09..da34d3e5b 100644 --- a/src/sensesp/controllers/system_status_controller.h +++ b/src/sensesp/controllers/system_status_controller.h @@ -32,12 +32,11 @@ class SystemStatusController : public ValueConsumer, /// ValueConsumer interface for ValueConsumer (Networking object /// state updates) - virtual void set(WiFiState new_value, - uint8_t input_channel = 0) override; + virtual void set(WiFiState new_value, uint8_t input_channel = 0) override; /// ValueConsumer interface for ValueConsumer /// (SKWSClient object state updates) virtual void set(SKWSConnectionState new_value, - uint8_t input_channel = 0) override; + uint8_t input_channel = 0) override; protected: void update_state(const SystemStatus new_state) { diff --git a/src/sensesp/system/hash.cpp b/src/sensesp/system/hash.cpp index b2ce1ec33..d05b4987a 100644 --- a/src/sensesp/system/hash.cpp +++ b/src/sensesp/system/hash.cpp @@ -4,8 +4,6 @@ #include "mbedtls/md5.h" #include "mbedtls/base64.h" -#include "sensesp/net/debug_output.h" - using namespace sensesp; /** @@ -92,4 +90,3 @@ String Base64Sha1(String payload_str) { return encoded_str; } - diff --git a/src/sensesp/system/local_debug.h b/src/sensesp/system/local_debug.h index 9c700a3f0..95ca75225 100644 --- a/src/sensesp/system/local_debug.h +++ b/src/sensesp/system/local_debug.h @@ -1,34 +1,19 @@ #ifndef _local_debug_H_ #define _local_debug_H_ +#include "esp32-hal-log.h" #include "Arduino.h" #include "Print.h" namespace sensesp { -#ifndef DEBUG_DISABLED - -#define rdebugA(fmt, ...) \ - if (Debug.isActive(Debug.ANY)) \ - Serial.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__) -#define rdebugP(fmt, ...) \ - if (Debug.isActive(Debug.PROFILER)) \ - Serial.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__) -#define rdebugV(fmt, ...) \ - if (Debug.isActive(Debug.VERBOSE)) \ - Serial.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__) -#define rdebugD(fmt, ...) \ - if (Debug.isActive(Debug.DEBUG)) \ - Serial.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__) -#define rdebugI(fmt, ...) \ - if (Debug.isActive(Debug.INFO)) \ - Serial.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__) -#define rdebugW(fmt, ...) \ - if (Debug.isActive(Debug.WARNING)) \ - Serial.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__) -#define rdebugE(fmt, ...) \ - if (Debug.isActive(Debug.ERROR)) \ - Serial.printf("(%s)(C%d) " fmt, __func__, xPortGetCoreID(), ##__VA_ARGS__) +#define rdebugA(fmt, ...) ESP_LOGV("SensESP", fmt, ##__VA_ARGS__) +#define rdebugP(fmt, ...) ESP_LOGV("SensESP", fmt, ##__VA_ARGS__) +#define rdebugV(fmt, ...) ESP_LOGV("SensESP", fmt, ##__VA_ARGS__) +#define rdebugD(fmt, ...) ESP_LOGD("SensESP", fmt, ##__VA_ARGS__) +#define rdebugI(fmt, ...) ESP_LOGI("SensESP", fmt, ##__VA_ARGS__) +#define rdebugW(fmt, ...) ESP_LOGW("SensESP", fmt, ##__VA_ARGS__) +#define rdebugE(fmt, ...) ESP_LOGE("SensESP", fmt, ##__VA_ARGS__) // With newline @@ -43,12 +28,12 @@ namespace sensesp { // New way: To compatibility with SerialDebug (can use RemoteDebug or // SerialDebug) This is my favorite :) -#define debugV(fmt, ...) rdebugVln(fmt, ##__VA_ARGS__) -#define debugD(fmt, ...) rdebugDln(fmt, ##__VA_ARGS__) -#define debugI(fmt, ...) rdebugIln(fmt, ##__VA_ARGS__) -#define debugW(fmt, ...) rdebugWln(fmt, ##__VA_ARGS__) -#define debugE(fmt, ...) rdebugEln(fmt, ##__VA_ARGS__) -#define debugA(fmt, ...) rdebugVln(fmt, ##__VA_ARGS__) +#define debugV(fmt, ...) rdebugV(fmt, ##__VA_ARGS__) +#define debugD(fmt, ...) rdebugD(fmt, ##__VA_ARGS__) +#define debugI(fmt, ...) rdebugI(fmt, ##__VA_ARGS__) +#define debugW(fmt, ...) rdebugW(fmt, ##__VA_ARGS__) +#define debugE(fmt, ...) rdebugE(fmt, ##__VA_ARGS__) +#define debugA(fmt, ...) rdebugV(fmt, ##__VA_ARGS__) class LocalDebug { public: @@ -76,18 +61,6 @@ class LocalDebug { uint8_t lastDebugLevel_ = DEBUG; }; -#else // DEBUG_DISABLED - -#define debugA(...) -#define debugP(...) -#define debugV(...) -#define debugD(...) -#define debugI(...) -#define debugW(...) -#define debugE(...) - -#endif - } // namespace sensesp #endif diff --git a/src/sensesp/transforms/enable.h b/src/sensesp/transforms/enable.h index 6d380a64c..a2084dd71 100644 --- a/src/sensesp/transforms/enable.h +++ b/src/sensesp/transforms/enable.h @@ -1,7 +1,7 @@ -#ifndef _enable_H_ -#define _enable_H_ +#ifndef SENSESP_SRC_SENSESP_TRANSFORMS_ENABLE_H_ +#define SENSESP_SRC_SENSESP_TRANSFORMS_ENABLE_H_ -#include "transforms/transform.h" +#include "sensesp/transforms/transform.h" namespace sensesp { diff --git a/src/sensesp/transforms/time_counter.h b/src/sensesp/transforms/time_counter.h index d8abe8f9f..2c4b8c7a7 100644 --- a/src/sensesp/transforms/time_counter.h +++ b/src/sensesp/transforms/time_counter.h @@ -1,6 +1,7 @@ +#ifndef SENSESP_SRC_TRANSFORMS_TIME_COUNTER_H_ +#define SENSESP_SRC_TRANSFORMS_TIME_COUNTER_H_ + #include "sensesp/transforms/transform.h" -#ifndef SENSESP_TRANSFORMS_TIME_COUNTER_H_ -#define SENSESP_TRANSFORMS_TIME_COUNTER_H_ namespace sensesp { @@ -30,8 +31,7 @@ static const char kTimeCounterSchema[] = R"({ template class TimeCounter : public Transform { public: - TimeCounter(String config_path) - : Transform(config_path) { + TimeCounter(String config_path) : Transform(config_path) { this->load_configuration(); } @@ -82,9 +82,7 @@ class TimeCounter : public Transform { return true; } - virtual String get_config_schema() override { - return kTimeCounterSchema; - } + virtual String get_config_schema() override { return kTimeCounterSchema; } protected: int previous_state_ = -1; // -1 means uninitialized diff --git a/src/sensesp/ui/ui_controls.h b/src/sensesp/ui/ui_controls.h index 73346adca..8c98ee6fe 100644 --- a/src/sensesp/ui/ui_controls.h +++ b/src/sensesp/ui/ui_controls.h @@ -2,6 +2,7 @@ #define SENSESP_SRC_UI_CONTROLS_H_ #include "sensesp.h" + #include "sensesp/system/configurable.h" namespace sensesp { @@ -45,9 +46,7 @@ class NumberConfig : public Configurable { class CheckboxConfig : public Configurable { public: CheckboxConfig(bool value, String title, String config_path) - : value_(value), - title_(title), - Configurable(config_path) { + : value_(value), title_(title), Configurable(config_path) { load_configuration(); } @@ -71,8 +70,7 @@ enum class SelectType { class SelectConfig : public Configurable { public: SelectConfig(String value, String title, String config_path, - std::vector options, - SelectType format) + std::vector options, SelectType format) : value_(value), title_(title), options_(options), diff --git a/src/sensesp_base_app.cpp b/src/sensesp_base_app.cpp index cae21d9cb..050bea7bd 100644 --- a/src/sensesp_base_app.cpp +++ b/src/sensesp_base_app.cpp @@ -3,16 +3,15 @@ namespace sensesp { void SetupSerialDebug(uint32_t baudrate) { - Serial.begin(baudrate); + SetupLogging(); - // A small delay and one debugI() are required so that - // the serial output displays everything -#ifndef DEBUG_DISABLED - delay(100); - Debug.setSerialEnabled(true); - delay(100); -#endif - debugI("\nSerial debugging enabled"); + if (baudrate != 115200) { + ESP_LOGW("SensESP", "SetupSerialDebug baudrate parameter is ignored."); + } +} + +void SetupLogging(esp_log_level_t default_level) { + esp_log_level_set("*", default_level); } SensESPBaseApp* SensESPBaseApp::instance_ = nullptr; @@ -26,8 +25,6 @@ SensESPBaseApp::SensESPBaseApp() { "/system/hostname"); hostname_->set_description("Device hostname"); hostname_->set_sort_order(0); - // create a remote debugger object - debug_output_ = new DebugOutput(); } /** diff --git a/src/sensesp_base_app.h b/src/sensesp_base_app.h index d5e44727f..02543020f 100644 --- a/src/sensesp_base_app.h +++ b/src/sensesp_base_app.h @@ -7,7 +7,9 @@ #endif #include "sensesp.h" -#include "sensesp/net/debug_output.h" + +#include "esp_log.h" + #include "sensesp/system/filesystem.h" #include "sensesp/system/observablevalue.h" @@ -16,6 +18,7 @@ namespace sensesp { constexpr auto kDefaultHostname = "SensESP"; void SetupSerialDebug(uint32_t baudrate); +void SetupLogging(esp_log_level_t default_level=ESP_LOG_VERBOSE); /** * @brief The base class for SensESP applications. @@ -71,7 +74,6 @@ class SensESPBaseApp { PersistingObservableValue* hostname_; Filesystem* filesystem_; - DebugOutput* debug_output_; const SensESPBaseApp* set_hostname(String hostname) { hostname_->set(hostname); From cc71419babfd77ac1b70d8e91459bc6693495ece Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sat, 25 May 2024 20:32:53 +0300 Subject: [PATCH 04/12] Change deprecated ADC enum value --- src/sensesp/sensors/analog_reader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sensesp/sensors/analog_reader.h b/src/sensesp/sensors/analog_reader.h index 29cad05fe..ee8796c1b 100644 --- a/src/sensesp/sensors/analog_reader.h +++ b/src/sensesp/sensors/analog_reader.h @@ -24,7 +24,7 @@ class BaseAnalogReader { class ESP32AnalogReader : public BaseAnalogReader { private: int pin_; - adc_atten_t attenuation_ = ADC_ATTEN_DB_11; + adc_atten_t attenuation_ = ADC_ATTEN_DB_12; // This should work with ESP32 and newer variants, ADCs are different adc_bits_width_t bit_width_ = (adc_bits_width_t) ADC_WIDTH_BIT_DEFAULT; // maximum voltage readout for 3.3V VDDA when attenuation_ is set to 11 dB From f821a6ef368777f8b59db621ab7c80c7b3805262 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sat, 25 May 2024 21:21:49 +0300 Subject: [PATCH 05/12] Throw an error if CORE_DEBUG_LEVEL is not defined --- src/sensesp.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sensesp.h b/src/sensesp.h index 1d32cb289..47a1bd739 100644 --- a/src/sensesp.h +++ b/src/sensesp.h @@ -10,6 +10,10 @@ "ESP8266 isn't supported by SensESP version 2. To compile an existing project, add @^1.0.0 to the SensESP depdenency in platformio.ini." #endif +#ifndef CORE_DEBUG_LEVEL +#error "SensESP v3 requires CORE_DEBUG_LEVEL to be defined. See https://signalk.org/SensESP/pages/migration/." +#endif + namespace sensesp { // Typically, pulling a namespace into another is something to be avoided, From ccda8ea798b1c17f984069f76d3bca3316dd0607 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sun, 26 May 2024 21:15:48 +0300 Subject: [PATCH 06/12] Document the logging changes --- docs/pages/migration/index.md | 85 ++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 11 deletions(-) diff --git a/docs/pages/migration/index.md b/docs/pages/migration/index.md index bd79578a8..c549a088e 100644 --- a/docs/pages/migration/index.md +++ b/docs/pages/migration/index.md @@ -4,14 +4,77 @@ title: Migrating From Version 1 nav_order: 70 --- -# Migrating SensESP Version 1 Projects to Version 2 +# Migration Guides for SensESP Major Versions + +## Migrating SensESP Version 2 Projects to Version 3 + + + +### Logging + +Previous SensESP versions logged to the serial port using the `debugX` functions, where `X` is the log level. +This pattern was inherited from the RemoteDebug library. +SensESP v3 has switched to using standard ESP-IDF logging functions. +They allow redirecting log messages to different outputs, which will be used in future SensESP versions to provide logging to the web interface. + +To enable logging in SensESP v3, change the `build_flags` in your `platformio.ini` file to include the following: + +```ini +build_flags = + -D LED_BUILTIN=2 + ; Max (and default) debugging level in Arduino ESP32 Core + -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE + ; Arduino Core bug workaround: define the log tag for the Arduino + ; logging macros. + -D TAG='"ARDUINO"' + ; Use the ESP-IDF logging library - required by SensESP. + -D USE_ESP_IDF_LOG +``` + +The `debugX` functions are still available, but they are now just wrappers around the ESP-IDF logging functions. +In any new code, use the `ESP_LOGX` functions, where `X` is the log level. +These require a tag argument, which is a string that identifies the source of the log message. +You can use any tag you like, but for simple programs, you can use the `__FILE__` macro, which expands to the name of the current file. + +The allowed log levels are: + +- `NONE`: No log output +- `ERROR`: Critical errors, software module can not recover on its own +- `WARN`: Error conditions from which recovery measures have been taken +- `INFO`: Information messages which describe normal flow of events +- `DEBUG`: Extra information which is not necessary for normal use (values, pointers, sizes, etc). +- `VERBOSE`: Bigger chunks of debugging information, or frequent messages which can potentially flood the output. + +Here is an example of how to use the `ESP_LOGX` functions: + +```c++ +ESP_LOGI(__FILE__, "Initializing NMEA2000"); +... +ESP_LOGD(__FILE__, "Sending value %d to fobulator %s", value, fobulator_name); +... +ESP_LOGE(__FILE__, "Failed to initialize NMEA2000"); +``` + +To enable logging in previous SensESP versions, you had to call `SetupSerialDebug(115200)` as the first line in your `setup()` function. +In new SensESP versions, replace this with the new `SetupLogging()` function call to set logging defaults. +The old `SetupSerialDebug` function is still available, but it is now just a wrapper around `SetupLogging`. + +It is possible to change the log level for individual tags. +Here is an example of how to set the overall log level to `INFO` and the log level for the `main.cpp` tag to `DEBUG`: + +```c++ +esp_log_level_set("*", ESP_LOG_INFO); +esp_log_level_set("main.cpp", ESP_LOG_DEBUG); +``` + +## Migrating SensESP Version 1 Projects to Version 2 SensESP version 2 has a number of backwards-incompatible changes compared to the previous version. Most of the changes are trivial, while some others require a bit of more work to update the code. This document walks through the most important changes, and explains how to update your project to the new version. -## ESP8266 Support Removed +### ESP8266 Support Removed If your project uses ESP8266 hardware, you will either have to update to an ESP32 device, *or* you can keep using SensESP version 1. To peg your project to SensESP v1, change the SensESP dependency in your project's `platformio.ini` file `lib_deps` section to this: @@ -20,9 +83,9 @@ lib_deps = SignalK/SensESP @ ^1.0.8 ``` -## Main Program Structure +### Main Program Structure -### Setup and Loop Functions +#### Setup and Loop Functions SensESP builds on [ReactESP](https://github.com/mairas/ReactESP), which is an event-based framework for developing ESP32 firmware. Previous versions of ReactESP defined the Arduino Framework default `setup()` and `loop()` functions internally and relied on a lambda function for initializing the program and defining the top-level functionality: @@ -56,7 +119,7 @@ void setup() { void loop() { app.tick(); } ``` -### Namespace Usage +#### Namespace Usage In projects with a lot of dependencies, it is common that some upstream library exports some very generic symbol names, which then causes conflicts or hard-to-debug issues in the code being developed. The standard C++ approach to mitigate these issues is to use a namespace. @@ -87,7 +150,7 @@ namespace sensesp { } ``` -## External Sensors +### External Sensors All Sensor classes requiring external libraries have been removed. Reducing the number of external dependencies improves code stability and improves build times. @@ -97,7 +160,7 @@ Most, however, have been removed in favor of a more generic approach, namely the The `RepeatSensor` class allows you to easily interface any external hardware sensor libraries with SensESP. See the `RepeatSensor` tutorials ([part 1](../tutorials/bmp280), [part 2](../tutorials/bmp280)) for more details. -## Renamed Classes and Types +### Renamed Classes and Types Type-specific Consumer and Producer class names have been renamed to more closely match the native C++ types. @@ -109,7 +172,7 @@ Similarly, names with other types have been renamed to more closely match the st To better reflect the intent and the functionality, the `Enable` class has been renamed to `Startable`. -## Class Interface Changes +### Class Interface Changes Some class public interfaces have been changed. @@ -117,7 +180,7 @@ The [`DigitalInputState`](https://signalk.org/SensESP/generated/docs/classsenses The [`DigitalInputChange`](https://signalk.org/SensESP/generated/docs/classsensesp_1_1_digital_input_change.html) implementation has been simplified and the constructor no longer requres the `read_delay` argument. -## System Info Sensors +### System Info Sensors SensESP v1 had so called "standard sensors" that transmit information on the operation of the device: free memory, number of event loop executions per second, device IP address, and so on. The standard sensors were initialized using a SensESP constructor or builder bitfield argument: @@ -135,7 +198,7 @@ sensesp_app = builder.enable_free_mem_sensor() ->get_app(); ``` -## Remote Debugger Disabled +### Remote Debugger Disabled The Remote Debugger allows you to connect to the device over telnet and view the log messages and even reset the device, all without a USB cable connection. Even though this is a neat and useful feature, it was not widely known and uses *a lot* of memory. @@ -161,7 +224,7 @@ build_flags = -D DEBUG_DISABLED ``` -## Over-The-Air (OTA) Firmware Updates +### Over-The-Air (OTA) Firmware Updates OTA firmware updates have been supported already for a long time. To improve security, OTA updates are now enabled only if an OTA password is defined in the App builder: From 683f233954932164df279e6bd0d3778356bec2d4 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sun, 26 May 2024 21:16:13 +0300 Subject: [PATCH 07/12] Update the default platformio.ini file --- platformio.ini | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/platformio.ini b/platformio.ini index be957237e..c97be9438 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,6 +14,8 @@ ; examples/platformio.ini instead. [env:esp32dev] +platform = espressif32 +board = esp32dev framework = arduino lib_ldf_mode = deep @@ -29,18 +31,21 @@ lib_deps = bblanchon/ArduinoJson @ ^7.0.0 pfeerick/elapsedMillis @ ^1.0.6 bxparks/AceButton @ ^1.10.1 -platform = espressif32 build_unflags = -Werror=reorder board_build.partitions = min_spiffs.csv monitor_filters = esp32_exception_decoder extra_scripts = pre:extra_script.py check_skip_packages = true -board = esp32dev build_flags = -D LED_BUILTIN=2 - ; Uncomment the following to disable debug output altogether - ;-D DEBUG_DISABLED + ; Max (and default) debugging level in Arduino ESP32 Core + -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE + ; Arduino Core bug workaround: define the log tag for the Arduino + ; logging macros. + -D TAG='"Arduino"' + ; Use the ESP-IDF logging library - required by SensESP. + -D USE_ESP_IDF_LOG ; Uncomment the following to use the OTA interface for flashing. ; "mydevice" must correspond to the device hostname. From a6d4706fa74c1765a7e0a763ec44ba75e70a1d15 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sat, 1 Jun 2024 16:57:35 +0300 Subject: [PATCH 08/12] Remove non-existent include --- src/sensesp_app.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sensesp_app.h b/src/sensesp_app.h index 16e5d2793..4a0aa1583 100644 --- a/src/sensesp_app.h +++ b/src/sensesp_app.h @@ -10,7 +10,6 @@ #endif #include "sensesp/controllers/system_status_controller.h" -#include "sensesp/net/debug_output.h" #include "sensesp/net/discovery.h" #include "sensesp/net/http_server.h" #include "sensesp/net/networking.h" From 17ccf34eb7b1a027b317826bd07d26181c5574b1 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sat, 1 Jun 2024 16:57:55 +0300 Subject: [PATCH 09/12] Update examples --- examples/analog_input.cpp | 4 +--- examples/async_repeat_sensor.cpp | 5 +---- examples/chain_counter.cpp | 2 +- examples/constant_sensor.cpp | 5 +---- examples/freertos_tasks.cpp | 5 +---- .../fuel_level_sensor_example.cpp | 4 +--- examples/hysteresis.cpp | 2 +- examples/lambda_transform.cpp | 2 +- examples/manual_networking.cpp | 2 +- .../milone_level_sensor/milone_level_sensor.cpp | 4 +--- examples/minimal_app.cpp | 2 +- examples/platformio.ini | 16 ++++++++++++---- examples/raw_json.cpp | 4 +--- examples/relay_control.cpp | 4 +--- examples/repeat_sensor_analog_input.cpp | 5 +---- examples/rpm_counter.cpp | 4 +--- examples/smart_switch/remote_switch_example.cpp | 5 +---- examples/smart_switch/smart_switch_example.cpp | 5 +---- examples/temperature_sender.cpp | 5 +---- examples/time_counter.cpp | 5 +---- 20 files changed, 31 insertions(+), 59 deletions(-) diff --git a/examples/analog_input.cpp b/examples/analog_input.cpp index 68200e9ce..d52003f6f 100644 --- a/examples/analog_input.cpp +++ b/examples/analog_input.cpp @@ -17,9 +17,7 @@ reactesp::ReactESP app; // The setup function performs one-time application initialization. void setup() { // Some initialization boilerplate when in debug mode... -#ifndef SERIAL_DEBUG_DISABLED - SetupSerialDebug(115200); -#endif + SetupLogging(); // Create the global SensESPApp() object. SensESPAppBuilder builder; diff --git a/examples/async_repeat_sensor.cpp b/examples/async_repeat_sensor.cpp index 1a0cf2b8a..de1fc9d2d 100644 --- a/examples/async_repeat_sensor.cpp +++ b/examples/async_repeat_sensor.cpp @@ -17,10 +17,7 @@ reactesp::ReactESP app; // The setup function performs one-time application initialization. void setup() { -// Some initialization boilerplate when in debug mode... -#ifndef SERIAL_DEBUG_DISABLED - SetupSerialDebug(115200); -#endif + SetupLogging(); // Create the global SensESPApp() object. SensESPAppBuilder builder; diff --git a/examples/chain_counter.cpp b/examples/chain_counter.cpp index b0f20c903..c48faee4d 100644 --- a/examples/chain_counter.cpp +++ b/examples/chain_counter.cpp @@ -25,7 +25,7 @@ using namespace sensesp; ReactESP app; void setup() { - SetupSerialDebug(115200); + SetupLogging(); SensESPAppBuilder builder; sensesp_app = builder.set_hostname("ChainCounter") diff --git a/examples/constant_sensor.cpp b/examples/constant_sensor.cpp index 05bce5e17..77e26e313 100644 --- a/examples/constant_sensor.cpp +++ b/examples/constant_sensor.cpp @@ -20,10 +20,7 @@ using namespace sensesp; reactesp::ReactESP app; void setup() { - // Some initialization boilerplate when in debug mode... -#ifndef SERIAL_DEBUG_DISABLED - SetupSerialDebug(115200); -#endif + SetupLogging(); // Create the builder object SensESPAppBuilder builder; diff --git a/examples/freertos_tasks.cpp b/examples/freertos_tasks.cpp index 33c17b232..7055cbbd9 100644 --- a/examples/freertos_tasks.cpp +++ b/examples/freertos_tasks.cpp @@ -35,10 +35,7 @@ void ToggleTestOutputPin(void *parameter) { // The setup function performs one-time application initialization. void setup() { -// Some initialization boilerplate when in debug mode... -#ifndef SERIAL_DEBUG_DISABLED - SetupSerialDebug(115200); -#endif + SetupLogging(); SensESPMinimalAppBuilder builder; SensESPMinimalApp *sensesp_app = builder.set_hostname("async")->get_app(); diff --git a/examples/fuel_level_sensor/fuel_level_sensor_example.cpp b/examples/fuel_level_sensor/fuel_level_sensor_example.cpp index a622efd15..81033b66d 100644 --- a/examples/fuel_level_sensor/fuel_level_sensor_example.cpp +++ b/examples/fuel_level_sensor/fuel_level_sensor_example.cpp @@ -10,9 +10,7 @@ using namespace sensesp; ReactESP app; void setup() { -#ifndef SERIAL_DEBUG_DISABLED - SetupSerialDebug(115200); -#endif + SetupLogging(); // Set up sensesp SensESPAppBuilder builder; diff --git a/examples/hysteresis.cpp b/examples/hysteresis.cpp index 864c85392..0633507a7 100644 --- a/examples/hysteresis.cpp +++ b/examples/hysteresis.cpp @@ -12,7 +12,7 @@ using namespace sensesp; ReactESP app; void setup() { - SetupSerialDebug(115200); + SetupLogging(); SensESPAppBuilder builder; sensesp_app = builder.set_hostname("sensesp-hysteresis-example") diff --git a/examples/lambda_transform.cpp b/examples/lambda_transform.cpp index c41b8c644..3337ad42b 100644 --- a/examples/lambda_transform.cpp +++ b/examples/lambda_transform.cpp @@ -11,7 +11,7 @@ using namespace sensesp; ReactESP app; void setup() { - SetupSerialDebug(115200); + SetupLogging(); // Create a new SensESPApp object. This is the direct constructor call, and // an equivalent alternative to using the SensESPAppBuilder class. diff --git a/examples/manual_networking.cpp b/examples/manual_networking.cpp index 01e0b7f52..609f68ad2 100644 --- a/examples/manual_networking.cpp +++ b/examples/manual_networking.cpp @@ -24,7 +24,7 @@ const uint8_t input_pin1 = 0; ReactESP app; void setup() { - SetupSerialDebug(115200); + SetupLogging(); SensESPMinimalAppBuilder builder; auto sensesp_app = builder.set_hostname("counter-test")->get_app(); diff --git a/examples/milone_level_sensor/milone_level_sensor.cpp b/examples/milone_level_sensor/milone_level_sensor.cpp index 52dadf904..53120516d 100644 --- a/examples/milone_level_sensor/milone_level_sensor.cpp +++ b/examples/milone_level_sensor/milone_level_sensor.cpp @@ -47,9 +47,7 @@ ReactESP app; void setup() { // Some initialization boilerplate when in debug mode... -#ifndef SERIAL_DEBUG_DISABLED - SetupSerialDebug(115200); -#endif + SetupLogging(); // Create a builder object SensESPAppBuilder builder; diff --git a/examples/minimal_app.cpp b/examples/minimal_app.cpp index 86614852c..9282817f0 100644 --- a/examples/minimal_app.cpp +++ b/examples/minimal_app.cpp @@ -29,7 +29,7 @@ const uint8_t output_pin2 = 21; ReactESP app; void setup() { - SetupSerialDebug(115200); + SetupLogging(); SensESPMinimalAppBuilder builder; auto sensesp_app = builder.set_hostname("counter-test")->get_app(); diff --git a/examples/platformio.ini b/examples/platformio.ini index 346a721b9..386bc72a8 100644 --- a/examples/platformio.ini +++ b/examples/platformio.ini @@ -15,7 +15,7 @@ [platformio] ;set default_envs to whichever board(s) you use. Build/Run/etc processes those envs -default_envs = +default_envs = esp32dev [env] @@ -46,11 +46,19 @@ monitor_filters = esp32_exception_decoder [env:esp32dev] extends = espressif32_base board = esp32dev -; Verify that this is the correct pin number for your board! -build_flags = + +build_flags = + ; Verify that this is the correct pin number for your board! -D LED_BUILTIN = 2 + ; Max (and default) debugging level in Arduino ESP32 Core + -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE + ; Arduino Core bug workaround: define the log tag for the Arduino + ; logging macros. + -D TAG='"Arduino"' + ; Use the ESP-IDF logging library - required by SensESP. + -D USE_ESP_IDF_LOG + ; uncomment and change these if PlatformIO can't auto-detect ; the ports ;upload_port = /dev/tty.SLAB_USBtoUART ;monitor_port = /dev/tty.SLAB_USBtoUART - diff --git a/examples/raw_json.cpp b/examples/raw_json.cpp index e06975bf5..78ffb7077 100644 --- a/examples/raw_json.cpp +++ b/examples/raw_json.cpp @@ -14,9 +14,7 @@ reactesp::ReactESP app; ObservableValue toggler; void setup() { -#ifndef SERIAL_DEBUG_DISABLED - SetupSerialDebug(115200); -#endif + SetupLogging(); SensESPAppBuilder builder; SensESPApp *sensesp_app = builder.set_hostname("json_demo") diff --git a/examples/relay_control.cpp b/examples/relay_control.cpp index 7d3b5ef7a..3ba345539 100644 --- a/examples/relay_control.cpp +++ b/examples/relay_control.cpp @@ -23,9 +23,7 @@ ReactESP app; void setup() { // Some initialization boilerplate when in debug mode... -#ifndef SERIAL_DEBUG_DISABLED - SetupSerialDebug(115200); -#endif + SetupLogging(); // Create a builder object SensESPAppBuilder builder; diff --git a/examples/repeat_sensor_analog_input.cpp b/examples/repeat_sensor_analog_input.cpp index c59ec847d..766a96ebd 100644 --- a/examples/repeat_sensor_analog_input.cpp +++ b/examples/repeat_sensor_analog_input.cpp @@ -30,10 +30,7 @@ float analog_read_callback() { return analogRead(kAnalogInputPin) / 4096.0; } // The setup function performs one-time application initialization. void setup() { -// Some initialization boilerplate when in debug mode... -#ifndef SERIAL_DEBUG_DISABLED - SetupSerialDebug(115200); -#endif + SetupLogging(); // Create the global SensESPApp() object. SensESPAppBuilder builder; diff --git a/examples/rpm_counter.cpp b/examples/rpm_counter.cpp index 45e23ffb6..459ba791e 100644 --- a/examples/rpm_counter.cpp +++ b/examples/rpm_counter.cpp @@ -14,9 +14,7 @@ using namespace sensesp; ReactESP app; void setup() { -#ifndef SERIAL_DEBUG_DISABLED - SetupSerialDebug(115200); -#endif + SetupLogging(); SensESPAppBuilder builder; sensesp_app = builder.get_app(); diff --git a/examples/smart_switch/remote_switch_example.cpp b/examples/smart_switch/remote_switch_example.cpp index 781f10248..3d0a4ea9d 100644 --- a/examples/smart_switch/remote_switch_example.cpp +++ b/examples/smart_switch/remote_switch_example.cpp @@ -40,10 +40,7 @@ using namespace sensesp; ReactESP app; void setup() { -// Some initialization boilerplate when in debug mode... -#ifndef SERIAL_DEBUG_DISABLED - SetupSerialDebug(115200); -#endif + SetupLogging(); // Create a builder object SensESPAppBuilder builder; diff --git a/examples/smart_switch/smart_switch_example.cpp b/examples/smart_switch/smart_switch_example.cpp index 31c1ad50d..c48e36ad2 100644 --- a/examples/smart_switch/smart_switch_example.cpp +++ b/examples/smart_switch/smart_switch_example.cpp @@ -43,10 +43,7 @@ using namespace sensesp; ReactESP app; void setup() { -// Some initialization boilerplate when in debug mode... -#ifndef SERIAL_DEBUG_DISABLED - SetupSerialDebug(115200); -#endif + SetupLogging(); // Create a builder object SensESPAppBuilder builder; diff --git a/examples/temperature_sender.cpp b/examples/temperature_sender.cpp index d1920a410..a048b2884 100644 --- a/examples/temperature_sender.cpp +++ b/examples/temperature_sender.cpp @@ -60,10 +60,7 @@ class TemperatureInterpreter : public CurveInterpolator { ReactESP app; void setup() { -// Some initialization boilerplate when in debug mode... -#ifndef SERIAL_DEBUG_DISABLED - SetupSerialDebug(115200); -#endif + SetupLogging(); // Create the global SensESPApp() object by first creating a // SensESPAppBuilder object, then setting some hard-coded diff --git a/examples/time_counter.cpp b/examples/time_counter.cpp index b7b0a0d53..ebec86c2d 100644 --- a/examples/time_counter.cpp +++ b/examples/time_counter.cpp @@ -31,10 +31,7 @@ unsigned long freq_start_time = 0; int freq = 0; void setup() { - // Some initialization boilerplate when in debug mode... -#ifndef SERIAL_DEBUG_DISABLED - SetupSerialDebug(115200); -#endif + SetupLogging(); // Create the builder object SensESPAppBuilder builder; From 80c922f94ffdba6a82ba10f119a06f376282fb43 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sat, 1 Jun 2024 17:06:41 +0300 Subject: [PATCH 10/12] Also update test builds --- ci/platformio-esp32dev.ini | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ci/platformio-esp32dev.ini b/ci/platformio-esp32dev.ini index c45f13e16..52e26ef5a 100644 --- a/ci/platformio-esp32dev.ini +++ b/ci/platformio-esp32dev.ini @@ -15,3 +15,9 @@ board_build.partitions = min_spiffs.csv monitor_filters = esp32_exception_decoder build_flags = -D LED_BUILTIN=2 + -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE + ; Arduino Core bug workaround: define the log tag for the Arduino + ; logging macros. + -D TAG='"Arduino"' + ; Use the ESP-IDF logging library - required by SensESP. + -D USE_ESP_IDF_LOG From f41631c4df4a95e2caeeb2aa074a110da2731afa Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sat, 1 Jun 2024 17:11:15 +0300 Subject: [PATCH 11/12] Remove EDSP8266 CI platformio.ini Unsupported since v1... --- ci/platformio-d1_mini.ini | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 ci/platformio-d1_mini.ini diff --git a/ci/platformio-d1_mini.ini b/ci/platformio-d1_mini.ini deleted file mode 100644 index e3d5ee2d3..000000000 --- a/ci/platformio-d1_mini.ini +++ /dev/null @@ -1,18 +0,0 @@ -; CI platformio.ini for d1_mini - -[env] -; Global data for all [env:***] -framework = arduino -lib_ldf_mode = deep -monitor_speed = 115200 -lib_deps = ${PROJDIR} - -[env:d1_mini] -platform = espressif8266 -board = d1_mini -board_build.ldscript = eagle.flash.4m1m.ld -build_flags = - -Wall - -Wno-reorder - -D LED_BUILTIN=2 -board_build.f_cpu = 160000000L From 8868449bce7f1f7c21cceab51747c2276dbc8125 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sat, 1 Jun 2024 17:11:32 +0300 Subject: [PATCH 12/12] Update GitHub Actions file --- .github/workflows/test.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 499880e35..326078101 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,6 @@ on: [push, pull_request] jobs: build: - runs-on: ubuntu-latest strategy: matrix: @@ -26,13 +25,19 @@ jobs: target_device: - esp32dev steps: - - uses: actions/checkout@v1 - - name: Set up Python - uses: actions/setup-python@v1 + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + with: + path: | + ~/.cache/pip + ~/.platformio/.cache + key: ${{ runner.os }}-pio + - uses: actions/setup-python@v4 + with: + python-version: "3.11" - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install platformio + pip install --upgrade platformio - name: Run PlatformIO run: ci/run-ci.sh env: