🔥 Clean up arduino libs
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#include <settings/ap_settings.h>
|
||||
#include <utils/timing.h>
|
||||
#include <WiFi.h>
|
||||
#include "esp_timer.h"
|
||||
#include <string>
|
||||
|
||||
class APService : public StatefulService<APSettings> {
|
||||
public:
|
||||
|
||||
@@ -33,3 +33,4 @@ class Websocket : CommAdapterBase {
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <PsychicHttp.h>
|
||||
|
||||
#include <LittleFS.h>
|
||||
#include <string>
|
||||
|
||||
#define ESP_FS LittleFS
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <template/stateful_persistence.h>
|
||||
#include <settings/mdns_settings.h>
|
||||
#include <utils/timing.h>
|
||||
#include <string>
|
||||
|
||||
class MDNSService : public StatefulService<MDNSSettings> {
|
||||
private:
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <IPAddress.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <utils/json_utils.h>
|
||||
#include <utils/ip_utils.h>
|
||||
#include <template/state_result.h>
|
||||
#include <string>
|
||||
|
||||
#include <DNSServer.h>
|
||||
#include <IPAddress.h>
|
||||
|
||||
#ifndef FACTORY_AP_PROVISION_MODE
|
||||
#define FACTORY_AP_PROVISION_MODE AP_MODE_DISCONNECTED
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <IPAddress.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <utils/json_utils.h>
|
||||
#include <utils/ip_utils.h>
|
||||
#include <template/state_result.h>
|
||||
#include <string>
|
||||
|
||||
@@ -66,11 +64,12 @@ typedef struct {
|
||||
JsonUtils::readIP(json, "subnet_mask", subnetMask);
|
||||
JsonUtils::readIP(json, "dns_ip_1", dnsIP1);
|
||||
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;
|
||||
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;
|
||||
ESP_LOGW("WiFiSettings", "Invalid static IP configuration - falling back to DHCP");
|
||||
}
|
||||
@@ -88,11 +87,11 @@ inline wifi_settings_t createDefaultWiFiSettings() {
|
||||
.channel = -1,
|
||||
.password = FACTORY_WIFI_PASSWORD,
|
||||
.staticIPConfig = false,
|
||||
.localIP = INADDR_NONE,
|
||||
.gatewayIP = INADDR_NONE,
|
||||
.subnetMask = INADDR_NONE,
|
||||
.dnsIP1 = INADDR_NONE,
|
||||
.dnsIP2 = INADDR_NONE,
|
||||
.localIP = IPAddress(0, 0, 0, 0),
|
||||
.gatewayIP = IPAddress(0, 0, 0, 0),
|
||||
.subnetMask = IPAddress(0, 0, 0, 0),
|
||||
.dnsIP1 = IPAddress(0, 0, 0, 0),
|
||||
.dnsIP2 = IPAddress(0, 0, 0, 0),
|
||||
.available = false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef SYSTEM_SERVICE_H
|
||||
#define SYSTEM_SERVICE_H
|
||||
#pragma once
|
||||
|
||||
#include <ESPmDNS.h>
|
||||
#include <PsychicHttp.h>
|
||||
@@ -7,6 +6,8 @@
|
||||
// #include <communication/websocket_adapter.h>
|
||||
#include <filesystem.h>
|
||||
#include <global.h>
|
||||
#include "esp_timer.h"
|
||||
#include <string>
|
||||
|
||||
#define MAX_ESP_ANALYTICS_SIZE 2024
|
||||
#define EVENT_ANALYTICS "analytics"
|
||||
@@ -27,6 +28,4 @@ void metrics(JsonObject &root);
|
||||
void emitMetrics();
|
||||
|
||||
const char *resetReason(esp_reset_reason_t reason);
|
||||
} // namespace system_service
|
||||
|
||||
#endif
|
||||
} // namespace system_service
|
||||
@@ -10,7 +10,7 @@
|
||||
*
|
||||
* Copyright (C) 2018 - 2023 rjwats
|
||||
* Copyright (C) 2023 theelims
|
||||
* Copyright (C) 2024 runeharlyk
|
||||
* Copyright (C) 2025 runeharlyk
|
||||
*
|
||||
* All Rights Reserved. This software may be modified and distributed under
|
||||
* the terms of the LGPL v3 license. See the LICENSE file for details.
|
||||
|
||||
@@ -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
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef JsonUtils_h
|
||||
#define JsonUtils_h
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <utils/ip_utils.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <string>
|
||||
|
||||
@@ -11,22 +9,21 @@ class JsonUtils {
|
||||
static void readIP(const JsonVariant &root, const std::string &key, IPAddress &ip, const std::string &def) {
|
||||
IPAddress defaultIp = {};
|
||||
if (!defaultIp.fromString(def.c_str())) {
|
||||
defaultIp = INADDR_NONE;
|
||||
defaultIp = IPAddress(0, 0, 0, 0);
|
||||
}
|
||||
readIP(root, key, ip, defaultIp);
|
||||
}
|
||||
|
||||
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())) {
|
||||
ip = defaultIp;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif // end JsonUtils
|
||||
};
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef MATHUTILS_H
|
||||
#define MATHUTILS_H
|
||||
#pragma once
|
||||
|
||||
#include <dspm_mult.h>
|
||||
#include <cmath>
|
||||
@@ -68,6 +67,4 @@ static constexpr float combinatorial_constexpr(const int n, int k) {
|
||||
result /= (i + 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef TIMING_H
|
||||
#define TIMING_H
|
||||
#pragma once
|
||||
|
||||
#include "esp_timer.h"
|
||||
|
||||
@@ -40,5 +39,3 @@
|
||||
name##_count = 0; \
|
||||
last_time = esp_timer_get_time() / 1000; \
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <PsychicHttp.h>
|
||||
#include <IPAddress.h>
|
||||
#include <WiFi.h>
|
||||
#include <ESPmDNS.h>
|
||||
#include <string>
|
||||
|
||||
#include <filesystem.h>
|
||||
#include <utils/timing.h>
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#include <ap_service.h>
|
||||
#include "esp_timer.h"
|
||||
#include <string>
|
||||
|
||||
static const char *TAG = "APService";
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <filesystem.h>
|
||||
#include <string>
|
||||
|
||||
static const char *TAG = "FileService";
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <mdns_service.h>
|
||||
#include <string>
|
||||
|
||||
static const char *TAG = "MDNSService";
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#include "system_service.h"
|
||||
#include "esp_timer.h"
|
||||
#include <string>
|
||||
|
||||
namespace system_service {
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <wifi_service.h>
|
||||
#include <string>
|
||||
|
||||
WiFiService::WiFiService()
|
||||
: _persistence(WiFiSettings::read, WiFiSettings::update, this, WIFI_SETTINGS_FILE),
|
||||
@@ -102,10 +101,10 @@ void WiFiService::getNetworkStatus(JsonObject &root) {
|
||||
root["gateway_ip"] = WiFi.gatewayIP().toString();
|
||||
IPAddress dnsIP1 = WiFi.dnsIP(0);
|
||||
IPAddress dnsIP2 = WiFi.dnsIP(1);
|
||||
if (dnsIP1 != INADDR_NONE) {
|
||||
if (dnsIP1 != IPAddress(0, 0, 0, 0)) {
|
||||
root["dns_ip_1"] = dnsIP1.toString();
|
||||
}
|
||||
if (dnsIP2 != INADDR_NONE) {
|
||||
if (dnsIP2 != IPAddress(0, 0, 0, 0)) {
|
||||
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);
|
||||
} else {
|
||||
// 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());
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <Arduino.h>
|
||||
#include "www_mount.hpp"
|
||||
|
||||
static esp_err_t web_send(PsychicRequest* req, const WebAsset& asset) {
|
||||
|
||||
Reference in New Issue
Block a user