2019-05-27 19:17:05 +00:00
|
|
|
#include <Arduino.h>
|
2019-05-21 03:52:57 +00:00
|
|
|
#include <ESP8266WiFi.h>
|
|
|
|
#include <ESP8266mDNS.h>
|
|
|
|
#include <ArduinoOTA.h>
|
2019-05-28 19:19:35 +00:00
|
|
|
#include <SimpleList.h>
|
2019-05-21 03:52:57 +00:00
|
|
|
|
2019-05-29 22:49:54 +00:00
|
|
|
#include "ntp.h"
|
2019-05-21 03:52:57 +00:00
|
|
|
#include "config.h"
|
2019-05-28 03:46:25 +00:00
|
|
|
#include "animations.h"
|
2019-05-28 19:19:35 +00:00
|
|
|
#include "wifi.h"
|
|
|
|
#include "ota.h"
|
|
|
|
#include "my_fastled.h"
|
2019-05-29 22:49:54 +00:00
|
|
|
#include "EffectEntry.h"
|
|
|
|
#include "my_mqtt.h"
|
2019-05-21 03:52:57 +00:00
|
|
|
#include "functions.h"
|
|
|
|
#include "text.h"
|
2019-05-22 04:52:41 +00:00
|
|
|
#include "effects.h"
|
2019-05-21 03:52:57 +00:00
|
|
|
|
2019-05-29 22:49:54 +00:00
|
|
|
uint8_t starting_up = OTA_STARTUP_DELAY;
|
|
|
|
int loop_timeouts = 0;
|
|
|
|
long loop_started_at = 0;
|
2019-05-30 11:08:24 +00:00
|
|
|
uint8_t baseHue = 0; // defined as extern in prototypes.h
|
2019-05-23 19:18:15 +00:00
|
|
|
|
2019-05-21 03:52:57 +00:00
|
|
|
void setup() {
|
|
|
|
Serial.begin(74880);
|
2019-05-30 09:12:40 +00:00
|
|
|
LOGln("Core * Starting");
|
2019-05-29 22:49:54 +00:00
|
|
|
setup_effects();
|
2019-05-21 03:52:57 +00:00
|
|
|
wifi_setup();
|
|
|
|
ota_setup();
|
|
|
|
fastled_setup();
|
2019-05-25 21:48:55 +00:00
|
|
|
ntpClient.begin();
|
2019-05-29 22:49:54 +00:00
|
|
|
mqtt_setup();
|
2019-05-30 09:12:40 +00:00
|
|
|
LOGln("Core * Setup complete");
|
2019-05-31 03:46:17 +00:00
|
|
|
|
|
|
|
current_effect->start();
|
2019-05-23 19:18:15 +00:00
|
|
|
}
|
2019-05-21 03:52:57 +00:00
|
|
|
|
|
|
|
void loop() {
|
2019-05-23 19:18:15 +00:00
|
|
|
loop_started_at = millis();
|
2019-05-21 03:52:57 +00:00
|
|
|
ota_loop();
|
|
|
|
|
|
|
|
if (starting_up > 0) {
|
|
|
|
EVERY_N_SECONDS(1) {
|
2019-05-23 19:18:15 +00:00
|
|
|
Serial.print("Core * Waiting for OTA... "); Serial.println(starting_up);
|
2019-05-21 03:52:57 +00:00
|
|
|
starting_up--;
|
|
|
|
clear();
|
|
|
|
for (int i=0; i<starting_up; i++) {
|
|
|
|
leds[XYsafe(i, 0)] = CRGB(0xff0000);
|
|
|
|
}
|
|
|
|
FastLED.show();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2019-05-27 19:17:05 +00:00
|
|
|
|
2019-05-25 21:48:55 +00:00
|
|
|
ntpClient.update();
|
2019-05-29 22:49:54 +00:00
|
|
|
mqtt_loop();
|
2019-05-27 19:17:05 +00:00
|
|
|
|
2019-05-30 11:08:24 +00:00
|
|
|
EVERY_N_MILLISECONDS(100) {
|
|
|
|
baseHue++;
|
|
|
|
}
|
|
|
|
|
2019-05-21 03:52:57 +00:00
|
|
|
EVERY_N_MILLISECONDS(1000 / FPS) {
|
2019-05-31 21:57:46 +00:00
|
|
|
//LOGln("Core * loop running");
|
2019-05-21 03:52:57 +00:00
|
|
|
current_effect->loop();
|
2019-05-31 21:57:46 +00:00
|
|
|
//LOGln("Core * loop ran");
|
2019-05-23 20:14:15 +00:00
|
|
|
|
|
|
|
if (current_effect->can_be_shown_with_clock()) {
|
2019-05-27 19:17:05 +00:00
|
|
|
effect_clock.loop(current_effect->clock_as_mask(), CRGB(0xFFFFFF), CRGB(0x000000));
|
2019-05-23 20:14:15 +00:00
|
|
|
}
|
2019-05-29 23:36:30 +00:00
|
|
|
FastLED.show();
|
2019-05-21 03:52:57 +00:00
|
|
|
}
|
2019-05-29 23:36:30 +00:00
|
|
|
|
2019-05-31 21:59:32 +00:00
|
|
|
EVERY_N_SECONDS(15) {
|
|
|
|
if (REPORT_METRICS) {
|
2019-05-30 11:09:38 +00:00
|
|
|
mqtt_publish("free_heap", ESP.getFreeHeap());
|
2019-05-31 21:59:32 +00:00
|
|
|
mqtt_publish("uptime", millis()/1000);
|
2019-05-30 11:09:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-23 19:18:15 +00:00
|
|
|
|
|
|
|
if (MONITOR_LOOP_TIMES && millis()-loop_started_at>=MONITOR_LOOP_TIME_THRESHOLD) {
|
|
|
|
LOG("Core * Loop took "); LOG(millis()-loop_started_at); LOGln("ms.");
|
|
|
|
loop_timeouts++;
|
|
|
|
LOG("Core * Timeout counter is now "); LOGln(loop_timeouts);
|
|
|
|
if (loop_timeouts >= MONITOR_LOOP_TIME_COUNT_MAX) {
|
|
|
|
ESP.restart();
|
|
|
|
}
|
|
|
|
} else if (loop_timeouts > 0) {
|
|
|
|
loop_timeouts--;
|
|
|
|
}
|
2019-05-21 03:52:57 +00:00
|
|
|
}
|