mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 01:31:19 +00:00
update spritz code
This commit is contained in:
parent
a467b2e3ad
commit
e785135cbc
@ -1,6 +1,7 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <PubSubClient.h>
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
const char* ssid = "Xiaomi_Router";
|
||||
const char* password = "UYQQMTHF";
|
||||
|
||||
@ -23,6 +24,8 @@ const int mqtt_port = 1883;
|
||||
const char* mqtt_server = "192.168.31.140";
|
||||
const char* mqtt_client = "WemosD1MiniClient-Spritz";
|
||||
|
||||
bool isCurrentlySpritzing = false;
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
pinMode(leftValve, OUTPUT);
|
||||
@ -88,10 +91,12 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
||||
payloadString += (char)payload[i];
|
||||
}
|
||||
|
||||
Serial.println("-- Ready for action --");
|
||||
|
||||
DynamicJsonDocument result(1024);
|
||||
deserializeJson(result, payloadString);
|
||||
|
||||
if(strcmp(topic, subscribeSpritzTopic) == 0) {
|
||||
if(strcmp(topic, subscribeSpritzTopic) == 0 && !isCurrentlySpritzing) {
|
||||
int secondsAperol = result["aperol"];
|
||||
int secondsProsecco = result["prosecco"];
|
||||
int secondsWater = result["water"];
|
||||
@ -100,6 +105,8 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
||||
}
|
||||
|
||||
void spritzLogic(int secondsAperol, int secondsProsecco, int secondsWater) {
|
||||
isCurrentlySpritzing = true;
|
||||
if (secondsAperol > 0) {
|
||||
// APEROL
|
||||
Serial.println("-- Start flow -- APEROL");
|
||||
Serial.println("Pompe en avant !"); // Start pump
|
||||
@ -115,7 +122,8 @@ void spritzLogic(int secondsAperol, int secondsProsecco, int secondsWater) {
|
||||
Serial.println("Pompe fermée");
|
||||
digitalWrite(centerPump, LOW);
|
||||
Serial.println("-- End flow -- APEROL");
|
||||
|
||||
}
|
||||
if (secondsProsecco > 0) {
|
||||
Serial.println("-- Start flow -- PROSECCO");
|
||||
Serial.println("Pompe en avant !"); // Start pump
|
||||
digitalWrite(rightPump, HIGH);
|
||||
@ -130,7 +138,8 @@ void spritzLogic(int secondsAperol, int secondsProsecco, int secondsWater) {
|
||||
Serial.println("Pompe fermée");
|
||||
digitalWrite(rightPump, LOW);
|
||||
Serial.println("-- End flow -- PROSECCO");
|
||||
|
||||
}
|
||||
if (secondsWater > 0) {
|
||||
Serial.println("-- Start flow -- WATER");
|
||||
Serial.println("Pompe en avant !"); // Start pump
|
||||
digitalWrite(leftPump, HIGH);
|
||||
@ -145,6 +154,8 @@ void spritzLogic(int secondsAperol, int secondsProsecco, int secondsWater) {
|
||||
Serial.println("Pompe fermée");
|
||||
digitalWrite(leftPump, LOW);
|
||||
Serial.println("-- End flow -- WATER");
|
||||
}
|
||||
isCurrentlySpritzing = false;
|
||||
}
|
||||
|
||||
void reconnect() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user