/*************************************************************
  Download latest ERa library here:
    https://github.com/eoh-jsc/era-lib/releases/latest
    https://www.arduino.cc/reference/en/libraries/era
    https://registry.platformio.org/libraries/eoh-ltd/ERa/installation

    ERa website:                https://e-ra.io
    ERa blog:                   https://iotasia.org
    ERa forum:                  https://forum.eoh.io
    Follow us:                  https://www.fb.com/EoHPlatform
 *************************************************************/

// Enable debug console
// Set CORE_DEBUG_LEVEL = 3 first
#define ERA_DEBUG

// #define DEFAULT_MQTT_KEEPALIVE 10
// You should get Auth Token in the ERa App or ERa Dashboard
#define ERA_AUTH_TOKEN "37275d4c-fc8c-4e8a-a601-d78086cb41fb"

#include <Arduino.h>
#include <ERaSimpleEsp32.hpp>
#include <ERa/ERaTimer.hpp>

const char ssid[] = "Wokwi-GUEST";
const char pass[] = "";

ERaTimer timer;

/* This function print uptime every second */
void timerEvent() {
    ERA_LOG("Timer", "Uptime: %d", ERaMillis() / 1000L);
}

void setup() {
    /* Setup debug console */
    Serial.begin(115200);

    /* Enable get config after reset */
    ERa.askConfigWhenRestart();
    
    ERa.begin(ssid, pass);

    /* Setup timer called function every second */
    timer.setInterval(1000L, timerEvent);
}

void loop() {
    ERa.run();
    timer.run();
    delay(10);
}