make a lot of things better

This commit is contained in:
2023-07-05 02:38:18 +02:00
parent e4c5ddb9ab
commit ac995522db
6 changed files with 62 additions and 33 deletions
+10 -3
View File
@@ -33,7 +33,7 @@ const char mqttId[] = "bewaesserungArduino123";
ShiftRegister reg(RCLK_PIN, SRCLK_PIN, SRSER_PIN, 2);
Pump pump(SSR_PIN, PRESSURE_PIN, INT_HALL_PIN, STATUS_LED_1_PIN);
Valve valves;
Valve valves(MAX_VALVE_OPEN);
EthernetClient ethClient;
PubSubClient client(ethClient);
@@ -126,7 +126,11 @@ void callback(char* topic, byte* payload, unsigned int length) {
} else if (doc.containsKey("pump")) {
uint8_t mode = doc["pump"]["mode"];
uint8_t duration = doc["pump"]["duration"];
if (mode)
if (mode == Pump::State::OnStupid)
pump.activateWithoutSecurity();
else if (mode == Pump::State::clearErrorHelper)
pump.clearError();
else if (mode)
pump.activate(duration);
else
pump.stop();
@@ -168,6 +172,7 @@ void sendPumpStatus() {
JsonObject pumpJson = doc.createNestedObject("pump");
pumpJson["status"] = pump.getStatus();
pumpJson["duration"] = pump.getRunningTime();
pumpJson["remaining"] = pump.getRemainingTime();
pumpJson["pressure"] = pump.getPressure();
pumpJson["flow"] = pump.getFlow();
@@ -183,10 +188,11 @@ void sendValveStatus(uint8_t valveNumber) {
JsonObject valve = doc.createNestedObject("valve");
valve["timeLeft"] = valves.getTimeLeft(valveNumber);
valve["number"] = valveNumber;
char buffer[256];
char topic[64];
sprintf(topic, "%s/valve_%d", mainTopic, valveNumber);
sprintf(topic, "%s/valve/%d", mainTopic, valveNumber);
size_t n = serializeJson(doc, buffer);
client.publish(topic, buffer, n);
}
@@ -197,6 +203,7 @@ void sendInfo() {
JsonObject info = doc.createNestedObject("valve");
info["uptime"] = millis() / 1000;
info["opened"] = valves.getNumOfOpen();
info["max"] = valves.getMaxOpen();
char buffer[256];
char topic[64];