refactor: remove NVS/CLI config, use mimi_secrets.h as sole configuration method
All configuration is now done exclusively through mimi_secrets.h at build time. Removed NVS read/write logic, CLI config commands (wifi_set, set_tg_token, set_api_key, set_model, set_proxy, clear_proxy, set_search_key), and setter functions from all modules. CLI retains debug/maintenance commands only. Updated all documentation to reflect the change. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
#include "serial_cli.h"
|
||||
#include "mimi_config.h"
|
||||
#include "wifi/wifi_manager.h"
|
||||
#include "telegram/telegram_bot.h"
|
||||
#include "llm/llm_proxy.h"
|
||||
#include "memory/memory_store.h"
|
||||
#include "memory/session_mgr.h"
|
||||
#include "proxy/http_proxy.h"
|
||||
#include "tools/tool_web_search.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@@ -18,26 +14,6 @@
|
||||
|
||||
static const char *TAG = "cli";
|
||||
|
||||
/* --- wifi_set command --- */
|
||||
static struct {
|
||||
struct arg_str *ssid;
|
||||
struct arg_str *password;
|
||||
struct arg_end *end;
|
||||
} wifi_set_args;
|
||||
|
||||
static int cmd_wifi_set(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse(argc, argv, (void **)&wifi_set_args);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, wifi_set_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
wifi_manager_set_credentials(wifi_set_args.ssid->sval[0],
|
||||
wifi_set_args.password->sval[0]);
|
||||
printf("WiFi credentials saved. Restart to apply.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --- wifi_status command --- */
|
||||
static int cmd_wifi_status(int argc, char **argv)
|
||||
{
|
||||
@@ -46,60 +22,6 @@ static int cmd_wifi_status(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --- set_tg_token command --- */
|
||||
static struct {
|
||||
struct arg_str *token;
|
||||
struct arg_end *end;
|
||||
} tg_token_args;
|
||||
|
||||
static int cmd_set_tg_token(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse(argc, argv, (void **)&tg_token_args);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, tg_token_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
telegram_set_token(tg_token_args.token->sval[0]);
|
||||
printf("Telegram bot token saved.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --- set_api_key command --- */
|
||||
static struct {
|
||||
struct arg_str *key;
|
||||
struct arg_end *end;
|
||||
} api_key_args;
|
||||
|
||||
static int cmd_set_api_key(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse(argc, argv, (void **)&api_key_args);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, api_key_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
llm_set_api_key(api_key_args.key->sval[0]);
|
||||
printf("API key saved.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --- set_model command --- */
|
||||
static struct {
|
||||
struct arg_str *model;
|
||||
struct arg_end *end;
|
||||
} model_args;
|
||||
|
||||
static int cmd_set_model(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse(argc, argv, (void **)&model_args);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, model_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
llm_set_model(model_args.model->sval[0]);
|
||||
printf("Model set.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --- memory_read command --- */
|
||||
static int cmd_memory_read(int argc, char **argv)
|
||||
{
|
||||
@@ -176,51 +98,6 @@ static int cmd_heap_info(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --- set_proxy command --- */
|
||||
static struct {
|
||||
struct arg_str *host;
|
||||
struct arg_int *port;
|
||||
struct arg_end *end;
|
||||
} proxy_args;
|
||||
|
||||
static int cmd_set_proxy(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse(argc, argv, (void **)&proxy_args);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, proxy_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
http_proxy_set(proxy_args.host->sval[0], (uint16_t)proxy_args.port->ival[0]);
|
||||
printf("Proxy set. Restart to apply.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --- clear_proxy command --- */
|
||||
static int cmd_clear_proxy(int argc, char **argv)
|
||||
{
|
||||
http_proxy_clear();
|
||||
printf("Proxy cleared. Restart to apply.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --- set_search_key command --- */
|
||||
static struct {
|
||||
struct arg_str *key;
|
||||
struct arg_end *end;
|
||||
} search_key_args;
|
||||
|
||||
static int cmd_set_search_key(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse(argc, argv, (void **)&search_key_args);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, search_key_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
tool_web_search_set_key(search_key_args.key->sval[0]);
|
||||
printf("Search API key saved.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --- restart command --- */
|
||||
static int cmd_restart(int argc, char **argv)
|
||||
{
|
||||
@@ -244,18 +121,6 @@ esp_err_t serial_cli_init(void)
|
||||
|
||||
/* Register commands */
|
||||
|
||||
/* wifi_set */
|
||||
wifi_set_args.ssid = arg_str1(NULL, NULL, "<ssid>", "WiFi SSID");
|
||||
wifi_set_args.password = arg_str1(NULL, NULL, "<password>", "WiFi password");
|
||||
wifi_set_args.end = arg_end(2);
|
||||
esp_console_cmd_t wifi_set_cmd = {
|
||||
.command = "wifi_set",
|
||||
.help = "Set WiFi SSID and password",
|
||||
.func = &cmd_wifi_set,
|
||||
.argtable = &wifi_set_args,
|
||||
};
|
||||
esp_console_cmd_register(&wifi_set_cmd);
|
||||
|
||||
/* wifi_status */
|
||||
esp_console_cmd_t wifi_status_cmd = {
|
||||
.command = "wifi_status",
|
||||
@@ -264,39 +129,6 @@ esp_err_t serial_cli_init(void)
|
||||
};
|
||||
esp_console_cmd_register(&wifi_status_cmd);
|
||||
|
||||
/* set_tg_token */
|
||||
tg_token_args.token = arg_str1(NULL, NULL, "<token>", "Telegram bot token");
|
||||
tg_token_args.end = arg_end(1);
|
||||
esp_console_cmd_t tg_token_cmd = {
|
||||
.command = "set_tg_token",
|
||||
.help = "Set Telegram bot token",
|
||||
.func = &cmd_set_tg_token,
|
||||
.argtable = &tg_token_args,
|
||||
};
|
||||
esp_console_cmd_register(&tg_token_cmd);
|
||||
|
||||
/* set_api_key */
|
||||
api_key_args.key = arg_str1(NULL, NULL, "<key>", "Anthropic API key");
|
||||
api_key_args.end = arg_end(1);
|
||||
esp_console_cmd_t api_key_cmd = {
|
||||
.command = "set_api_key",
|
||||
.help = "Set Claude API key",
|
||||
.func = &cmd_set_api_key,
|
||||
.argtable = &api_key_args,
|
||||
};
|
||||
esp_console_cmd_register(&api_key_cmd);
|
||||
|
||||
/* set_model */
|
||||
model_args.model = arg_str1(NULL, NULL, "<model>", "Model identifier");
|
||||
model_args.end = arg_end(1);
|
||||
esp_console_cmd_t model_cmd = {
|
||||
.command = "set_model",
|
||||
.help = "Set LLM model (default: " MIMI_LLM_DEFAULT_MODEL ")",
|
||||
.func = &cmd_set_model,
|
||||
.argtable = &model_args,
|
||||
};
|
||||
esp_console_cmd_register(&model_cmd);
|
||||
|
||||
/* memory_read */
|
||||
esp_console_cmd_t mem_read_cmd = {
|
||||
.command = "memory_read",
|
||||
@@ -343,37 +175,6 @@ esp_err_t serial_cli_init(void)
|
||||
};
|
||||
esp_console_cmd_register(&heap_cmd);
|
||||
|
||||
/* set_search_key */
|
||||
search_key_args.key = arg_str1(NULL, NULL, "<key>", "Brave Search API key");
|
||||
search_key_args.end = arg_end(1);
|
||||
esp_console_cmd_t search_key_cmd = {
|
||||
.command = "set_search_key",
|
||||
.help = "Set Brave Search API key for web_search tool",
|
||||
.func = &cmd_set_search_key,
|
||||
.argtable = &search_key_args,
|
||||
};
|
||||
esp_console_cmd_register(&search_key_cmd);
|
||||
|
||||
/* set_proxy */
|
||||
proxy_args.host = arg_str1(NULL, NULL, "<host>", "Proxy host/IP");
|
||||
proxy_args.port = arg_int1(NULL, NULL, "<port>", "Proxy port");
|
||||
proxy_args.end = arg_end(2);
|
||||
esp_console_cmd_t proxy_cmd = {
|
||||
.command = "set_proxy",
|
||||
.help = "Set HTTP proxy (e.g. set_proxy 192.168.1.83 7897)",
|
||||
.func = &cmd_set_proxy,
|
||||
.argtable = &proxy_args,
|
||||
};
|
||||
esp_console_cmd_register(&proxy_cmd);
|
||||
|
||||
/* clear_proxy */
|
||||
esp_console_cmd_t clear_proxy_cmd = {
|
||||
.command = "clear_proxy",
|
||||
.help = "Remove proxy configuration",
|
||||
.func = &cmd_clear_proxy,
|
||||
};
|
||||
esp_console_cmd_register(&clear_proxy_cmd);
|
||||
|
||||
/* restart */
|
||||
esp_console_cmd_t restart_cmd = {
|
||||
.command = "restart",
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "esp_http_client.h"
|
||||
#include "esp_crt_bundle.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "nvs.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
static const char *TAG = "llm";
|
||||
@@ -71,7 +70,6 @@ static esp_err_t http_event_handler(esp_http_client_event_t *evt)
|
||||
|
||||
esp_err_t llm_proxy_init(void)
|
||||
{
|
||||
/* Build-time secrets take highest priority */
|
||||
if (MIMI_SECRET_API_KEY[0] != '\0') {
|
||||
strncpy(s_api_key, MIMI_SECRET_API_KEY, sizeof(s_api_key) - 1);
|
||||
}
|
||||
@@ -79,27 +77,10 @@ esp_err_t llm_proxy_init(void)
|
||||
strncpy(s_model, MIMI_SECRET_MODEL, sizeof(s_model) - 1);
|
||||
}
|
||||
|
||||
/* Fall back to NVS for values not set at build time */
|
||||
if (s_api_key[0] == '\0' || s_model[0] == '\0') {
|
||||
nvs_handle_t nvs;
|
||||
esp_err_t err = nvs_open(MIMI_NVS_LLM, NVS_READONLY, &nvs);
|
||||
if (err == ESP_OK) {
|
||||
if (s_api_key[0] == '\0') {
|
||||
size_t len = sizeof(s_api_key);
|
||||
nvs_get_str(nvs, MIMI_NVS_KEY_API_KEY, s_api_key, &len);
|
||||
}
|
||||
if (strcmp(s_model, MIMI_LLM_DEFAULT_MODEL) == 0) {
|
||||
size_t len = sizeof(s_model);
|
||||
nvs_get_str(nvs, MIMI_NVS_KEY_MODEL, s_model, &len);
|
||||
}
|
||||
nvs_close(nvs);
|
||||
}
|
||||
}
|
||||
|
||||
if (s_api_key[0]) {
|
||||
ESP_LOGI(TAG, "LLM proxy initialized (model: %s)", s_model);
|
||||
} else {
|
||||
ESP_LOGW(TAG, "No API key. Use CLI: set_api_key <KEY>");
|
||||
ESP_LOGW(TAG, "No API key. Set MIMI_SECRET_API_KEY in mimi_secrets.h");
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -467,30 +448,3 @@ esp_err_t llm_chat_tools(const char *system_prompt,
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* ── NVS helpers ──────────────────────────────────────────────── */
|
||||
|
||||
esp_err_t llm_set_api_key(const char *api_key)
|
||||
{
|
||||
nvs_handle_t nvs;
|
||||
ESP_ERROR_CHECK(nvs_open(MIMI_NVS_LLM, NVS_READWRITE, &nvs));
|
||||
ESP_ERROR_CHECK(nvs_set_str(nvs, MIMI_NVS_KEY_API_KEY, api_key));
|
||||
ESP_ERROR_CHECK(nvs_commit(nvs));
|
||||
nvs_close(nvs);
|
||||
|
||||
strncpy(s_api_key, api_key, sizeof(s_api_key) - 1);
|
||||
ESP_LOGI(TAG, "API key saved");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t llm_set_model(const char *model)
|
||||
{
|
||||
nvs_handle_t nvs;
|
||||
ESP_ERROR_CHECK(nvs_open(MIMI_NVS_LLM, NVS_READWRITE, &nvs));
|
||||
ESP_ERROR_CHECK(nvs_set_str(nvs, MIMI_NVS_KEY_MODEL, model));
|
||||
ESP_ERROR_CHECK(nvs_commit(nvs));
|
||||
nvs_close(nvs);
|
||||
|
||||
strncpy(s_model, model, sizeof(s_model) - 1);
|
||||
ESP_LOGI(TAG, "Model set to: %s", s_model);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "mimi_config.h"
|
||||
|
||||
/**
|
||||
* Initialize the LLM proxy. Reads API key and model from NVS.
|
||||
* Initialize the LLM proxy.
|
||||
*/
|
||||
esp_err_t llm_proxy_init(void);
|
||||
|
||||
@@ -24,16 +24,6 @@ esp_err_t llm_proxy_init(void);
|
||||
esp_err_t llm_chat(const char *system_prompt, const char *messages_json,
|
||||
char *response_buf, size_t buf_size);
|
||||
|
||||
/**
|
||||
* Save the Anthropic API key to NVS.
|
||||
*/
|
||||
esp_err_t llm_set_api_key(const char *api_key);
|
||||
|
||||
/**
|
||||
* Save the model identifier to NVS.
|
||||
*/
|
||||
esp_err_t llm_set_model(const char *model);
|
||||
|
||||
/* ── Tool Use Support ──────────────────────────────────────────── */
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -134,10 +134,10 @@ void app_main(void)
|
||||
|
||||
ESP_LOGI(TAG, "All services started!");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "WiFi connection timeout. Configure via CLI: wifi_set <SSID> <PASS>");
|
||||
ESP_LOGW(TAG, "WiFi connection timeout. Check MIMI_SECRET_WIFI_SSID in mimi_secrets.h");
|
||||
}
|
||||
} else {
|
||||
ESP_LOGW(TAG, "No WiFi credentials. Configure via CLI: wifi_set <SSID> <PASS>");
|
||||
ESP_LOGW(TAG, "No WiFi credentials. Set MIMI_SECRET_WIFI_SSID in mimi_secrets.h");
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "MimiClaw ready. Type 'help' for CLI commands.");
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
/* MimiClaw Global Configuration */
|
||||
|
||||
/* Build-time secrets (highest priority, override NVS) */
|
||||
/* Build-time secrets (sole configuration method) */
|
||||
#if __has_include("mimi_secrets.h")
|
||||
#include "mimi_secrets.h"
|
||||
#endif
|
||||
@@ -88,18 +88,3 @@
|
||||
#define MIMI_CLI_PRIO 3
|
||||
#define MIMI_CLI_CORE 0
|
||||
|
||||
/* NVS Namespaces */
|
||||
#define MIMI_NVS_WIFI "wifi_config"
|
||||
#define MIMI_NVS_TG "tg_config"
|
||||
#define MIMI_NVS_LLM "llm_config"
|
||||
#define MIMI_NVS_PROXY "proxy_config"
|
||||
#define MIMI_NVS_SEARCH "search_config"
|
||||
|
||||
/* NVS Keys */
|
||||
#define MIMI_NVS_KEY_SSID "ssid"
|
||||
#define MIMI_NVS_KEY_PASS "password"
|
||||
#define MIMI_NVS_KEY_TG_TOKEN "bot_token"
|
||||
#define MIMI_NVS_KEY_API_KEY "api_key"
|
||||
#define MIMI_NVS_KEY_MODEL "model"
|
||||
#define MIMI_NVS_KEY_PROXY_HOST "host"
|
||||
#define MIMI_NVS_KEY_PROXY_PORT "port"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* MimiClaw Build-time Secrets
|
||||
*
|
||||
* This is the ONLY way to configure MimiClaw.
|
||||
* Copy this file to mimi_secrets.h and fill in your values.
|
||||
* Non-empty values here take HIGHEST priority (override NVS/CLI).
|
||||
* Leave empty ("") to use NVS values set via CLI.
|
||||
* After any change, rebuild: idf.py fullclean && idf.py build
|
||||
*
|
||||
* cp mimi_secrets.h.example mimi_secrets.h
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "nvs.h"
|
||||
#include "esp_tls.h"
|
||||
#include "esp_crt_bundle.h"
|
||||
|
||||
@@ -21,26 +20,14 @@ __attribute__((constructor)) static void proxy_log_level(void)
|
||||
esp_log_level_set(TAG, ESP_LOG_WARN);
|
||||
}
|
||||
|
||||
/* ── Config (cached from NVS) ─────────────────────────────────── */
|
||||
|
||||
static char s_proxy_host[64] = {0};
|
||||
static uint16_t s_proxy_port = 0;
|
||||
|
||||
esp_err_t http_proxy_init(void)
|
||||
{
|
||||
/* Build-time secrets take highest priority */
|
||||
if (MIMI_SECRET_PROXY_HOST[0] != '\0' && MIMI_SECRET_PROXY_PORT[0] != '\0') {
|
||||
strncpy(s_proxy_host, MIMI_SECRET_PROXY_HOST, sizeof(s_proxy_host) - 1);
|
||||
s_proxy_port = (uint16_t)atoi(MIMI_SECRET_PROXY_PORT);
|
||||
} else {
|
||||
nvs_handle_t nvs;
|
||||
esp_err_t err = nvs_open(MIMI_NVS_PROXY, NVS_READONLY, &nvs);
|
||||
if (err == ESP_OK) {
|
||||
size_t len = sizeof(s_proxy_host);
|
||||
nvs_get_str(nvs, MIMI_NVS_KEY_PROXY_HOST, s_proxy_host, &len);
|
||||
nvs_get_u16(nvs, MIMI_NVS_KEY_PROXY_PORT, &s_proxy_port);
|
||||
nvs_close(nvs);
|
||||
}
|
||||
}
|
||||
|
||||
if (s_proxy_host[0] && s_proxy_port) {
|
||||
@@ -56,36 +43,6 @@ bool http_proxy_is_enabled(void)
|
||||
return s_proxy_host[0] != '\0' && s_proxy_port != 0;
|
||||
}
|
||||
|
||||
esp_err_t http_proxy_set(const char *host, uint16_t port)
|
||||
{
|
||||
nvs_handle_t nvs;
|
||||
ESP_ERROR_CHECK(nvs_open(MIMI_NVS_PROXY, NVS_READWRITE, &nvs));
|
||||
ESP_ERROR_CHECK(nvs_set_str(nvs, MIMI_NVS_KEY_PROXY_HOST, host));
|
||||
ESP_ERROR_CHECK(nvs_set_u16(nvs, MIMI_NVS_KEY_PROXY_PORT, port));
|
||||
ESP_ERROR_CHECK(nvs_commit(nvs));
|
||||
nvs_close(nvs);
|
||||
|
||||
strncpy(s_proxy_host, host, sizeof(s_proxy_host) - 1);
|
||||
s_proxy_port = port;
|
||||
ESP_LOGI(TAG, "Proxy set to %s:%d", s_proxy_host, s_proxy_port);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t http_proxy_clear(void)
|
||||
{
|
||||
nvs_handle_t nvs;
|
||||
ESP_ERROR_CHECK(nvs_open(MIMI_NVS_PROXY, NVS_READWRITE, &nvs));
|
||||
nvs_erase_key(nvs, MIMI_NVS_KEY_PROXY_HOST);
|
||||
nvs_erase_key(nvs, MIMI_NVS_KEY_PROXY_PORT);
|
||||
nvs_commit(nvs);
|
||||
nvs_close(nvs);
|
||||
|
||||
s_proxy_host[0] = '\0';
|
||||
s_proxy_port = 0;
|
||||
ESP_LOGI(TAG, "Proxy cleared");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* ── Proxied TLS connection ───────────────────────────────────── */
|
||||
|
||||
struct proxy_conn {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* Initialize proxy module — loads config from NVS.
|
||||
* Initialize proxy module.
|
||||
*/
|
||||
esp_err_t http_proxy_init(void);
|
||||
|
||||
@@ -14,16 +14,6 @@ esp_err_t http_proxy_init(void);
|
||||
*/
|
||||
bool http_proxy_is_enabled(void);
|
||||
|
||||
/**
|
||||
* Save proxy host and port to NVS.
|
||||
*/
|
||||
esp_err_t http_proxy_set(const char *host, uint16_t port);
|
||||
|
||||
/**
|
||||
* Remove proxy config from NVS.
|
||||
*/
|
||||
esp_err_t http_proxy_clear(void);
|
||||
|
||||
/* ── Proxied HTTPS connection ─────────────────────────────────── */
|
||||
|
||||
typedef struct proxy_conn proxy_conn_t;
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "esp_log.h"
|
||||
#include "esp_http_client.h"
|
||||
#include "esp_crt_bundle.h"
|
||||
#include "nvs.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
static const char *TAG = "telegram";
|
||||
@@ -257,21 +256,10 @@ static void telegram_poll_task(void *arg)
|
||||
|
||||
esp_err_t telegram_bot_init(void)
|
||||
{
|
||||
/* Build-time secret takes highest priority */
|
||||
if (s_bot_token[0] == '\0') {
|
||||
nvs_handle_t nvs;
|
||||
esp_err_t err = nvs_open(MIMI_NVS_TG, NVS_READONLY, &nvs);
|
||||
if (err == ESP_OK) {
|
||||
size_t len = sizeof(s_bot_token);
|
||||
nvs_get_str(nvs, MIMI_NVS_KEY_TG_TOKEN, s_bot_token, &len);
|
||||
nvs_close(nvs);
|
||||
}
|
||||
}
|
||||
|
||||
if (s_bot_token[0]) {
|
||||
ESP_LOGI(TAG, "Telegram bot token loaded (len=%d)", (int)strlen(s_bot_token));
|
||||
} else {
|
||||
ESP_LOGW(TAG, "No Telegram bot token. Use CLI: set_tg_token <TOKEN>");
|
||||
ESP_LOGW(TAG, "No Telegram bot token. Set MIMI_SECRET_TG_TOKEN in mimi_secrets.h");
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -369,15 +357,3 @@ esp_err_t telegram_send_message(const char *chat_id, const char *text)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t telegram_set_token(const char *token)
|
||||
{
|
||||
nvs_handle_t nvs;
|
||||
ESP_ERROR_CHECK(nvs_open(MIMI_NVS_TG, NVS_READWRITE, &nvs));
|
||||
ESP_ERROR_CHECK(nvs_set_str(nvs, MIMI_NVS_KEY_TG_TOKEN, token));
|
||||
ESP_ERROR_CHECK(nvs_commit(nvs));
|
||||
nvs_close(nvs);
|
||||
|
||||
strncpy(s_bot_token, token, sizeof(s_bot_token) - 1);
|
||||
ESP_LOGI(TAG, "Telegram bot token saved");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
/**
|
||||
* Initialize the Telegram bot.
|
||||
* Reads bot token from NVS.
|
||||
*/
|
||||
esp_err_t telegram_bot_init(void);
|
||||
|
||||
@@ -21,7 +20,3 @@ esp_err_t telegram_bot_start(void);
|
||||
*/
|
||||
esp_err_t telegram_send_message(const char *chat_id, const char *text);
|
||||
|
||||
/**
|
||||
* Save the Telegram bot token to NVS.
|
||||
*/
|
||||
esp_err_t telegram_set_token(const char *token);
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "esp_http_client.h"
|
||||
#include "esp_crt_bundle.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "nvs.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
static const char *TAG = "web_search";
|
||||
@@ -44,40 +43,18 @@ static esp_err_t http_event_handler(esp_http_client_event_t *evt)
|
||||
|
||||
esp_err_t tool_web_search_init(void)
|
||||
{
|
||||
/* Build-time secret takes highest priority */
|
||||
if (MIMI_SECRET_SEARCH_KEY[0] != '\0') {
|
||||
strncpy(s_search_key, MIMI_SECRET_SEARCH_KEY, sizeof(s_search_key) - 1);
|
||||
} else {
|
||||
nvs_handle_t nvs;
|
||||
esp_err_t err = nvs_open(MIMI_NVS_SEARCH, NVS_READONLY, &nvs);
|
||||
if (err == ESP_OK) {
|
||||
size_t len = sizeof(s_search_key);
|
||||
nvs_get_str(nvs, MIMI_NVS_KEY_API_KEY, s_search_key, &len);
|
||||
nvs_close(nvs);
|
||||
}
|
||||
}
|
||||
|
||||
if (s_search_key[0]) {
|
||||
ESP_LOGI(TAG, "Web search initialized (key configured)");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "No search API key. Use CLI: set_search_key <KEY>");
|
||||
ESP_LOGW(TAG, "No search API key. Set MIMI_SECRET_SEARCH_KEY in mimi_secrets.h");
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t tool_web_search_set_key(const char *api_key)
|
||||
{
|
||||
nvs_handle_t nvs;
|
||||
ESP_ERROR_CHECK(nvs_open(MIMI_NVS_SEARCH, NVS_READWRITE, &nvs));
|
||||
ESP_ERROR_CHECK(nvs_set_str(nvs, MIMI_NVS_KEY_API_KEY, api_key));
|
||||
ESP_ERROR_CHECK(nvs_commit(nvs));
|
||||
nvs_close(nvs);
|
||||
|
||||
strncpy(s_search_key, api_key, sizeof(s_search_key) - 1);
|
||||
ESP_LOGI(TAG, "Search API key saved");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* ── URL-encode a query string ────────────────────────────────── */
|
||||
|
||||
static size_t url_encode(const char *src, char *dst, size_t dst_size)
|
||||
@@ -237,7 +214,7 @@ static esp_err_t search_via_proxy(const char *path, search_buf_t *sb)
|
||||
esp_err_t tool_web_search_execute(const char *input_json, char *output, size_t output_size)
|
||||
{
|
||||
if (s_search_key[0] == '\0') {
|
||||
snprintf(output, output_size, "Error: No search API key configured. Use set_search_key command.");
|
||||
snprintf(output, output_size, "Error: No search API key configured. Set MIMI_SECRET_SEARCH_KEY in mimi_secrets.h");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
* Initialize web search tool — loads API key from NVS.
|
||||
* Initialize web search tool.
|
||||
*/
|
||||
esp_err_t tool_web_search_init(void);
|
||||
|
||||
@@ -18,7 +18,3 @@ esp_err_t tool_web_search_init(void);
|
||||
*/
|
||||
esp_err_t tool_web_search_execute(const char *input_json, char *output, size_t output_size);
|
||||
|
||||
/**
|
||||
* Save Brave Search API key to NVS.
|
||||
*/
|
||||
esp_err_t tool_web_search_set_key(const char *api_key);
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
#include "esp_log.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_netif.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "nvs.h"
|
||||
|
||||
static const char *TAG = "wifi";
|
||||
|
||||
@@ -72,34 +70,15 @@ esp_err_t wifi_manager_init(void)
|
||||
|
||||
esp_err_t wifi_manager_start(void)
|
||||
{
|
||||
wifi_config_t wifi_cfg = {0};
|
||||
|
||||
/* Build-time secrets take highest priority */
|
||||
if (MIMI_SECRET_WIFI_SSID[0] != '\0') {
|
||||
strncpy((char *)wifi_cfg.sta.ssid, MIMI_SECRET_WIFI_SSID, sizeof(wifi_cfg.sta.ssid) - 1);
|
||||
strncpy((char *)wifi_cfg.sta.password, MIMI_SECRET_WIFI_PASS, sizeof(wifi_cfg.sta.password) - 1);
|
||||
} else {
|
||||
/* Fall back to NVS */
|
||||
nvs_handle_t nvs;
|
||||
esp_err_t err = nvs_open(MIMI_NVS_WIFI, NVS_READONLY, &nvs);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "No WiFi credentials. Use CLI: wifi_set <SSID> <PASS>");
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
size_t len = sizeof(wifi_cfg.sta.ssid);
|
||||
err = nvs_get_str(nvs, MIMI_NVS_KEY_SSID, (char *)wifi_cfg.sta.ssid, &len);
|
||||
if (err != ESP_OK) {
|
||||
nvs_close(nvs);
|
||||
ESP_LOGW(TAG, "SSID not found in NVS");
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
len = sizeof(wifi_cfg.sta.password);
|
||||
nvs_get_str(nvs, MIMI_NVS_KEY_PASS, (char *)wifi_cfg.sta.password, &len);
|
||||
nvs_close(nvs);
|
||||
if (MIMI_SECRET_WIFI_SSID[0] == '\0') {
|
||||
ESP_LOGW(TAG, "No WiFi credentials. Set MIMI_SECRET_WIFI_SSID in mimi_secrets.h");
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
wifi_config_t wifi_cfg = {0};
|
||||
strncpy((char *)wifi_cfg.sta.ssid, MIMI_SECRET_WIFI_SSID, sizeof(wifi_cfg.sta.ssid) - 1);
|
||||
strncpy((char *)wifi_cfg.sta.password, MIMI_SECRET_WIFI_PASS, sizeof(wifi_cfg.sta.password) - 1);
|
||||
|
||||
ESP_LOGI(TAG, "Connecting to SSID: %s", wifi_cfg.sta.ssid);
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg));
|
||||
@@ -126,18 +105,6 @@ bool wifi_manager_is_connected(void)
|
||||
return s_connected;
|
||||
}
|
||||
|
||||
esp_err_t wifi_manager_set_credentials(const char *ssid, const char *password)
|
||||
{
|
||||
nvs_handle_t nvs;
|
||||
ESP_ERROR_CHECK(nvs_open(MIMI_NVS_WIFI, NVS_READWRITE, &nvs));
|
||||
ESP_ERROR_CHECK(nvs_set_str(nvs, MIMI_NVS_KEY_SSID, ssid));
|
||||
ESP_ERROR_CHECK(nvs_set_str(nvs, MIMI_NVS_KEY_PASS, password));
|
||||
ESP_ERROR_CHECK(nvs_commit(nvs));
|
||||
nvs_close(nvs);
|
||||
ESP_LOGI(TAG, "WiFi credentials saved for SSID: %s", ssid);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
const char *wifi_manager_get_ip(void)
|
||||
{
|
||||
return s_ip_str;
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
/**
|
||||
* Initialize WiFi subsystem (STA mode).
|
||||
* Reads SSID/password from NVS. If not set, waits for serial configuration.
|
||||
*/
|
||||
esp_err_t wifi_manager_init(void);
|
||||
|
||||
@@ -31,11 +30,6 @@ esp_err_t wifi_manager_wait_connected(uint32_t timeout_ms);
|
||||
*/
|
||||
bool wifi_manager_is_connected(void);
|
||||
|
||||
/**
|
||||
* Save WiFi credentials to NVS.
|
||||
*/
|
||||
esp_err_t wifi_manager_set_credentials(const char *ssid, const char *password);
|
||||
|
||||
/**
|
||||
* Get the current IP address string (or "0.0.0.0" if not connected).
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user