Compilable version with wifi support - need to test

This commit is contained in:
2025-11-29 16:24:56 -06:00
parent 8bb08d2819
commit d6dfa5d681
9 changed files with 320 additions and 28 deletions

View File

@@ -5,21 +5,54 @@
#include "NimBLEDevice.h"
#include "BLE.hpp"
#include "WiFi.hpp"
#include "setup.hpp"
extern "C" void app_main() {
esp_err_t ret = nvs_flash_init();
esp_err_t ret = nvs_flash_init(); // change to secure init logic soon!!
// 2. If NVS is full or corrupt (common after flashing new code), erase and retry
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
init_wifi();
NimBLEAdvertising* pAdv = initBLE();
WiFi bmWiFi;
bmWiFi.init();
nvs_handle_t WiFiHandle;
nvs_open("WiFiCreds", NVS_READWRITE, &WiFiHandle);
size_t ssidSize;
esp_err_t WiFiPrefsError = nvs_get_str(WiFiHandle, "SSID", NULL, &ssidSize);
size_t pwSize;
WiFiPrefsError |= nvs_get_str(WiFiHandle, "PW", NULL, &pwSize);
uint8_t authMode;
WiFiPrefsError |= nvs_get_u8(WiFiHandle, "AuthMode", &authMode);
if (WiFiPrefsError == ESP_ERR_NVS_NOT_FOUND) {
// Make the RGB LED a certain color (Blue?)
nvs_close(WiFiHandle);
initialSetup();
} else if (WiFiPrefsError == ESP_OK) {
char ssid[ssidSize];
nvs_get_str(WiFiHandle, "SSID", ssid, &ssidSize);
char pw[pwSize];
nvs_get_str(WiFiHandle, "PW", pw, &pwSize);
nvs_close(WiFiHandle);
// TODO: add enterprise support
if (!bmWiFi.attemptConnect(ssid, pw, (wifi_auth_mode_t)authMode)) {
// Make RGB LED certain color (Blue?)
initialSetup();
}
} else {
// Make RGB LED certain color (Blue?)
nvs_close(WiFiHandle);
printf("Program error in Wifi Connection\n");
initialSetup();
}
// Main loop
while (1) {
BLEtick(pAdv);
vTaskDelay(pdMS_TO_TICKS(10));
// Your main application logic here
vTaskDelay(pdMS_TO_TICKS(100));
}
}