53 lines
1.4 KiB
C++
53 lines
1.4 KiB
C++
#include "nvs_flash.h"
|
|
#include "nvs.h"
|
|
#include "nvs_handle.hpp"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
#include <inttypes.h>
|
|
#include <stdio.h>
|
|
#include <expected>
|
|
|
|
#include "wifi_provisioner.hpp"
|
|
|
|
extern "C" void app_main(void)
|
|
{
|
|
esp_err_t err = nvs_flash_init();
|
|
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND)
|
|
{
|
|
// NVS partition was truncated and needs to be erased
|
|
// Retry nvs_flash_init
|
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
err = nvs_flash_init();
|
|
}
|
|
|
|
ESP_ERROR_CHECK(err);
|
|
|
|
auto* provisioner = new WifiProvisioner("wifi_settings", [](const auto& params)
|
|
{
|
|
printf("Settings successfully done.");
|
|
});
|
|
if (!provisioner->addParameter("SSID", "ssid", WifiProvisioner::Parameter::Type::STRING).has_value())
|
|
{
|
|
printf("Error adding parameter.");
|
|
return;
|
|
}
|
|
|
|
if (!provisioner->addParameter("Password", "password", WifiProvisioner::Parameter::Type::STRING).has_value())
|
|
{
|
|
printf("Error adding parameter.");
|
|
return;
|
|
}
|
|
|
|
if (!provisioner->parametersAreConfigured())
|
|
{
|
|
auto result = provisioner->startProvisioning();
|
|
if (!result.has_value())
|
|
printf("Error: %s\n", esp_err_to_name(result.error()));
|
|
else
|
|
printf("Provisioning started...\n");
|
|
}
|
|
}
|