17:03:51.299 -> ets Jun 8 2016 00:22:57
17:03:51.299 ->
17:03:51.299 -> rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
17:03:51.299 -> configsip: 0, SPIWP:0xee
17:03:51.299 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
17:03:51.299 -> mode:DIO, clock div:1
17:03:51.299 -> load:0x3fff0030,len:1344
17:03:51.299 -> load:0x40078000,len:13964
17:03:51.299 -> load:0x40080400,len:3600
17:03:51.299 -> entry 0x400805f0
17:03:52.674 -> Connecting to WiFi...
17:03:53.682 -> Connecting to WiFi...
17:03:54.673 -> Connecting to WiFi...
17:03:54.673 -> Connected to WiFi
nothing is yet connected to the esp
the esp is powered by my pc but i tried another power supply, stil nothing
any help would be great
- #include <WiFi.h>
- #include <ESPAsyncWebServer.h>
- #include <Adafruit_Sensor.h>
- #include <DHT.h>
- // Replace with your network credentials
- const char* ssid = "Kovar";
- const char* password = "xxxxx";
- // Create an instance of the DHT sensor
- #define DHTPIN 2
- #define DHTTYPE DHT22
- DHT dht(DHTPIN, DHTTYPE);
- // Define relay and sensor pins
- int relayPins[] = {4, 5, 6, 7, 8, 9, 10, 11};
- const int soilSensorPins[] = {34, 35, 32, 33, 25, 26}; // Soil humidity sensor pins on ESP32
- // Define buzzer pin
- int buzzerPin = 12;
- // Define watering duration
- const int wateringDuration = 10000; // in milliseconds (10 seconds)
- // Create an instance of the AsyncWebServer
- AsyncWebServer server(80);
- // Array to store last watered times for each sensor
- unsigned long lastWateredTimes[6] = {0};
- void setup() {
- Serial.begin(115200);
- // Connect to Wi-Fi
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- Serial.println("Connecting to WiFi...");
- }
- Serial.println("Connected to WiFi");
- // Initialize DHT sensor
- dht.begin();
- // Initialize relay and sensor pins
- for (int i = 0; i < 8; i++) {
- pinMode(relayPins[i], OUTPUT);
- }
- // Set sensor pins as INPUT
- for (int i = 0; i < 6; i++) {
- pinMode(soilSensorPins[i], INPUT);
- }
- // Set buzzer pin as OUTPUT
- pinMode(buzzerPin, OUTPUT);
- // Route for root URL
- server.on("/", HTTP_GET, handleRoot);
- // Route for manual watering
- server.on("/water", HTTP_POST, handleWater);
- // Start server
- server.begin();
- }
- void loop() {
- // Read sensor data and update web page
- updateSensorData();
- // Check temperature and sound the buzzer if it's too low
- checkTemperature();
- delay(10000); // Delay for 10 seconds
- }
- void handleRoot(AsyncWebServerRequest *request) {
- String html = "<html><body>";
- html += "<h1>Plant Watering System</h1>";
- // Display sensor data
- for (int i = 0; i < 6; i++) {
- html += "<p>Humidity Sensor " + String(i + 1) + ": " + String(analogRead(soilSensorPins[i])) + "</p>";
- html += "<p>Last Watered: " + getLastWateredTime(i) + "</p>";
- }
- // Manual watering form
- html += "<form action='/water' method='post'>";
- html += "<label for='relay'>Select Relay:</label>";
- html += "<select name='relay'>";
- for (int i = 0; i < 8; i++) {
- html += "<option value='" + String(i) + "'>Relay " + String(i + 1) + "</option>";
- }
- html += "</select>";
- html += "<label for='duration'>Watering Duration (seconds):</label>";
- html += "<input type='number' name='duration' min='1' value='10'>";
- html += "<input type='submit' value='Water Plants'>";
- html += "</form>";
- html += "<p>Temperature: " + String(dht.readTemperature()) + " ℃</p>";
- html += "<p>Humidity: " + String(dht.readHumidity()) + " %</p>";
- html += "</body></html>";
- request->send(200, "text/html", html);
- }
- void updateSensorData() {
- // Update sensor data on the web page
- // Activate the relay corresponding to the sensor for 10 seconds if humidity is below 50%
- for (int i = 0; i < 6; i++) {
- int humidity = analogRead(soilSensorPins[i]);
- if (humidity < 50) {
- activateRelay(i);
- delay(wateringDuration);
- deactivateRelay(i);
- updateLastWateredTime(i);
- }
- }
- }
- void checkTemperature() {
- // Check temperature and sound the buzzer if it's too low (below 15°C)
- float temperature = dht.readTemperature();
- if (temperature < 15) {
- digitalWrite(buzzerPin, HIGH);
- // You can add code here to display a warning popup on the web page
- } else {
- digitalWrite(buzzerPin, LOW);
- }
- }
- void activateRelay(int relayIndex) {
- // Activate the specified relay
- digitalWrite(relayPins[relayIndex], HIGH);
- }
- void deactivateRelay(int relayIndex) {
- // Deactivate the specified relay
- digitalWrite(relayPins[relayIndex], LOW);
- }
- String getLastWateredTime(int sensorIndex) {
- // Return the last watered time for the specified sensor
- unsigned long lastWateredTime = lastWateredTimes[sensorIndex];
- return (lastWateredTime == 0) ? "N/A" : String(lastWateredTime);
- }
- void updateLastWateredTime(int sensorIndex) {
- // Update the last watered time for the specified sensor
- lastWateredTimes[sensorIndex] = millis();
- }
- void handleWater(AsyncWebServerRequest *request) {
- // Handle manual watering form submission
- String relayIndexStr = request->arg("relay");
- String durationStr = request->arg("duration");
- if (relayIndexStr.length() > 0 && durationStr.length() > 0) {
- int relayIndex = relayIndexStr.toInt();
- int wateringDuration = durationStr.toInt() * 1000;
- activateRelay(relayIndex);
- delay(wateringDuration);
- deactivateRelay(relayIndex);
- updateLastWateredTime(relayIndex);
- }
- request->redirect("/");
- }