reef-pi :: An opensource reef tank controller based on Raspberry Pi.

tfabio

New Member
View Badges
Joined
Mar 4, 2023
Messages
3
Reaction score
1
Location
Uk
Rating - 0%
0   0   0
Posted in the FB group too and Brandon spotted the issue: I used already wired JST cable and they can be fitted only on one way. I didn't notice that the way the connectors were supposed to be fitted was on the other way around of what the Leviathan board was expecting. Basically, I connected the V+ to the V-.... and fried up the PI.

Thanks Sral for the help.
 

Sral

Valuable Member
View Badges
Joined
May 2, 2022
Messages
1,006
Reaction score
976
Location
Germany
Rating - 0%
0   0   0
Posted in the FB group too and Brandon spotted the issue: I used already wired JST cable and they can be fitted only on one way. I didn't notice that the way the connectors were supposed to be fitted was on the other way around of what the Leviathan board was expecting. Basically, I connected the V+ to the V-.... and fried up the PI.

Thanks Sral for the help.
Sry to hear that, I just spotted the same thing :crying-face:
 

Sral

Valuable Member
View Badges
Joined
May 2, 2022
Messages
1,006
Reaction score
976
Location
Germany
Rating - 0%
0   0   0
Guess that's a good lesson for everybody who wants to make these kind of boards: try including a simple reverse polarity circuit made with a p-MOSFET, if you can find the space. Cost of the MOSFET: likely a few cents vs the cost for a fried Raspberry Pi, where I don't want to guess the amount of time, money and swearing involved right now.
 

Dom

Full Time Reef Keeper
View Badges
Joined
Apr 29, 2016
Messages
5,853
Reaction score
6,395
Location
NY
Rating - 0%
0   0   0
Hmmm... okay... I have a raspberry pi... now I know what I'm going to do with it...
 

Dave's Reef

Active Member
View Badges
Joined
Nov 4, 2018
Messages
102
Reaction score
150
Rating - 0%
0   0   0
Hi everyone. I have been updating my reef-pi and wanted to use an esp32 to monitor a hand full of level switches. Is there a tutorial out there on setting the esp32 up with reef-pi? I've searched for day with no luck. Thank for any help you can provide.
 

Sral

Valuable Member
View Badges
Joined
May 2, 2022
Messages
1,006
Reaction score
976
Location
Germany
Rating - 0%
0   0   0
Hi everyone. I have been updating my reef-pi and wanted to use an esp32 to monitor a hand full of level switches. Is there a tutorial out there on setting the esp32 up with reef-pi? I've searched for day with no luck. Thank for any help you can provide.
I have made a preliminary one in this thread

One thing to watch out for: the ESP32 board currently reboots every 5-10 minutes which causes sensors to read as „0“ if you ask their status during these instances. Reboot is very quick and a matter of seconds though. I’m currently working on a solution.
 

Dave's Reef

Active Member
View Badges
Joined
Nov 4, 2018
Messages
102
Reaction score
150
Rating - 0%
0   0   0
I have made a preliminary one in this thread

One thing to watch out for: the ESP32 board currently reboots every 5-10 minutes which causes sensors to read as „0“ if you ask their status during these instances. Reboot is very quick and a matter of seconds though. I’m currently working on a solution.
Thank you ill will be giving this a go over next weekend
 

Simonv92

Active Member
View Badges
Joined
Oct 21, 2014
Messages
108
Reaction score
97
Location
Italy
Rating - 0%
0   0   0
I think I've found a bug in v 6.0... If I disconnect any DS18B20 probe while the controller is power on I read -1°C which kicks ON my heater as my threshold is set to 23°C...
I think this is pretty dangerous as any sensor fault will turn on the heater (or anything else)...
There's a way to disable the temperature controller if the sensor goes bad?

edit:
I think we can achieve some kind of protection using 2 sensors:
- Sensor 1 is the main sensor which controls heater and chiller (and alerts)
- Sensor 2 will run a macro to disable sensor 1 if he reads value outside of the alerts range

What do you think? Have you implemented some kind of redundancy?
 
Last edited:

Simonv92

Active Member
View Badges
Joined
Oct 21, 2014
Messages
108
Reaction score
97
Location
Italy
Rating - 0%
0   0   0
Thanks for the kind words, working on bringing back that GUI. :) For the DHT22 you can run a python script like this, if you edit it so only the humidity is saved to the file you can import it in reef-pi using the file driver. If you can get away from I2C its best, I know it's tempting though with 2 wires vs 16.

