Farmassist is a smart farming app for IoT and AI-powered plant disease detection. It is built with Flutter and uses Firebase as its backend.
View Agricultural News | Receive IoT Telemetry Data | Detect Plant Disease |
You can download the latest version of the Android APK here.
Architecture Diagram of Farmassist
The above illustration shows a high level overview of the Farmassist project. Farmassist consists of 3 subsystems:
- Farm Management Subsystem: Users can view agricultural news and manage planting and harvesting data.
- IoT Monitoring Subsystem: Users can view IoT telemetry data from the farm in the form of charts and receive alert notifications for abnormal telemetry data.
- Plant Disease Detection Subsystem: Users can take a picture of a diseased plant via camera to detect the disease type.
The backend services used are as follows:
- Firebase Authentication
- Cloud Firestore
- Realtime Database
- Cloud Functions
- Cloud Messaging
- Google Cloud AutoML Vision
The following sections explain more detail about the services and components used by the corresponding subsystems.
The signup and login flow of Farmassist is developed using the Bloc library and Firebase Authentication. After a user signs up successfully, the user data will be stored in the data model of Cloud Firestore as shown below:
{
"users": { // "users" collection
"4lbwvicymz71LfY9POHZ": { // "userId" document
"id": "4lbwvicymz71LfY9POHZ",
"email": "example@farmassist.com",
"displayName": "Jack",
"tokens": [ ... ] // used by Cloud Messaging
},
"4DkFgqNdjZnEh78YmsE3": { ... },
// more "userId" documents
}
}
Cloud Firestore, a NoSQL, document-oriented database, is used to store farm management data using key-value pairs. In Cloud Firestore, each collection consists of a number of documents in which each document can store a number of subcollections.
There are 2 types of farm management data stored: planting data and harvesting data. An example of the data model for harvesting data is shown below:
{
"planting": { // "planting" collection
"4lbwvicymz71LfY9POHZ": { // "userId" document
"months": { // "months" subcollection
"jan": { // "jan" document
"plantName": "tomato",
"noOfPlants": "100",
"plantDate": "25-03-2021",
"estimatedHarvestWeek": "9",
"harvestDate": "25-5-2021",
"harvested": true
},
"feb": { ... } // "feb" document
// more documents for the remaining months
}
},
// more "userId" documents
}
}
Under farm management, 2 extra APIs are used:
- News API is used to fetch top headlines for science category.
- OpenWeather API is used to obtain weather data of the farm location.
Realtime Database acts as a repository of IoT telemetry data that performs data synchronization with the Farmassist app. The overall process of IoT monitoring is described as follows:
- When new telemetry data is stored in Realtime Database, Cloud Functions will be triggered.
- Cloud Functions execute a function to check for abnormal values in the received telemetry data.
- If abnormal values exist, Cloud Functions will call Cloud Messaging service to send an alert notification to the relevant app user, which is identified by a unique token.
5 types of telemetry data are stored as JSON objects in Realtime Database:
- Air Humidity (%)
- Air Temperature (°C)
- Soil Moisture (%)
- Soil pH (pH)
- Soil Salinity (Millisiemens/cm)
Each telemetry data is stored as a key-value pair of timestamp and value. An example of the data model for telemetry data is shown below:
{
"telemetry_data": {
"4lbwvicymz71LfY9POHZ": { // userId
"humidity": {
"1617979596947": "56.64", // timestamp: value
"1617979596949": "55.89",
// more values
},
"moisture": { ... },
"pH": { ... },
"salinity": { ... },
"temperature": { ... }
},
// more telemetry data from other users
}
}
For demonstration purpose, a minimal IoT device simulator is built to send telemetry data to Realtime Database. For more information, you can refer to Farmassist IoT Device Simulator.
The code for Cloud Functions can be found in Farmassist Firebase.
A plant disease detection model was trained using Google Cloud AutoML Vision. The training dataset is a subset of PlantVillage dataset from Mendeley Data. A total of 2,941 diseased plant images that consists of 6 disease categories were used:
- Corn Common Rust (500 images)
- Corn Gray Leaf Spot (441 images)
- Potato Early Blight (500 images)
- Strawberry Leaf Scorch (500 images)
- Tomato Leaf Mold (500 images)
- Tomato Mosaic Virus (500 images)
After training, the model was exported as a TensorFlow Lite model, which is suitable to be run on a mobile device. You can find the trained model here.
Some of the useful Flutter packages used in the Farmassist app are listed in the table below. Refer to pubspec.yaml for the complete package information.
Package | Functions |
---|---|
Provider | A simple state management tool |
bloc and flutter_bloc | A state management library implemented using BLoC design pattern |
fl_chart | A powerful Flutter chart library with beautiful UI |
getwidget | A Flutter UI library with 1000+ pre-made UI components |
Things to do if you want to fork or contribute to the project.
- Create a Firebase project and add Firebase to your Flutter app.
- Refer to Farmassist IoT Device Simulator to see how fake telemetery data can be sent to Realtime Database.
- Refer to Farmassist Firebase for the Cloud Functions code that call Cloud Messaging service.
- Refer to Edge Device Model Quickstart if you want to train your own model for plant disease detection.
- Refer to CI/CD for Flutter Apps Using GitHub Actions to set up a workflow that can release an APK for your Flutter app whenever someone pushes the code to GitHub. Instead of using
push
event, I set up a manual trigger withworkflow_dispatch
event.
- GitHub: Farmassist IoT Device Simulator
- GitHub: Farmassist Firebase
- Bloc: Flutter Firebase Login Tutorial
- FlutterFire: Cloud Messaging Usage
- Google Cloud AutoML Vision: Edge Device Model Quickstart
- Medium: AutoML Vision—How To Train Your Model?
- Medium: CI/CD for Flutter Apps Using GitHub Actions
- GitHub: Farmsmart Flutter App
- GitHub: Best Flutter UI Templates