mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
remove static functions from System class
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include <APSettingsService.h>
|
||||
|
||||
#include "../../src/emsesp_stub.hpp" // proddy added
|
||||
|
||||
APSettingsService::APSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
||||
: _httpEndpoint(APSettings::read, APSettings::update, this, server, AP_SETTINGS_SERVICE_PATH, securityManager)
|
||||
, _fsPersistence(APSettings::read, APSettings::update, this, fs, AP_SETTINGS_FILE)
|
||||
@@ -21,7 +23,7 @@ void APSettingsService::reconfigureAP() {
|
||||
|
||||
void APSettingsService::loop() {
|
||||
// if we have an ETH connection, quit
|
||||
if (emsesp::System::ethernet_connected()) {
|
||||
if (emsesp::EMSESP::system_.ethernet_connected()) {
|
||||
return;
|
||||
}
|
||||
unsigned long currentMillis = uuid::get_uptime();
|
||||
@@ -51,8 +53,8 @@ void APSettingsService::startAP() {
|
||||
WiFi.softAP(_state.ssid.c_str(), _state.password.c_str());
|
||||
if (!_dnsServer) {
|
||||
IPAddress apIp = WiFi.softAPIP();
|
||||
Serial.print(F("Starting captive portal on "));
|
||||
Serial.println(apIp);
|
||||
// Serial.print(F("Starting captive portal on "));
|
||||
// Serial.println(apIp);
|
||||
_dnsServer = new DNSServer;
|
||||
_dnsServer->start(DNS_PORT, "*", apIp);
|
||||
}
|
||||
@@ -60,7 +62,7 @@ void APSettingsService::startAP() {
|
||||
|
||||
void APSettingsService::stopAP() {
|
||||
if (_dnsServer) {
|
||||
Serial.println(F("Stopping captive portal"));
|
||||
// Serial.println(F("Stopping captive portal"));
|
||||
_dnsServer->stop();
|
||||
delete _dnsServer;
|
||||
_dnsServer = nullptr;
|
||||
|
||||
@@ -8,9 +8,7 @@
|
||||
#include <DNSServer.h>
|
||||
#include <IPAddress.h>
|
||||
|
||||
#include <uuid/common.h>
|
||||
|
||||
#include "../../src/system.h" // proddy added
|
||||
#include <uuid/common.h> // proddy added for get_uptime()
|
||||
|
||||
#define MANAGE_NETWORK_DELAY 10000
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
#include <AsyncTCP.h>
|
||||
#include <WiFi.h>
|
||||
#include <ETH.h>
|
||||
|
||||
#include <FeaturesService.h>
|
||||
#include <APSettingsService.h>
|
||||
@@ -25,9 +24,7 @@
|
||||
#include <NetworkSettingsService.h>
|
||||
#include <NetworkStatus.h>
|
||||
|
||||
#ifdef PROGMEM_WWW
|
||||
#include <WWWData.h>
|
||||
#endif
|
||||
|
||||
class ESP8266React {
|
||||
public:
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
#include <MqttSettingsService.h>
|
||||
|
||||
// forward declarators
|
||||
namespace emsesp {
|
||||
class EMSESP {
|
||||
public:
|
||||
static Mqtt mqtt_;
|
||||
static DallasSensor dallassensor_;
|
||||
};
|
||||
} // namespace emsesp
|
||||
#include "../../src/emsesp_stub.hpp" // proddy added
|
||||
|
||||
/**
|
||||
* Retains a copy of the cstr provided in the pointer provided using dynamic allocation.
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <FSPersistence.h>
|
||||
#include <AsyncMqttClient.h>
|
||||
#include <ESPUtils.h>
|
||||
|
||||
#include <uuid/common.h>
|
||||
|
||||
#define MQTT_RECONNECTION_DELAY 1000
|
||||
@@ -60,8 +61,7 @@ static String generateClientId() {
|
||||
#define FACTORY_MQTT_MAX_TOPIC_LENGTH 128
|
||||
#endif
|
||||
|
||||
|
||||
#define EMSESP_DEFAULT_BOOL_FORMAT 1 // on/off
|
||||
#define EMSESP_DEFAULT_BOOL_FORMAT 1 // on/off
|
||||
#define EMSESP_DEFAULT_DALLAS_FORMAT 1 // sensorid
|
||||
#define EMSESP_DEFAULT_HA_CLIMATE_FORMAT 1 // current temp
|
||||
#define EMSESP_DEFAULT_MQTT_QOS 0
|
||||
@@ -69,10 +69,6 @@ static String generateClientId() {
|
||||
#define EMSESP_DEFAULT_HA_ENABLED false
|
||||
#define EMSESP_DEFAULT_PUBLISH_TIME 10
|
||||
|
||||
#include "../../src/system.h"
|
||||
#include "../../src/mqtt.h"
|
||||
#include "../../src/dallassensor.h"
|
||||
|
||||
class MqttSettings {
|
||||
public:
|
||||
// host and port - if enabled
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <MqttStatus.h>
|
||||
|
||||
#include "../../src/emsesp_stub.hpp" // proddy added
|
||||
|
||||
MqttStatus::MqttStatus(AsyncWebServer * server, MqttSettingsService * mqttSettingsService, SecurityManager * securityManager)
|
||||
: _mqttSettingsService(mqttSettingsService) {
|
||||
server->on(MQTT_STATUS_SERVICE_PATH,
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
#include <ESPAsyncTCP.h>
|
||||
#endif
|
||||
|
||||
#include "../../src/mqtt.h" // proddy added
|
||||
|
||||
#include <MqttSettingsService.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <AsyncJson.h>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <NetworkStatus.h>
|
||||
|
||||
#include "../../src/emsesp_stub.hpp" // proddy added
|
||||
|
||||
NetworkStatus::NetworkStatus(AsyncWebServer * server, SecurityManager * securityManager) {
|
||||
server->on(NETWORK_STATUS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&NetworkStatus::networkStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED));
|
||||
}
|
||||
@@ -8,7 +10,7 @@ void NetworkStatus::networkStatus(AsyncWebServerRequest * request) {
|
||||
AsyncJsonResponse * response = new AsyncJsonResponse(false, MAX_NETWORK_STATUS_SIZE);
|
||||
JsonObject root = response->getRoot();
|
||||
|
||||
bool ethernet_connected = emsesp::System::ethernet_connected();
|
||||
bool ethernet_connected = emsesp::EMSESP::system_.ethernet_connected();
|
||||
wl_status_t wifi_status = WiFi.status();
|
||||
|
||||
// see if Ethernet is connected
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <WiFi.h>
|
||||
#include <AsyncTCP.h>
|
||||
|
||||
#include "../../src/system.h" // proddy added
|
||||
#include <ETH.h>
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <AsyncJson.h>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <OTASettingsService.h>
|
||||
|
||||
#include "../../src/emsesp_stub.hpp" // proddy added
|
||||
|
||||
OTASettingsService::OTASettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
||||
: _httpEndpoint(OTASettings::read, OTASettings::update, this, server, OTA_SETTINGS_SERVICE_PATH, securityManager)
|
||||
, _fsPersistence(OTASettings::read, OTASettings::update, this, fs, OTA_SETTINGS_FILE)
|
||||
@@ -39,11 +41,11 @@ void OTASettingsService::configureArduinoOTA() {
|
||||
|
||||
_arduinoOTA->onStart([]() {
|
||||
// Serial.println(F("Starting"));
|
||||
emsesp::System::upload_status(true);
|
||||
emsesp::EMSESP::system_.upload_status(true);
|
||||
});
|
||||
_arduinoOTA->onEnd([]() {
|
||||
// Serial.println(F("\r\nEnd"));
|
||||
emsesp::System::upload_status(false);
|
||||
emsesp::EMSESP::system_.upload_status(false);
|
||||
});
|
||||
|
||||
// _arduinoOTA->onProgress([](unsigned int progress, unsigned int total) {
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
#include <ArduinoOTA.h>
|
||||
#include <WiFiUdp.h>
|
||||
|
||||
#include "../../src/system.h" // proddy added
|
||||
|
||||
#ifndef FACTORY_OTA_PORT
|
||||
#define FACTORY_OTA_PORT 8266
|
||||
#endif
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#if FT_ENABLED(FT_SECURITY)
|
||||
|
||||
#include "../../src/emsesp_stub.hpp" // proddy added
|
||||
|
||||
SecuritySettingsService::SecuritySettingsService(AsyncWebServer * server, FS * fs)
|
||||
: _httpEndpoint(SecuritySettings::read, SecuritySettings::update, this, server, SECURITY_SETTINGS_PATH, this)
|
||||
, _fsPersistence(SecuritySettings::read, SecuritySettings::update, this, fs, SECURITY_SETTINGS_FILE)
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
#include <HttpEndpoint.h>
|
||||
#include <FSPersistence.h>
|
||||
|
||||
#include "../../src/version.h" // added by proddy
|
||||
|
||||
#ifndef FACTORY_ADMIN_USERNAME
|
||||
#define FACTORY_ADMIN_USERNAME "admin"
|
||||
#endif
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <SecurityManager.h>
|
||||
|
||||
#include <uuid/log.h> // proddy added
|
||||
#include "../../src/system.h" // proddy added
|
||||
|
||||
#define MAX_ESP_STATUS_SIZE 1024
|
||||
#define SYSTEM_STATUS_SERVICE_PATH "/rest/systemStatus"
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#if FT_ENABLED(FT_SECURITY)
|
||||
|
||||
#include "../../src/emsesp_stub.h" // proddy added
|
||||
|
||||
SecuritySettingsService::SecuritySettingsService(AsyncWebServer* server, FS* fs) :
|
||||
_httpEndpoint(SecuritySettings::read, SecuritySettings::update, this, server, SECURITY_SETTINGS_PATH, this),
|
||||
_fsPersistence(SecuritySettings::read, SecuritySettings::update, this, fs, SECURITY_SETTINGS_FILE),
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
#include <HttpEndpoint.h>
|
||||
#include <FSPersistence.h>
|
||||
|
||||
#include "../../src/version.h" // added by proddy
|
||||
|
||||
#ifndef FACTORY_ADMIN_USERNAME
|
||||
#define FACTORY_ADMIN_USERNAME "admin"
|
||||
#endif
|
||||
|
||||
38
src/emsesp_stub.hpp
Normal file
38
src/emsesp_stub.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* EMS-ESP - https://github.com/proddy/EMS-ESP
|
||||
* Copyright 2020 Paul Derbyshire
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef EMSESP_EMSESP_STUB_H
|
||||
#define EMSESP_EMSESP_STUB_H
|
||||
|
||||
// forward declarator
|
||||
// used to bind EMS-ESP functions to external frameworks
|
||||
#include "system.h"
|
||||
#include "mqtt.h"
|
||||
#include "dallassensor.h"
|
||||
#include "version.h"
|
||||
|
||||
namespace emsesp {
|
||||
class EMSESP {
|
||||
public:
|
||||
static Mqtt mqtt_;
|
||||
static System system_;
|
||||
static DallasSensor dallassensor_;
|
||||
};
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user