2019-12-03 23:16:06 +00:00
|
|
|
#include <ESP8266React.h>
|
2020-05-14 22:23:45 +00:00
|
|
|
#include <LightMqttSettingsService.h>
|
|
|
|
#include <LightStateService.h>
|
2018-11-11 16:44:29 +00:00
|
|
|
#include <FS.h>
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
#define SERIAL_BAUD_RATE 115200
|
|
|
|
|
|
|
|
AsyncWebServer server(80);
|
2019-09-30 20:28:24 +00:00
|
|
|
ESP8266React esp8266React(&server, &SPIFFS);
|
2020-05-14 22:23:45 +00:00
|
|
|
LightMqttSettingsService lightMqttSettingsService =
|
|
|
|
LightMqttSettingsService(&server, &SPIFFS, esp8266React.getSecurityManager());
|
|
|
|
LightStateService lightStateService = LightStateService(&server,
|
|
|
|
esp8266React.getSecurityManager(),
|
|
|
|
esp8266React.getMqttClient(),
|
|
|
|
&lightMqttSettingsService);
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
void setup() {
|
2019-08-09 14:53:39 +00:00
|
|
|
// start serial and filesystem
|
2019-06-07 19:08:46 +00:00
|
|
|
Serial.begin(SERIAL_BAUD_RATE);
|
2019-09-30 20:28:24 +00:00
|
|
|
|
|
|
|
// start the file system (must be done before starting the framework)
|
2019-12-29 17:54:12 +00:00
|
|
|
#ifdef ESP32
|
|
|
|
SPIFFS.begin(true);
|
|
|
|
#elif defined(ESP8266)
|
2019-06-07 19:08:46 +00:00
|
|
|
SPIFFS.begin();
|
2019-12-29 17:54:12 +00:00
|
|
|
#endif
|
2019-09-30 20:28:24 +00:00
|
|
|
|
|
|
|
// start the framework and demo project
|
|
|
|
esp8266React.begin();
|
2019-09-30 20:38:44 +00:00
|
|
|
|
2020-05-14 22:23:45 +00:00
|
|
|
// load the initial light settings
|
|
|
|
lightStateService.begin();
|
|
|
|
|
|
|
|
// start the light service
|
|
|
|
lightMqttSettingsService.begin();
|
2019-09-30 20:28:24 +00:00
|
|
|
|
2019-08-09 14:53:39 +00:00
|
|
|
// start the server
|
2019-06-07 19:08:46 +00:00
|
|
|
server.begin();
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2019-08-09 14:53:39 +00:00
|
|
|
// run the framework's loop function
|
2019-09-30 20:28:24 +00:00
|
|
|
esp8266React.loop();
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|