IoT Cloud Solution for Reef Tank Data Monitoring and Remote Control
Use an ESP8266 Wifi board (Arduino compatible) with pH meter and temperature sensor to publish sensor data through MQTT. The MQTT broker is hosted on the cloud. Using a Node-RED to subscribe to the MQTT sensor data and store to InfluxDB. Grafana is used to show the historical sensor data and set alert conditions for the value worthing notification. You can also ask Siri to report the last status of your reef tank.
- Monitor historical pH value of your reef tank, including the two-point calibration
- Monitor historical temperature of your reef tank
- Get the status of my tank by Siri
- Get alert notification by Slack
- Low cost
- Private Cloud Solution
-
Local Side
- ESP8266 board with wifi
- Analog pH Meter Pro Sensor
- Calibration Solution pH7 and pH10
- DS18B20 waterproof temperature sensor
- Breadboard
- Breadboard connectors
- Micro USB cable and power adapter
-
Cloud Side
- A server (CPU:1 Core, 1GB RAM at least)
- Public IP (If private IP, you can only access inside the local network. Use port forward to access on the internet)
- Install Docker Engine on the server, include log rotation setting.
- Install GIT to get the source code on Github
-
For example, my cloud settings are as follows:
- Apply an AWS EC2 VM
- Choose Ubuntu 16.04 t2.micro
- Create a Security Group. Add Rule for TCP, Source: Anywhere, with
- MQTT:1883
- NodeRed:1880
- Grafana:3000
- InfluxDB:8086
- Instances > Actions > Networking > Change Security Groups.
- Install Docker
./bin/system/install_docker.sh
- Add Port in iptable
./bin/system/add_port.sh
- Save iptables
./bin/system/save_iptables.sh
- Apply an AWS EC2 VM
-
Get the source code on server
git clone https://github.com/samuelchiang/auto_tank.git
-
docker swarm init
docker swarm init
-
Start server
./start.sh
-
Check 4 services are running (REPLICAS are all 1/1)
# docker service ls ID NAME MODE REPLICAS IMAGE PORTS xpsuie57lg4t auto_tank_grafana replicated 1/1 grafana/grafana:latest *:3000->3000/tcp eyogf84hi5r5 auto_tank_influxdb replicated 1/1 influxdb:latest *:8086->8086/tcp r2rswub5twid auto_tank_mqtt replicated 1/1 eclipse-mosquitto:latest *:1883->1883/tcp 4wru608dlc0s auto_tank_nodered replicated 1/1 nodered/node-red:latest *:1880->1880/tcp
-
Optional: MQTT broker default Username:Password is admin:admin. To change it, you can refer my example as follows:
# docker ps -a |grep mqtt 1e4aa4a364db eclipse-mosquitto:latest "/docker-entrypoint.…" 41 minutes ago Up 41 minutes 1883/tcp auto_tank_mqtt.1.ygfkpzlf3qpn82koc2c2prftt # docker exec -ti auto_tank_mqtt.1.ygfkpzlf3qpn82koc2c2prftt sh # cd /mosquitto/config/ /mosquitto/config # ls mosquitto.conf mqttpasswd /mosquitto/config # mosquitto_passwd -c mqttpasswd admin Password: your_password_here # exit # docker service update auto_tank_mqtt
-
To setup InfluxDB username and password and create database, you can refer my example as follows (change 'your password'):
# docker ps -a|grep influx 5c790c7b4dcb influxdb:latest "/entrypoint.sh infl…" 54 minutes ago Up 54 minutes 8086/tcp auto_tank_influxdb.1.v7fss7y63fbfo5zqpqa1c3x2f root@ubuntu:~/auto_tank/node-red/data# docker exec -ti auto_tank_influxdb.1.v7fss7y63fbfo5zqpqa1c3x2f influx Connected to http://localhost:8086 version 1.7.8 InfluxDB shell version: 1.7.8 > CREATE USER admin WITH PASSWORD 'your password' WITH ALL PRIVILEGES > auth username: admin password: > CREATE DATABASE "mytank" > show databases name: databases name ---- _internal mytank > CREATE RETENTION POLICY "a_year" ON "mytank" DURATION 52w REPLICATION 1 DEFAULT > exit
- Browse Node-RED
- Using a browser to open
http://<server ip>:1880/
, default username, password is admin:admin - (Optional) You can change Node-RED password
- Using a browser to open
- Import Flows from file
- Find
flows.json
in project pathnode-red/data/
- Press Top-Right menu button > Import > flows.json
- Find
- Configure InfluxDB
- Press Top-Right menu button > Manage palette > Install > search influxdb > install node-red-contrib-influxdb
- On "Data Storer" tab, click "influxdb" node > edit server > input Username:Password > Done > Deploy
- Press the timestamp for Query (SELECT * FROM dev1), you can see the debug message, now it's [ empty ] because of no data, but no error.
- Configure MQTT
- On "Data Storer" tab, click "data/dev1" node > edit server > Security > input MQTT Username:Password (default) admin:admin > Done > Deploy
- If the username and password is correct, the MQTT "data/dev1" node show "connected".
- Browse Grafana
- Using a browser to open
http://<server ip>:3000/
, default username, password is admin:admin, the web UI will ask you to change the password.
- Using a browser to open
- Configure Data Source
- On "Home Dashboard", Add data source > InfluxDB
- URL:
http://influxdb:8086
- Database:
mytank
- User:
admin
- Password:
your password
- URL:
- Save & Test => Data source is working
- On "Home Dashboard", Add data source > InfluxDB
- Import Dashboard
- Find
MyTank-xxxx.json
in project pathgrafana_dashboard/
- On Left menu: "+" > Import > Upload .json file >
MyTank-xxxx.json
> Select a InfluxDB data source > InfluxDB > Import - Now you get a dashboard with pH and temperature, but no data.
- Find
- Install Arduino driver for your PC or Mac
- Use Arduino IDE for ESP8266
- Connect ESP8266, DS18B20 and pH meter with a breadboard, the pin is shown as the architecture picture on the overview section.
- Configure program
PH_Meter
- Find Arduino file
ph_meter.ino
on project patharduino/PH_Meter/
- Use Arduino IDE to open file:
ph_meter.ino
- Edit the parameters:
- const char* ssid = “Your Wifi AP SSID";
- const char* password = "Your Wifi AP Password";
- const char* mqttServer = "MQTT IP address";
- const char* mqttUserName = “MQTT username;
- const char* mqttPwd = "MQTT password";
- Install Libraries
- How to install
- From Sketch > Include Library > Manage Libraries > Library Manager
- Verify
- Upload
- Find Arduino file
- Check if data is publishing
- From Node-RED Data Storer Debug message, you can check if there are message as below for every 20 seconds.
"{ "id":"dev1", "temp":24.31, "ph":8.34, "voltage":777.76}"
- From Grafana Dashboard, there are data for pH and temperature.
-
How it works: Voltages V1, V2 are measured at PH7 and PH10. Since the pH meter can be regarded as linear in a small range, it's a linear function:
pH = S*voltage+Offset
7 = S*V1+Offset 10 = S*V2+Offset => S = (10-7) / (V2-V1) => Offset = 7 - S*V1
-
Calibration procedure:
- The pH probe is first washed with ordinary cold water, then blotted with tissue paper (do not use rough toilet paper), do not rotate it, otherwise, it will permanently damage the probe coating, seriously affecting the accuracy!
- Browse Node-RED > PH Calibration tab
- Put the probe into the pH7 calibration solution and wait at least 1.5cm for 20 seconds, then click the box on the left side of cmd_ph7cal. After 10 seconds, the average value V1 will be automatically obtained.
- Put the probe into the pH10 calibration solution and wait at least 1.5cm for 20 seconds. Then click the box on the left side of cmd_ph10cal. After 10 seconds, the average value V2 will be automatically obtained, which the calibration is done.
- The calibration order of pH7 and pH10 cannot be reversed. The two calibrations must be completed at one time, otherwise please restart ESP8266.
- The Calibration result can be seen by the Node-RED debug message, with MQTT topic 'event/dev1', in my case
{ "id":"dev1", "ts":"20:41:36", "voltage7":593.32, "voltage10":1008.61, "ph_slope":"0.007247947", "ph_offset":"2.699647957”}
- The data can also be seen by the Node-RED debug message, with MQTT topic 'data/dev1', in my case
{ "id":"dev1", "temp":23.75, "ph":8.36, "voltage":781.42}
- Use iPhone to install Shortcut App
- Use a browser to open the Shortcut link, install it in your shortcut app.
- This app will ask for input server_ip, influxdb_username, and influxdb_password, fill them.
- Press play button to execute
- Press the setting button, "Add to Siri". Then you can get the tank status by Siri voice command.
- InfluxDB - Time Series Database
- Grafana - The open observability platform
- Node-RED - Flow-based development tool
- Mosquitto - Lightweight MQTT Broker
- Docker - Container Platform
- Arduino - Open-source hardware of microcontroller
- ESP8266 - low-cost Wi-Fi microchip with full TCP/IP stack and microcontroller capability. Compatible with Arduino
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Samuel Chiang - Initial work
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details
- pH8.4 - I start Reef Tank from here
- REEF2REEF - Worlds largest reef tank user forum
- shih87: Siri Control of Apex (SCA) without HomeBridge - Inspire me to get data over Siri
- KHG author - Inspire me for how to calibrate pH