Group AN CHAY CS2019 2022 - 2023 Project
Clone the project, then go to terminal to install all the required packages
pip install -r requirements.txt
Follow the steps below to successfully use our application:
- Create an Adafruit IO Account and create 4 feeds named
Humidity
,Temperature
,Intrusion Detector
andWater Pump
. Make sure their keys arehumidity
,intrusion-detector
,temperature
andwater-pump
respectively.
-
Retrieve Adafruit API key as instructed in the above image. Make sure that all of your feeds are public so that the mobile app can retrieve the IoT Dashboard data using Adafruit API.
-
Place your Adafruit API key on the config.yml file (note that you will have to create this file by your self and place it on the root folder of the project). For example, in the
/config.yml
file:
aio_key: PLACE_YOUR_ADAFRUIT_IO_API_KEY_HERE
- Create an IoT Dashboard to track your data. You can customize it by your own. Take ours as an example:
-
Create Visual Crossing account to begin using Visual Crossing Weather API.
-
Go to Weather Query Builder to get the URL for querying weather forcast. You can choose any options that you like, from day range to weather elements. Then copy the URL as instructed on the below image.
- Go to MainActivity.java and replace my Visual Crossing API URL with the one that you copied in the previous step:
static Calendar calendar = Calendar.getInstance();
static Map<String, String> dictionary = new HashMap<>();
static String url = "YOUR_VISUAL_CROSSING_URL";
@Override
protected void onCreate(Bundle savedInstanceState) {
- Use the
Adafruit IO Key
in the step 3 and place it where theAdafruit API Key
appears: MainActivity.java, MQTTHelper.java. For example, onMainActivity.java
, at functionsendPostRequest
:
private void sendPostRequest(boolean isChecked, String feedKey) {
OkHttpClient client = new OkHttpClient();
// Create the request body
String data = isChecked ? "OFF" : "ON";
RequestBody requestBody = new FormBody.Builder()
.add("X-AIO-Key", "PLACE_YOUR_ADAFRUIT_API_KEY_HERE") // Add your Adafruit API key
.add("value", data) // Add any other data you want to send to the Adafruit API
.build();
// Create the request
Request request = new Request.Builder()
.url(url + feedKey + "/data") // Set the URL of the Adafruit API endpoint
.post(requestBody) // Set the request method to POST and the request body
.build();
- Start the remote monitoring system. You should be able to see a screen with title
Intrusion Warning
appears on your screen:
- Start the mobile application. You should be able to see the app like this:
- At your
Intrusion Warning
window, use your mouse to draw a polygon represents your interested area, for example, your crop field. Then, when you finish, pressd
to trigger the object detector. When you want to stop the object detector, pressq
.
-
Check your
IoT Dashboard
andMobile Application
. -
In case you want to use the sensors, setup your sensors and connect the sensors through cables. Open
Device Manager
on your PC, find the port that connects to the sensors. Then, use the name of that port to place in the main.py, at functiongetPort()
. For example, if your connected port isCOM5
, then yourgetPort()
function should look like this:
def getPort():
ports = serial.tools.list_ports.comports()
N = len(ports)
commPort = "None"
for i in range (0, N):
port = ports[i]
strPort = str(port)
if "COM5" in strPort: # CHANGE COM PORT NUMBER HERE IN DEVICE MANAGER
splitPort = strPort.split(" ")
commPort = (splitPort[0])
return commPort
- At main.py, change those 2 lines so that the
monitoring system
can interpret the sensor's data. In this project, we use RS485 MODBUS protocol:
### SEND COMMAND TO ACTUATORS
points = []
animals_and_persons = ["person", "dog", "cat", "bird", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe"]
data_air2_temp = [3, 3, 0, 0, 0, 1, 133, 232] # CHANGE THIS LINE FOR TEMPERATURE SENSOR
data_air2_humi = [3, 3, 0, 1, 0, 1, 212, 40] # CHANGE THIS LINE FOR HUMIDITY SENSOR