feat: add CYD ThermoPro bridge firmware skeleton
Add PlatformIO project for the ESP32-2432S028R that: - Reads ThermoPro BLE BBQ thermometers via NimBLE-Arduino - Exposes /api/health, /api/latest, and /api/settings HTTP endpoints - Serves a captive-portal setup UI and touch dashboard - Persists WiFi/BLE/settings in NVS via Preferences Builds cleanly with pio run.
This commit is contained in:
@@ -1,42 +1,7 @@
|
||||
#include "WiFiManager.hpp"
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
namespace cyd {
|
||||
|
||||
namespace {
|
||||
constexpr const char* setupHtml = R"rawliteral(
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>CYD ThermoPro Setup</title>
|
||||
<style>
|
||||
body { font-family: system-ui, sans-serif; margin: 1rem; max-width: 500px; }
|
||||
label { display: block; margin-top: 1rem; font-weight: bold; }
|
||||
input { width: 100%; padding: 0.5rem; box-sizing: border-box; }
|
||||
button { margin-top: 1.5rem; padding: 0.6rem 1.2rem; font-size: 1rem; }
|
||||
.note { color: #555; font-size: 0.9rem; margin-top: 0.25rem; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CYD ThermoPro Setup</h1>
|
||||
<p>Enter your WiFi credentials and ThermoPro MAC address, then save.</p>
|
||||
<form method="POST" action="/setup">
|
||||
<label>WiFi Network (SSID)</label>
|
||||
<input type="text" name="ssid" required>
|
||||
<label>WiFi Password</label>
|
||||
<input type="password" name="pass" required>
|
||||
<label>ThermoPro MAC</label>
|
||||
<input type="text" name="mac" placeholder="C9:48:1D:B1:E1:E7" required>
|
||||
<div class="note">Format: AA:BB:CC:DD:EE:FF. Use a BLE scanner if you don't know it.</div>
|
||||
<button type="submit">Save & Reboot</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
)rawliteral";
|
||||
} // namespace
|
||||
|
||||
WiFiManager::WiFiManager(SettingsManager& settings) : settings_(settings) {
|
||||
}
|
||||
|
||||
@@ -86,9 +51,8 @@ void WiFiManager::update() {
|
||||
|
||||
case State::AccessPoint:
|
||||
case State::FallbackToAp:
|
||||
if (portalRunning_) {
|
||||
if (apRunning_) {
|
||||
dnsServer_.processNextRequest();
|
||||
portalServer_.handleClient();
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -144,13 +108,10 @@ void WiFiManager::startAccessPoint_() {
|
||||
IPAddress ip = WiFi.softAPIP();
|
||||
Serial.printf("WiFiManager: AP '%s' started at %s\n", kApSsid, ip.toString().c_str());
|
||||
|
||||
// DNS redirect: any hostname requested while connected to the AP resolves
|
||||
// to the CYD. The HTTP server in ApiServer serves the setup page at /.
|
||||
dnsServer_.start(53, "*", ip);
|
||||
|
||||
portalServer_.on("/", HTTP_GET, [this]() { handlePortalRoot_(); });
|
||||
portalServer_.on("/setup", HTTP_POST, [this]() { handlePortalSubmit_(); });
|
||||
portalServer_.onNotFound([this]() { handlePortalNotFound_(); });
|
||||
portalServer_.begin();
|
||||
portalRunning_ = true;
|
||||
apRunning_ = true;
|
||||
|
||||
if (modeCallback_) {
|
||||
modeCallback_(true);
|
||||
@@ -158,65 +119,9 @@ void WiFiManager::startAccessPoint_() {
|
||||
}
|
||||
|
||||
void WiFiManager::stopAccessPoint_() {
|
||||
portalRunning_ = false;
|
||||
portalServer_.close();
|
||||
apRunning_ = false;
|
||||
dnsServer_.stop();
|
||||
WiFi.softAPdisconnect(true);
|
||||
}
|
||||
|
||||
void WiFiManager::handlePortalRoot_() {
|
||||
portalServer_.send(200, "text/html", setupHtml);
|
||||
}
|
||||
|
||||
void WiFiManager::handlePortalSubmit_() {
|
||||
String ssid = portalServer_.arg("ssid");
|
||||
String pass = portalServer_.arg("pass");
|
||||
String mac = portalServer_.arg("mac");
|
||||
|
||||
if (ssid.length() == 0 || mac.length() == 0) {
|
||||
portalServer_.send(400, "text/html", "<h1>Error</h1><p>SSID and MAC are required.</p><a href='/'>Go back</a>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SettingsManager::isValidMac(mac)) {
|
||||
portalServer_.send(422, "text/html", "<h1>Error</h1><p>Invalid MAC address format.</p><a href='/'>Go back</a>");
|
||||
return;
|
||||
}
|
||||
|
||||
settings_.setWifiSsid(ssid);
|
||||
settings_.setWifiPass(pass);
|
||||
settings_.setThermoproMac(mac);
|
||||
settings_.save();
|
||||
|
||||
String html = R"rawliteral(
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Saved</title>
|
||||
<style>body { font-family: system-ui, sans-serif; margin: 1rem; }</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Settings saved</h1>
|
||||
<p>The CYD will reboot and connect to your WiFi network.</p>
|
||||
<p>If it fails to connect, it will reopen this setup network.</p>
|
||||
</body>
|
||||
</html>
|
||||
)rawliteral";
|
||||
portalServer_.send(200, "text/html", html);
|
||||
|
||||
delay(500);
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
void WiFiManager::handlePortalNotFound_() {
|
||||
redirectToPortal_(portalServer_);
|
||||
}
|
||||
|
||||
void WiFiManager::redirectToPortal_(WebServer& server) {
|
||||
server.sendHeader("Location", "http://" + String(kSetupDomain) + "/", true);
|
||||
server.send(302, "text/plain", "Redirecting to setup portal...");
|
||||
}
|
||||
|
||||
} // namespace cyd
|
||||
|
||||
Reference in New Issue
Block a user