add bed cooler project.

This commit is contained in:
2026-06-28 13:15:53 -05:00
commit 0f2a03044c
46 changed files with 3597 additions and 0 deletions

37
include/README Normal file
View File

@@ -0,0 +1,37 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the convention is to give header files names that end with `.h'.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

179
include/app.h Normal file
View File

@@ -0,0 +1,179 @@
#pragma once
#include <Arduino.h>
#include <DNSServer.h>
#include <Preferences.h>
#include <WebServer.h>
#include <WiFi.h>
#ifndef LED_BUILTIN
#define LED_BUILTIN 8
#endif
#ifndef FACTORY_RESET_PIN
#define FACTORY_RESET_PIN 4
#endif
#ifndef FACTORY_RESET_ACTIVE_LEVEL
#define FACTORY_RESET_ACTIVE_LEVEL LOW
#endif
#ifndef DS18B20_PIN
#define DS18B20_PIN 3
#endif
#ifndef PROJECT_NAME
#define PROJECT_NAME "TSL Bed Cooler"
#endif
extern const char *APP_VERSION;
extern const char *PROJECT_NAME_VALUE;
extern const char *DEFAULT_ADMIN;
extern const char *DEFAULT_UPDATE_URL;
extern const uint32_t FACTORY_RESET_HOLD_MS;
extern const size_t MAX_USERS;
extern const size_t MAX_TOKENS;
extern const bool DEFAULT_LED_INVERTED;
extern const byte DNS_PORT;
extern const IPAddress SETUP_AP_IP;
extern const IPAddress SETUP_AP_GATEWAY;
extern const IPAddress SETUP_AP_SUBNET;
extern const char *WWW_ROOT;
extern const char *LOG_DIR;
extern const char *LOG_FILE_PATH;
enum LogLevel : uint8_t {
LOG_ERROR = 0,
LOG_WARN = 1,
LOG_SECURITY_AUDIT = 2,
LOG_INFO = 3,
LOG_DEBUG = 4
};
struct User {
String name;
String passwordHash;
String roles;
bool active;
};
struct Token {
String value;
String user;
String roles;
uint32_t lastSeen;
};
typedef void (*RouteHandler)();
struct ApiDef {
const char *path;
const char *method;
const char *defaultRole;
bool publicByDefault;
RouteHandler handler;
RouteHandler uploadHandler;
};
extern WebServer server;
extern DNSServer dnsServer;
extern Preferences prefs;
extern Token tokens[];
extern ApiDef apiDefs[];
extern const size_t API_DEF_COUNT;
extern ApiDef customApiDefs[];
extern const size_t CUSTOM_API_DEF_COUNT;
extern LogLevel currentLogLevel;
extern size_t maxLogBytes;
extern bool setupMode;
extern uint8_t ledBrightness;
extern bool ledInverted;
extern String updateUrl;
extern String networkHostname;
extern bool networkDhcp;
extern String networkIp;
extern String networkGateway;
extern String networkSubnet;
extern String networkDns1;
extern String networkDns2;
String jsonEscape(const String &s);
String jsonOk(const String &payload = "");
String jsonError(const String &message);
void sendJson(int code, const String &body);
String requestBody();
String jsonStringValue(const String &json, const char *key, const String &fallback = "");
int jsonIntValue(const String &json, const char *key, int fallback = 0);
bool jsonBoolValue(const String &json, const char *key, bool fallback = false);
String jsonRolesValue(const String &json, const char *key, const String &fallback = "");
String chipId();
String deviceName();
String defaultDeviceName();
String sha256(const String &input);
String passwordHash(const String &password);
String prefString(const char *key, const String &fallback = "");
void loadSettings();
bool hasRole(const String &roles, const String &role);
bool validName(const String &s);
String cleanRoles(const String &roles);
bool isKnownRole(const String &role);
bool isSystemRole(const String &role);
String allRoles();
String rolesJson();
bool addCustomRole(const String &role);
bool deleteCustomRole(const String &role);
size_t parseUsers(User *users, size_t maxUsers);
void saveUsers(User *users, size_t count);
bool findUser(const String &name, User &user);
String createToken(const User &user);
Token *currentToken();
ApiDef *findApi(const String &path, const String &method);
String configuredRole(ApiDef *api);
bool authorize();
void appendLog(LogLevel level, const String &message);
void applyLed();
void factoryReset();
void checkFactoryResetPin();
bool connectWifi();
void handleSetupPage();
bool handleHtmlFileRequest();
void redirectToSetupPage();
void handleCaptiveProbe();
void handleFavicon();
void handleAdminPage();
void handleWifiScan();
void handleSetupSubmit();
void handleLogin();
void handleLogout();
void handleMe();
void handleUsersGet();
void handleUsersPost();
void handlePassword();
void handleRolesGet();
void handleRolesPost();
void handleRolesDelete();
void handleApisGet();
void handleApisPost();
void handleSettingsGet();
void handleSettingsPost();
void handleLogsGet();
void handleLogsClear();
void handleFilesList();
void handleFileDownload();
void handleFactoryReset();
void handleConfigExport();
void handleConfigImport();
void handleOtaCheck();
void handleOtaRun();
void handleUpdateUploadDone();
void handleUpdateUploadChunk();
void handleCertGet();
void handleCertPost();
void registerRoutes();

7
include/custom_api.h Normal file
View File

@@ -0,0 +1,7 @@
#pragma once
void handlePing();
void handleAdd();
void handleLed();
void handleUptime();
void handleUptimeEvents();