|
@ -41,31 +41,8 @@ String getIdentifier() { |
|
|
return String(identifier); |
|
|
return String(identifier); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void blink(unsigned long delayOff, unsigned long delayOn) { |
|
|
|
|
|
static unsigned long next = millis(); |
|
|
|
|
|
static bool status = HIGH; |
|
|
|
|
|
if (next < millis()) { |
|
|
|
|
|
status = !status; |
|
|
|
|
|
digitalWrite(LED_PIN, LED_PIN_INVERSE ? !status : status); |
|
|
|
|
|
next += ((status) ? delayOff : delayOn); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void showStatus() { |
|
|
|
|
|
if (wifiConnected()) { |
|
|
|
|
|
if (WiFi.getMode() == WIFI_AP) { |
|
|
|
|
|
blink(2000, 2000); |
|
|
|
|
|
} else { |
|
|
|
|
|
blink(5000, 500); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
blink(500, 500); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void hardwareSetup() { |
|
|
void hardwareSetup() { |
|
|
Serial.begin(SERIAL_BAUDRATE); |
|
|
Serial.begin(SERIAL_BAUDRATE); |
|
|
pinMode(LED_PIN, OUTPUT); |
|
|
|
|
|
SPIFFS.begin(); |
|
|
SPIFFS.begin(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -83,8 +60,6 @@ void getFSVersion(char * buffer) { |
|
|
|
|
|
|
|
|
void hardwareLoop() { |
|
|
void hardwareLoop() { |
|
|
|
|
|
|
|
|
showStatus(); |
|
|
|
|
|
|
|
|
|
|
|
// Heartbeat
|
|
|
// Heartbeat
|
|
|
static unsigned long last_heartbeat = 0; |
|
|
static unsigned long last_heartbeat = 0; |
|
|
if (mqttConnected()) { |
|
|
if (mqttConnected()) { |
|
@ -129,6 +104,7 @@ void setup() { |
|
|
|
|
|
|
|
|
hardwareSetup(); |
|
|
hardwareSetup(); |
|
|
buttonSetup(); |
|
|
buttonSetup(); |
|
|
|
|
|
ledSetup(); |
|
|
|
|
|
|
|
|
welcome(); |
|
|
welcome(); |
|
|
|
|
|
|
|
@ -173,6 +149,7 @@ void loop() { |
|
|
|
|
|
|
|
|
hardwareLoop(); |
|
|
hardwareLoop(); |
|
|
buttonLoop(); |
|
|
buttonLoop(); |
|
|
|
|
|
ledLoop(); |
|
|
wifiLoop(); |
|
|
wifiLoop(); |
|
|
otaLoop(); |
|
|
otaLoop(); |
|
|
mqttLoop(); |
|
|
mqttLoop(); |
|
|