This folder contains the backend code for the Plant Disease Detection project. The backend is built using Flask and integrates a deep learning model for real-time plant disease detection.
- This ESP32 system supports querying data via WhatsApp messages.
- Using Twilio, users can send text queries to receive real-time information about:
- Temperature
- Humidity
- Water Level
- Light Intensity
- Soil Humidity
-
Real-time data updates are now sent to Google Sheets using Google Apps Script.
-
The Apps Script function for processing POST requests:
function doPost(e) { try { Logger.log("Received POST request: " + JSON.stringify(e)); // Log the entire event object if (e.postData) { var sheet = SpreadsheetApp.openById("YOUR_SPREADSHEET_ID").getActiveSheet(); var data = JSON.parse(e.postData.contents); Logger.log("Parsed data: " + JSON.stringify(data)); // Log the parsed data sheet.appendRow([new Date(), data.humidity, data.temperature, data.waterLevel, data.soilHumidity]); return ContentService.createTextOutput("Success"); } else { Logger.log("No postData received"); return ContentService.createTextOutput("Error: No postData received"); } } catch (error) { Logger.log("Error: " + error.message); return ContentService.createTextOutput("Error: " + error.message); } }
-
Steps to deploy the Apps Script:
- Save the script in your Google Apps Script editor.
- Deploy it as a web app.
- Paste the web app URL into the
secrets.h
file.
- Download the pre-trained model from the following link: Google Drive - Model.
-
Create a directory named
model
in theBackend
folder and place the downloaded model files into this directory:mkdir model
-
Install the required Python packages listed in
requirements.txt
:pip install -r requirements.txt
-
Start the Flask application by running the following command in the terminal:
python leafdisease.py
Outside the Backend
folder, there is an Server
and Client
folder used for programming the ESP32 microcontroller and connecting it to Blynk.
-
Create
secrets.h
- Inside the
src
folder of theServer
andClient
project, create a file namedsecrets.h
with the following content:
#ifndef SECRETS_H #define SECRETS_H #define WIFI_SSID "YourWiFiSSID" #define WIFI_PASSWORD "YourWiFiPassword" #define BLYNK_TEMPLATE_ID "YourBlynkTemplateID" #define BLYNK_TEMPLATE_NAME "YourBlynkTemplateName" #define BLYNK_AUTH_TOKEN "YourBlynkAuthToken" #define SERVER_ADDRESS "YourServerAddress" #define SERVER_PORT YourServerPort #define APPSCRIPTS_URL "https://script.google.com/macros/s/YOUR_APPSCRIPTS_WEBAPP_URL/exec" #define THINGESP_USERNAME "YourThingESPUsername" #define TWILILO_PROJECTNAME "YourTwilioProjectName" #define TWILILO_DEVICENAME "YourTwilioDeviceName" #endif // SECRETS_H
- Inside the
-
Install Necessary Libraries
- Use PlatformIO to manage and upload the code. Ensure all required libraries are installed in the
platformio.ini
file.
- Use PlatformIO to manage and upload the code. Ensure all required libraries are installed in the
-
Upload the Code
- Connect your ESP32 to the computer and upload the code using PlatformIO.
- The project utilizes the MobileNet-SSD model
- Repository: MobileNet-SSD.
- The training dataset used for plant disease detection is the PlantVillage Dataset
- Repository: PlantVillage Dataset.
leafdisease.py
: Main application file containing the Flask server and functions for detecting diseases in plants.model/
: Directory containing the pre-trained models.requirements.txt
: File listing the dependencies required for the project.Server/
: Folder for ESP32 firmware that control water pump , ultrasonic sensor and soil humimidity sensor and send data back to Client.Client/
: Folder for ESP32 firmware that control lcd display , humidity sensor , temperature sensor , light sensor. this folder needs to connect with Blynk platform and Google sheets. also can command waterpump via Blynk's virtual button and send command to Server.
This project relies on the following Python libraries:
- OpenCV: For video capture and processing.
- NumPy: For numerical computations.
- Keras: For deep learning model integration.
- TensorFlow: Backend for the Keras model.
- Flask: For building the server application.
- Flask-CORS: To enable Cross-Origin Resource Sharing.
- You can clone another front-end project here Plant Svelte Front-end and use it as a front-end to control this system.
- Ensure your camera is connected and accessible by OpenCV before starting the application.
- You can adjust the confidence threshold and other parameters in the
leafdisease.py
file to improve detection performance. - For ESP32, ensure your WiFi credentials and Blynk details are correctly configured in the
secrets.h
file. - Test WhatsApp query responses to confirm integration with Twilio.
- Verify that data updates are reflected in Google Sheets.