mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 09:41: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,6 +105,8 @@ 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) {
|
||||||
|
isCurrentlySpritzing = true;
|
||||||
|
if (secondsAperol > 0) {
|
||||||
// APEROL
|
// APEROL
|
||||||
Serial.println("-- Start flow -- APEROL");
|
Serial.println("-- Start flow -- APEROL");
|
||||||
Serial.println("Pompe en avant !"); // Start pump
|
Serial.println("Pompe en avant !"); // Start pump
|
||||||
@ -115,7 +122,8 @@ void spritzLogic(int secondsAperol, int secondsProsecco, int secondsWater) {
|
|||||||
Serial.println("Pompe fermée");
|
Serial.println("Pompe fermée");
|
||||||
digitalWrite(centerPump, LOW);
|
digitalWrite(centerPump, LOW);
|
||||||
Serial.println("-- End flow -- APEROL");
|
Serial.println("-- End flow -- APEROL");
|
||||||
|
}
|
||||||
|
if (secondsProsecco > 0) {
|
||||||
Serial.println("-- Start flow -- PROSECCO");
|
Serial.println("-- Start flow -- PROSECCO");
|
||||||
Serial.println("Pompe en avant !"); // Start pump
|
Serial.println("Pompe en avant !"); // Start pump
|
||||||
digitalWrite(rightPump, HIGH);
|
digitalWrite(rightPump, HIGH);
|
||||||
@ -130,7 +138,8 @@ void spritzLogic(int secondsAperol, int secondsProsecco, int secondsWater) {
|
|||||||
Serial.println("Pompe fermée");
|
Serial.println("Pompe fermée");
|
||||||
digitalWrite(rightPump, LOW);
|
digitalWrite(rightPump, LOW);
|
||||||
Serial.println("-- End flow -- PROSECCO");
|
Serial.println("-- End flow -- PROSECCO");
|
||||||
|
}
|
||||||
|
if (secondsWater > 0) {
|
||||||
Serial.println("-- Start flow -- WATER");
|
Serial.println("-- Start flow -- WATER");
|
||||||
Serial.println("Pompe en avant !"); // Start pump
|
Serial.println("Pompe en avant !"); // Start pump
|
||||||
digitalWrite(leftPump, HIGH);
|
digitalWrite(leftPump, HIGH);
|
||||||
@ -146,6 +155,8 @@ void spritzLogic(int secondsAperol, int secondsProsecco, int secondsWater) {
|
|||||||
digitalWrite(leftPump, LOW);
|
digitalWrite(leftPump, LOW);
|
||||||
Serial.println("-- End flow -- WATER");
|
Serial.println("-- End flow -- WATER");
|
||||||
}
|
}
|
||||||
|
isCurrentlySpritzing = false;
|
||||||
|
}
|
||||||
|
|
||||||
void reconnect() {
|
void reconnect() {
|
||||||
// Loop until we're reconnected
|
// Loop until we're reconnected
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user