Coding an Offline Water Quality Logger for Tilapia Ponds
Author: Marcial Rey (In Between Bamboos Farm)
Tilapia are incredibly hardy fish, but they have their limits. A sudden spike in ammonia or a drop in dissolved oxygen can wipe out an entire pond overnight. The best way to prevent a catastrophic crash is to track your water metrics daily—specifically pH, ammonia levels, and water temperature.
Historically, farmers have recorded this data on paper logbooks, which usually end up wet, illegible, or lost. To solve this, I am coding a custom digital water quality logger for my pond using PHP and MySQL. Here is how I am digitizing my aquaculture data.
The Logic Behind the Logger
Because I already built a 24/7 solar aerator to maintain oxygen levels, my primary concern is monitoring the biological waste (ammonia) and the acidity (pH) of the water. The digital logger is designed to be a simple, mobile-friendly web form that I can access on my phone while standing right at the edge of the pond.
When I test the water, I simply input the numbers into the app. The app then sends that data securely to a local database, creating a permanent, timestamped history of the pond's exact health.
The Code: Sending Pond Metrics to the Database
For developers looking to build their own environmental tracking software, here is the core backend PHP logic. This script catches the data submitted from the mobile form and securely inserts it into the MySQL database.
<?php
// 1. Establish the Database Connection
$conn = new mysqli('localhost', 'admin_user', 'secure_password', 'agritech_db');
// Terminate if the connection fails
if ($conn->connect_error) {
die("Database Connection Failed: " . $conn->connect_error);
}
// 2. Capture the manual test results (Simulated form inputs)
$ph_level = 7.2;
$ammonia_ppm = 0.25;
$water_temp_c = 28.5;
$log_time = date("Y-m-d H:i:s"); // Auto-generates the current timestamp
// 3. Prepare the SQL Statement
$sql = "INSERT INTO pond_health_logs (ph_level, ammonia_level, temperature, recorded_at)
VALUES ('$ph_level', '$ammonia_ppm', '$water_temp_c', '$log_time')";
// 4. Execute and Verify
if ($conn->query($sql) === TRUE) {
echo "Success: Water quality metrics securely logged to the server!";
} else {
echo "Database Error: " . $conn->error;
}
// Close the connection to save server memory
$conn->close();
?>
Why Digital Tracking Matters
By keeping this data in a relational database rather than a paper notebook, the software can actively work for me. The next phase of this development project is writing a script that analyzes this data over time. If the database notices the ammonia levels steadily creeping up over a three-day period, the app will automatically trigger an alert to my phone, telling me to perform a water exchange before the fish are ever in danger!