Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ Discussions: <https://github.com/smart-swimmingpool/smart-swimmingpool.github.io
- [x] Independent of specific smarthome servers
- [x] [openHAB](https://www.openhab.org) since Version 2.4 using MQTT Homie
- [x] [Home Assistant](https://www.home-assistant.io/) using MQTT Homie
- [x] Timesync via NTP (europe.pool.ntp.org)
- [x] Timesync via NTP (configurable server, default: pool.ntp.org)
- [x] Configurable timezone with DST support (10 major timezones available)
- [x] Logging-Information via Homie-Node

## Planned Features

- [ ] Configurable NTP Server (currently hardcoded: europe.pool.ntp.org)
- [ ] be more smart: self learning for improved pool pump timed circulation for cleaning and heating
- [ ] two separate circulation cycles
- [ ] store configuration changes persistent on conroller
Expand Down
9 changes: 5 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ lib_deps =
NTPClient @ 3.1.0
TimeZone @ 1.2.4
ArduinoJson @ 6.18.0
ESP32Async/ESPAsyncWebServer @ ^3.6.0 ; Asynchronous HTTP/WebSocket Server [oai_citation_attribution:1‡PlatformIO Community](https://community.platformio.org/t/how-come-lib-deps-esp-async-webserver-works/24853?utm_source=chatgpt.com)
ESP32Async/ESPAsyncTCP @ ^2.0.0 ; TCP-Layer für ESP8266
thomasfredericks/Bounce2
marvinroger/AsyncMqttClient
https://github.com/me-no-dev/ESPAsyncWebServer.git
thomasfredericks/Bounce2
marvinroger/AsyncMqttClient
; git+https://github.com/xoseperez/Time.git
git+https://github.com/homieiot/homie-esp8266.git#develop
;../homie-esp8266
Expand Down Expand Up @@ -71,6 +70,8 @@ framework = arduino
build_type = debug
build_flags = -D SERIAL_SPEED=${common.serial_speed}
lib_deps = ${common_env_data.lib_deps}
lib_ldf_mode = chain+
lib_ignore = ESP Async WebServer

monitor_port = COM12
monitor_speed = ${common.serial_speed}
Expand Down
9 changes: 9 additions & 0 deletions src/PoolController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ namespace PoolController {
// set mesurement intervals
const std::uint32_t _loopInterval = this->loopIntervalSetting_.get();

// Initialize NTP client with configured server
timeClientSetup(this->ntpServerSetting_.get());

// Set the timezone from configuration
setTimezoneIndex(this->timezoneSetting_.get());

Expand Down Expand Up @@ -119,6 +122,12 @@ namespace PoolController {
}
);

this->ntpServerSetting_.setDefaultValue("pool.ntp.org").setValidator(
[](const char* const candidate) -> bool {
return candidate != nullptr && strlen(candidate) > 0;
}
);

this->temperatureMaxPoolSetting_.setDefaultValue(28.5).setValidator(
[](const long candidate) -> bool {
return candidate >= 0 && candidate <= 30;
Expand Down
1 change: 1 addition & 0 deletions src/PoolController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace PoolController {
auto setupHandler() -> void;

HomieSetting<long> loopIntervalSetting_ { "loop-interval", "The processing interval in seconds" };
HomieSetting<const char*> ntpServerSetting_ { "ntp-server", "NTP server address (e.g., pool.ntp.org, europe.pool.ntp.org)" };
HomieSetting<long> timezoneSetting_ { "timezone", "Timezone index (0=Central EU, 1=Eastern EU, 2=Western EU, 3=US Eastern, 4=US Central, 5=US Mountain, 6=US Pacific, 7=Australian Eastern, 8=Japan, 9=China)" };
HomieSetting<double> temperatureMaxPoolSetting_ { "temperature-max-pool", "Maximum temperature of solar" };
HomieSetting<double> temperatureMinSolarSetting_ { "temperature-min-solar", "Minimum temperature of solar" };
Expand Down
5 changes: 3 additions & 2 deletions src/Rule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Rule {

public:
Rule() : _poolTemp(0.0), _solarTemp(0.0), _poolMaxTemp(0.0), _solarMinTemp(0.0), _hysteresis(0.0){};
virtual ~Rule() = default;

void setPoolTemperature(float temp) { _poolTemp = temp; };
float getPoolTemperature() { return _poolTemp; };
Expand All @@ -28,8 +29,8 @@ class Rule {
/**
* get the Mode for which the Rule is created.
*/
virtual const char* getMode();
virtual void loop();
virtual const char* getMode() = 0;
virtual void loop() = 0;

protected:
float _poolTemp;
Expand Down
20 changes: 12 additions & 8 deletions src/TimeClientHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
#include "TimeClientHelper.hpp"

// NTP Client
const char *TC_SERVER = "europe.pool.ntp.org";

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, TC_SERVER);
NTPClient* timeClient = nullptr;

// Central European Time (Berlin, Paris, ...)
TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; // Central European Summer Time
Expand Down Expand Up @@ -74,9 +72,15 @@ TimeZoneInfo _timezones[10] = {

int _selectedTimezoneIndex = 0; // Default to Central European Time

void timeClientSetup() {
void timeClientSetup(const char* ntpServer) {
// Create NTP client with configured server
if (timeClient != nullptr) {
delete timeClient;
}
timeClient = new NTPClient(ntpUDP, ntpServer);

// initialize NTP Client
timeClient.begin();
timeClient->begin();

// Set callback for time library and leave the sync to the NTP client
setSyncProvider(getUtcTime);
Expand All @@ -88,9 +92,9 @@ int getTzCount() {
}

time_t getUtcTime() {
if (timeClient.update()) {
return timeClient.getEpochTime();
} else {
if (timeClient && timeClient->update()) {
return timeClient->getEpochTime();
} else {
return 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/TimeClientHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct TimeZoneInfo
Timezone *timezone;
};

void timeClientSetup();
void timeClientSetup(const char* ntpServer);
int getTzCount();
time_t getUtcTime();
time_t getTimeFor(int index, TimeChangeRule **tcr);
Expand Down
Loading