55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
/*
|
|
* Setup and loop functions
|
|
*/
|
|
|
|
/*************************** Sketch Code ************************************/
|
|
void setup() {
|
|
// Write banner
|
|
PRINTLN_SERIAL("");
|
|
PRINTLN_SERIAL("");
|
|
PRINTLN_SERIAL("Booting " __FILE__ " built on " __DATE__ ", " __TIME__);
|
|
|
|
// Generate device name from MAC
|
|
PRINTLN_SERIAL("Network interface: " + WiFi.macAddress());
|
|
settings.name = DEVICEPREFIX;
|
|
int devlen = settings.name.length();
|
|
settings.name = settings.name + "_" + WiFi.macAddress();
|
|
settings.name.remove(devlen+3, 1);
|
|
settings.name.remove(devlen+5, 1);
|
|
settings.name.remove(devlen+7, 1);
|
|
settings.name.remove(devlen+9, 1);
|
|
settings.name.remove(devlen+11, 1);
|
|
// Only keep the last 6 characters from the MAC, hopefully that will be 'unique enough' in the LAN
|
|
// If we run in to trouble, this can painlessly be removed and the resulting device name will just be longer
|
|
settings.name.remove(devlen+1, 6);
|
|
|
|
PRINTLN_SERIAL("Figured out who I am \\O/");
|
|
|
|
wifi_setup();
|
|
|
|
#ifdef ENABLE_MQTT
|
|
mqtt_setup();
|
|
#endif
|
|
#ifdef ENABLE_SONOFF
|
|
sonoff_setup();
|
|
#endif
|
|
#ifdef ENABLE_MOON
|
|
moon_setup();
|
|
#endif
|
|
// Start the cooperative scheduler loops
|
|
PRINTLN_SERIAL("Done setting up, ready for main loop \\O/");
|
|
}
|
|
|
|
void loop() {
|
|
wifi_loop();
|
|
#ifdef ENABLE_MQTT
|
|
mqtt_loop();
|
|
#endif
|
|
#ifdef ENABLE_SONOFF
|
|
sonoff_loop();
|
|
#endif
|
|
#ifdef ENABLE_MOON
|
|
moon_loop();
|
|
#endif
|
|
}
|