2024-05-22 11:54:43 -07:00

86 lines
1.2 KiB
C++

/// © MiroZ 2024
#include "App.h"
#include <Arduino.h>
#include "Settings.h"
#include "errors.h"
#include "OTA.h"
#include "ProvisionSoftAP.h"
#include <ESPmDNS.h>
#include "Mqtt.h"
#include <time.h>
#define LED_PIN 26
//static const char * TAG = "app";
App::App()
{
}
void App::init()
{
m_led = new Led(LED_PIN);
m_wifi = new Wifi();
bool needs_provision = true;
if(SETTINGS.wifi.num > 0)
{
// try connecting
m_led->setColor(0, 255, 0);
uint32_t status = m_wifi->start();
if(status == WH_OK)
{
ESP_LOGI(TAG, "Getting local time");
struct tm timeinfo;
configTime(0, 0, "pool.ntp.org");
if(getLocalTime(&timeinfo))
ESP_LOGI(TAG, "Got local time");
else
ESP_LOGE(TAG, "Failed to get local time");
m_led->setColor(0, 0, 0);
MDNS.begin("esp32");
needs_provision = false;
}
}
if(needs_provision)
{
m_led->setPulse(0, 0, 255);
ProvisionSoftAP provision(80);
provision.start();
}
ota_update::OTA ota(*this);
ota.start();
m_led->setColor(0, 0, 0);
Mqtt m;
m.test();
// Mqtt::test();
}
void App::start()
{
while(true)
{
vTaskDelay(pdMS_TO_TICKS(10020));
}
}
void App::readSensors()
{
}
void App::reportSensors()
{
}