http
This commit is contained in:
parent
2d22c2f136
commit
d9be78d738
@ -10,6 +10,7 @@ lib_deps = milesburton/DallasTemperature
|
|||||||
https://github.com/adafruit/MAX6675-library
|
https://github.com/adafruit/MAX6675-library
|
||||||
paulstoffregen/OneWire
|
paulstoffregen/OneWire
|
||||||
bblanchon/ArduinoJson
|
bblanchon/ArduinoJson
|
||||||
|
https://github.com/me-no-dev/ESPAsyncWebServer.git
|
||||||
upload_port = /dev/ttyUSB0
|
upload_port = /dev/ttyUSB0
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_port = /dev/ttyUSB0
|
monitor_port = /dev/ttyUSB0
|
||||||
|
|||||||
27
src/patrix/http.cpp
Normal file
27
src/patrix/http.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include "http.h"
|
||||||
|
|
||||||
|
#include <ESPAsyncWebServer.h>
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
|
AsyncWebServer server(80);
|
||||||
|
|
||||||
|
void httpIndex(AsyncWebServerRequest *request) {
|
||||||
|
request->send(200, "text/plain", R"(<a href="/reboot">reboot</a>)");
|
||||||
|
}
|
||||||
|
|
||||||
|
void httpReboot(AsyncWebServerRequest *request) {
|
||||||
|
info("Rebooting...");
|
||||||
|
request->redirect("/");
|
||||||
|
request->client()->close();
|
||||||
|
yield();
|
||||||
|
|
||||||
|
restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
void httpSetup() {
|
||||||
|
server.on("/", HTTP_GET, httpIndex);
|
||||||
|
server.on("/reboot", HTTP_GET, httpReboot);
|
||||||
|
server.begin();
|
||||||
|
}
|
||||||
6
src/patrix/http.h
Normal file
6
src/patrix/http.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef HTTP_H
|
||||||
|
#define HTTP_H
|
||||||
|
|
||||||
|
void httpSetup();
|
||||||
|
|
||||||
|
#endif
|
||||||
10
src/patrix/system.cpp
Normal file
10
src/patrix/system.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include "system.h"
|
||||||
|
|
||||||
|
#include <Esp.h>
|
||||||
|
|
||||||
|
#include "wifi.h"
|
||||||
|
|
||||||
|
void restart() {
|
||||||
|
wifiOff();
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
6
src/patrix/system.h
Normal file
6
src/patrix/system.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef SYSTEM_H
|
||||||
|
#define SYSTEM_H
|
||||||
|
|
||||||
|
void restart();
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#define WIFI_TIMEOUT_MILLIS 10000
|
#define WIFI_TIMEOUT_MILLIS 10000
|
||||||
|
|
||||||
|
auto wifiEnabled = true;
|
||||||
|
|
||||||
auto wifiConnected = false;
|
auto wifiConnected = false;
|
||||||
|
|
||||||
auto wifiTryMillis = 0UL;
|
auto wifiTryMillis = 0UL;
|
||||||
@ -52,6 +54,11 @@ void wifiSetupOTA() {
|
|||||||
ArduinoOTA.begin();
|
ArduinoOTA.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wifiOff() {
|
||||||
|
info("wifi disabled");
|
||||||
|
wifiEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
void wifiLoop() {
|
void wifiLoop() {
|
||||||
const auto currentState = WiFi.localIP() != 0;
|
const auto currentState = WiFi.localIP() != 0;
|
||||||
if (wifiConnected != currentState) {
|
if (wifiConnected != currentState) {
|
||||||
@ -65,6 +72,9 @@ void wifiLoop() {
|
|||||||
WiFi.disconnect();
|
WiFi.disconnect();
|
||||||
}
|
}
|
||||||
} else if (!wifiConnected) {
|
} else if (!wifiConnected) {
|
||||||
|
if (!wifiEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (wifiTryMillis == 0 || millis() - wifiTryMillis >= WIFI_TIMEOUT_MILLIS) {
|
if (wifiTryMillis == 0 || millis() - wifiTryMillis >= WIFI_TIMEOUT_MILLIS) {
|
||||||
wifiTryMillis = millis();
|
wifiTryMillis = millis();
|
||||||
WiFiClass::hostname(wifiHost);
|
WiFiClass::hostname(wifiHost);
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
#ifndef WIFI_H
|
#ifndef WIFI_H
|
||||||
#define WIFI_H
|
#define WIFI_H
|
||||||
|
|
||||||
|
void wifiOff();
|
||||||
|
|
||||||
void wifiLoop();
|
void wifiLoop();
|
||||||
|
|
||||||
bool isWiFiConnected();
|
bool isWiFiConnected();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user