Merge branch 'dev2' of https://github.com/emsesp/EMS-ESP32 into dev2

This commit is contained in:
MichaelDvP
2023-07-21 09:16:51 +02:00
34 changed files with 69 additions and 72 deletions

View File

@@ -54,7 +54,7 @@ bool PButton::init(uint8_t pin, bool pullMode) {
#if defined(ESP32)
pinMode(pin_, pullMode ? INPUT_PULLUP : INPUT_PULLDOWN);
#else // esp8266 and standalone
#else // esp8266 and standalone
pinMode(pin_, pullMode ? INPUT_PULLUP : INPUT);
#endif
enabled_ = (digitalRead(pin_) == pullMode); // see if a button is connected

View File

@@ -47,21 +47,21 @@ class PButton {
bool pullMode_;
bool enabled_;
bool state_; // Value read from button
bool lastState_; // Last value of button state
bool dblClickWaiting_; // whether we're waiting for a double click (down)
bool dblClickOnNextUp_; // whether to register a double click on next release, or whether to wait and click
bool singleClickOK_; // whether it's OK to do a single click
bool state_; // Value read from button
bool lastState_; // Last value of button state
bool dblClickWaiting_; // whether we're waiting for a double click (down)
bool dblClickOnNextUp_; // whether to register a double click on next release, or whether to wait and click
bool singleClickOK_; // whether it's OK to do a single click
uint32_t downTime_; // time the button was pressed down
uint32_t upTime_; // time the button was released
uint32_t downTime_; // time the button was pressed down
uint32_t upTime_; // time the button was released
bool ignoreUP_; // whether to ignore the button release because the click+hold was triggered
bool waitForUP_; // when held, whether to wait for the up event
bool longPressHappened_; // whether or not the hold event happened already
bool vLongPressHappened_; // whether or not the long hold event happened already
bool buttonBusy_; // false if idle
bool buttonBusy_; // false if idle
buttonEventHandler cb_onClick, cb_onDblClick, cb_onLongPress, cb_onVLongPress;
};

View File

@@ -197,7 +197,7 @@ const char * MqttClient::getClientId() const {
}
void MqttClient::loop() {
switch (_state) {
switch ((State)_state) { // modified by proddy for EMS-ESP compiling standalone
case State::disconnected:
#if defined(ARDUINO_ARCH_ESP32)
if (_useInternalTask == espMqttClientTypes::UseInternalTask::YES) {

View File

@@ -123,8 +123,7 @@ class MqttClient {
#elif defined(ARDUINO_ARCH_ESP8266) && EMC_ESP8266_MULTITHREADING
std::atomic<bool> _xSemaphore = false;
#elif defined(__linux__)
// added mutable to compile EMS-ESP standalone
mutable std::mutex mtx;
mutable std::mutex mtx; // modified by proddy for EMS-ESP compiling standalone
#endif
uint8_t _rxBuffer[EMC_RX_BUFFER_SIZE];

View File

@@ -38,7 +38,7 @@ bool ClientPosix::connect(IPAddress ip, uint16_t port) {
memset(&_host, 0, sizeof(_host));
_host.sin_family = AF_INET;
_host.sin_addr.s_addr = htonl(uint32_t(ip));
_host.sin_port = ::htons(port);
_host.sin_port = htons(port); // modified by proddy for EMS-ESP compiling standalone
int ret = ::connect(_sockfd, (struct sockaddr *)&_host, sizeof(_host));

View File

@@ -1,6 +1,6 @@
#include <APSettingsService.h>
#include "../../src/emsesp_stub.hpp" // proddy added
#include "../../src/emsesp_stub.hpp"
APSettingsService::APSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
: _httpEndpoint(APSettings::read, APSettings::update, this, server, AP_SETTINGS_SERVICE_PATH, securityManager)

View File

@@ -18,10 +18,7 @@ void FactoryResetService::handleRequest(AsyncWebServerRequest * request) {
* Delete function assumes that all files are stored flat, within the config directory.
*/
void FactoryResetService::factoryReset() {
/*
* Based on LittleFS. Modified by proddy
* Could be replaced with fs.rmdir(FS_CONFIG_DIRECTORY) in IDF 4.2
*/
// TODO Could be replaced with fs.rmdir(FS_CONFIG_DIRECTORY) in IDF 4.2
File root = fs->open(FS_CONFIG_DIRECTORY);
File file;
while (file = root.openNextFile()) {

View File

@@ -1,7 +1,7 @@
#include <FeaturesService.h>
#include "../../src/emsesp_stub.hpp" // proddy added
#include "../../src/emsesp_stub.hpp"
using namespace std::placeholders; // for `_1` etc
using namespace std::placeholders; // for `_1` etc
FeaturesService::FeaturesService(AsyncWebServer * server) {
server->on(FEATURES_SERVICE_PATH, HTTP_GET, std::bind(&FeaturesService::features, this, _1));

View File

@@ -115,7 +115,7 @@ class HttpPostEndpoint {
response->setLength();
if (outcome == StateUpdateResult::CHANGED_RESTART) {
response->setCode(205); // added by proddy, reboot required
response->setCode(205); // reboot required
}
request->send(response);
}

View File

@@ -1,8 +1,8 @@
#include <MqttSettingsService.h>
#include "../../src/emsesp_stub.hpp" // proddy added
#include "../../src/emsesp_stub.hpp"
using namespace std::placeholders; // for `_1` etc
using namespace std::placeholders; // for `_1` etc
/**
* Retains a copy of the cstr provided in the pointer provided using dynamic allocation.
@@ -144,7 +144,6 @@ void MqttSettingsService::onConfigUpdated() {
_reconfigureMqtt = true;
_disconnectedAt = 0;
// added by proddy
startClient();
emsesp::EMSESP::mqtt_.start(); // reload EMS-ESP MQTT settings
}
@@ -231,7 +230,6 @@ void MqttSettings::read(MqttSettings & settings, JsonObject & root) {
root["clean_session"] = settings.cleanSession;
root["entity_format"] = settings.entity_format;
// added by proddy for EMS-ESP
root["publish_time_boiler"] = settings.publish_time_boiler;
root["publish_time_thermostat"] = settings.publish_time_thermostat;
root["publish_time_solar"] = settings.publish_time_solar;

View File

@@ -76,7 +76,7 @@ class MqttSettings {
uint16_t keepAlive;
bool cleanSession;
// proddy EMS-ESP specific
// EMS-ESP specific
String base;
uint16_t publish_time_boiler;
uint16_t publish_time_thermostat;

View File

@@ -1,6 +1,6 @@
#include <MqttStatus.h>
#include "../../src/emsesp_stub.hpp" // proddy added
#include "../../src/emsesp_stub.hpp"
using namespace std::placeholders; // for `_1` etc
@@ -20,9 +20,9 @@ void MqttStatus::mqttStatus(AsyncWebServerRequest * request) {
root["client_id"] = _mqttSettingsService->getClientId();
root["disconnect_reason"] = (uint8_t)_mqttSettingsService->getDisconnectReason();
root["mqtt_queued"] = emsesp::Mqtt::publish_queued(); // mdvp added
root["mqtt_fails"] = emsesp::Mqtt::publish_fails(); // proddy added
root["connect_count"] = emsesp::Mqtt::connect_count(); // mdvp added
root["mqtt_queued"] = emsesp::Mqtt::publish_queued();
root["mqtt_fails"] = emsesp::Mqtt::publish_fails();
root["connect_count"] = emsesp::Mqtt::connect_count();
response->setLength();
request->send(response);

View File

@@ -1,7 +1,7 @@
#include <NTPSettingsService.h>
#include <esp_sntp.h>
#include "../../src/emsesp_stub.hpp" // proddy added
#include "../../src/emsesp_stub.hpp"
using namespace std::placeholders; // for `_1` etc

View File

@@ -1,5 +1,5 @@
#include <NTPStatus.h>
#include "../../src/emsesp_stub.hpp" // proddy added
#include "../../src/emsesp_stub.hpp"
using namespace std::placeholders; // for `_1` etc

View File

@@ -69,7 +69,7 @@ void NetworkSettingsService::manageSTA() {
esp_wifi_set_bandwidth((wifi_interface_t)ESP_IF_WIFI_STA, WIFI_BW_HT40);
}
if (networkSettings.nosleep) {
WiFi.setSleep(false); // turn off sleep - WIFI_PS_NONE
WiFi.setSleep(false); // turn off sleep - WIFI_PS_NONE
}
WiFi.begin(_state.ssid.c_str(), _state.password.c_str()); // attempt to connect to the network
esp_wifi_set_max_tx_power(networkSettings.tx_power * 4); // set power after wifi is startet for C3

View File

@@ -1,6 +1,6 @@
#include <NetworkStatus.h>
#include "../../src/emsesp_stub.hpp" // proddy added
#include "../../src/emsesp_stub.hpp"
using namespace std::placeholders; // for `_1` etc

View File

@@ -1,6 +1,6 @@
#include <OTASettingsService.h>
#include "../../src/emsesp_stub.hpp" // proddy added
#include "../../src/emsesp_stub.hpp"
using namespace std::placeholders; // for `_1` etc

View File

@@ -2,7 +2,7 @@
#if FT_ENABLED(FT_SECURITY)
#include "../../src/emsesp_stub.hpp" // proddy added
#include "../../src/emsesp_stub.hpp"
SecuritySettingsService::SecuritySettingsService(AsyncWebServer * server, FS * fs)
: _httpEndpoint(SecuritySettings::read, SecuritySettings::update, this, server, SECURITY_SETTINGS_PATH, this)

View File

@@ -19,7 +19,7 @@
enum class StateUpdateResult {
CHANGED = 0, // The update changed the state and propagation should take place if required
CHANGED_RESTART, // a restart of the device is needed - added by proddy
CHANGED_RESTART, // a restart of the device is needed
UNCHANGED, // The state was unchanged, propagation should not take place
ERROR // There was a problem updating the state, propagation should not take place
};

View File

@@ -1,7 +1,7 @@
#include <SystemStatus.h>
#include <esp_ota_ops.h>
#include "../../src/emsesp_stub.hpp" // proddy added
#include "../../src/emsesp_stub.hpp"
using namespace std::placeholders; // for `_1` etc
@@ -39,7 +39,7 @@ void SystemStatus::systemStatus(AsyncWebServerRequest * request) {
const esp_partition_t * partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
if (partition != NULL) { // factory partition found
root["has_loader"] = true;
} else { // check for not empty, smaller OTA partition
} else { // check for not empty, smaller OTA partition
partition = esp_ota_get_next_update_partition(NULL);
if (partition) {
uint64_t buffer;

View File

@@ -22,7 +22,6 @@
namespace uuid {
// added by proddy for EMS-ESP
static uint64_t now_millis = 0;
// returns system uptime in seconds

View File

@@ -21,7 +21,7 @@
namespace uuid {
void loop() {
set_uptime(); // added by proddy
set_uptime();
}
} // namespace uuid

View File

@@ -102,8 +102,8 @@ void loop();
*/
uint64_t get_uptime_ms();
uint32_t get_uptime(); // added by proddy for EMS-ESP
uint32_t get_uptime_sec(); // added by proddy for EMS-ESP
uint32_t get_uptime();
uint32_t get_uptime_sec();
void set_uptime();

View File

@@ -65,7 +65,6 @@ void Shell::display_prompt() {
std::string context = context_text();
print(prompt_prefix());
// colors added by proddy
if (!hostname.empty()) {
print(COLOR_BRIGHT_GREEN);
print(COLOR_BOLD_ON);
@@ -78,7 +77,6 @@ void Shell::display_prompt() {
print(COLOR_BOLD_ON);
print(context);
print(COLOR_RESET);
// print(' ');
}
print(prompt_suffix());
print(' ');

View File

@@ -365,7 +365,7 @@ bool SyslogService::can_transmit() {
#endif
if (!emsesp::EMSESP::system_.network_connected()) {
return false; // added by proddy. Check Ethernet
return false;
}
const uint64_t now = uuid::get_uptime_ms();