17#include <pico/async_context.h>
18#include <pico/async_context_freertos.h>
39#ifdef PICO_HTTP_ENABLE_JWT
48 networkTaskHandle(nullptr)
56 std::cout <<
"[Framework Manager] Initializing framework..." << std::endl;
72 printf(
"[Framework Manager] Failed to initialize network stack.\n");
82#if WIFI_REBOOT_ON_FAILURE
83 printf(
"[Framework Manager] WiFi failed — rebooting...\n");
86 printf(
"[Framework Manager] WiFi failed after retries. Continuing without network.\n");
90 printf(
"[Framework Manager] Framework services initialized.\n");
94 printf(
"[Framework Manager] Network up. Notifying app task...\n");
106 nlohmann::json j = nlohmann::json::parse(
"{\"warmup\":true}",
nullptr,
false);
120 std::string(
"warmup");
123 vTaskDelay(pdMS_TO_TICKS(1));
130 vTaskDelete(
nullptr);
138 printf(
"[FrameworkManager] HttpServer started, notifying TimeManager...\n");
150#if WIFI_MONITOR_INTERVAL_MS > 0
151 static uint32_t lastCheck = 0;
152 static int networkFailures = 0;
153 uint32_t now = xTaskGetTickCount() * portTICK_PERIOD_MS;
158 printf(
"[FrameworkManager] Polling for Wi-Fi status...\n");
162 printf(
"[FrameworkManager] Reconnect failed. Restarting Wi-Fi...\n");
173 printf(
"[FrameworkManager] Rebooting after 3 failed recovery attempts.\n");
205 TRACE(
"Tracing initialized from framework.");
Macro-based debug trace system with optional SD file logging.
#define TRACE_INIT(MODULE_NAME)
Declare trace usage in a source file for a given module.
#define TRACE(...)
Default trace (INFO level).
void setTraceOutputToFile(StorageManager *sm, const std::string &path)
Set trace output to SD file using FatFsStorageManager.
Event pub/sub manager for embedded applications using FreeRTOS.
Defines the Event structure and related utilities for event messaging.
Base class for applications using the PicoFramework.
Orchestrates application startup and network initialization.
Stateless singleton class for creating and validating JWTs using HMAC-SHA256.
constexpr uint32_t eventMask(Enum e)
Helper function to create an event mask from an enum value.
static AppContext & getInstance()
void initFrameworkServices()
static constexpr std::uintptr_t getTypeKey()
Base class for applications using the framework.
virtual void start()
Initializes the application and its framework services.
Base class for event-driven control logic in embedded applications.
Starts and coordinates core system services like networking and time sync.
void onEvent(const Event &event)
Handles events posted to the FrameworkManager.
void poll()
Polling function for the FrameworkManager.
FrameworkApp * app
Pointer to the application task.
void setupTraceFromConfig()
Sets up debug tracing from configuration.
FrameworkManager(FrameworkApp *app, Router &router)
Constructor.
static void app_task(void *params)
Placeholder for an application-level task, if used.
void onStart()
Initializes the network and application tasks.
Network network
Network management.
Forward declaration for potential routing needs.
HttpRequest & setMethod(const std::string &method)
Set the HTTP method (e.g., GET, POST).
HttpRequest & setPath(const std::string &path)
Set the request path.
std::string getHeader(const std::string &field) const
Get a specific header field (case-insensitive).
HttpRequest & setHeader(const std::string &key, const std::string &value)
static bool initialize()
Start Wi-Fi with resilience, retrying connection if it fails.
static bool checkAndReconnect()
Attempt to connect to Wi-Fi with retries.
static bool startWifiWithResilience()
Start Wi-Fi with resilience, retrying connection if it fails.
static bool restart_wifi()
Restart the Wi-Fi interface.
The central router for handling HTTP requests and middleware.
void onNetworkReady()
hanles network ready event.
void start()
Start the time manager.
Delegates to user or system configuration.
#define WIFI_MONITOR_INTERVAL_MS
This setting defines the interval for checking WiFi connection status The default is 30000 ms (30 sec...
#define WIFI_REBOOT_ON_FAILURE
This setting defines whether to reboot the device on WiFi connection failure The default is false,...
Represents a framework event, optionally carrying payload data.
Notification notification
Notification identifier (system or user)
SystemNotification system
void rebootSystem()
Reboot the device immediately.
System utilities for diagnostics, memory, stack usage, and tracing.