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 <ESP8266WiFi.h>
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
|
|
||||||
const char* ssid = "Xiaomi_Router";
|
const char* ssid = "Xiaomi_Router";
|
||||||
const char* password = "UYQQMTHF";
|
const char* password = "UYQQMTHF";
|
||||||
|
|
||||||
@ -23,6 +24,8 @@ const int mqtt_port = 1883;
|
|||||||
const char* mqtt_server = "192.168.31.140";
|
const char* mqtt_server = "192.168.31.140";
|
||||||
const char* mqtt_client = "WemosD1MiniClient-Spritz";
|
const char* mqtt_client = "WemosD1MiniClient-Spritz";
|
||||||
|
|
||||||
|
bool isCurrentlySpritzing = false;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
pinMode(leftValve, OUTPUT);
|
pinMode(leftValve, OUTPUT);
|
||||||
@ -88,10 +91,12 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
|||||||
payloadString += (char)payload[i];
|
payloadString += (char)payload[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Serial.println("-- Ready for action --");
|
||||||
|
|
||||||
DynamicJsonDocument result(1024);
|
DynamicJsonDocument result(1024);
|
||||||
deserializeJson(result, payloadString);
|
deserializeJson(result, payloadString);
|
||||||
|
|
||||||
if(strcmp(topic, subscribeSpritzTopic) == 0) {
|
if(strcmp(topic, subscribeSpritzTopic) == 0 && !isCurrentlySpritzing) {
|
||||||
int secondsAperol = result["aperol"];
|
int secondsAperol = result["aperol"];
|
||||||
int secondsProsecco = result["prosecco"];
|
int secondsProsecco = result["prosecco"];
|
||||||
int secondsWater = result["water"];
|
int secondsWater = result["water"];
|
||||||
@ -100,51 +105,57 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void spritzLogic(int secondsAperol, int secondsProsecco, int secondsWater) {
|
void spritzLogic(int secondsAperol, int secondsProsecco, int secondsWater) {
|
||||||
// APEROL
|
isCurrentlySpritzing = true;
|
||||||
Serial.println("-- Start flow -- APEROL");
|
if (secondsAperol > 0) {
|
||||||
Serial.println("Pompe en avant !"); // Start pump
|
// APEROL
|
||||||
digitalWrite(centerPump, HIGH);
|
Serial.println("-- Start flow -- APEROL");
|
||||||
delay(500);
|
Serial.println("Pompe en avant !"); // Start pump
|
||||||
Serial.println("Valve ouverte");
|
digitalWrite(centerPump, HIGH);
|
||||||
digitalWrite(centerValve, HIGH);
|
delay(500);
|
||||||
Serial.println("Versage");
|
Serial.println("Valve ouverte");
|
||||||
delay(secondsAperol);
|
digitalWrite(centerValve, HIGH);
|
||||||
Serial.println("Valve fermée");
|
Serial.println("Versage");
|
||||||
digitalWrite(centerValve, LOW);
|
delay(secondsAperol);
|
||||||
delay(500);
|
Serial.println("Valve fermée");
|
||||||
Serial.println("Pompe fermée");
|
digitalWrite(centerValve, LOW);
|
||||||
digitalWrite(centerPump, LOW);
|
delay(500);
|
||||||
Serial.println("-- End flow -- APEROL");
|
Serial.println("Pompe fermée");
|
||||||
|
digitalWrite(centerPump, LOW);
|
||||||
Serial.println("-- Start flow -- PROSECCO");
|
Serial.println("-- End flow -- APEROL");
|
||||||
Serial.println("Pompe en avant !"); // Start pump
|
}
|
||||||
digitalWrite(rightPump, HIGH);
|
if (secondsProsecco > 0) {
|
||||||
delay(500);
|
Serial.println("-- Start flow -- PROSECCO");
|
||||||
Serial.println("Valve ouverte");
|
Serial.println("Pompe en avant !"); // Start pump
|
||||||
digitalWrite(rightValve, HIGH);
|
digitalWrite(rightPump, HIGH);
|
||||||
Serial.println("Versage");
|
delay(500);
|
||||||
delay(secondsProsecco);
|
Serial.println("Valve ouverte");
|
||||||
Serial.println("Valve fermée");
|
digitalWrite(rightValve, HIGH);
|
||||||
digitalWrite(rightValve, LOW);
|
Serial.println("Versage");
|
||||||
delay(500);
|
delay(secondsProsecco);
|
||||||
Serial.println("Pompe fermée");
|
Serial.println("Valve fermée");
|
||||||
digitalWrite(rightPump, LOW);
|
digitalWrite(rightValve, LOW);
|
||||||
Serial.println("-- End flow -- PROSECCO");
|
delay(500);
|
||||||
|
Serial.println("Pompe fermée");
|
||||||
Serial.println("-- Start flow -- WATER");
|
digitalWrite(rightPump, LOW);
|
||||||
Serial.println("Pompe en avant !"); // Start pump
|
Serial.println("-- End flow -- PROSECCO");
|
||||||
digitalWrite(leftPump, HIGH);
|
}
|
||||||
delay(500);
|
if (secondsWater > 0) {
|
||||||
Serial.println("Valve ouverte");
|
Serial.println("-- Start flow -- WATER");
|
||||||
digitalWrite(leftValve, HIGH);
|
Serial.println("Pompe en avant !"); // Start pump
|
||||||
Serial.println("Versage");
|
digitalWrite(leftPump, HIGH);
|
||||||
delay(secondsWater);
|
delay(500);
|
||||||
Serial.println("Valve fermée");
|
Serial.println("Valve ouverte");
|
||||||
digitalWrite(leftValve, LOW);
|
digitalWrite(leftValve, HIGH);
|
||||||
delay(500);
|
Serial.println("Versage");
|
||||||
Serial.println("Pompe fermée");
|
delay(secondsWater);
|
||||||
digitalWrite(leftPump, LOW);
|
Serial.println("Valve fermée");
|
||||||
Serial.println("-- End flow -- WATER");
|
digitalWrite(leftValve, LOW);
|
||||||
|
delay(500);
|
||||||
|
Serial.println("Pompe fermée");
|
||||||
|
digitalWrite(leftPump, LOW);
|
||||||
|
Serial.println("-- End flow -- WATER");
|
||||||
|
}
|
||||||
|
isCurrentlySpritzing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reconnect() {
|
void reconnect() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user