Compare commits

..

4 Commits

Author SHA1 Message Date
801b99a3a7 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	platformio.ini
#	src/io.cpp
2025-09-01 09:51:42 +02:00
4e5fff2498 WiFi logging 2025-09-01 09:49:14 +02:00
b88df843ad Output.cycle FIX 2025-09-01 09:47:01 +02:00
ae1c6f5cda GosundSP111 2025-09-01 09:45:58 +02:00
4 changed files with 31 additions and 12 deletions

View File

@ -26,7 +26,7 @@ upload_speed = ${common.upload_speed}
monitor_speed = ${common.monitor_speed}
build.filesystem = ${common.build.filesystem}
lib_deps = ${common.lib_deps}
build_flags = -D Sonoff4ChPro -D CORE_DEBUG_LEVEL=0
build_flags = -D Sonoff4ChPro -D ESP32_TESTBOARD -D CORE_DEBUG_LEVEL=0
[env:GosundSP111]
platform = ${common.platform}
@ -47,4 +47,4 @@ upload_speed = ${common.upload_speed}
monitor_speed = ${common.monitor_speed}
build.filesystem = ${common.build.filesystem}
lib_deps = ${common.lib_deps}
build_flags = -D GosundSP111 -D CORE_DEBUG_LEVEL=0
build_flags = -D GosundSP111 -D ESP32_TESTBOARD -D CORE_DEBUG_LEVEL=0

View File

@ -27,14 +27,15 @@ protected:
unsigned long stateMillis = 0;
void _write(const bool state) {
if (state != get()) {
void _write(const bool wanted) {
const auto current = get();
if (wanted != current) {
if (logState) {
Serial.printf("[RELAY] \"%s\" = %s\n", name.c_str(), state ? "ON" : "OFF");
Serial.printf("[RELAY] \"%s\" = %s\n", name.c_str(), wanted ? "ON" : "OFF");
}
stateMillis = millis();
}
digitalWrite(pin, state ^ inverted ? HIGH : LOW);
digitalWrite(pin, wanted ^ inverted ? HIGH : LOW);
}
void _applyInitial() {
@ -73,19 +74,21 @@ public:
}
void cycle(const unsigned long onMillis_, const unsigned long offMillis_, const unsigned long onCount_ = -1) {
set(false); // this sets onCount=0, so do this first
this->onMillis = onMillis_;
this->offMillis = offMillis_;
this->onCount = onCount_;
set(false);
}
void loop() {
if (get()) {
if (onMillis > 0 && millis() - stateMillis > onMillis) {
const auto status = get();
const auto ageMillis = millis() - stateMillis;
if (status) {
if (onMillis > 0 && ageMillis >= onMillis) {
_write(false);
}
} else {
if (offMillis > 0 && millis() - stateMillis > offMillis && onCount != 0) {
if (offMillis > 0 && ageMillis >= offMillis && onCount != 0) {
_write(true);
if (onCount > 0) {
onCount--;

View File

@ -2,7 +2,10 @@
#ifdef GosundSP111
Output status("Status", 0, true, false);
#ifndef ESP32_TESTBOARD
#define STATUS_PIN 0
#define STATUS_INVERT true
#endif
Button button0(13, true, true, [](const ButtonEvent event) { buttonCallback(relay0, event); });
@ -12,6 +15,11 @@ Relay relay0(0, "RELAY #0", 15, false, true);
#ifdef Sonoff4ChPro
#ifndef ESP32_TESTBOARD
#define STATUS_PIN 13
#define STATUS_INVERT true
#endif
Output status("Status", 13, true, false);
Button button0(0, true, true, [](const ButtonEvent event) { buttonCallback(relay0, event); });
@ -32,6 +40,13 @@ Relay relay3(3, "RELAY #3", 15, false, true);
#endif
#ifdef ESP32_TESTBOARD
#define STATUS_PIN 2
#define STATUS_INVERT false
#endif
Output status("Status", STATUS_PIN, STATUS_INVERT, true);
void buttonCallback(Output &output, const ButtonEvent event) {
if (event == BUTTON_PRESSED) {
output.toggle();

View File

@ -30,6 +30,7 @@ void wifiConnect() {
const auto wifiSSID = configRead(CONFIG_WIFI_SSID, DEFAULT_WIFI_SSID);
const auto wifiPass = configRead(CONFIG_WIFI_PASSWORD, DEFAULT_WIFI_PASSWORD, true, true);
Serial.printf("[WiFi] Connecting: \"%s\"\n", wifiSSID.c_str());
WiFi.hostname(hostname);
WiFi.begin(wifiSSID.c_str(), wifiPass.c_str());
wifiLast = max(1UL, millis());
@ -50,7 +51,7 @@ void wifiLoop() {
} else {
if (connected) {
status.set(false);
Serial.printf("[WiFi] Connected as \"%s\" (%s)\n", WiFi.getHostname(), WiFi.localIP().toString().c_str());
Serial.printf("[WiFi] Connected \"%s\" as \"%s\" (%s)\n", WiFi.SSID().c_str(), WiFi.getHostname(), WiFi.localIP().toString().c_str());
ArduinoOTA.begin();
httpSetup();
} else if (wifiLast == 0 || millis() - wifiLast >= 10000) {