From 611f06b0a16a838692ff8d1a5aedadfc026fd931 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sun, 8 Dec 2024 12:40:54 +0200 Subject: [PATCH 01/39] Reimplement LED blinker to support RGB LEDs --- src/sensesp/system/system_status_led.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sensesp/system/system_status_led.h b/src/sensesp/system/system_status_led.h index 428cea265..93c5ae7bf 100644 --- a/src/sensesp/system/system_status_led.h +++ b/src/sensesp/system/system_status_led.h @@ -3,6 +3,7 @@ #include #include +#include #include "lambda_consumer.h" #include "led_blinker.h" @@ -128,7 +129,7 @@ class SystemStatusLed : public BaseSystemStatusLed { class RGBSystemStatusLed : public BaseSystemStatusLed { public: RGBSystemStatusLed(uint8_t pin, uint8_t brightness = 40) - : BaseSystemStatusLed(), pin_{pin} {} + : BaseSystemStatusLed(), pin_{pin}, brightness_{brightness} {} protected: uint8_t pin_; From 43ab0811038e878cee1e0b3ddf3ba2c291f5d117 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Tue, 17 Dec 2024 14:50:48 +0200 Subject: [PATCH 02/39] Make the RGB LED blue when connected to SK --- src/sensesp/system/system_status_led.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sensesp/system/system_status_led.cpp b/src/sensesp/system/system_status_led.cpp index 474650642..34d63c58c 100644 --- a/src/sensesp/system/system_status_led.cpp +++ b/src/sensesp/system/system_status_led.cpp @@ -32,7 +32,7 @@ LEDPattern ws_connecting_pattern = { // PATTERN: ******************__ LEDPattern ws_connected_pattern = { - frag_linear_fade(900, 200, CRGB::Green), + frag_linear_fade(900, 200, CRGB::Blue), frag_linear_fade(100, 100, CRGB::Black), }; From 80c2db1e364072091458bd8145df7653fd45050c Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sun, 15 Dec 2024 23:05:23 +0200 Subject: [PATCH 03/39] Field removed in esp-idf 5 --- src/sensesp/net/http_server.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sensesp/net/http_server.h b/src/sensesp/net/http_server.h index 6834e9b78..028f76345 100644 --- a/src/sensesp/net/http_server.h +++ b/src/sensesp/net/http_server.h @@ -88,7 +88,6 @@ class HTTPServer : public FileSystemSaveable { .method = HTTP_GET, .handler = call_request_dispatcher, .user_ctx = this, - .is_websocket = false, }; httpd_register_uri_handler(server_, &uri); uri.method = HTTP_HEAD; From fa5070d10f6492063c4d48c1b11b604176c49e6d Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sun, 15 Dec 2024 23:05:57 +0200 Subject: [PATCH 04/39] Use Arduino analogRead for AnalogReader --- src/sensesp/sensors/analog_input.cpp | 4 +-- src/sensesp/sensors/analog_input.h | 1 + src/sensesp/sensors/analog_reader.h | 39 ++-------------------------- 3 files changed, 4 insertions(+), 40 deletions(-) diff --git a/src/sensesp/sensors/analog_input.cpp b/src/sensesp/sensors/analog_input.cpp index cac18e5d3..e60ad4022 100644 --- a/src/sensesp/sensors/analog_input.cpp +++ b/src/sensesp/sensors/analog_input.cpp @@ -16,9 +16,7 @@ AnalogInput::AnalogInput(uint8_t pin, unsigned int read_delay, analog_reader_ = std::unique_ptr(new AnalogReader(pin)); load(); - if (this->analog_reader_->configure()) { - event_loop()->onRepeat(read_delay, [this]() { this->update(); }); - } + event_loop()->onRepeat(read_delay, [this]() { this->update(); }); } void AnalogInput::update() { this->emit(output_scale * analog_reader_->read()); } diff --git a/src/sensesp/sensors/analog_input.h b/src/sensesp/sensors/analog_input.h index eb802aae8..eeaa0c9a9 100644 --- a/src/sensesp/sensors/analog_input.h +++ b/src/sensesp/sensors/analog_input.h @@ -40,6 +40,7 @@ namespace sensesp { * make this parameter be the maximum voltage that you would send into the * voltage divider circuit. */ +[[deprecated("Use RepeatSensor and Arduino analogReadMilliVolts() instead")]] class AnalogInput : public FloatSensor { public: AnalogInput(uint8_t pin = A0, unsigned int read_delay = 200, diff --git a/src/sensesp/sensors/analog_reader.h b/src/sensesp/sensors/analog_reader.h index 5de3b2f1e..69d3ac2ce 100644 --- a/src/sensesp/sensors/analog_reader.h +++ b/src/sensesp/sensors/analog_reader.h @@ -4,9 +4,6 @@ #include "sensesp.h" #include "Arduino.h" -#if defined(ESP32) -#include "esp_adc_cal.h" -#endif namespace sensesp { @@ -18,49 +15,17 @@ class BaseAnalogReader { int output_scale_; public: - virtual bool configure() = 0; virtual float read() = 0; }; class ESP32AnalogReader : public BaseAnalogReader { protected: int pin_; - 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 - const float kVmax_ = 3300; - int8_t adc_channel_; - esp_adc_cal_characteristics_t adc_characteristics_; - const int kVref_ = 1100; // voltage reference, in mV public: - ESP32AnalogReader(int pin) : pin_{pin} { - if (!(32 <= pin && pin <= 39)) { - ESP_LOGE(__FILENAME__, "Only ADC1 is supported at the moment"); - adc_channel_ = -1; - return; - } - adc_channel_ = digitalPinToAnalogChannel(pin); - } - - bool configure() { - if (adc_channel_ == -1) { - return false; - } - adc1_config_width(bit_width_); - adc1_config_channel_atten((adc1_channel_t)adc_channel_, attenuation_); - esp_adc_cal_characterize(ADC_UNIT_1, attenuation_, bit_width_, kVref_, - &adc_characteristics_); - return true; - } + ESP32AnalogReader(int pin) : pin_{pin} {} - float read() { - uint32_t voltage; - esp_adc_cal_get_voltage((adc_channel_t)adc_channel_, &adc_characteristics_, - &voltage); - return voltage / kVmax_; - } + float read() { return analogRead(pin_); } }; typedef ESP32AnalogReader AnalogReader; From 603d7f2696cf6589d9da491a1fecf5af5afdd871 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sun, 15 Dec 2024 23:07:25 +0200 Subject: [PATCH 05/39] Fix template class constructor syntax --- src/sensesp/sensors/sensor.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sensesp/sensors/sensor.h b/src/sensesp/sensors/sensor.h index 3b1ebf08a..e38ac364d 100644 --- a/src/sensesp/sensors/sensor.h +++ b/src/sensesp/sensors/sensor.h @@ -1,10 +1,11 @@ #ifndef SENSESP_SENSORS_SENSOR_H_ #define SENSESP_SENSORS_SENSOR_H_ +#include #include -#include "sensesp/system/saveable.h" #include "sensesp/system/observable.h" +#include "sensesp/system/saveable.h" #include "sensesp/system/valueproducer.h" #include "sensesp_base_app.h" @@ -39,8 +40,7 @@ class SensorConfig : virtual public Observable, public FileSystemSaveable { template class Sensor : public SensorConfig, virtual public ValueProducer { public: - Sensor(String config_path) - : SensorConfig(config_path), ValueProducer() {} + Sensor(String config_path) : SensorConfig(config_path), ValueProducer() {} }; typedef Sensor FloatSensor; @@ -63,7 +63,7 @@ class RepeatSensor : public Sensor { * produce. * @tparam T The type of the value returned by the callback function. */ - RepeatSensor(unsigned int repeat_interval_ms, std::function callback) + RepeatSensor(unsigned int repeat_interval_ms, std::function callback) : Sensor(""), repeat_interval_ms_(repeat_interval_ms), returning_callback_(callback) { @@ -85,8 +85,8 @@ class RepeatSensor : public Sensor { * to be called when output becomes available. * @tparam T The type of the value returned by the callback function. */ - RepeatSensor(unsigned int repeat_interval_ms, - std::function*)> callback) + RepeatSensor(unsigned int repeat_interval_ms, + std::function*)> callback) : Sensor(""), repeat_interval_ms_(repeat_interval_ms), emitting_callback_(callback) { From 718c20c1dcff2a27335a9407ecd29656da7eb5e1 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sun, 15 Dec 2024 23:08:01 +0200 Subject: [PATCH 06/39] Support MDNS Arduino 3 changes --- src/sensesp/signalk/signalk_ws_client.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sensesp/signalk/signalk_ws_client.cpp b/src/sensesp/signalk/signalk_ws_client.cpp index cc59a808a..d145b9a72 100644 --- a/src/sensesp/signalk/signalk_ws_client.cpp +++ b/src/sensesp/signalk/signalk_ws_client.cpp @@ -9,6 +9,7 @@ #include "Arduino.h" #include "elapsedMillis.h" +#include "esp_arduino_version.h" #include "sensesp/signalk/signalk_listener.h" #include "sensesp/signalk/signalk_put_request.h" #include "sensesp/signalk/signalk_put_request_listener.h" @@ -74,7 +75,8 @@ static void websocket_event_handler(void* handler_args, esp_event_base_t base, } } -SKWSClient::SKWSClient(const String& config_path, std::shared_ptr sk_delta_queue, +SKWSClient::SKWSClient(const String& config_path, + std::shared_ptr sk_delta_queue, const String& server_address, uint16_t server_port, bool use_mdns) : FileSystemSaveable{config_path}, @@ -383,7 +385,12 @@ bool SKWSClient::get_mdns_service(String& server_address, // no service found return false; } + +#if ESP_ARDUINO_VERSION_MAJOR < 3 server_address = MDNS.IP(0).toString(); +#else + server_address = MDNS.address(0).toString(); +#endif server_port = MDNS.port(0); ESP_LOGI(__FILENAME__, "Found server %s (port %d)", server_address.c_str(), server_port); From 78837eb8eaba6e335029e9ff012920ec2af675ff Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sun, 15 Dec 2024 23:08:30 +0200 Subject: [PATCH 07/39] Support Mbedtls Arduino 3 changes --- src/sensesp/system/hash.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/sensesp/system/hash.cpp b/src/sensesp/system/hash.cpp index 1e0210c0e..bae2538ad 100644 --- a/src/sensesp/system/hash.cpp +++ b/src/sensesp/system/hash.cpp @@ -1,5 +1,7 @@ #include "hash.h" +#include "esp_arduino_version.h" + #include "mbedtls/base64.h" #include "mbedtls/md.h" #include "mbedtls/md5.h" @@ -50,9 +52,15 @@ String MD5(const String& payload_str) { uint8_t i; uint8_t buf_[16] = {0}; mbedtls_md5_init(&ctx_); +#if ESP_ARDUINO_VERSION_MAJOR > 2 + mbedtls_md5_starts(&ctx_); + mbedtls_md5_update(&ctx_, (const uint8_t *)payload, payload_length); + mbedtls_md5_finish(&ctx_, buf_); +#else mbedtls_md5_starts_ret(&ctx_); mbedtls_md5_update_ret(&ctx_, (const uint8_t *)payload, payload_length); mbedtls_md5_finish_ret(&ctx_, buf_); +#endif mbedtls_md5_free(&ctx_); for (i = 0; i < 16; i++) { sprintf(output + (i * 2), "%02x", buf_[i]); From 598174b96853cb6d05da8a549c824aacced240a2 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sun, 15 Dec 2024 23:09:02 +0200 Subject: [PATCH 08/39] Deprecate PWMOutput Also update it to support Arduino 3. --- src/sensesp/system/pwm_output.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/sensesp/system/pwm_output.h b/src/sensesp/system/pwm_output.h index 5c7ce33f5..4329c0f4f 100644 --- a/src/sensesp/system/pwm_output.h +++ b/src/sensesp/system/pwm_output.h @@ -1,16 +1,17 @@ #ifndef SENSESP_SYSTEM_PWM_OUTPUT_H #define SENSESP_SYSTEM_PWM_OUTPUT_H +#include #include +#include "esp_arduino_version.h" #include "valueconsumer.h" namespace sensesp { /** - * @brief Provides a cross platform mechanism for generating - * Pulse Width Modulation signals over one or more GPIO pins - * on the MCU. + * @brief DEPRECATED. Use Android native ledcAttach and ledcWrite instead. + * *

