From 22d12049c9df33a69215eb17d298422a2871bd4b Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Thu, 12 Dec 2024 18:35:25 +0200 Subject: [PATCH 1/3] Fix the minimal_app example --- examples/minimal_app.cpp | 93 +++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 48 deletions(-) diff --git a/examples/minimal_app.cpp b/examples/minimal_app.cpp index 2f614619a..2f264767a 100644 --- a/examples/minimal_app.cpp +++ b/examples/minimal_app.cpp @@ -1,22 +1,16 @@ #include -#include "sensesp/net/http_server.h" -#include "sensesp/net/networking.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/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_minimal_app_builder.h" using namespace sensesp; const unsigned int read_delay = 500; -const uint8_t input_pin1 = 15; -const uint8_t output_pin1 = 18; -const uint8_t input_pin2 = 13; -const uint8_t output_pin2 = 21; - // This is a sample program to demonstrate how to instantiate a // SensESPMinimalApp application and only enable some required components // explicitly. @@ -32,43 +26,46 @@ void setup() { SensESPMinimalAppBuilder builder; auto sensesp_app = builder.set_hostname("counter-test")->get_app(); - // 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(); - - 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)); }); + 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(); + } } void loop() { event_loop()->tick(); } From 4a13269e716d5dd39f440dde1fa27f9a802d125c Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Thu, 12 Dec 2024 18:36:26 +0200 Subject: [PATCH 2/3] Improve comment wording --- src/sensesp_app.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sensesp_app.h b/src/sensesp_app.h index f69ed4b6e..d2d0c43bb 100644 --- a/src/sensesp_app.h +++ b/src/sensesp_app.h @@ -180,7 +180,7 @@ class SensESPApp : public SensESPBaseApp { ConfigItem(this->http_server_); - // create the SK delta object + // create the SK delta queue sk_delta_queue_ = std::make_shared(); // create the websocket client From 0673e0ee0b4ea9ac73118be8783abb2ef506073a Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Fri, 13 Dec 2024 20:55:05 +0200 Subject: [PATCH 3/3] Pin the default platform version --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index d58ca0afb..75f8e1b44 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,7 +14,7 @@ ; examples/platformio.ini instead. [env:esp32dev] -platform = espressif32 +platform = espressif32 @ ^6.9.0 board = esp32dev framework = arduino lib_ldf_mode = deep