Skip to content

rjsears/Fish_Tank_Monitor_and_Control

Repository files navigation

Fish Tank Control
Fish Tank Control & Monitoring Documentation (V1.0.0)

Be sure to ⭐ my repo so you can keep up to date on any updates and progress!

GitHub last commit GitHub issues License

This Repo is designed to monitor and manage our smart fish tank.  It is not really designed as a "plug-and-play" application, rather a starting point for someone that wants to use all (or part) of the repo to monitor and manage their own fish tank. Hopefully, this might provide some inspiration for others in regard to their tank automation projects. Contributions are always welcome.

Screenshot of Main Control Panel


Overview & Theory of Operation

Using a combination of sensors and smart power strips, this repo provides the basis for someone to manage and monitor their own fresh or saltwater tank. It is not really intended to be a "plug-and-play" installable repo but rather a starting point for someone that is interested in creating their own solution using parts of this repo. That being said, one could use almost everything here, but some of the elements rely on stuff I have already in place such as the power/solar monitoring that you see on the main gauge page and the influx/Grafana. Those items can still be added and I plan on updating the documentation to show how to install and configure both influxDB as well as Grafana.

The system utilizes python3, flask, MySQL8, influxDB and Grafana. There is one Arduino sketch for the Feather that I use to gather the sensor data itself. I have all of the parts listed below in the parts section so you can see where to get them and the expense. Overall, it was minimal based on what it provides, at least in my opinion.

We utilize a CO2 injection system to help with our plants. Utilizing a smart power strip we turn on the pH controller which monitors the pH in the tank. We do this about an hour before the lights come on in the tank. The pH controller is set to shoot for a full 1 point pH drop during the time the lights in the tank are on. When it turns on, it will see that the pH in the tank is roughly 7 and start to inject CO2. Once the pH in the tank drops to around 6, the controller shuts off the flow of CO2 into the tank. It will continue to do this throughout the day until we get ready to shut off our lights. Since plants only photosynthesize during the day, we don't need CO2 injection at night. Once the CO2 shuts down for the day, we automatically turn on an air pump to drive the pH back up to 7. This CO2 management combined with nutrient dosing provides a fantastic environment for our plants as well as our fish. It is a fine balance and our monitoring system is designed to keep the balance in place.


Our Tank


The system is designed to monitor(m), record(r) and provide system notifications(n) on the following parameters:

  • Temperature (m, r, n)
  • pH (m, r, n)
  • Toxic Free Ammonia (NH3) (m, r, n)
  • Bound Ammonix (NH4) (m, r)
  • O2 Potential (m, r)
  • Electrical Conductivity in μS/cm (m, r, n)
  • Total Disolved Solids in ppm (m, r, n)
  • PAR (m, r)
  • LUX (m, r)
  • Kelvin (m, r)

The system is also designed to allow manual entry of the following parameters:

  • GH (r)
  • KH (r)
  • PO4 (r)

Screenshot of Manual Parameter Entry


Notifications

One of the best aspects of the system (IMHO) is the notification system. With this system, you can create highly refined notifications based on pretty much every monitored/measured parameter. Notification via E-Mail, SMS (Twilio($)) and PushBullet are supported as well as configurable logging and logging levels:

Screenshot of Notification Panel


Log Viewing

Log viewing can be done via the web interface. We utilize Pimp My Log as the backend to provide the web interface to the generated logs providing a means to view them without having to ssh into the main server:
Screenshot of Notification Panel


Since I have an existing InfluxDB and Grafana server, I can view historical data as well:

Grafana Historical Data



Pieces & Parts

Here is a list of all of the parts that I utilized to build this project along with links to where I purchased them.

Seneye Reef Kit with Web Server

The Seneye Reef Kit provides the sensors we use to measure Ammonia (Bound & Free), O2 Potential, PAR, LUX & Kelvin. It also measures pH and Temperature, however we utilize the Atlas probes for those measurements. Seneye has an API to access the information from the Reef Kit. This requires internet access so in the even of loss of internet, you would lose access to these readings.

Purchased from: Amazon
Price: $469.00

Seneye Reef Pack


Atlas Scientific Hydroponic Sensor Kit

This kit utilizes a Adafruit WiFi Feather Arduino clone connected to pH, EC and DS18B20 probes. Data is uploaded to Thingspeak about every 10 to 15 seconds and our script reaches out to the Thingspeak API to grab the data. Eventually we will rewrite the sketch to log to our local MySQL/Influx database and eliminate Thingspeak entirely.

Purchased from: Atlas Scientific
Price: $349.00

Atlas Scientific Hydroponic Sensor Kit


American Marine PINPOINT pH Controller

This is a pH monitor and controller. We utilize CO2 injection and we manage the level of injection by monitoring the pH in the tank. This controller allows us to set the desired pH level and manages our CO2 injection solenoid based on the current pH level of the tank.

Purchased from: Amazon
Price: $197.00

