SaladBox
I am making this project because i have the issue where i have to maintain a little garden but i can't check the plants everyday.
My goal is to make an automated device to automatically water my little crops and regulate the temperatures.
When starting a project the first step is always to order the components.
Here are the ones i used for my project:
- Raspberry PI
- Jump wires
- 2x breadboard
- Resistors
- 2004A I2C LCD display.
- 4x relay board
- LDR
- Water level sensor
- Moisture sensor
- DHT11
- 12V pump
- 12V Powersupply
- DS18B20 temperature sensor
Setting Up the Raspberry PI
To start our project we'll need a working operating system on your Raspberry PI
First you'll need to download the Raspbian operating system from the website of Raspberry PI and second of you'll need to download Win32DiskImager (download: https://win32diskimager.download/)
Write Raspbian to your SD card:
1. Insert your SD card into your PC (you may need an adaptor)
2. Open Win32DiskImager
3. Select your image
4. Select your SD card
5. Press the "Write" button
for more information see this tutorial:
Adding things in boot directory:
before you're able to boot your pi you'll still need to configure some stuff on your PC.
1. Acces your boot directory
2. Open cmdline.txt
3. add "169.254.10.1" at the end of the document and save it
4. add a file called "ssh" to the boot directory (DO NOT GIVE THIS FILE AN EXTENSION)
5. After you've done this you can remove your SD card from your PC.
for more information see this website: https://www.raspberrypi.org/documentation/remote-a...
Establishing connection:
To connect to your PI you'll (again) need to install a piece of software, you'll need to install PuTTY this can be found here: https://www.putty.org/.
1. install and open PuTTY
2. fill in the static IP addres 169.254.10.1
3. put 22 in the box "port" this is the port that the ssh protocol uses
4. make sure the connection type is set to SSH
5. press "open"
6. fill in the default username: pi
7. fill in the default password: raspberry
now we're going to install WiFi, for this we'll need root user
1. sudo raspi-config
2. go to "Network options"
4. Select your country
5. Fill in the SSID (name of your Wifi network)
6. Fill in the PSK (password)
7. reboot just to be sure
alternatively you can use the command line to connect to your WiFi network
1. sudo -i
fill in the name and password of your WiFi network
2. wpa_passphrase "NAME" "PASSWORD" >> /etc/wpa_supplicant/wpa_supplicant.conf
3. wpa_cli
4. interface wlan0
5. reconfigure
In this project i'm using a couple of sensors that use the one-wire bus and I²C
1. sudo raspi-config
2. Interfacing options
3. enable I2C
4. enable the one-wire bus
5. reboot
Connecting the Electronics
Before we continue with the software side of things lets take a moment to connect our electronics.
Importing the Database
In this project i used MariaDB to store the data of my sensors, but because the Pi doesn't have this installed by default we will have to run a couple of commands to install this programm and get it running
- sudo apt-install mariadbserver
- sudo mysql_secure_installation
note: it will ask you for a login the default login for mysql is: root
if you want more info about this process: https://raspberrytips.com/install-mariadb-raspber...
Getting the Code
Before you can download the code from my github we have to configure the version of python, because our PI uses an older version of python by default so we have to upgrade it.
All of these commands are to be executed in PuTTY.
- update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
- update-alternatives --install /usr/bin/python python /usr/bin/python3 2
Now we've got the right version of python we can install some addons
- pip install Python-mysql-connector
- pip install flask
- pip install flask_cors
- pip install flask_socketio
- apt-get install apache2 -y
To view my code you can surf to my github: https://github.com/CoudronLukas/SaladBox
To clone my code you have to execute a command in PuTTY
- git clone https://github.com/CoudronLukas/SaladBox.git
Database
Included in the repository is a .sql file that will store our data.
to import the sql file execute these commands:
- mysql
- import database saladbox_db
- quit
- mysql -u root -p saladbox_db < (Path to back-end)/saladbox_db.sql
Front-End
To edit the webpage you have to edit the index.html file, this file can be found in var/www/html
To see your website type in the IP of your Raspberry PI or connect the PI with an ethernet cable to your laptop and type in the static IP 169.254.10.1
Connecting the Dots
At this point we already have the electronics, the database, the front-end and the back-end wich is great but if we want a fully working project we still have to make sure it runs automatically when you plug your project in.
Do achieve this we need to make a service.
for more information: https://www.raspberrypi.org/documentation/linux/usage/systemd.md
On your PI create a file app.service
nano app.service
Paste this exact code into it:
<pre>[Unit] Description=[YOUR DESCRIPTION] After=network.target [Service] ExecStart=/usr/bin/python3 -u main.py WorkingDirectory=/home/pi/Project1 StandardOutput=inherit StandardError=inherit Restart=always User=pi [Install] WantedBy=multi-user.target
Copy this file into /etc/systemd/system as root
sudo cp myscript.service /etc/systemd/system/myscript.service
Now you have to start the service
sudo systemctl start myscript.service
To stop the service
sudo systemctl stop myscript.service
Now reboot you PI.
sudo reboot