- Install docker if its not already installed.
- Make sure port 3306 is available. Usually this port is used for MySQL. If the port is in use you need to stop MySQL from usign the port manually before continuing:
-
- Open taskmanager.
- Go to service tab.
- Find MySQL80.
- Right click on the name and click stop.
-
- Go to the terminal and give the following command: lsof -nP +c 15 | grep LISTEN
- Look for port 3306 to see which program is using the port.
- Open a new terminal window and give the following command to close the program using port 3306: sudo killall name of the program using the port
- Enter the password from your computer.
- Open a new terminal in the folder where the project is located.
- Run the following command: docker-compose up -d (This step only needs to be done one time, after that the docker container will be running at all times)
- Install Mosquitto if its not already installed.
- Run mosquitto.exe from the location where you have installed Mosquitto.
- Create a new file in presentation/src/main/resources named application.properties.
- Find the application.properties.dist and copy the content in your application.properties file.
- Update the oopa.mqtt.client IP adress in the application.properties file to: tcp://{IP adress}. The IP adress is the adress where your local Mosquitto broker is running. Update the client id to: Plantmood-CentralSystem and the topic to: Plantmood/AllPlantMoods/Data
- You can now run the application in your preffered IDE.
For now the application is connected to a local database. To acces the database go to: localhost:8081
The database is only accessible after the docker command is executed.
When installing the project for the first time, enter the following command in the root of your project:
make && make git
chmod +x .githooks/pre-commit && git config core.hooksPath .githooks
To calculate if your plant needs extra water, is healthy or has too much water, an algorithm is created to determine the status. In the PlantmoodService the function GetPlantmoodStatus, checks the last 5 results from the Plantmood and checks the database for what kind of plantspecies is linked. The algorithm works as follows:
- All PlantmoodHistories are requested and ordered by date.
- A sublist is created with the last 5 measured results for a specific Plantmood SN
- All the measurements from the sublist are weighted. The latest measurement is multiplied by 1. Foreach extra measurement the weight is lowered by 0.2.
- All weigthed measures are summed and divided by the sum of the weight to get a weighted average.
-
- If the weighted average is lower than the minimum humidity of the Plantspecies, the returned mood will be "Plant needs water"
- If the weighted average is higher than the maximum humidity of the Plantspecies, the returned mood will be "Plant has too much water"
- If the weighted average is between the minimum and maximum humidity of the Plantspecies, the returned mood will be "Water level is good"
This algorithm is chosen, because it is less dependent of outliers when multiple points are being used. We believe that the latest measurement is the most valuable, so that is where the weigthed values come in. The more recent measurements are counted more heavily.
For securing the server, we make use of jwt. You can only use the api calls when you are signed in. To get a jwt token, use the following steps:
- Make sure you have te variable oop.jwt.secret in your application.properties (copy the application.properties.dist).
- Create a user. Use the following endpoint: api/v1/user/create
- Login with your email and password. Use the following endpoint: api/v1/login
- In the response, you get a token. Copy this token and save it as an authorized header with Bearer before the token (example: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0MSIsImV4cCI6MTU5MTgwNDg1MywiaWF0IjoxNTkxNzk0MDUzfQ.v0KNp5SAKvCkfkmYMhq42ahsW2cZ5t7cnDkLqfDFWKU).
- You are now able to get the data from other endpoints