diff --git a/platformio.ini b/platformio.ini index 8ca97a0..f423ca6 100644 --- a/platformio.ini +++ b/platformio.ini @@ -24,7 +24,7 @@ platform = espressif32 board = esp32dev framework = arduino upload_protocol = espota -upload_port = 192.168.1.167 +upload_port = 192.168.1.235 upload_flags = --auth=P@ssw0rd lib_deps = knolleary/PubSubClient@^2.8 diff --git a/src/credentials.h b/src/credentials.h index a564377..79a7967 100644 --- a/src/credentials.h +++ b/src/credentials.h @@ -1,4 +1,4 @@ -#define WLAN_SSID "TP-LINK-HOME" +#define WLAN_SSID "TP-LINK-OUT" #define WLAN_PASS "6JM54UG4EX" #define MQTT_USER "admin" diff --git a/src/main.cpp b/src/main.cpp index 64df3d8..de1f606 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 +="\n"; ptr +="
\n"; ptr +="Valve is OPEN
CLOSE\n"; } else { ptr +="Valve is CLOSED
OPEN\n";