Hi @robsworld78, can you please help in the step to add DHT22 sensor in Reef-Pi? I've done some test but I can only see the values in the command line... Thank you!
 

Sral

Valuable Member
View Badges
Joined
May 2, 2022
Messages
1,006
Reaction score
976
Location
Germany
Rating - 0%
0   0   0
I think I've found a bug in v 6.0... If I disconnect any DS18B20 probe while the controller is power on I read -1°C which kicks ON my heater as my threshold is set to 23°C...
I think this is pretty dangerous as any sensor fault will turn on the heater (or anything else)...
There's a way to disable the temperature controller if the sensor goes bad?

edit:
I think we can achieve some kind of protection using 2 sensors:
- Sensor 1 is the main sensor which controls heater and chiller (and alerts)
- Sensor 2 will run a macro to disable sensor 1 if he reads value outside of the alerts range

What do you think? Have you implemented some kind of redundancy?
I have suggested the same thing for sensors in general, e.g. an „error mode“ where values are disregarded and maybe even hand control over to a backup. For pH and Temperature these are the obvious error values of 0 and -1 (or -127 for the DS18B20 on the ESP32, if I remember correctly).
Alternatively one could let the user decide for an allowed range of values.

It’s definitely on @Ranjib‘s list.
 

robsworld78

Well-Known Member
View Badges
Joined
Feb 14, 2020
Messages
952
Reaction score
1,281
Location
Edmonton, Canada
Rating - 0%
0   0   0
Hi @robsworld78, can you please help in the step to add DHT22 sensor in Reef-Pi? I've done some test but I can only see the values in the command line... Thank you!
Hi Simon, if you have data in the terminal then it should just be a matter of splitting up the data in it's own CSV file. Here's the code from that link tweaked a bit, untested but should work. You'll have to change the pin number.

In reef-pi when you add the "analog-file" driver use these paths to read the temperature and humidity, you need to setup a driver for each if you want to see both. After you add the drivers then add an analog connector for both and remember to go to the admin tab and press the "reload" button after. Then you should be able to add them to the pH tab.

/var/lib/reef-pi/dht22/temperature.txt

/var/lib/reef-pi/dht22/humidity.txt


Python:
import os
import time
import Adafruit_DHT

DHT_SENSOR = Adafruit_DHT.DHT22
DHT_PIN = 4

try:
    f = open('/var/lib/reef-pi/dht22/temperature.txt', 'w')
    f.write('Temperature\r\n')

    f = open('/var/lib/reef-pi/dht22/humidity.txt', 'w')
    f.write('Humidity\r\n')
except:
    pass

while True:
    humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)

    if humidity is not None and temperature is not None:
        f.write('{0},{1},{2:0.1f}*C,{3:0.1f}%\r\n'.format(time.strftime('%m/%d/%y'), time.strftime('%H:%M'), temperature, humidity))
    else:
        print("Failed to retrieve data from humidity sensor")

    time.sleep(30)
 

robsworld78

Well-Known Member
View Badges
Joined
Feb 14, 2020
Messages
952
Reaction score
1,281
Location
Edmonton, Canada
Rating - 0%
0   0   0
thank you very much @robsworld78!! It’ll test it and let you know!
regarding the auto run of the script it is better to start at boot and let it run with a sleep command at the end or schedule the script with crontab?
Thank you again!!
No problem but I really messed up the code, that's what I get for rushing, unfortunately I can't edit that post. Still untested but should work. I must get to bed now but tomorrow I'll post a service file so the script runs when the Pi boots.

Python:
import os
import time
import Adafruit_DHT

DHT_SENSOR = Adafruit_DHT.DHT22
DHT_PIN = 4

while True:
    humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)

    if temperature is not None:
        f = open('/var/lib/reef-pi/dht22/temperature.txt', 'w')
        f.write(temperature)

    if humidity is not None:
        f = open('/var/lib/reef-pi/dht22/humidity.txt', 'w')
        f.write(humidity)

    time.sleep(30)
 

Simonv92

Active Member
View Badges
Joined
Oct 21, 2014
Messages
108
Reaction score
97
Location
Italy
Rating - 0%
0   0   0
Thank you again @robsworld78!! I've tested the python script, I think that the only missing part is a conversion from float to string to print the right value. I've tryed with:

