|
|
|
@ -10,6 +10,9 @@ |
|
|
|
#define MQTT_HOST "192.168.1.146" |
|
|
|
#define MQTT_PORT 1883 |
|
|
|
|
|
|
|
#define OPENED HIGH |
|
|
|
#define CLOSED LOW |
|
|
|
|
|
|
|
void openValve(); |
|
|
|
void closeValve(); |
|
|
|
void stopValve(); |
|
|
|
@ -29,7 +32,6 @@ int ButtonClose = 19; |
|
|
|
|
|
|
|
int MotorPin1 = 25; // estende il braccio
|
|
|
|
int MotorPin2 = 26; // ritrae il braccio
|
|
|
|
int duration = 60000; |
|
|
|
|
|
|
|
WebServer server(80); |
|
|
|
|
|
|
|
@ -54,7 +56,7 @@ void setup_wifi() { |
|
|
|
Serial.println("WiFi connected"); |
|
|
|
Serial.print("IP address: "); |
|
|
|
Serial.println(WiFi.localIP()); |
|
|
|
Serial.print("Starting OTA..."); |
|
|
|
Serial.println("Starting OTA..."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@ -121,18 +123,18 @@ void setup() { |
|
|
|
pinMode(MotorPin2, OUTPUT); |
|
|
|
|
|
|
|
setup_wifi(); |
|
|
|
setup_ota(); |
|
|
|
//setup_mqtt();
|
|
|
|
setup_mqtt(); |
|
|
|
setup_http(); |
|
|
|
setup_ota(); |
|
|
|
} |
|
|
|
|
|
|
|
void loop() { |
|
|
|
ArduinoOTA.handle(); |
|
|
|
|
|
|
|
// if (!client.connected()) {
|
|
|
|
// reconnect();
|
|
|
|
// }
|
|
|
|
// client.loop();
|
|
|
|
if (!client.connected()) { |
|
|
|
reconnect(); |
|
|
|
} |
|
|
|
client.loop(); |
|
|
|
|
|
|
|
server.handleClient(); |
|
|
|
|
|
|
|
@ -143,14 +145,16 @@ void loop() { |
|
|
|
buttonCloseState = !buttonOpenState; |
|
|
|
digitalWrite(MotorPin1, LOW); |
|
|
|
digitalWrite(MotorPin2, HIGH); |
|
|
|
ValveState = HIGH; |
|
|
|
|
|
|
|
ValveState = OPENED; |
|
|
|
} |
|
|
|
|
|
|
|
if(buttonCloseState == LOW) { |
|
|
|
buttonOpenState = !buttonCloseState; |
|
|
|
digitalWrite(MotorPin1, HIGH); |
|
|
|
digitalWrite(MotorPin2, LOW); |
|
|
|
ValveState = LOW; |
|
|
|
|
|
|
|
ValveState = CLOSED; |
|
|
|
} |
|
|
|
|
|
|
|
if(buttonOpenState == HIGH && buttonCloseState == HIGH) { |
|
|
|
@ -187,18 +191,14 @@ void openValve() { |
|
|
|
Serial.println("Opening valve..."); |
|
|
|
digitalWrite(MotorPin1, LOW); |
|
|
|
digitalWrite(MotorPin2, HIGH); |
|
|
|
delay(duration); |
|
|
|
stopValve(); |
|
|
|
ValveState = HIGH; |
|
|
|
ValveState = OPENED; |
|
|
|
} |
|
|
|
|
|
|
|
void closeValve() { |
|
|
|
Serial.println("Closing valve..."); |
|
|
|
digitalWrite(MotorPin1, HIGH); |
|
|
|
digitalWrite(MotorPin2, LOW); |
|
|
|
delay(duration); |
|
|
|
stopValve(); |
|
|
|
ValveState = LOW; |
|
|
|
ValveState = CLOSED; |
|
|
|
} |
|
|
|
|
|
|
|
void stopValve() { |
|
|
|
@ -222,7 +222,7 @@ String SendHTML(uint8_t ValveState) { |
|
|
|
ptr +="</head>\n"; |
|
|
|
ptr +="<body>\n"; |
|
|
|
ptr +="<h1>Linear Actuator</h1>\n"; |
|
|
|
if(ValveState == HIGH) { |
|
|
|
if(ValveState == OPENED) { |
|
|
|
ptr +="<p>Valve is OPEN</p><a class=\"button button-close\" href=\"/close\">CLOSE</a>\n"; |
|
|
|
} else { |
|
|
|
ptr +="<p>Valve is CLOSED</p><a class=\"button button-open\" href=\"/open\">OPEN</a>\n"; |
|
|
|
|