This class works by defining a "PWM channel". GPIO pins * are assigned to a channel, and then the channel is used when * setting the pwm value. The pwm value is a float number between @@ -42,12 +43,12 @@ class PWMOutput : public ValueConsumer { * next unassigned pin. */ PWMOutput(int pin = -1, int pwm_channel = -1, int channel_frequency = 5000, - int channel_resolution = 13) + int channel_resolution = 13) __attribute__((deprecated)) : ValueConsumer(), pwm_channel_{static_cast(pwm_channel)}, channel_frequency_{channel_frequency}, channel_resolution_{channel_resolution}, - pwmrange_{static_cast(pow(2, channel_resolution) - 1)} { + pwmrange_{static_cast((1 << channel_resolution) - 1)} { if (pin >= 0) { pwm_channel_ = assign_channel(pin, pwm_channel); } @@ -98,8 +99,13 @@ class PWMOutput : public ValueConsumer { pin); pinMode(pin, OUTPUT); +#if ESP_ARDUINO_VERSION_MAJOR > 2 + ledcAttachChannel(pin, channel_frequency_, channel_resolution_, + pwm_channel); +#else ledcSetup(pwm_channel, channel_frequency_, channel_resolution_); ledcAttachPin(pin, pwm_channel); +#endif return pwm_channel; } @@ -117,7 +123,11 @@ class PWMOutput : public ValueConsumer { int const output_val = value * pwmrange_; // ESP_LOGD(__FILENAME__, "Setting PWM channel %d to %d", pwm_channel_, // output_val); +#if ESP_ARDUINO_VERSION_MAJOR > 2 + ledcWriteChannel(pwm_channel_, output_val); +#else ledcWrite(pwm_channel_, output_val); +#endif } else { ESP_LOGW(__FILENAME__, "No pin assigned to channel %d. Ignoring set_pwm()", From 156b36ec79bfeec8942d9089625036671576f718 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sun, 15 Dec 2024 23:09:26 +0200 Subject: [PATCH 09/39] Change neopixelWrite -> rgbLedWrite --- src/sensesp/system/system_status_led.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/sensesp/system/system_status_led.h b/src/sensesp/system/system_status_led.h index 93c5ae7bf..e34f88ea7 100644 --- a/src/sensesp/system/system_status_led.h +++ b/src/sensesp/system/system_status_led.h @@ -101,7 +101,7 @@ class BaseSystemStatusLed { class SystemStatusLed : public BaseSystemStatusLed { public: SystemStatusLed(uint8_t pin, uint8_t brightness = 255) - : pwm_output_{PWMOutput(pin, -1, 2000, 8)}, + : pwm_output_{PWMOutput(pin, 2000, 8)}, BaseSystemStatusLed(), brightness_{brightness} {} @@ -135,9 +135,8 @@ class RGBSystemStatusLed : public BaseSystemStatusLed { uint8_t pin_; uint8_t brightness_; void show() override { - neopixelWrite(pin_, brightness_ * leds_[0].r / 255, - brightness_ * leds_[0].g / 255, - brightness_ * leds_[0].b / 255); + rgbLedWrite(pin_, brightness_ * leds_[0].r / 255, + brightness_ * leds_[0].g / 255, brightness_ * leds_[0].b / 255); } void set_brightness(uint8_t brightness) override { brightness_ = brightness; } From caac6e4f78a261f7b0f668d8eedf3c3d27e3b946 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Tue, 17 Dec 2024 16:13:38 +0200 Subject: [PATCH 10/39] Use the correct call for RGB LED updates --- src/sensesp/system/system_status_led.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sensesp/system/system_status_led.h b/src/sensesp/system/system_status_led.h index e34f88ea7..19437c1b4 100644 --- a/src/sensesp/system/system_status_led.h +++ b/src/sensesp/system/system_status_led.h @@ -10,6 +10,13 @@ #include "pwm_output.h" #include "sensesp/controllers/system_status_controller.h" +#include "esp_arduino_version.h" + +#if ESP_ARDUINO_VERSION_MAJOR < 3 +#define rgbLedWrite neopixelWrite +#endif + + namespace sensesp { // LED patterns. It isn't strictly speaking necessary to have these public, @@ -123,7 +130,7 @@ class SystemStatusLed : public BaseSystemStatusLed { }; // Direct use of FastLED breaks when the WiFi client is enabled. Thus, -// use the Arduino ESP32 Core native neopixelWrite function instead. That +// use the Arduino ESP32 Core native rgbLedWrite function instead. That // seems to work with WiFi as well. class RGBSystemStatusLed : public BaseSystemStatusLed { From d1b9f1057ae913d8e1d7f5eae567a83bf144d329 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Sun, 15 Dec 2024 23:09:48 +0200 Subject: [PATCH 11/39] Add ESP-IDF managed_components to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d479c141d..a4e8c7cb0 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ docs/Gemfile.lock docs/.bundle docs/_site +managed_components From b50ebc861e36a07ad76bb82691b9705a5a415154 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Fri, 13 Dec 2024 19:53:09 +0200 Subject: [PATCH 12/39] Use pioarduino by default --- platformio.ini | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index 308d921db..272994f24 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,11 +14,17 @@ ; examples/platformio.ini instead. [env:esp32dev] -platform = espressif32 @ ^6.9.0 +platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip board = esp32dev framework = arduino lib_ldf_mode = deep +;board_build.embed_txtfiles = +; managed_components/espressif__esp_insights/server_certs/https_server.crt +; managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt +; managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt +; managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt + ; Serial upload and monitor settings ;monitor_port = /dev/tty.usbserial-310 @@ -35,6 +41,8 @@ lib_deps = pfeerick/elapsedMillis @ ^1.0.6 bxparks/AceButton @ ^1.10.1 fastled/FastLED @ ^3.9.4 + esp_websocket_client=https://components.espressif.com/api/downloads/?object_type=component&object_id=dbc87006-9a4b-45e6-a6ab-b286174cb413 + build_unflags = -Werror=reorder board_build.partitions = min_spiffs.csv @@ -48,7 +56,7 @@ build_flags = -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; Arduino Core bug workaround: define the log tag for the Arduino ; logging macros. - -D TAG='"Arduino"' + ;-D TAG='"Arduino"' ; Use the ESP-IDF logging library - required by SensESP. -D USE_ESP_IDF_LOG From 31de49fd3dc2c63a4a7d96c19c40929fd9e272e5 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Tue, 17 Dec 2024 14:48:13 +0200 Subject: [PATCH 13/39] Add a dependency to the ESP-IDF websocket component --- library.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library.json b/library.json index fb0cbda09..5c0042b61 100644 --- a/library.json +++ b/library.json @@ -30,6 +30,10 @@ "name": "ReactESP", "version": "^3.1.0" }, + { + "name": "esp_websocket_client", + "version": "https://components.espressif.com/api/downloads/?object_type=component&object_id=dbc87006-9a4b-45e6-a6ab-b286174cb413" + }, { "owner": "bblanchon", "name": "ArduinoJson", From 55d61451e2429cdcf1b159bc21f5dc1602c715d2 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Tue, 17 Dec 2024 14:49:20 +0200 Subject: [PATCH 14/39] Don't import FastLED in headers FastLED defines JsonDocument which conflicts with ArduinoJson. --- src/sensesp/system/led_blinker.cpp | 2 ++ src/sensesp/system/led_blinker.h | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sensesp/system/led_blinker.cpp b/src/sensesp/system/led_blinker.cpp index ddfd3326d..235a261c7 100644 --- a/src/sensesp/system/led_blinker.cpp +++ b/src/sensesp/system/led_blinker.cpp @@ -1,5 +1,7 @@ #include "led_blinker.h" +#include "FastLED.h" + namespace sensesp { LEDPatternFragment frag_solid_color(uint32_t duration_ms, const CRGB& color) { diff --git a/src/sensesp/system/led_blinker.h b/src/sensesp/system/led_blinker.h index c6c6c541c..e3b3ef339 100644 --- a/src/sensesp/system/led_blinker.h +++ b/src/sensesp/system/led_blinker.h @@ -2,9 +2,9 @@ #define SENSESP_SYSTEM_LED_BLINKER_H_ #include -#include #include +#include "crgb.h" #include "sensesp/signalk/signalk_ws_client.h" namespace sensesp { @@ -128,7 +128,9 @@ class LEDPattern { LEDPattern(const std::vector& fragments) : fragments_(fragments) {} LEDPattern(const std::initializer_list& fragments) - : fragments_(fragments), current_fragment_idx_(0), fragment_begin_ms_(0) {} + : fragments_(fragments), + current_fragment_idx_(0), + fragment_begin_ms_(0) {} // Assignment operator LEDPattern& operator=(const LEDPattern& other) { From 67f81d46b7d93896ac2cb425d01c1dde7430fd6f Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Tue, 17 Dec 2024 14:49:50 +0200 Subject: [PATCH 15/39] Rename event_loop_param to avoid a name conflict --- src/sensesp/system/stream_producer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sensesp/system/stream_producer.h b/src/sensesp/system/stream_producer.h index 1c2d225b9..ac1bca03d 100644 --- a/src/sensesp/system/stream_producer.h +++ b/src/sensesp/system/stream_producer.h @@ -37,12 +37,12 @@ class StreamLineProducer : public ValueProducer { public: StreamLineProducer( Stream* stream, - std::shared_ptr event_loop = event_loop(), + std::shared_ptr event_loop_param = event_loop(), int max_line_length = 256) : stream_{stream}, max_line_length_{max_line_length} { buf_ = new char[max_line_length_ + 1]; read_event_ = - event_loop->onAvailable(*stream_, [this]() { this->receive_line(); }); + event_loop_param->onAvailable(*stream_, [this]() { this->receive_line(); }); } protected: From 1ecbc69fec5db0862d3765ccb467be6513c0d131 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Tue, 17 Dec 2024 14:50:12 +0200 Subject: [PATCH 16/39] Explicitly include ArduinoJson --- src/sensesp/signalk/signalk_ws_client.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sensesp/signalk/signalk_ws_client.h b/src/sensesp/signalk/signalk_ws_client.h index d76e862df..9b1b7ebca 100644 --- a/src/sensesp/signalk/signalk_ws_client.h +++ b/src/sensesp/signalk/signalk_ws_client.h @@ -3,6 +3,7 @@ #include "sensesp.h" +#include #include #include #include @@ -37,7 +38,8 @@ class SKWSClient : public FileSystemSaveable, ///////////////////////////////////////////////////////// // main task methods - SKWSClient(const String& config_path, std::shared_ptr sk_delta_queue, + SKWSClient(const String& config_path, + std::shared_ptr sk_delta_queue, const String& server_address, uint16_t server_port, bool use_mdns = true); @@ -162,9 +164,7 @@ class SKWSClient : public FileSystemSaveable, SKWSConnectionState get_connection_state() { return task_connection_state_; } }; -inline const String ConfigSchema(const SKWSClient& obj) { - return "null"; -} +inline const String ConfigSchema(const SKWSClient& obj) { return "null"; } inline bool ConfigRequiresRestart(const SKWSClient& obj) { return true; } From 8581f33b320794b7f233d62a43045a02e50a3806 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Tue, 17 Dec 2024 17:09:59 +0200 Subject: [PATCH 17/39] Don't use PWMOutput for system_status_led --- src/sensesp/system/system_status_led.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/sensesp/system/system_status_led.h b/src/sensesp/system/system_status_led.h index 19437c1b4..dd31a8ffc 100644 --- a/src/sensesp/system/system_status_led.h +++ b/src/sensesp/system/system_status_led.h @@ -7,7 +7,6 @@ #include "lambda_consumer.h" #include "led_blinker.h" -#include "pwm_output.h" #include "sensesp/controllers/system_status_controller.h" #include "esp_arduino_version.h" @@ -108,22 +107,25 @@ class BaseSystemStatusLed { class SystemStatusLed : public BaseSystemStatusLed { public: SystemStatusLed(uint8_t pin, uint8_t brightness = 255) - : pwm_output_{PWMOutput(pin, 2000, 8)}, - BaseSystemStatusLed(), - brightness_{brightness} {} + : BaseSystemStatusLed(), + pin_{pin}, + brightness_{brightness} { + ledcAttach(pin, 2000, 8); + } protected: - PWMOutput pwm_output_; + uint8_t pin_; uint8_t brightness_; void show() override { // Convert the RGB color to a single brightness value using the // perceptual luminance formula. - float value = ((0.2126 * leds_[0].r + // Red contribution + // value is scaled to 0-255. + int value = ((0.2126 * leds_[0].r + // Red contribution 0.7152 * leds_[0].g + // Green contribution 0.0722 * leds_[0].b // Blue contribution ) * - brightness_ / (255.0 * 256.0)); - pwm_output_.set(value); + brightness_ / (255.0)); + ledcWrite(pin_, value); } void set_brightness(uint8_t brightness) override { brightness_ = brightness; } From eff8bffc4e98b335345a73b16c99f3415f09f8c3 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Tue, 17 Dec 2024 17:17:46 +0200 Subject: [PATCH 18/39] Don't use PWMOutput in rgb_led.* --- src/sensesp/system/rgb_led.cpp | 16 ++++++++++------ src/sensesp/system/rgb_led.h | 7 +++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/sensesp/system/rgb_led.cpp b/src/sensesp/system/rgb_led.cpp index ed8f9dd70..da87552bb 100644 --- a/src/sensesp/system/rgb_led.cpp +++ b/src/sensesp/system/rgb_led.cpp @@ -4,16 +4,19 @@ namespace sensesp { +constexpr int kPWMResolution = 13; + RgbLed::RgbLed(int led_r_pin, int led_g_pin, int led_b_pin, String config_path, long int led_on_rgb, long int led_off_rgb, bool common_anode) : FileSystemSaveable(config_path), - led_r_output_{std::make_shared(led_r_pin)}, - led_g_output_{std::make_shared(led_g_pin)}, - led_b_output_{std::make_shared(led_b_pin)}, led_on_rgb_{led_on_rgb}, led_off_rgb_{led_off_rgb}, common_anode_{common_anode} { this->load(); + + ledcAttach(led_r_pin, 5000, kPWMResolution); + ledcAttach(led_g_pin, 5000, kPWMResolution); + ledcAttach(led_b_pin, 5000, kPWMResolution); } // Calculate the PWM value to send to analogWrite() based on the specified @@ -50,13 +53,14 @@ bool RgbLed::from_json(const JsonObject& config) { void RgbLed::set_color(long new_value) { float r = get_pwm(new_value, 16, common_anode_); - led_r_output_->set(r); + const int max_brightness = 1 << kPWMResolution; + ledcWrite(led_r_pin_, static_cast(r * max_brightness)); float g = get_pwm(new_value, 8, common_anode_); - led_g_output_->set(g); + ledcWrite(led_g_pin_, static_cast(g * max_brightness)); float b = get_pwm(new_value, 0, common_anode_); - led_b_output_->set(b); + ledcWrite(led_b_pin_, static_cast(b * max_brightness)); } const String ConfigSchema(const RgbLed& obj) { diff --git a/src/sensesp/system/rgb_led.h b/src/sensesp/system/rgb_led.h index 1628e3abd..e40b3c073 100644 --- a/src/sensesp/system/rgb_led.h +++ b/src/sensesp/system/rgb_led.h @@ -24,7 +24,6 @@ namespace sensesp { * two channel color led). Specify -1 for any pin for that channel * to be ignored. The color values used still have to adhere to * the 24 bit color definition however. - * @see PWMOutput */ class RgbLed : public FileSystemSaveable { public: @@ -77,9 +76,9 @@ class RgbLed : public FileSystemSaveable { virtual bool from_json(const JsonObject& config) override; protected: - std::shared_ptr led_r_output_ = nullptr; - std::shared_ptr led_g_output_ = nullptr; - std::shared_ptr led_b_output_ = nullptr; + uint8_t led_r_pin_; + uint8_t led_g_pin_; + uint8_t led_b_pin_; long led_on_rgb_; long led_off_rgb_; bool common_anode_; From 2ebaa1a63aabf75b8d2db3bf361ebad74047acaf Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Tue, 17 Dec 2024 18:42:48 +0200 Subject: [PATCH 19/39] Adjust default log level --- src/sensesp_base_app.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sensesp_base_app.h b/src/sensesp_base_app.h index 6501c59df..d1414bd04 100644 --- a/src/sensesp_base_app.h +++ b/src/sensesp_base_app.h @@ -18,7 +18,7 @@ namespace sensesp { constexpr auto kDefaultHostname = "SensESP"; -inline void SetupLogging(esp_log_level_t default_level = ESP_LOG_VERBOSE) { +inline void SetupLogging(esp_log_level_t default_level = ESP_LOG_DEBUG) { esp_log_level_set("*", default_level); } From e3325c0fe471fcc4e9c6e2d6aba53034940e781b Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Tue, 17 Dec 2024 18:43:20 +0200 Subject: [PATCH 20/39] Adjust default GPIO LED and button macro names --- src/sensesp_app.h | 6 +++--- src/sensesp_base_app.h | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/sensesp_app.h b/src/sensesp_app.h index dcdb6d5e2..ea3025b56 100644 --- a/src/sensesp_app.h +++ b/src/sensesp_app.h @@ -195,8 +195,8 @@ class SensESPApp : public SensESPBaseApp { // create a system status led and connect it if (system_status_led_ == nullptr) { -#ifdef PIN_NEOPIXEL - system_status_led_ = std::make_shared(PIN_NEOPIXEL); +#ifdef PIN_RGB_LED + system_status_led_ = std::make_shared(PIN_RGB_LED); #elif defined(LED_BUILTIN) system_status_led_ = std::make_shared(LED_BUILTIN); #endif @@ -308,7 +308,7 @@ class SensESPApp : public SensESPBaseApp { std::shared_ptr system_status_led_; std::shared_ptr system_status_controller_ = std::make_shared(); - int button_gpio_pin_ = SENSESP_BUTTON_PIN; + int button_gpio_pin_ = BUTTON_BUILTIN; std::shared_ptr button_handler_; std::shared_ptr networking_; diff --git a/src/sensesp_base_app.h b/src/sensesp_base_app.h index d1414bd04..1008971b4 100644 --- a/src/sensesp_base_app.h +++ b/src/sensesp_base_app.h @@ -1,9 +1,10 @@ #ifndef SENSESP_BASE_APP_H_ #define SENSESP_BASE_APP_H_ -#ifndef SENSESP_BUTTON_PIN -// Default button pin is 0 (GPIO0), normally connected to the BOOT button -#define SENSESP_BUTTON_PIN 0 +#ifndef BUTTON_BUILTIN +// Default button pin on ESP32-DevKitC devices is 0 (GPIO0), +// normally connected to the BOOT button. +#define BUTTON_BUILTIN 0 #endif #include "sensesp.h" From 87ab286ec93c88840b405f2e86a50013500f210d Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Tue, 17 Dec 2024 18:43:32 +0200 Subject: [PATCH 21/39] Restructure and comment platformio.ini --- platformio.ini | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/platformio.ini b/platformio.ini index 272994f24..b1411f085 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,24 +14,39 @@ ; examples/platformio.ini instead. [env:esp32dev] + platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip +; Comment the line above and uncomment this line to choose the legacy Arduino 2 core +;platform = espressif32 @ ^4.4.0 + +; Change the board to reflect the actual board you are using. board = esp32dev + framework = arduino +; Switch to the line below to use Arduino as an ESP-IDF component, providing full +; access to the ESP-IDF build configuration. +; framework = espidf, arduino + lib_ldf_mode = deep +; If using "framework = espidf, arduino", uncomment the following lines. + ;board_build.embed_txtfiles = ; managed_components/espressif__esp_insights/server_certs/https_server.crt ; managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt ; managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt ; managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt -; Serial upload and monitor settings +; Serial upload and monitor settings. Often the default "Auto" setting is fine, +; but you can normally set these in VSCode. Look for the tiny plug symbol +; and "Auto" text in the bottom bar. ;monitor_port = /dev/tty.usbserial-310 ;upload_port = /dev/tty.usbserial-310 -;upload_speed = 460800 -; For maximum upload speed, uncomment the following line and comment out the -; line above. + +; Lower the upload speed if you experience upload problems. Good values are +; 115200, 230400, 460800, or 921600. + upload_speed = 2000000 monitor_speed = 115200 @@ -43,19 +58,21 @@ lib_deps = fastled/FastLED @ ^3.9.4 esp_websocket_client=https://components.espressif.com/api/downloads/?object_type=component&object_id=dbc87006-9a4b-45e6-a6ab-b286174cb413 - -build_unflags = -Werror=reorder +; This line defines the partition table to use. The default has two app +; partitions, one for OTA updates and one for the running app, but the +; SPIFFS filesystem is quite small. For 8 MB flash boards such as HALMET, +; you can use "default_8MB.csv" instead. board_build.partitions = min_spiffs.csv -monitor_filters = esp32_exception_decoder -extra_scripts = - pre:extra_script.py -check_skip_packages = true + build_flags = + ; The LED and button pins for the ESP32 DevKitC, SH-ESP32 and HALMET boards -D LED_BUILTIN=2 + -D BUTTON_BUILTIN=0 + ; If the board has an RGB LED, uncomment and adjust the following line + ;-D PIN_RGB_LED=8 ; 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. + ; Arduino Core 2.x bug workaround. Uncomment this if using Arduino 2.x! ;-D TAG='"Arduino"' ; Use the ESP-IDF logging library - required by SensESP. -D USE_ESP_IDF_LOG @@ -76,7 +93,15 @@ build_flags = ;debug_tool = esp-prog ;debug_init_break = tbreak setup +; You shouldn't need to change anything below this line + test_build_src = true check_tool = clangtidy check_flags = clangtidy: --fix --format-style=file --config-file=.clang-tidy + +build_unflags = -Werror=reorder +monitor_filters = esp32_exception_decoder +extra_scripts = + pre:extra_script.py +check_skip_packages = true From 2e560860a0e9876caa153eddd07707bf54ff7b3b Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 10:29:12 +0200 Subject: [PATCH 22/39] Implement CI test matrix Reduce the number of examples to build but add multiple devices and platforms. --- .github/workflows/{test.yml => ci.yml} | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) rename .github/workflows/{test.yml => ci.yml} (55%) diff --git a/.github/workflows/test.yml b/.github/workflows/ci.yml similarity index 55% rename from .github/workflows/test.yml rename to .github/workflows/ci.yml index 2193a1446..00c2f4190 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/ci.yml @@ -8,31 +8,30 @@ jobs: strategy: matrix: example: - - examples/minimal_app.cpp - - examples/analog_input.cpp - - examples/hysteresis.cpp - examples/lambda_transform.cpp - - examples/manual_networking.cpp - examples/minimal_app.cpp - - examples/relay_control.cpp - - examples/rpm_counter.cpp - - examples/async_repeat_sensor.cpp + - examples/listener.cpp - examples/repeat_sensor_analog_input.cpp - - examples/freertos_tasks.cpp - - examples/raw_json.cpp - - examples/constant_sensor.cpp - - examples/time_counter.cpp - target_device: + - examples/rpm_counter.cpp + device: - esp32dev + - esp32-c3-devkitm-1 + platform: + - arduino + - pioarduino + - espard + exclude: + - platform: arduino + device: esp32-c3-devkitm-1 steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 + - uses: actions/checkout@v4 + - uses: actions/cache@v4 with: path: | ~/.cache/pip ~/.platformio/.cache key: ${{ runner.os }}-pio - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: "3.11" - name: Install dependencies @@ -42,4 +41,5 @@ jobs: run: ci/run-ci.sh env: PLATFORMIO_CI_SRC: ${{ matrix.example }} - CI_TARGET_DEVICE: ${{ matrix.target_device }} + CI_DEVICE: ${{ matrix.device }} + CI_PLATFORM: ${{ matrix.platform }} From ac77679de2ac4f81179df366b9dd4807250024d9 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 10:29:42 +0200 Subject: [PATCH 23/39] Add ini files for different platforms --- ci/platformio-esp32dev.ini | 23 ----------------------- ci/platformio_arduino.ini | 20 ++++++++++++++++++++ ci/platformio_espard.ini | 23 +++++++++++++++++++++++ ci/platformio_pioarduino.ini | 17 +++++++++++++++++ 4 files changed, 60 insertions(+), 23 deletions(-) delete mode 100644 ci/platformio-esp32dev.ini create mode 100644 ci/platformio_arduino.ini create mode 100644 ci/platformio_espard.ini create mode 100644 ci/platformio_pioarduino.ini diff --git a/ci/platformio-esp32dev.ini b/ci/platformio-esp32dev.ini deleted file mode 100644 index 52e26ef5a..000000000 --- a/ci/platformio-esp32dev.ini +++ /dev/null @@ -1,23 +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:esp32dev] -platform = espressif32 -board = esp32dev -build_unflags = -Werror=reorder -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 diff --git a/ci/platformio_arduino.ini b/ci/platformio_arduino.ini new file mode 100644 index 000000000..08ba54a98 --- /dev/null +++ b/ci/platformio_arduino.ini @@ -0,0 +1,20 @@ +[env:default] +; Global data for all [env:***] +platform = espressif32 @ ^4.4.0 +framework = arduino +lib_ldf_mode = deep +monitor_speed = 115200 +lib_deps = ${sysenv.PROJDIR} + +board = ${sysenv.CI_DEVICE} +build_unflags = -Werror=reorder +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 diff --git a/ci/platformio_espard.ini b/ci/platformio_espard.ini new file mode 100644 index 000000000..f50d0236e --- /dev/null +++ b/ci/platformio_espard.ini @@ -0,0 +1,23 @@ +[env:default] +; Global data for all [env:***] +platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip +framework = espif, arduino +lib_ldf_mode = deep +monitor_speed = 115200 +lib_deps = ${sysenv.PROJDIR} + +board_build.embed_txtfiles = + managed_components/espressif__esp_insights/server_certs/https_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt + +board = ${sysenv.CI_DEVICE} +build_unflags = -Werror=reorder +board_build.partitions = ${sysenv.PROJDIR}/min_spiffs.csv +monitor_filters = esp32_exception_decoder +build_flags = + -D LED_BUILTIN=2 + -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE + ; Use the ESP-IDF logging library - required by SensESP. + -D USE_ESP_IDF_LOG diff --git a/ci/platformio_pioarduino.ini b/ci/platformio_pioarduino.ini new file mode 100644 index 000000000..b598845bd --- /dev/null +++ b/ci/platformio_pioarduino.ini @@ -0,0 +1,17 @@ +[env:default] +; Global data for all [env:***] +platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip +framework = arduino +lib_ldf_mode = deep +monitor_speed = 115200 +lib_deps = ${sysenv.PROJDIR} + +board = ${sysenv.CI_DEVICE} +build_unflags = -Werror=reorder +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 + ; Use the ESP-IDF logging library - required by SensESP. + -D USE_ESP_IDF_LOG From 640524f8d7864cdd096acaf30aabdbcb52f29839 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 10:31:15 +0200 Subject: [PATCH 24/39] Use env variables to customize the ini file --- ci/run-ci.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ci/run-ci.sh b/ci/run-ci.sh index eca0865ba..371bc6895 100755 --- a/ci/run-ci.sh +++ b/ci/run-ci.sh @@ -4,11 +4,8 @@ set -euo pipefail # assume this command is always run from the project root directory -PROJDIR=$(pwd) - -# replace the -sed -e "s|\${PROJDIR}|$PROJDIR|" ci/platformio-${CI_TARGET_DEVICE}.ini > ci/platformio.ini +export PROJDIR=$(pwd) # the example to build comes from $PLATFORMIO_CI_SRC -pio ci -c ci/platformio.ini +pio ci -c ci/platformio_${CI_PLATFORM}.ini From 714c8cc6dc4447543f615fc18920cc205e9c8138 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 10:31:31 +0200 Subject: [PATCH 25/39] Add command handlers to freertos_tasks example --- examples/freertos_tasks.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/examples/freertos_tasks.cpp b/examples/freertos_tasks.cpp index 6183dbb42..e64e049cd 100644 --- a/examples/freertos_tasks.cpp +++ b/examples/freertos_tasks.cpp @@ -7,6 +7,10 @@ #include "sensesp/net/discovery.h" #include "sensesp/net/http_server.h" #include "sensesp/net/networking.h" +#include "sensesp/net/web/app_command_handler.h" +#include "sensesp/net/web/base_command_handler.h" +#include "sensesp/net/web/config_handler.h" +#include "sensesp/net/web/static_file_handler.h" #include "sensesp/sensors/digital_input.h" #include "sensesp/signalk/signalk_delta_queue.h" #include "sensesp/signalk/signalk_output.h" @@ -41,6 +45,12 @@ void setup() { auto networking = std::make_shared("/system/networking", "", ""); auto http_server = std::make_shared(); + // Add the default HTTP server response handlers + add_static_file_handlers(http_server); + add_base_app_http_command_handlers(http_server); + add_app_http_command_handlers(http_server, networking); + add_config_handlers(http_server); + // create the SK delta object auto sk_delta_queue_ = std::make_shared(); From ff87ba4720e81a69913014b81bc5f8d9493a3bb5 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 10:31:47 +0200 Subject: [PATCH 26/39] Rename relay_control example to listener --- examples/{relay_control.cpp => listener.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{relay_control.cpp => listener.cpp} (100%) diff --git a/examples/relay_control.cpp b/examples/listener.cpp similarity index 100% rename from examples/relay_control.cpp rename to examples/listener.cpp From de1ad56469dbcd8dcdf0d11a55b5f7d94e31be84 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 10:32:03 +0200 Subject: [PATCH 27/39] Add command handlers to minimal_app.cpp --- examples/minimal_app.cpp | 94 ++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 43 deletions(-) diff --git a/examples/minimal_app.cpp b/examples/minimal_app.cpp index 2f264767a..6f514f437 100644 --- a/examples/minimal_app.cpp +++ b/examples/minimal_app.cpp @@ -1,10 +1,15 @@ #include +#include "sensesp/net/http_server.h" +#include "sensesp/net/networking.h" +#include "sensesp/net/web/app_command_handler.h" +#include "sensesp/net/web/base_command_handler.h" #include "sensesp/net/web/config_handler.h" #include "sensesp/net/web/static_file_handler.h" -#include "sensesp/signalk/signalk_delta_queue.h" -#include "sensesp/signalk/signalk_ws_client.h" -#include "sensesp/system/button.h" +#include "sensesp/sensors/digital_input.h" +#include "sensesp/transforms/lambda_transform.h" +#include "sensesp/transforms/linear.h" +#include "sensesp/transforms/typecast.h" #include "sensesp_minimal_app_builder.h" using namespace sensesp; @@ -26,46 +31,49 @@ void setup() { SensESPMinimalAppBuilder builder; auto sensesp_app = builder.set_hostname("counter-test")->get_app(); - auto button_handler = std::make_shared(0); - - // As an example, we'll connect to WiFi manually using the Arduino ESP32 WiFi - // library instead of using the SensESP Networking class. - - WiFi.mode(WIFI_STA); // Optional - WiFi.begin("ssid", "password"); - Serial.println("\nConnecting"); - - while (WiFi.status() != WL_CONNECTED) { - Serial.print("."); - delay(100); - } - - Serial.println("\nConnected to the WiFi network"); - Serial.print("Local ESP32 IP: "); - Serial.println(WiFi.localIP()); - - // Initiate the objects you need for your application here. Have a look - // at sensesp_app.h and pick the necessary items from there. - - // create the SK delta queue - auto sk_delta_queue = std::make_shared(); - - // Use this if you want to hardcode the Signal K server address - String sk_server_address = "openplotter.local"; - // Use this if you want to hardcode the Signal K server port - uint16_t sk_server_port = 3000; - // Set this to true if you want to use mDNS to discover the Signal K server - bool use_mdns = false; - - auto ws_client = - std::make_shared("/System/Signal K Settings", sk_delta_queue, - sk_server_address, sk_server_port, use_mdns); - - // To avoid garbage collecting all shared pointers - // created in setup(), loop from here. - while (true) { - loop(); - } + // manually create Networking and HTTPServer objects to enable + // the HTTP configuration interface + + auto networking = std::make_shared("/system/networking", "", ""); + auto http_server = std::make_shared(); + + // Add the default HTTP server response handlers + add_static_file_handlers(http_server); + add_base_app_http_command_handlers(http_server); + add_app_http_command_handlers(http_server, networking); + add_config_handlers(http_server); + + auto digin1 = std::make_shared(input_pin1, INPUT, RISING, + read_delay); + auto digin2 = std::make_shared(input_pin2, INPUT, CHANGE, + read_delay); + + auto scaled1 = std::make_shared(2, 1, "/digin1/scale"); + auto scaled2 = std::make_shared(4, -1, "/digin2/scale"); + digin1->connect_to(scaled1); + + auto lambda_transform1 = + std::make_shared>([](int input) { + Serial.printf("millis: %d\n", millis()); + Serial.printf("Counter 1: %d\n", input); + return input; + }); + scaled1->connect_to(lambda_transform1); + auto lambda_transform2 = + std::make_shared>([](int input) { + Serial.printf("Counter 2: %d\n", input); + return input; + }); + + digin2->connect_to(scaled2)->connect_to(lambda_transform2); + + pinMode(output_pin1, OUTPUT); + event_loop()->onRepeat( + 5, []() { digitalWrite(output_pin1, !digitalRead(output_pin1)); }); + + pinMode(output_pin2, OUTPUT); + event_loop()->onRepeat( + 100, []() { digitalWrite(output_pin2, !digitalRead(output_pin2)); }); } void loop() { event_loop()->tick(); } From f9ccd3da5dc049ca9c01006a4bb3e172689869e5 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 10:32:21 +0200 Subject: [PATCH 28/39] Update the repeat_sensor example --- examples/repeat_sensor_analog_input.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/examples/repeat_sensor_analog_input.cpp b/examples/repeat_sensor_analog_input.cpp index 7fcf5198a..5925e2c17 100644 --- a/examples/repeat_sensor_analog_input.cpp +++ b/examples/repeat_sensor_analog_input.cpp @@ -6,11 +6,9 @@ * sensor library into a SensESP sensor. This file demonstrates its use with * the built-in analog input sensor. * - * Note that for analog input, it's actually better to use the AnalogInput - * sensor class as demonstrated by the analog_input.cpp example file. The - * AnalogInput class compensates for the ESP32 ADC nonlinearities. The approach - * presented here, however, can be used with any sensor library compatible with - * arduino-esp32. + * Note that even though this input reads just an analog voltage, + * the approach presented here can be used with any sensor library compatible + * with arduino-esp32. * */ @@ -23,8 +21,11 @@ using namespace sensesp; // GPIO pin that we'll be using for the analog input. const uint8_t kAnalogInputPin = 36; -// define a callback function that reads the analog input -float analog_read_callback() { return analogRead(kAnalogInputPin) / 4096.0; } +// define a callback function that reads the analog input and returns the value +// in volts. +float analog_read_callback() { + return analogReadMilliVolts(kAnalogInputPin) / 1000.; +} // The setup function performs one-time application initialization. void setup() { @@ -51,7 +52,7 @@ void setup() { // // To find valid Signal K Paths that fits your need you look at this link: // https://signalk.org/specification/1.4.0/doc/vesselsBranch.html - const char* sk_path = "environment.indoor.illuminance"; + const char* sk_path = "example.input.voltage"; // Connect the output of the analog input to the SKOutput object which // transmits the results to the Signal K server. As part of @@ -60,7 +61,7 @@ void setup() { // the display name for this value, to be used by any Signal K // consumer that displays it, is "Indoor light". analog_input->connect_to( - new SKOutputFloat(sk_path, "", new SKMetadata("ratio", "Indoor light"))); + new SKOutputFloat(sk_path, "", new SKMetadata("V", "Voltage"))); } void loop() { event_loop()->tick(); } From 823c3e66bdbfcaaa699ef390f1c45c681c61d3ae Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 10:32:46 +0200 Subject: [PATCH 29/39] Provide a default min_spiffs.csv for espard build --- min_spiffs.csv | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 min_spiffs.csv diff --git a/min_spiffs.csv b/min_spiffs.csv new file mode 100644 index 000000000..0990a3b46 --- /dev/null +++ b/min_spiffs.csv @@ -0,0 +1,7 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x5000, +otadata, data, ota, 0xe000, 0x2000, +app0, app, ota_0, 0x10000, 0x1E0000, +app1, app, ota_1, 0x1F0000,0x1E0000, +spiffs, data, spiffs, 0x3D0000,0x20000, +coredump, data, coredump,0x3F0000,0x10000, From 0b2901e3c04dd261e1798b70ce40210fcd477dac Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 10:35:02 +0200 Subject: [PATCH 30/39] Provide sdkconfig.defaults --- sdkconfig.defaults | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 sdkconfig.defaults diff --git a/sdkconfig.defaults b/sdkconfig.defaults new file mode 100644 index 000000000..bd83c808a --- /dev/null +++ b/sdkconfig.defaults @@ -0,0 +1,13 @@ +CONFIG_AUTOSTART_ARDUINO=y +# CONFIG_WS2812_LED_ENABLE is not set +CONFIG_FREERTOS_HZ=1000 +CONFIG_MBEDTLS_PSK_MODES=y +CONFIG_MBEDTLS_KEY_EXCHANGE_PSK=y +CONFIG_ESPTOOLPY_FLASHFREQ="80m" +CONFIG_ESPTOOLPY_FLASHFREQ_80M=y +CONFIG_ESPTOOLPY_FLASHMODE_QIO=y +CONFIG_ESPTOOLPY_FLASHSIZE="4MB" +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096 +CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=n +CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024 From 31c0d757ee5e5d7979d97f28daca187136aa494b Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 19:02:52 +0200 Subject: [PATCH 31/39] Fix rgb_led and system_status_led Arduino 2 builds --- src/sensesp/system/rgb_led.cpp | 22 +++++++++++++++------- src/sensesp/system/rgb_led.h | 15 ++++++++++++--- src/sensesp/system/system_status_led.h | 11 +++++++++++ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/sensesp/system/rgb_led.cpp b/src/sensesp/system/rgb_led.cpp index da87552bb..479dc0083 100644 --- a/src/sensesp/system/rgb_led.cpp +++ b/src/sensesp/system/rgb_led.cpp @@ -4,19 +4,22 @@ namespace sensesp { -constexpr int kPWMResolution = 13; - RgbLed::RgbLed(int led_r_pin, int led_g_pin, int led_b_pin, String config_path, long int led_on_rgb, long int led_off_rgb, bool common_anode) : FileSystemSaveable(config_path), led_on_rgb_{led_on_rgb}, led_off_rgb_{led_off_rgb}, - common_anode_{common_anode} { + common_anode_{common_anode}, + led_r_pin_{led_r_pin}, + led_g_pin_{led_g_pin}, + led_b_pin_{led_b_pin} { this->load(); +#if ESP_ARDUINO_VERSION_MAJOR > 2 ledcAttach(led_r_pin, 5000, kPWMResolution); ledcAttach(led_g_pin, 5000, kPWMResolution); ledcAttach(led_b_pin, 5000, kPWMResolution); +#endif } // Calculate the PWM value to send to analogWrite() based on the specified @@ -54,13 +57,18 @@ bool RgbLed::from_json(const JsonObject& config) { void RgbLed::set_color(long new_value) { float r = get_pwm(new_value, 16, common_anode_); const int max_brightness = 1 << kPWMResolution; - ledcWrite(led_r_pin_, static_cast(r * max_brightness)); - float g = get_pwm(new_value, 8, common_anode_); - ledcWrite(led_g_pin_, static_cast(g * max_brightness)); - float b = get_pwm(new_value, 0, common_anode_); + +#if ESP_ARDUINO_VERSION_MAJOR > 2 + ledcWrite(led_r_pin_, static_cast(r * max_brightness)); + ledcWrite(led_g_pin_, static_cast(g * max_brightness)); ledcWrite(led_b_pin_, static_cast(b * max_brightness)); +#else + pwm_output_r_.set(r); + pwm_output_g_.set(g); + pwm_output_b_.set(b); +#endif } const String ConfigSchema(const RgbLed& obj) { diff --git a/src/sensesp/system/rgb_led.h b/src/sensesp/system/rgb_led.h index e40b3c073..d83db0b2f 100644 --- a/src/sensesp/system/rgb_led.h +++ b/src/sensesp/system/rgb_led.h @@ -5,9 +5,12 @@ #include "sensesp/system/lambda_consumer.h" #include "sensesp/ui/config_item.h" #include "valueconsumer.h" +#include "esp_arduino_version.h" namespace sensesp { +constexpr int kPWMResolution = 13; + /** * @brief A special device object that can be used to control * a multi-channel color rgb LED light using up to 3 digital output @@ -76,12 +79,18 @@ class RgbLed : public FileSystemSaveable { virtual bool from_json(const JsonObject& config) override; protected: - uint8_t led_r_pin_; - uint8_t led_g_pin_; - uint8_t led_b_pin_; + + int led_r_pin_; + int led_g_pin_; + int led_b_pin_; long led_on_rgb_; long led_off_rgb_; bool common_anode_; +#if ESP_ARDUINO_VERSION_MAJOR < 3 + PWMOutput pwm_output_r_{led_r_pin_, -1, 5000, kPWMResolution}; + PWMOutput pwm_output_g_{led_g_pin_, -1, 5000, kPWMResolution}; + PWMOutput pwm_output_b_{led_b_pin_, -1, 5000, kPWMResolution}; +#endif void set_color(long new_value); }; diff --git a/src/sensesp/system/system_status_led.h b/src/sensesp/system/system_status_led.h index dd31a8ffc..958083265 100644 --- a/src/sensesp/system/system_status_led.h +++ b/src/sensesp/system/system_status_led.h @@ -10,8 +10,10 @@ #include "sensesp/controllers/system_status_controller.h" #include "esp_arduino_version.h" +#include "esp_idf_version.h" #if ESP_ARDUINO_VERSION_MAJOR < 3 +#include "pwm_output.h" #define rgbLedWrite neopixelWrite #endif @@ -110,11 +112,16 @@ class SystemStatusLed : public BaseSystemStatusLed { : BaseSystemStatusLed(), pin_{pin}, brightness_{brightness} { +#if ESP_ARDUINO_VERSION_MAJOR >= 3 ledcAttach(pin, 2000, 8); +#endif } protected: uint8_t pin_; +#if ESP_ARDUINO_VERSION_MAJOR < 3 + PWMOutput pwm_output_{pin_, -1, 2000, 8}; +#endif uint8_t brightness_; void show() override { // Convert the RGB color to a single brightness value using the @@ -125,7 +132,11 @@ class SystemStatusLed : public BaseSystemStatusLed { 0.0722 * leds_[0].b // Blue contribution ) * brightness_ / (255.0)); +#if ESP_ARDUINO_VERSION_MAJOR >= 3 ledcWrite(pin_, value); +#else + pwm_output_.set(value / 255.0); +#endif } void set_brightness(uint8_t brightness) override { brightness_ = brightness; } From aafbc7866335188b102350cceae6fddd768ef064 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 19:03:16 +0200 Subject: [PATCH 32/39] Remove the esp_websocket_client dependency from library.json --- library.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/library.json b/library.json index 5c0042b61..fb0cbda09 100644 --- a/library.json +++ b/library.json @@ -30,10 +30,6 @@ "name": "ReactESP", "version": "^3.1.0" }, - { - "name": "esp_websocket_client", - "version": "https://components.espressif.com/api/downloads/?object_type=component&object_id=dbc87006-9a4b-45e6-a6ab-b286174cb413" - }, { "owner": "bblanchon", "name": "ArduinoJson", From 74363eb95bfe8a00eb4cdeda91cdec649a1b932e Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 19:03:32 +0200 Subject: [PATCH 33/39] Provide a multi-environment platformio.ini --- platformio.ini | 249 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 180 insertions(+), 69 deletions(-) diff --git a/platformio.ini b/platformio.ini index b1411f085..6050e0053 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,52 +1,29 @@ ; PlatformIO Project Configuration File ; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -; IMPORTANT: This file defines the environment for building SensESP -; itself when doing feature development. It must NOT be used as a template -; for projects merely based on SensESP. For that purpose, use the file -; examples/platformio.ini instead. - -[env:esp32dev] - -platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip -; Comment the line above and uncomment this line to choose the legacy Arduino 2 core -;platform = espressif32 @ ^4.4.0 +[platformio] -; Change the board to reflect the actual board you are using. -board = esp32dev +; Change the default environment to match your board. Valid options are: +; - arduino_esp32 +; - pioarduino_esp32 +; - espidf_esp32 +; - pioarduino_esp32c3 +; - espidf_esp32c3 +; - shesp32 +; - halmet +; - halser -framework = arduino -; Switch to the line below to use Arduino as an ESP-IDF component, providing full -; access to the ESP-IDF build configuration. -; framework = espidf, arduino +default_envs = pioarduino_esp32c3 -lib_ldf_mode = deep +[env] -; If using "framework = espidf, arduino", uncomment the following lines. - -;board_build.embed_txtfiles = -; managed_components/espressif__esp_insights/server_certs/https_server.crt -; managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt -; managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt -; managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt - -; Serial upload and monitor settings. Often the default "Auto" setting is fine, -; but you can normally set these in VSCode. Look for the tiny plug symbol -; and "Auto" text in the bottom bar. +; Options common for all working environments +;; Uncomment and change these if PlatformIO can't auto-detect the ports ;monitor_port = /dev/tty.usbserial-310 ;upload_port = /dev/tty.usbserial-310 - -; Lower the upload speed if you experience upload problems. Good values are -; 115200, 230400, 460800, or 921600. - upload_speed = 2000000 monitor_speed = 115200 @@ -56,52 +33,186 @@ lib_deps = pfeerick/elapsedMillis @ ^1.0.6 bxparks/AceButton @ ^1.10.1 fastled/FastLED @ ^3.9.4 - esp_websocket_client=https://components.espressif.com/api/downloads/?object_type=component&object_id=dbc87006-9a4b-45e6-a6ab-b286174cb413 - -; This line defines the partition table to use. The default has two app -; partitions, one for OTA updates and one for the running app, but the -; SPIFFS filesystem is quite small. For 8 MB flash boards such as HALMET, -; you can use "default_8MB.csv" instead. -board_build.partitions = min_spiffs.csv + ; Add any additional dependencies here + ;ttlappalainen/NMEA2000-library + ;NMEA2000_twai=https://github.com/skarlsson/NMEA2000_twai build_flags = - ; The LED and button pins for the ESP32 DevKitC, SH-ESP32 and HALMET boards - -D LED_BUILTIN=2 - -D BUTTON_BUILTIN=0 - ; If the board has an RGB LED, uncomment and adjust the following line - ;-D PIN_RGB_LED=8 ; Max (and default) debugging level in Arduino ESP32 Core -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE - ; Arduino Core 2.x bug workaround. Uncomment this if using Arduino 2.x! - ;-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. -; "mypassword" must correspond to the device OTA password. +; This line defines the partition table to use. "min_spiffs" has two app +; partitions, one for OTA updates and one for the running app, but the +; SPIFFS filesystem is quite small. For 8 MB flash boards such as HALMET, +; you can use "default_8MB.csv" instead. + +board_build.partitions = min_spiffs.csv + +;; Uncomment the following lines to use Over-the-air (OTA) Updates ;upload_protocol = espota -;upload_port = mydevice.local -;upload_port = 192.168.4.1 +;upload_port = IP_ADDRESS_OF_ESP_HERE ;upload_flags = -; --auth=mypassword -; --auth="password" - -; JTAG debugging settings +; --auth=YOUR_OTA_PASSWORD -;upload_protocol = esp-prog -;debug_tool = esp-prog -;debug_init_break = tbreak setup +; You shouldn't need to touch the settings in this section below this line. -; You shouldn't need to change anything below this line +build_unflags = + -Werror=reorder +monitor_filters = esp32_exception_decoder test_build_src = true check_tool = clangtidy check_flags = clangtidy: --fix --format-style=file --config-file=.clang-tidy -build_unflags = -Werror=reorder -monitor_filters = esp32_exception_decoder -extra_scripts = - pre:extra_script.py -check_skip_packages = true + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Platform configurations follow + +[arduino] + +platform = espressif32 @ ^6.9.0 +framework = arduino + +lib_ignore = + esp_websocket_client + +build_flags = + ${env.build_flags} + ; Arduino Core bug workaround: define the log tag for the Arduino + ; logging macros. + -D TAG='"Arduino"' + +[pioarduino] + +platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip +framework = arduino + +; The library.json format doesn't support dependencies conditional on the +; platform version, so we have to use the lib_deps option to specify the +; esp_websocket_client library only for the ESP-IDF framework. + +lib_deps = + ${env.lib_deps} + esp_websocket_client=https://components.espressif.com/api/downloads/?object_type=component&object_id=dbc87006-9a4b-45e6-a6ab-b286174cb413 + +build_flags = + ${env.build_flags} + +[espidf] + +platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip +framework = espidf, arduino + +board_build.embed_txtfiles = + managed_components/espressif__esp_insights/server_certs/https_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt + +; The library.json format doesn't support dependencies conditional on the +; platform version, so we have to use the lib_deps option to specify the +; esp_websocket_client library only for the ESP-IDF framework. + +lib_deps = + ${env.lib_deps} + esp_websocket_client=https://components.espressif.com/api/downloads/?object_type=component&object_id=dbc87006-9a4b-45e6-a6ab-b286174cb413 + +build_flags = + ${env.build_flags} + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Board configurations follow + +[esp32] + +board = esp32dev +build_flags = + ${env.build_flags} + -D BUTTON_BUILTIN=0 + -D LED_BUILTIN=2 + +[esp32c3] + +board = esp32-c3-devkitm-1 +build_flags = + ${env.build_flags} + -D SENSESP_BUTTON_PIN=9 + -D PIN_RGB_LED=8 + ; Use the CDC USB port as Serial + -DARDUINO_USB_MODE=1 + -DARDUINO_USB_CDC_ON_BOOT=1 + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Permutations of platform and device. + +[env:arduino_esp32] + +extends = arduino, esp32 +build_flags = + ${arduino.build_flags} + ${esp32.build_flags} + +[env:pioarduino_esp32] + +extends = pioarduino, esp32 +build_flags = + ${pioarduino.build_flags} + ${esp32.build_flags} + +[env:espidf_esp32] + +extends = espidf, esp32 +build_flags = + ${espidf.build_flags} + ${esp32.build_flags} + +[env:arduino_esp32c3] + +extends = arduino, esp32c3 +build_flags = + ${arduino.build_flags} + ${esp32c3.build_flags} + +[env:pioarduino_esp32c3] + +extends = pioarduino, esp32c3 +build_flags = + ${pioarduino.build_flags} + ${esp32c3.build_flags} + +[env:espidf_esp32c3] + +extends = espidf, esp32c3 +build_flags = + ${espidf.build_flags} + ${esp32c3.build_flags} + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Individual board configurations + +[env:shesp32] + +extends = pioarduino, esp32 +build_flags = + ${pioarduino.build_flags} + ${esp32.build_flags} + +[env:halmet] + +extends = pioarduino, esp32 +board_build.partitions = default_8MB.csv + +build_flags = + ${pioarduino.build_flags} + ${esp32.build_flags} + +[env:halser] + +extends = pioarduino, esp32c3 + +build_flags = + ${pioarduino.build_flags} + ${esp32c3.build_flags} From e04e5554bfcf5f42a6983404093f911557fccc82 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 19:04:39 +0200 Subject: [PATCH 34/39] Make CI build use the default platformio.ini Different platforms are boards are tested in a matrix. --- .github/workflows/ci.yml | 8 ++++---- ci/platformio_arduino.ini | 20 -------------------- ci/platformio_espard.ini | 23 ----------------------- ci/platformio_pioarduino.ini | 17 ----------------- ci/run-ci.sh | 2 +- 5 files changed, 5 insertions(+), 65 deletions(-) delete mode 100644 ci/platformio_arduino.ini delete mode 100644 ci/platformio_espard.ini delete mode 100644 ci/platformio_pioarduino.ini diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00c2f4190..2fa2a326c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,15 +14,15 @@ jobs: - examples/repeat_sensor_analog_input.cpp - examples/rpm_counter.cpp device: - - esp32dev - - esp32-c3-devkitm-1 + - esp32 + - esp32c3 platform: - arduino - pioarduino - - espard + - espidf exclude: - platform: arduino - device: esp32-c3-devkitm-1 + device: esp32c3 steps: - uses: actions/checkout@v4 - uses: actions/cache@v4 diff --git a/ci/platformio_arduino.ini b/ci/platformio_arduino.ini deleted file mode 100644 index 08ba54a98..000000000 --- a/ci/platformio_arduino.ini +++ /dev/null @@ -1,20 +0,0 @@ -[env:default] -; Global data for all [env:***] -platform = espressif32 @ ^4.4.0 -framework = arduino -lib_ldf_mode = deep -monitor_speed = 115200 -lib_deps = ${sysenv.PROJDIR} - -board = ${sysenv.CI_DEVICE} -build_unflags = -Werror=reorder -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 diff --git a/ci/platformio_espard.ini b/ci/platformio_espard.ini deleted file mode 100644 index f50d0236e..000000000 --- a/ci/platformio_espard.ini +++ /dev/null @@ -1,23 +0,0 @@ -[env:default] -; Global data for all [env:***] -platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip -framework = espif, arduino -lib_ldf_mode = deep -monitor_speed = 115200 -lib_deps = ${sysenv.PROJDIR} - -board_build.embed_txtfiles = - managed_components/espressif__esp_insights/server_certs/https_server.crt - managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt - managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt - managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt - -board = ${sysenv.CI_DEVICE} -build_unflags = -Werror=reorder -board_build.partitions = ${sysenv.PROJDIR}/min_spiffs.csv -monitor_filters = esp32_exception_decoder -build_flags = - -D LED_BUILTIN=2 - -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE - ; Use the ESP-IDF logging library - required by SensESP. - -D USE_ESP_IDF_LOG diff --git a/ci/platformio_pioarduino.ini b/ci/platformio_pioarduino.ini deleted file mode 100644 index b598845bd..000000000 --- a/ci/platformio_pioarduino.ini +++ /dev/null @@ -1,17 +0,0 @@ -[env:default] -; Global data for all [env:***] -platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip -framework = arduino -lib_ldf_mode = deep -monitor_speed = 115200 -lib_deps = ${sysenv.PROJDIR} - -board = ${sysenv.CI_DEVICE} -build_unflags = -Werror=reorder -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 - ; Use the ESP-IDF logging library - required by SensESP. - -D USE_ESP_IDF_LOG diff --git a/ci/run-ci.sh b/ci/run-ci.sh index 371bc6895..47bc3c8e1 100755 --- a/ci/run-ci.sh +++ b/ci/run-ci.sh @@ -8,4 +8,4 @@ export PROJDIR=$(pwd) # the example to build comes from $PLATFORMIO_CI_SRC -pio ci -c ci/platformio_${CI_PLATFORM}.ini +pio ci -e ${CI_PLATFORM}_${CI_DEVICE} --project-conf platformio.ini --lib . --exclude examples --exclude docs --exclude .pio From e4c94336a112b22183d6dfd4673a40859adac3d7 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 19:05:15 +0200 Subject: [PATCH 35/39] Add an 8MB partition map --- default_8MB.csv | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 default_8MB.csv diff --git a/default_8MB.csv b/default_8MB.csv new file mode 100644 index 000000000..0310ac629 --- /dev/null +++ b/default_8MB.csv @@ -0,0 +1,7 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x5000, +otadata, data, ota, 0xe000, 0x2000, +app0, app, ota_0, 0x10000, 0x330000, +app1, app, ota_1, 0x340000,0x330000, +spiffs, data, spiffs, 0x670000,0x180000, +coredump, data, coredump,0x7F0000,0x10000, \ No newline at end of file From e84aecd3e71d3973fce037c930a79afa517d28a9 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 22:28:58 +0200 Subject: [PATCH 36/39] Defer the ESP-IDF builds for now --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2fa2a326c..eb507449b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,10 @@ jobs: platform: - arduino - pioarduino - - espidf + # Can't build with espidf until there's a way to copy the + # sdkconfig.defaults file to the correct location in the + # CI build environment. + #- espidf exclude: - platform: arduino device: esp32c3 From faa3d5c30a038156c4c1c77bd7f5e072bbe17e6f Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 22:39:22 +0200 Subject: [PATCH 37/39] Fix the minimal_app example after a failed rebase --- examples/minimal_app.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/minimal_app.cpp b/examples/minimal_app.cpp index 6f514f437..d244b3cc6 100644 --- a/examples/minimal_app.cpp +++ b/examples/minimal_app.cpp @@ -16,6 +16,11 @@ using namespace sensesp; const unsigned int read_delay = 500; +constexpr int input_pin1 = 15; +constexpr int input_pin2 = 13; +constexpr int output_pin1 = 18; +constexpr int output_pin2 = 21; + // This is a sample program to demonstrate how to instantiate a // SensESPMinimalApp application and only enable some required components // explicitly. From 9d444b333a3b3d31c2c750760ff899682ea041dc Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 18 Dec 2024 22:39:50 +0200 Subject: [PATCH 38/39] Make ESP32 the default build platform --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 6050e0053..2fd359021 100644 --- a/platformio.ini +++ b/platformio.ini @@ -15,7 +15,7 @@ ; - halmet ; - halser -default_envs = pioarduino_esp32c3 +default_envs = pioarduino_esp32 [env] From 1ff708eefae1d21a627205d835366b1d7915da75 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Fri, 20 Dec 2024 13:08:30 +0200 Subject: [PATCH 39/39] Update the example platformio.ini file --- examples/platformio.ini | 245 ++++++++++++++++++++++++++++++++-------- 1 file changed, 197 insertions(+), 48 deletions(-) diff --git a/examples/platformio.ini b/examples/platformio.ini index 386bc72a8..93ce242b0 100644 --- a/examples/platformio.ini +++ b/examples/platformio.ini @@ -1,64 +1,213 @@ ; PlatformIO Project Configuration File ; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -; NOTE: This is an example platformio.ini file to be used as a template for -; derived projects. Do not use the file within the SensESP directory tree but -; instead create a new project in PlatformIO and copy this file and one of the -; example source files there. - [platformio] -;set default_envs to whichever board(s) you use. Build/Run/etc processes those envs -default_envs = - esp32dev + +; Change the default environment to match your board. Valid options are: +; - arduino_esp32 +; - pioarduino_esp32 +; - espidf_esp32 +; - pioarduino_esp32c3 +; - espidf_esp32c3 +; - shesp32 +; - halmet +; - halser + +default_envs = pioarduino_esp32c3 [env] -; Global data for all [env:***] -framework = arduino -lib_ldf_mode = deep + +; Options common for all working environments + +;; Uncomment and change these if PlatformIO can't auto-detect the ports +;monitor_port = /dev/tty.usbserial-310 +;upload_port = /dev/tty.usbserial-310 +upload_speed = 2000000 monitor_speed = 115200 + lib_deps = -; Comment out one of the following two paths that point to the -; SensESP library code. - -; This one is the "Release" version - the branch called "latest". - SignalK/SensESP - -; This one has all merged PR's, but is not yet an official "release" version. -; It is the branch called "master". This version is unstable and under continuous -; development and will break without warning. Use it only if you want to -; participate in SensESP development or need to test some yet unreleased feature. -; https://github.com/SignalK/SensESP - -;this section has config items common to all ESP32 boards -[espressif32_base] -platform = espressif32 -build_unflags = -Werror = reorder + ; Peg the SensESP version to 3.1.0 and compatible versions + SignalK/SensESP @ ^3.1.0 + ; To use the development version, use this line instead: + ; https://github.com/SignalK/SensESP.git#main + ; To use a local copy (for development purposes), use this line: + ; symlink:///Users/yourname/path/to/SensESP + ; Add any additional dependencies here + ;ttlappalainen/NMEA2000-library + ;NMEA2000_twai=https://github.com/skarlsson/NMEA2000_twai + +build_flags = + ; Max (and default) debugging level in Arduino ESP32 Core + -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE + ; Use the ESP-IDF logging library - required by SensESP. + -D USE_ESP_IDF_LOG + +; This line defines the partition table to use. "min_spiffs" has two app +; partitions, one for OTA updates and one for the running app, but the +; SPIFFS filesystem is quite small. For 8 MB flash boards such as HALMET, +; you can use "default_8MB.csv" instead. + board_build.partitions = min_spiffs.csv + +;; Uncomment the following lines to use Over-the-air (OTA) Updates +;upload_protocol = espota +;upload_port = IP_ADDRESS_OF_ESP_HERE +;upload_flags = +; --auth=YOUR_OTA_PASSWORD + +; You shouldn't need to touch the settings in this section below this line. + +build_unflags = + -Werror=reorder monitor_filters = esp32_exception_decoder -[env:esp32dev] -extends = espressif32_base +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Platform configurations follow + +[arduino] + +platform = espressif32 @ ^6.9.0 +framework = arduino + +lib_ignore = + esp_websocket_client + +build_flags = + ${env.build_flags} + ; Arduino Core bug workaround: define the log tag for the Arduino + ; logging macros. + -D TAG='"Arduino"' + +[pioarduino] + +platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip +framework = arduino + +; The library.json format doesn't support dependencies conditional on the +; platform version, so we have to use the lib_deps option to specify the +; esp_websocket_client library only for the ESP-IDF framework. + +lib_deps = + ${env.lib_deps} + esp_websocket_client=https://components.espressif.com/api/downloads/?object_type=component&object_id=dbc87006-9a4b-45e6-a6ab-b286174cb413 + +build_flags = + ${env.build_flags} + +[espidf] + +platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip +framework = espidf, arduino + +board_build.embed_txtfiles = + managed_components/espressif__esp_insights/server_certs/https_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt + managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt + +; The library.json format doesn't support dependencies conditional on the +; platform version, so we have to use the lib_deps option to specify the +; esp_websocket_client library only for the ESP-IDF framework. + +lib_deps = + ${env.lib_deps} + esp_websocket_client=https://components.espressif.com/api/downloads/?object_type=component&object_id=dbc87006-9a4b-45e6-a6ab-b286174cb413 + +build_flags = + ${env.build_flags} + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Board configurations follow + +[esp32] + board = esp32dev +build_flags = + ${env.build_flags} + -D BUTTON_BUILTIN=0 + -D LED_BUILTIN=2 + +[esp32c3] + +board = esp32-c3-devkitm-1 +build_flags = + ${env.build_flags} + -D SENSESP_BUTTON_PIN=9 + -D PIN_RGB_LED=8 + ; Use the CDC USB port as Serial + -DARDUINO_USB_MODE=1 + -DARDUINO_USB_CDC_ON_BOOT=1 + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Permutations of platform and device. + +[env:arduino_esp32] + +extends = arduino, esp32 +build_flags = + ${arduino.build_flags} + ${esp32.build_flags} + +[env:pioarduino_esp32] + +extends = pioarduino, esp32 +build_flags = + ${pioarduino.build_flags} + ${esp32.build_flags} + +[env:espidf_esp32] + +extends = espidf, esp32 +build_flags = + ${espidf.build_flags} + ${esp32.build_flags} + +[env:arduino_esp32c3] + +extends = arduino, esp32c3 +build_flags = + ${arduino.build_flags} + ${esp32c3.build_flags} + +[env:pioarduino_esp32c3] + +extends = pioarduino, esp32c3 +build_flags = + ${pioarduino.build_flags} + ${esp32c3.build_flags} + +[env:espidf_esp32c3] + +extends = espidf, esp32c3 +build_flags = + ${espidf.build_flags} + ${esp32c3.build_flags} + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Individual board configurations + +[env:shesp32] + +extends = pioarduino, esp32 +build_flags = + ${pioarduino.build_flags} + ${esp32.build_flags} + +[env:halmet] + +extends = pioarduino, esp32 +board_build.partitions = default_8MB.csv + +build_flags = + ${pioarduino.build_flags} + ${esp32.build_flags} + +[env:halser] + +extends = pioarduino, esp32c3 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 + ${pioarduino.build_flags} + ${esp32c3.build_flags}