This commit is contained in:
Patrick Haßel 2025-01-07 09:18:18 +01:00
parent 2d22c2f136
commit d9be78d738
7 changed files with 62 additions and 0 deletions

View File

@ -10,6 +10,7 @@ lib_deps = milesburton/DallasTemperature
https://github.com/adafruit/MAX6675-library
paulstoffregen/OneWire
bblanchon/ArduinoJson
https://github.com/me-no-dev/ESPAsyncWebServer.git
upload_port = /dev/ttyUSB0
upload_speed = 921600
monitor_port = /dev/ttyUSB0

27
src/patrix/http.cpp Normal file
View 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
View File

@ -0,0 +1,6 @@
#ifndef HTTP_H
#define HTTP_H
void httpSetup();
#endif

10
src/patrix/system.cpp Normal file
View 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
View File

@ -0,0 +1,6 @@
#ifndef SYSTEM_H
#define SYSTEM_H
void restart();
#endif

View File

@ -5,6 +5,8 @@
#define WIFI_TIMEOUT_MILLIS 10000
auto wifiEnabled = true;
auto wifiConnected = false;
auto wifiTryMillis = 0UL;
@ -52,6 +54,11 @@ void wifiSetupOTA() {
ArduinoOTA.begin();
}
void wifiOff() {
info("wifi disabled");
wifiEnabled = false;
}
void wifiLoop() {
const auto currentState = WiFi.localIP() != 0;
if (wifiConnected != currentState) {
@ -65,6 +72,9 @@ void wifiLoop() {
WiFi.disconnect();
}
} else if (!wifiConnected) {
if (!wifiEnabled) {
return;
}
if (wifiTryMillis == 0 || millis() - wifiTryMillis >= WIFI_TIMEOUT_MILLIS) {
wifiTryMillis = millis();
WiFiClass::hostname(wifiHost);

View File

@ -1,6 +1,8 @@
#ifndef WIFI_H
#define WIFI_H
void wifiOff();
void wifiLoop();
bool isWiFiConnected();