Faster response + MDNS
This commit is contained in:
parent
9ebca3698d
commit
ad2c64c63a
1 changed files with 9 additions and 6 deletions
15
src/main.cpp
15
src/main.cpp
|
@ -2,6 +2,7 @@
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
|
#include <ESP8266mDNS.h>
|
||||||
|
|
||||||
#define RELAY 4 // GPIO4
|
#define RELAY 4 // GPIO4
|
||||||
#define WIFI_NAME "TechInc"
|
#define WIFI_NAME "TechInc"
|
||||||
|
@ -18,6 +19,7 @@ boolean automatic = true;
|
||||||
// ----- //
|
// ----- //
|
||||||
|
|
||||||
void ensureWiFiConnection();
|
void ensureWiFiConnection();
|
||||||
|
void testInternet();
|
||||||
void relayOn();
|
void relayOn();
|
||||||
void relayOff();
|
void relayOff();
|
||||||
|
|
||||||
|
@ -73,9 +75,12 @@ void webSetup() {
|
||||||
server.on("/auto", []() {
|
server.on("/auto", []() {
|
||||||
server.send(200, "text/plain", "automatic mode");
|
server.send(200, "text/plain", "automatic mode");
|
||||||
automatic = true;
|
automatic = true;
|
||||||
|
ensureWiFiConnection();
|
||||||
|
testInternet();
|
||||||
});
|
});
|
||||||
|
|
||||||
server.begin();
|
server.begin();
|
||||||
|
if (MDNS.begin("internot")) { Serial.println("MDNS responder started"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
|
@ -83,9 +88,6 @@ void setup()
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
pinMode(RELAY, OUTPUT);
|
pinMode(RELAY, OUTPUT);
|
||||||
relayOn();
|
|
||||||
delay(2000);
|
|
||||||
relayOff();
|
|
||||||
ensureWiFiConnection();
|
ensureWiFiConnection();
|
||||||
setupOTA();
|
setupOTA();
|
||||||
webSetup();
|
webSetup();
|
||||||
|
@ -119,7 +121,7 @@ void ensureWiFiConnection()
|
||||||
if(status == WL_CONNECTED)
|
if(status == WL_CONNECTED)
|
||||||
return;
|
return;
|
||||||
else {
|
else {
|
||||||
relayOff();
|
if(!automatic) relayOff();
|
||||||
Serial.print("WiFi is disconnected, now connecting");
|
Serial.print("WiFi is disconnected, now connecting");
|
||||||
WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
|
WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
|
||||||
while(WiFi.status() != WL_CONNECTED) {
|
while(WiFi.status() != WL_CONNECTED) {
|
||||||
|
@ -162,9 +164,10 @@ void loop()
|
||||||
{
|
{
|
||||||
ensureWiFiConnection();
|
ensureWiFiConnection();
|
||||||
testInternet();
|
testInternet();
|
||||||
for(size_t i = 0; i < 5; i++) {
|
for(size_t i = 0; i < 20; i++) {
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
delay(1000);
|
delay(250);
|
||||||
server.handleClient();
|
server.handleClient();
|
||||||
|
MDNS.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue