#include "connection.h"

String wifiState;

void initWifiConnection(void)
{
  // Set custom callback functions
  WiFiSettings.onSuccess = []()
  {
    wifiState = "Success";
  };
  WiFiSettings.onFailure = []()
  {
    wifiState = "Failed";
  };
  WiFiSettings.onWaitLoop = []()
  {
    wifiState = "Waiting";
    return 500; // Delay next function call by 500ms
  };

  // Callback functions do not have to be lambda's, e.g.
  // WiFiSettings.onPortalWaitLoop = blink;

  // Define custom settings saved by WifiSettings
  // These will return the default if nothing was set before
  String host = WiFiSettings.string("server_host", "default.example.org");
  int port = WiFiSettings.integer("server_port", 443);

  // Connect to WiFi with a timeout of 30 seconds
  // Launches the portal if the connection failed
  WiFiSettings.connect(true, 30);
}

void initConnection(void)
{
  if (!LittleFS.begin())
  {
    Serial.println("An Error has occurred while mounting LittleFS");
  }
  initWifiConnection();
}

void handleConnection(void)
{
}