Python:
import os
import time
import Adafruit_DHT

DHT_SENSOR = Adafruit_DHT.DHT22
DHT_PIN = 4

while True:
    humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)

    if temperature is not None:
        temp_string = str(temperature)
        f = open('/var/lib/reef-pi/dht22/temperature.txt', 'w')
        f.write(temp_string)

    if humidity is not None:
        hum_string = str(humidity)
        f = open('/var/lib/reef-pi/dht22/humidity.txt', 'w')
        f.write(hum_string)

    time.sleep(30)

But it doesn't work...

Reef-Pi side I setup the file path and if I write manually any value in the files Reef-Pi show me that value :beaming-face-with-smiling-eyes:
 

Sral

Valuable Member
View Badges
Joined
May 2, 2022
Messages
1,006
Reaction score
976
Location
Germany
Rating - 0%
0   0   0
I believe you might be missing an f.close().

I would advise you to use something like the following:
Python:
import os
import time
import Adafruit_DHT

DHT_SENSOR = Adafruit_DHT.DHT22
DHT_PIN = 4

while True:
    humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
  
    if temperature is not None:
        with f = open('/var/lib/reef-pi/dht22/temperature.txt', 'w'):
            # go to beginning of the file
            f.seek()
            # write temperature as a floating point number(f)
            # with sign(+), 5 characters (5) and 1 digit(.1)
            f.write("{:+5.1f}".format(temperature))

    if humidity is not None:
        with f = open('/var/lib/reef-pi/dht22/humidity.txt', 'w'):
            # go to beginning of the file
            f.seek()
            # write humidity as a floating point number(f)
            # 4 characters (4) and 1 digit(.1)
            f.write("{:4.1f}".format(humidity))
  
    time.sleep(30) # in seconds
The "with" statement takes care of closing the file after writing under all curcumstances (and thus avoids errors)
and the format takes care of formating the numbers to the appropriate string representations, assuming they are numbers to begin with.

Depending on circumstances, one might also add a "f.truncate()" in between "f.seek()" and the "f.write(...)" to make sure the file is realy empty and won't contain any leftovers from old values.
 

Simonv92

Active Member
View Badges
Joined
Oct 21, 2014
Messages
108
Reaction score
97
Location
Italy
Rating - 0%
0   0   0
I believe you might be missing an f.close().

I would advise you to use something like the following:
Python:
import os
import time
import Adafruit_DHT

DHT_SENSOR = Adafruit_DHT.DHT22
DHT_PIN = 4

while True:
    humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
 
    if temperature is not None:
        with f = open('/var/lib/reef-pi/dht22/temperature.txt', 'w'):
            # go to beginning of the file
            f.seek()
            # write temperature as a floating point number(f)
            # with sign(+), 5 characters (5) and 1 digit(.1)
            f.write("{:+5.1f}".format(temperature))

    if humidity is not None:
        with f = open('/var/lib/reef-pi/dht22/humidity.txt', 'w'):
            # go to beginning of the file
            f.seek()
            # write humidity as a floating point number(f)
            # 4 characters (4) and 1 digit(.1)
            f.write("{:4.1f}".format(humidity))
 
    time.sleep(30) # in seconds
The "with" statement takes care of closing the file after writing under all curcumstances (and thus avoids errors)
and the format takes care of formating the numbers to the appropriate string representations, assuming they are numbers to begin with.

Depending on circumstances, one might also add a "f.truncate()" in between "f.seek()" and the "f.write(...)" to make sure the file is realy empty and won't contain any leftovers from old values.
Thank you @Sral, I've tryed the script but I have a SyntaxError in line 12:
with f = open('/var/lib/reef-pi/dht22/temperature.txt', 'w')

What can it be? Thank you!
 

Sral

Valuable Member
View Badges
Joined
May 2, 2022
Messages
1,006
Reaction score
976
Location
Germany
Rating - 0%
0   0   0
Thank you @Sral, I've tryed the script but I have a SyntaxError in line 12:
with f = open('/var/lib/reef-pi/dht22/temperature.txt', 'w')

What can it be? Thank you!
Looks like you have forgotten the ":" at the end of the line.

Ah, no, I think I screwed up the syntax, it should probably be:
Code:
with open('var/lib/reef-pi/dht22/temperature.txt') as f:

The corresponding "humidity.txt" for the humidity, of course.
 

Simonv92

