MeshTalos/main/controlplane.c
2025-12-31 14:53:05 +08:00

49 lines
1.4 KiB
C

#include "./lib/meshtalos.h"
#include "esp_err.h"
#include "network.h"
#include <esp_event.h>
#include <esp_littlefs.h>
#include <esp_log.h>
#include <nvs_flash.h>
#include <unistd.h>
#define BLOCKSIZE 4096
const char *TAG = "main";
void app_main(void) {
/* event initialization */
netif_start();
ESP_LOGI(TAG, "network inited");
esp_vfs_littlefs_conf_t conf = {.base_path = "/lfs",
.partition_label = "storage",
.format_if_mount_failed = true,
.dont_mount = false,
.partition = NULL};
esp_err_t ret = esp_vfs_littlefs_register(&conf);
if (ret != ESP_OK) {
if (ret == ESP_FAIL) {
ESP_LOGE(TAG, "Failed to mount or format filesystem");
} else if (ret == ESP_ERR_NOT_FOUND) {
ESP_LOGE(TAG, "Failed to find LittleFS partition");
} else {
ESP_LOGE(TAG, "Failed to initialize LittleFS (%s)", esp_err_to_name(ret));
}
return;
}
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
pdFALSE, pdFALSE, portMAX_DELAY);
if (bits & WIFI_CONNECTED_BIT) {
struct Meshtalos *control = mtsh_init();
if (control == NULL) {
ESP_LOGE("MESHTALOS", "failed init control");
abort();
}
mtsh_listen(control, 3030, 80);
}
}