American Marine PINPOINT pH Controller


TP-Link Kasa HS300 Smart Power Strip

I chose this power strip because there was a library already written to interact and control it from within Python. Very simple to setup and very simple to use programmatically.

Purchased from: Amazon
Price: $80.00

TP-Link Kasa HS300 Smart Power Strip


CO2Art Pro-Elite Series Advanced Aquarium Dual Stage CO2 Regulator

After much research, this is the CO2 regulator that we chose for our tank setup. Very high quality and the folks at CO2Art were very nice to deal with and answered a lot of questions before we purchased the unit.

Purchased from: CO2Art
Price: $269.00

CO2Art Pro-Elite Series Advanced Aquarium Dual Stage CO2 Regulator


Dependencies

There are a lot of moving parts to any particular project. I will try and list all of the dependencies that you will need to use this repo. It is outside the scope of this documentation to cover the installation and configuration of some of these items. Also, some of these are optional (like Influx/Grafana) depending on how much you want to impliment. Also, I don't plan on listing the more common libraries (like datetime) that come prepackaged with Python. If I had to add them (pip3 install xxx), I will list them here. I have included a "requirements.txt" file for use with pip3.


Installation and Configuration

To begin, you need to setup the hardware you plan on using. Follow the instuctions that came with the Seneye and/or Atlas Hydroponics kit and make sure they are calibrated and saving data correctly. Verify that you have all of the necessary API information that you will need for later in the setup.

Next, create any other accounts that you may need to use for your notifications. If you plan on using email notifications, please remember that your server must be configured ahead of time to send emails. This will vary based on what MTA you are using. Please read the documentation for your particular MTA and make sure you can send emails from the command line before turning on email notifications. Signup and set up Pushbullet (free) and/or Twilio ($) if you plan on using them for notifications. Make sure to note down your API credentials as we will need them later in the setup.

My project has been installed as the only project on my Proxmox server running Ubuntu Server 20.04 LTS (Focal Fossa). As such, I have no need for a virtual environment (virtenv) for Python. I would highly recommend using a virtual environment for this project if you are running this on anything that you use for other projects. Because this is the only thing in my container, it is set up such that it is the root website on my server. If you have other websites running on whatever device you are installing this on, you will have to make modifications to your apache configuration file. The config file included with this repo is based on my installation.

Also, because we are using Pimp My Logs, there is a special stanza in the routes.py that must be included for it to operate as I have mine configured. Again, if you have other things running on your chosen web server, configuration of PML will be different and you may have to make modifications to make it work correctly for you.

There are a LOT of different sites that will explain how to install and configure Apache, MySQL, InfluxDB, Grafana, PHP, etc so I will not waste space here duplicating those instructions.

Here is the directory structure that I use with my installation:

/var/www/fish_tank_control/
└── tank_control
    ├── pml
    ├── static
    │   └── css
    ├── templates
    └── utilities

Logs are stored in /var/log/tank_control

Create the necessary directories and change ownership:

mkdir -p /var/www/fish_tank_control
chown www-data:www-data /var/www/fish_tank_control
mkdir /var/log/tank_control
chown www-data:www-data /var/log/tank_control

All directories should be owned by your web server user, in my case that is www-data.

Once that is done and before we get started with the repo itself, we need to make sure all of our basic software has been installed. Before going any further, please install and test the following packages:

  • Web Server Software - If using Apache, the 000-default.conf file above should work for you.
  • uWSGI - needed for Flask
  • PHP - needed for PML
  • MySQL or other SQL engine & libraries
  • InfluxDB - If you plan on using it
  • Grafana - If you plan on using it
  • KasaSmartPowerStrip Library
  • Pimp My Log

Next you will need to setup your MySQL/SQL database. Add the necessary user and use the fishtanks_75planted.sql file to get your structure and initial data setup. My goal is to have multiple tanks being monitored so you may end up wanting to change the name, etc. If you do, please make sure you modify all the database calls to point to the correct database. This is setup in the system_info.py file and we will modify that once we get the repo.

Next, grab the repo via git or download it above and place it in the /var/www/fish_tank_monitor directory. Once you have done that, we need to modify the system_info.py file. This is the file where all of our database information and API credentials for Email, Twilio, Pushbullet, Seneye and Thingspeak are stored. Make all necessary changes and save the file.

Once you have completed all of these steps, you can change into your base directory and run the test flask file:

root@localhost:/root# cd /var/www/fish_tank_control/
root@localhost:/var/www/fish_tank_control# ./run.py 
 * Serving Flask app "tank_control" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: xxx-xxx-xxxx

You should now be able to open a web browser and visit your site:

http://x.x.x.x:8080 (where x.x.x.x is the IP address of your installation)

If all goes well, you should be greeted with the main site page. It is important that you do not use this in production, it is for debugging and testing only. Once you are happy with everything, switch to using Apache, Nginx or your preferred web engine.