Active Member
View Badges
Joined
Oct 21, 2014
Messages
108
Reaction score
97
Location
Italy
Rating - 0%
0   0   0
Thank you for the reply, I've make it work like that:


Python:
  GNU nano 5.4                                                                                                            DHT22_Read.py
import os
import time
import Adafruit_DHT

DHT_SENSOR = Adafruit_DHT.DHT22
DHT_PIN = 4

while True:
    humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)

    if temperature is not None:
        with open('/var/lib/reef-pi/dht22/temperature.txt', 'w') as my_file:
            # write temperature as a floating point number (f)
            # with sign(+), 5 characters (5) and 1 digit(.1)
            my_file.write("{:+5.1f}".format(temperature))

    if humidity is not None:
        with open('/var/lib/reef-pi/dht22/humidity.txt', 'w') as my_file2:
            # write humidity as a floating point number(f)
            # 4 characters (4) and 1 digit(.1)
            my_file2.write("{:4.1f}".format(humidity))

    with open('/var/lib/reef-pi/dht22/temperature.txt') as my_file:
        print(my_file.read())

    time.sleep(10) # in seconds

Don't know if it's the best way but it seems to work..
How can I make it auto start at boot?
 

robsworld78

Well-Known Member
View Badges
Joined
Feb 14, 2020
Messages
952
Reaction score
1,281
Location
Edmonton, Canada
Rating - 0%
0   0   0
Thank you for the reply, I've make it work like that:


Python:
  GNU nano 5.4                                                                                                            DHT22_Read.py
import os
import time
import Adafruit_DHT

DHT_SENSOR = Adafruit_DHT.DHT22
DHT_PIN = 4

while True:
    humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)

    if temperature is not None:
        with open('/var/lib/reef-pi/dht22/temperature.txt', 'w') as my_file:
            # write temperature as a floating point number (f)
            # with sign(+), 5 characters (5) and 1 digit(.1)
            my_file.write("{:+5.1f}".format(temperature))

    if humidity is not None:
        with open('/var/lib/reef-pi/dht22/humidity.txt', 'w') as my_file2:
            # write humidity as a floating point number(f)
            # 4 characters (4) and 1 digit(.1)
            my_file2.write("{:4.1f}".format(humidity))

    with open('/var/lib/reef-pi/dht22/temperature.txt') as my_file:
        print(my_file.read())

    time.sleep(10) # in seconds

Don't know if it's the best way but it seems to work..
How can I make it auto start at boot?
I think next time I better test. :) Glad you guys got it working.

Try this to get it running when the pi starts.

Create a new file using the command below.

sudo nano /etc/systemd/system/dht22.service

Paste in the following to the new file. You may need to change the first two lines under "service" section to point to the location you have the python script and also update the script file name to match.

Code:
[Unit]
Description=reef-pi DHT22
After=network.target

[Service]
ExecStart=/var/lib/reef-pi/dht22/humidity_logger.py
WorkingDirectory=/var/lib/reef-pi/dht22/
StandardOutput=inherit
StandardError=inherit
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

Then run the following two commands and reboot the Pi to see if it starts.

sudo systemctl enable dht22.service

sudo systemctl start dht22.service


If you run the following command you can see if it's running.

sudo systemctl status dht22.service
 

Simonv92

Active Member
View Badges
Joined
Oct 21, 2014
Messages
108
Reaction score
97
Location
Italy
Rating - 0%
0   0   0
Hi @robsworld78 thank you again,
I've tested your instruction, I only have to add the path to Python3 in the ExecStart command:

Python:
ExecStart=/usr/bin/python3 /var/lib/reef-pi/dht22/dht22_read.py

Now everything works fine :beaming-face-with-smiling-eyes:

I ask to both of you, @Sral & @robsworld78 can I write a post as a reference guide if someone else would like to use this type of sensor?
Thank you!
 

Going off the ledge: Would you be interested in a drop off aquarium?

  • I currently have a drop off style aquarium

    Votes: 2 1.8%
  • I don’t currently have a drop off style aquarium, but I have in the past.

    Votes: 1 0.9%
  • I haven’t had a drop off style aquarium, but I plan to in the future.

    Votes: 18 15.9%
  • I am interested in a drop off style aquarium, but have no plans to add one in the future.

    Votes: 50 44.2%
  • I am not interested in a drop off style aquarium.

    Votes: 39 34.5%
  • Other.

    Votes: 3 2.7%
Back
Top