Initial kesp32_app_base component

This commit is contained in:
2026-10-04 11:42:27 +09:00
commit e4e4d78b26
25 changed files with 2073 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
#pragma once
#include "esp_err.h"
#include <stdbool.h>
#include <stdint.h>
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
typedef esp_err_t (*esp32_app_base_product_start_fn_t)(void);
typedef esp_err_t (*esp32_app_base_health_check_fn_t)(void);
typedef struct {
const char *service_prefix;
int reset_gpio;
bool reset_active_low;
uint32_t reset_hold_ms;
esp32_app_base_product_start_fn_t product_start;
esp32_app_base_health_check_fn_t health_check;
const char *ntp_server;
const char *timezone;
uint32_t ntp_initial_wait_seconds;
bool ota_enabled;
const char *ota_url;
uint32_t ota_initial_delay_seconds;
uint32_t ota_check_interval_minutes;
uint32_t ota_retry_interval_minutes;
} esp32_app_base_config_t;
/** Owns NVS, Wi-Fi browser provisioning, NTP, OTA rollback and reset button. */
esp_err_t esp32_app_base_start(const esp32_app_base_config_t *config);
/** Network readiness event group for optional product services. */
EventGroupHandle_t esp32_app_base_network_events(void);
EventBits_t esp32_app_base_network_ready_bit(void);
+25
View File
@@ -0,0 +1,25 @@
#pragma once
#include "esp_err.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
typedef void (*mqtt_transport_connected_fn_t)(void *ctx);
typedef void (*mqtt_transport_message_fn_t)(const char *topic, size_t topic_len,
const char *data, size_t data_len, void *ctx);
typedef void (*mqtt_transport_heartbeat_fn_t)(void *ctx);
typedef struct {
const char *broker_uri;
const char *client_id;
const char *last_will_topic;
const char *last_will_payload;
uint32_t heartbeat_interval_seconds;
mqtt_transport_connected_fn_t on_connected;
mqtt_transport_message_fn_t on_message;
mqtt_transport_heartbeat_fn_t on_heartbeat;
void *ctx;
} mqtt_transport_config_t;
esp_err_t mqtt_transport_start(const mqtt_transport_config_t *config);
int mqtt_transport_publish(const char *topic, const char *payload, int qos, bool retain);
int mqtt_transport_subscribe(const char *topic, int qos);
+11
View File
@@ -0,0 +1,11 @@
#pragma once
#include "esp_err.h"
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
/** Mark an OTA image valid after application-level network diagnostics pass. */
esp_err_t ota_mark_running_app_valid(void);
/** Start the periodic HTTPS OTA worker when OTA is configured. */
esp_err_t ota_start_task(EventGroupHandle_t network_events, EventBits_t connected_bit);
+6
View File
@@ -0,0 +1,6 @@
#pragma once
#include <stdbool.h>
/** Compare strict major.minor.patch versions. Returns false for invalid input. */
bool ota_version_compare(const char *left, const char *right, int *order);
+6
View File
@@ -0,0 +1,6 @@
#pragma once
#include "esp_err.h"
/** Run one local HTTP health check against the captive portal. */
esp_err_t portal_self_test_start(void);
+10
View File
@@ -0,0 +1,10 @@
#pragma once
#include "esp_err.h"
#include "freertos/FreeRTOS.h"
/** Initialize and start periodic SNTP synchronization. */
esp_err_t time_sync_start(void);
/** Wait for the first successful synchronization and log local time. */
esp_err_t time_sync_wait(TickType_t timeout);
+31
View File
@@ -0,0 +1,31 @@
#pragma once
#include <stdint.h>
#include "esp_err.h"
#include "wifi_store.h"
typedef esp_err_t (*web_provisioning_apply_cb_t)(const wifi_store_credentials_t *credentials);
typedef void (*web_provisioning_expired_cb_t)(void);
typedef enum {
WEB_PROV_IDLE,
WEB_PROV_SCANNING,
WEB_PROV_CONNECTING,
WEB_PROV_CONNECTED,
WEB_PROV_FAILED,
} web_provisioning_state_t;
typedef struct {
const char *service_name;
uint32_t timeout_seconds;
web_provisioning_apply_cb_t apply_credentials;
web_provisioning_expired_cb_t expired;
} web_provisioning_config_t;
esp_err_t web_provisioning_start(const web_provisioning_config_t *config);
void web_provisioning_stop(void);
bool web_provisioning_is_active(void);
bool web_provisioning_is_connecting(void);
void web_provisioning_report_connected(const char *ip_address);
void web_provisioning_report_failure(const char *reason);
+19
View File
@@ -0,0 +1,19 @@
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "esp_err.h"
#define WIFI_STORE_SSID_MAX_LEN 32
#define WIFI_STORE_PASSWORD_MAX_LEN 64
typedef struct {
char ssid[WIFI_STORE_SSID_MAX_LEN + 1];
char password[WIFI_STORE_PASSWORD_MAX_LEN + 1];
} wifi_store_credentials_t;
esp_err_t wifi_store_load(wifi_store_credentials_t *credentials, bool *found);
esp_err_t wifi_store_save(const wifi_store_credentials_t *credentials);
esp_err_t wifi_store_erase(void);