🔥 Clean up arduino libs

This commit is contained in:
Rune Harlyk
2025-10-09 18:31:40 +02:00
parent bc31b1b2dd
commit b184449e7b
19 changed files with 31 additions and 76 deletions
+2
View File
@@ -4,6 +4,8 @@
#include <settings/ap_settings.h> #include <settings/ap_settings.h>
#include <utils/timing.h> #include <utils/timing.h>
#include <WiFi.h> #include <WiFi.h>
#include "esp_timer.h"
#include <string>
class APService : public StatefulService<APSettings> { class APService : public StatefulService<APSettings> {
public: public:
@@ -33,3 +33,4 @@ class Websocket : CommAdapterBase {
}; };
#endif #endif
+1
View File
@@ -3,6 +3,7 @@
#include <PsychicHttp.h> #include <PsychicHttp.h>
#include <LittleFS.h> #include <LittleFS.h>
#include <string>
#define ESP_FS LittleFS #define ESP_FS LittleFS
+1
View File
@@ -7,6 +7,7 @@
#include <template/stateful_persistence.h> #include <template/stateful_persistence.h>
#include <settings/mdns_settings.h> #include <settings/mdns_settings.h>
#include <utils/timing.h> #include <utils/timing.h>
#include <string>
class MDNSService : public StatefulService<MDNSSettings> { class MDNSService : public StatefulService<MDNSSettings> {
private: private:
-3
View File
@@ -1,15 +1,12 @@
#pragma once #pragma once
#include <WiFi.h> #include <WiFi.h>
#include <IPAddress.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <utils/json_utils.h> #include <utils/json_utils.h>
#include <utils/ip_utils.h>
#include <template/state_result.h> #include <template/state_result.h>
#include <string> #include <string>
#include <DNSServer.h> #include <DNSServer.h>
#include <IPAddress.h>
#ifndef FACTORY_AP_PROVISION_MODE #ifndef FACTORY_AP_PROVISION_MODE
#define FACTORY_AP_PROVISION_MODE AP_MODE_DISCONNECTED #define FACTORY_AP_PROVISION_MODE AP_MODE_DISCONNECTED
+9 -10
View File
@@ -1,10 +1,8 @@
#pragma once #pragma once
#include <WiFi.h> #include <WiFi.h>
#include <IPAddress.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <utils/json_utils.h> #include <utils/json_utils.h>
#include <utils/ip_utils.h>
#include <template/state_result.h> #include <template/state_result.h>
#include <string> #include <string>
@@ -66,11 +64,12 @@ typedef struct {
JsonUtils::readIP(json, "subnet_mask", subnetMask); JsonUtils::readIP(json, "subnet_mask", subnetMask);
JsonUtils::readIP(json, "dns_ip_1", dnsIP1); JsonUtils::readIP(json, "dns_ip_1", dnsIP1);
JsonUtils::readIP(json, "dns_ip_2", dnsIP2); JsonUtils::readIP(json, "dns_ip_2", dnsIP2);
if (IPUtils::isNotSet(dnsIP1) && IPUtils::isSet(dnsIP2)) { if (dnsIP1 == IPAddress(0, 0, 0, 0) && dnsIP2 != IPAddress(0, 0, 0, 0)) {
dnsIP1 = dnsIP2; dnsIP1 = dnsIP2;
dnsIP2 = INADDR_NONE; dnsIP2 = IPAddress(0, 0, 0, 0);
} }
if (IPUtils::isNotSet(localIP) || IPUtils::isNotSet(gatewayIP) || IPUtils::isNotSet(subnetMask)) { if (localIP == IPAddress(0, 0, 0, 0) || gatewayIP == IPAddress(0, 0, 0, 0) ||
subnetMask == IPAddress(0, 0, 0, 0)) {
staticIPConfig = false; staticIPConfig = false;
ESP_LOGW("WiFiSettings", "Invalid static IP configuration - falling back to DHCP"); ESP_LOGW("WiFiSettings", "Invalid static IP configuration - falling back to DHCP");
} }
@@ -88,11 +87,11 @@ inline wifi_settings_t createDefaultWiFiSettings() {
.channel = -1, .channel = -1,
.password = FACTORY_WIFI_PASSWORD, .password = FACTORY_WIFI_PASSWORD,
.staticIPConfig = false, .staticIPConfig = false,
.localIP = INADDR_NONE, .localIP = IPAddress(0, 0, 0, 0),
.gatewayIP = INADDR_NONE, .gatewayIP = IPAddress(0, 0, 0, 0),
.subnetMask = INADDR_NONE, .subnetMask = IPAddress(0, 0, 0, 0),
.dnsIP1 = INADDR_NONE, .dnsIP1 = IPAddress(0, 0, 0, 0),
.dnsIP2 = INADDR_NONE, .dnsIP2 = IPAddress(0, 0, 0, 0),
.available = false, .available = false,
}; };
} }
+3 -4
View File
@@ -1,5 +1,4 @@
#ifndef SYSTEM_SERVICE_H #pragma once
#define SYSTEM_SERVICE_H
#include <ESPmDNS.h> #include <ESPmDNS.h>
#include <PsychicHttp.h> #include <PsychicHttp.h>
@@ -7,6 +6,8 @@
// #include <communication/websocket_adapter.h> // #include <communication/websocket_adapter.h>
#include <filesystem.h> #include <filesystem.h>
#include <global.h> #include <global.h>
#include "esp_timer.h"
#include <string>
#define MAX_ESP_ANALYTICS_SIZE 2024 #define MAX_ESP_ANALYTICS_SIZE 2024
#define EVENT_ANALYTICS "analytics" #define EVENT_ANALYTICS "analytics"
@@ -28,5 +29,3 @@ void emitMetrics();
const char *resetReason(esp_reset_reason_t reason); const char *resetReason(esp_reset_reason_t reason);
} // namespace system_service } // namespace system_service
#endif
@@ -10,7 +10,7 @@
* *
* Copyright (C) 2018 - 2023 rjwats * Copyright (C) 2018 - 2023 rjwats
* Copyright (C) 2023 theelims * Copyright (C) 2023 theelims
* Copyright (C) 2024 runeharlyk * Copyright (C) 2025 runeharlyk
* *
* All Rights Reserved. This software may be modified and distributed under * All Rights Reserved. This software may be modified and distributed under
* the terms of the LGPL v3 license. See the LICENSE file for details. * the terms of the LGPL v3 license. See the LICENSE file for details.
-28
View File
@@ -1,28 +0,0 @@
#ifndef IPUtils_h
#define IPUtils_h
/**
* ESP32 SvelteKit
*
* A simple, secure and extensible framework for IoT projects for ESP32 platforms
* with responsive Sveltekit front-end built with TailwindCSS and DaisyUI.
* https://github.com/theelims/ESP32-sveltekit
*
* Copyright (C) 2018 - 2023 rjwats
* Copyright (C) 2023 theelims
*
* All Rights Reserved. This software may be modified and distributed under
* the terms of the LGPL v3 license. See the LICENSE file for details.
**/
#include <IPAddress.h>
const IPAddress IP_NOT_SET = IPAddress(INADDR_NONE);
class IPUtils {
public:
static bool isSet(const IPAddress &ip) { return ip != IP_NOT_SET; }
static bool isNotSet(const IPAddress &ip) { return ip == IP_NOT_SET; }
};
#endif // end IPUtils_h
+4 -7
View File
@@ -1,8 +1,6 @@
#ifndef JsonUtils_h #pragma once
#define JsonUtils_h
#include <Arduino.h> #include <Arduino.h>
#include <utils/ip_utils.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <string> #include <string>
@@ -11,22 +9,21 @@ class JsonUtils {
static void readIP(const JsonVariant &root, const std::string &key, IPAddress &ip, const std::string &def) { static void readIP(const JsonVariant &root, const std::string &key, IPAddress &ip, const std::string &def) {
IPAddress defaultIp = {}; IPAddress defaultIp = {};
if (!defaultIp.fromString(def.c_str())) { if (!defaultIp.fromString(def.c_str())) {
defaultIp = INADDR_NONE; defaultIp = IPAddress(0, 0, 0, 0);
} }
readIP(root, key, ip, defaultIp); readIP(root, key, ip, defaultIp);
} }
static void readIP(const JsonVariant &root, const std::string &key, IPAddress &ip, static void readIP(const JsonVariant &root, const std::string &key, IPAddress &ip,
const IPAddress &defaultIp = INADDR_NONE) { const IPAddress &defaultIp = IPAddress(0, 0, 0, 0)) {
if (!root[key].is<std::string>() || !ip.fromString(root[key].as<std::string>().c_str())) { if (!root[key].is<std::string>() || !ip.fromString(root[key].as<std::string>().c_str())) {
ip = defaultIp; ip = defaultIp;
} }
} }
static void writeIP(JsonVariant &root, const std::string &key, const IPAddress &ip) { static void writeIP(JsonVariant &root, const std::string &key, const IPAddress &ip) {
if (IPUtils::isSet(ip)) { if (ip != IPAddress(0, 0, 0, 0)) {
root[key] = ip.toString(); root[key] = ip.toString();
} }
} }
}; };
#endif // end JsonUtils
+1 -4
View File
@@ -1,5 +1,4 @@
#ifndef MATHUTILS_H #pragma once
#define MATHUTILS_H
#include <dspm_mult.h> #include <dspm_mult.h>
#include <cmath> #include <cmath>
@@ -69,5 +68,3 @@ static constexpr float combinatorial_constexpr(const int n, int k) {
} }
return result; return result;
} }
#endif
+1 -4
View File
@@ -1,5 +1,4 @@
#ifndef TIMING_H #pragma once
#define TIMING_H
#include "esp_timer.h" #include "esp_timer.h"
@@ -40,5 +39,3 @@
name##_count = 0; \ name##_count = 0; \
last_time = esp_timer_get_time() / 1000; \ last_time = esp_timer_get_time() / 1000; \
} }
#endif
+1 -1
View File
@@ -1,9 +1,9 @@
#pragma once #pragma once
#include <PsychicHttp.h> #include <PsychicHttp.h>
#include <IPAddress.h>
#include <WiFi.h> #include <WiFi.h>
#include <ESPmDNS.h> #include <ESPmDNS.h>
#include <string>
#include <filesystem.h> #include <filesystem.h>
#include <utils/timing.h> #include <utils/timing.h>
-2
View File
@@ -1,6 +1,4 @@
#include <ap_service.h> #include <ap_service.h>
#include "esp_timer.h"
#include <string>
static const char *TAG = "APService"; static const char *TAG = "APService";
-1
View File
@@ -1,5 +1,4 @@
#include <filesystem.h> #include <filesystem.h>
#include <string>
static const char *TAG = "FileService"; static const char *TAG = "FileService";
-1
View File
@@ -1,5 +1,4 @@
#include <mdns_service.h> #include <mdns_service.h>
#include <string>
static const char *TAG = "MDNSService"; static const char *TAG = "MDNSService";
-2
View File
@@ -1,6 +1,4 @@
#include "system_service.h" #include "system_service.h"
#include "esp_timer.h"
#include <string>
namespace system_service { namespace system_service {
+3 -4
View File
@@ -1,5 +1,4 @@
#include <wifi_service.h> #include <wifi_service.h>
#include <string>
WiFiService::WiFiService() WiFiService::WiFiService()
: _persistence(WiFiSettings::read, WiFiSettings::update, this, WIFI_SETTINGS_FILE), : _persistence(WiFiSettings::read, WiFiSettings::update, this, WIFI_SETTINGS_FILE),
@@ -102,10 +101,10 @@ void WiFiService::getNetworkStatus(JsonObject &root) {
root["gateway_ip"] = WiFi.gatewayIP().toString(); root["gateway_ip"] = WiFi.gatewayIP().toString();
IPAddress dnsIP1 = WiFi.dnsIP(0); IPAddress dnsIP1 = WiFi.dnsIP(0);
IPAddress dnsIP2 = WiFi.dnsIP(1); IPAddress dnsIP2 = WiFi.dnsIP(1);
if (dnsIP1 != INADDR_NONE) { if (dnsIP1 != IPAddress(0, 0, 0, 0)) {
root["dns_ip_1"] = dnsIP1.toString(); root["dns_ip_1"] = dnsIP1.toString();
} }
if (dnsIP2 != INADDR_NONE) { if (dnsIP2 != IPAddress(0, 0, 0, 0)) {
root["dns_ip_2"] = dnsIP2.toString(); root["dns_ip_2"] = dnsIP2.toString();
} }
} }
@@ -183,7 +182,7 @@ void WiFiService::configureNetwork(wifi_settings_t &network) {
WiFi.config(network.localIP, network.gatewayIP, network.subnetMask, network.dnsIP1, network.dnsIP2); WiFi.config(network.localIP, network.gatewayIP, network.subnetMask, network.dnsIP1, network.dnsIP2);
} else { } else {
// configure for DHCP // configure for DHCP
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); WiFi.config(IPAddress(0, 0, 0, 0), IPAddress(0, 0, 0, 0), IPAddress(0, 0, 0, 0));
} }
WiFi.setHostname(state().hostname.c_str()); WiFi.setHostname(state().hostname.c_str());
-1
View File
@@ -1,4 +1,3 @@
#include <Arduino.h>
#include "www_mount.hpp" #include "www_mount.hpp"
static esp_err_t web_send(PsychicRequest* req, const WebAsset& asset) { static esp_err_t web_send(PsychicRequest* req, const WebAsset& asset) {