76 lines
1.4 KiB
C++
76 lines
1.4 KiB
C++
#include <Arduino.h>
|
|
|
|
void checkWifiCallback();
|
|
void onWifiConnected();
|
|
void onButtonPressed();
|
|
void onButtonCallback();
|
|
|
|
#include <TaskScheduler.h>
|
|
Scheduler ts;
|
|
Task tCheckWifi(5 * TASK_MINUTE, TASK_ONCE, checkWifiCallback, &ts);
|
|
Task tWifiConnected(TASK_IMMEDIATE, TASK_ONCE, onWifiConnected, &ts);
|
|
Task tButton(TASK_IMMEDIATE, TASK_ONCE, onButtonCallback, &ts);
|
|
|
|
#include "wifi.h"
|
|
#include "display.h"
|
|
#include "bmp.h"
|
|
#include "ntp_time.h"
|
|
#include "mqtt.h"
|
|
#include "ota.h"
|
|
#include "ir.h"
|
|
|
|
#define BUTTON D3
|
|
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(9600);
|
|
|
|
pinMode(LED_BUILTIN, OUTPUT);
|
|
digitalWrite(LED_BUILTIN, HIGH);
|
|
|
|
Display::setup();
|
|
Ota::setup();
|
|
Ntp::setup();
|
|
Ir::setup();
|
|
Mqtt::setup();
|
|
Bmp::setup();
|
|
|
|
Wifi::setup();
|
|
|
|
pinMode(BUTTON, INPUT_PULLUP);
|
|
attachInterrupt(digitalPinToInterrupt(BUTTON), onButtonPressed, FALLING);
|
|
}
|
|
|
|
void loop() {
|
|
ts.execute();
|
|
}
|
|
|
|
void onWifiConnected() {
|
|
Serial.println("Wifi connected event");
|
|
Wifi::printStatus();
|
|
Ota::tLoop.enable();
|
|
if (!Ir::avrOn) tCheckWifi.restartDelayed();
|
|
Mqtt::connect();
|
|
if (time_t newTime = Ntp::updateTime()) {
|
|
Serial.println(asctime(localtime(&newTime)));
|
|
}
|
|
}
|
|
|
|
void checkWifiCallback() {
|
|
#if !WIFI_ALWAYS_ON
|
|
Serial.println("Wifi connection timed out");
|
|
Mqtt::disconnect();
|
|
Ota::tLoop.disable();
|
|
Wifi::disconnect();
|
|
#endif
|
|
}
|
|
|
|
ICACHE_RAM_ATTR void onButtonPressed() {
|
|
tButton.restart();
|
|
}
|
|
|
|
void onButtonCallback() {
|
|
Display::displayTemp(Bmp::data.readTemp());
|
|
}
|