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

OP
OP
Ranjib

Ranjib

7500 Club Member
View Badges
Joined
Apr 16, 2016
Messages
9,876
Reaction score
16,680
Location
Pleasant Hill, Concord
Rating - 0%
0   0   0
That's where I'm trying to name & assign them, in the connectors settings.

I was able to bypass the problem by using my tablet connecting to the reef pi server instead. Now I'm just having issues getting the relays to respond.
what the log says?
 
OP
OP
Ranjib

Ranjib

7500 Club Member
View Badges
Joined
Apr 16, 2016
Messages
9,876
Reaction score
16,680
Location
Pleasant Hill, Concord
Rating - 0%
0   0   0
So I'm hoping to be able to try this out this weekend, but if you have a chance to glance at it, does this look like it might work?


Code:
import requests
import time
from datetime import datetime
from datetime import time
from datetime import date
import math


num_expansions=15
#0 = White East
#1 = White Center
#2 = White West
#3 = Blue East
#4 = Blue Center
#5 = Blue West
#6 = OCW East
#7 = OCW Center
#8 = OCW West
#9 = Violets East
#10 = Violets Center
#11 = Violets West
#12 = Moonlight East
#13 = Moonlight Center
#14 = Moonlight West
#15 = NOT USED


#on time for channels 0-15  (15 is not used)
on_hour=[9,9,9,8,8,8,9,9,9,8,8,8,19,19,19,0]
on_minute=[0,15,30,0,15,30,15,30,45,15,30,45,0,15,30,0]

#off time for channels 0-15  (15 is not used)
off_hour=[18,18,18,20,20,20,17,18,18,19,20,20,9,9,9,0]
off_minute=[0,15,30,0,15,30,45,0,15,45,0,15,0,15,30,0]

#how long it takes for light to dim from min to max and max to min
slope_length=[100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,0]
slope_length=[i*600 for i in slope_length]

#the minimum PWM value from 0-4095
startPWM=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

#the maximum PWM value from 0-4095
endPWM=[1433,1433,1433,3841,3841,3841,1638,1638,1638,3686,3686,3686,220,220,220,0]
pwmDelta=[y-x for x,y in zip(startPWM,endPWM)]

pwm_value=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
smoothPhase=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
lastsecond=0

while True:

    #to run the pwm function 1 time per second
    import time
    currentsecond=int(round(time.time()))
    currentsecond=int(currentsecond)
    if currentsecond>lastsecond:
        lastsecond=currentsecond+0 #add how many seconds delay over 1 to 0

        now=datetime.now()

        current_hour=now.hour

        current_minute=now.minute

        current_second=now.second
              
        for a in range(num_expansions):

                start=[i*60 for i in on_hour]
                start=[x+y for x,y in zip(start,on_minute)]
                start=[i*600 for i in start]
                end=[i*60 for i in off_hour]
                end=[x+y for x,y in zip(end,off_minute)]
                end=[i*600 for i in end]
                current=(current_hour*60)+current_minute
                current=(current*600)+(current_second*10)

                if current<=start[a]:
                        pwm_value[pwm_value[a]]=0
                if current>=end[a]:
                        pwm_value[pwm_value[a]]=0
                if current>start[a]:
                        if current<end[a]:
                                pwmDelta[a] = endPWM[a]-startPWM[a];
                                if current > (start[a] + slope_length[a]):
                                        if current < (end[a] - slope_length[a]):
                                                #we are at the maximum value
                                                pwm_value[a]=endPWM[a]
                                        else:
                                                #we are in the phase down
                                                smoothPhase[a]=(((end[a]-current)/slope_length[a])*180)+180
                                                pwm_value[a]=startPWM[a]+(pwmDelta[a]*((1+(math.cos(math.radians(smoothPhase[a]))))/2.0))
                                else:
                                        #we are in the phase up
                                        smoothPhase[a]=(((current-start[a])/slope_length[a])*180)+180
                                        pwm_value[a]=startPWM[a]+(pwmDelta[a]*((1+(math.cos(math.radians(smoothPhase[a]))))/2.0))
                        else:
                                #we are after the ramp down has finished
                                pwm_value[a]=0
                else:
                        #we are before the ramp up has started
                        pwm_value[a]=0


                #print('Press Ctrl-C to quit... PWM value for channel',a,'is',pwm_value[a])

                if (a==0) or (a==3) or (a==6) or (a==9) or (a==12):
                    light_id = "East"
                if (a==1) or (a==4) or (a==7) or (a==10) or (a==13):
                    light_id = "Center"
                if (a==2) or (a==5) or (a==8) or (a==11) or (a==14):
                    light_id = "West"
                pin = a #this needs to change to correct pin
                ip = "127.0.0.1:8080"
                auth = ("reef-pi", "reef-pi")
                u = "http://" + ip + "/api/lights/" + light_id

                resp = requests.get(u, auth=auth)
                light = resp.json()
                light["channels"][pin]["auto"] = False #change the light to fixed mode
                light["channels"][pin]["fixed"] = pwm_value/40.95 #PWM value in % - should be changed in future
                resp = requests.post(u, auth=auth, json=light) #update light
              

                #pwm.setPWM(a, 0, pwm_value[a])
Some changes required. you have imported time twice. remove the second import statement inside the loop. light_id 's are not light names. If I understand correctly , you have three lights defined, and each of them has 5 channels (East, West, Center). The final value has to be converted into int, pwm_value/40.96 can be a float, so wrap that in int(pwm_value/40.96). I'll share an updated code soon...
Question: your lights dim smoothly across the entire 0-100% range? For kessil i have seen we cant dim it below 13% (it flickers below that), i was under the assumption that all other lights have same limitations.
 

aquaalgae

Community Member
View Badges
Joined
Mar 22, 2017
Messages
48
Reaction score
30
Rating - 0%
0   0   0
Some changes required. you have imported time twice. remove the second import statement inside the loop. light_id 's are not light names. If I understand correctly , you have three lights defined, and each of them has 5 channels (East, West, Center). The final value has to be converted into int, pwm_value/40.96 can be a float, so wrap that in int(pwm_value/40.96). I'll share an updated code soon...
Question: your lights dim smoothly across the entire 0-100% range? For kessil i have seen we cant dim it below 13% (it flickers below that), i was under the assumption that all other lights have same limitations.
I am not sure of the lowest PWM value that I can dim to, but it is less than 1-2%
 

Schreiber

Leviathan
View Badges
Joined
Jun 28, 2016
Messages
475
Reaction score
594
Location
Knoxville
Rating - 0%
0   0   0
I'm all good now. Is there something in the code that prevents is from using GPIO4? I tried starting on that one & it refused to work. All the others worked fine. I may just have a dead pin.
 

jcmental

Active Member
View Badges
Joined
Jan 25, 2018
Messages
114
Reaction score
137
Rating - 0%
0   0   0
I think I have mentioned earlier, but I’ll repeat that even with this, the kessil controller works flawlessly if I use pca9685 and a dedicated build
My lights work fine to, and I got a job lot of lm2569's from china 20 for £3.00 or in your money I'm guessing around $5
 
OP
OP
Ranjib

Ranjib

7500 Club Member
View Badges
Joined
Apr 16, 2016
Messages
9,876
Reaction score
16,680
Location
Pleasant Hill, Concord
Rating - 0%
0   0   0
I'm all good now. Is there something in the code that prevents is from using GPIO4? I tried starting on that one & it refused to work. All the others worked fine. I may just have a dead pin.
gpio4 is used by temperature sensors
 

Des Westcott

Well-Known Member
View Badges
Joined
May 29, 2018
Messages
646
Reaction score
1,025
Location
Durban - South Africa
Rating - 0%
0   0   0
Hey

Next dumb question :-)

The wires on my FS-IR02 level sensor are way too short. Will it be a hassle if I extend them? I can't imagine so as it's only an on / off signal, not a reading like Ph or Temp??

Thanks
 

janos

Active Member
View Badges
Joined
Jun 4, 2017
Messages
267
Reaction score
259
Location
Toronto,Canada
Rating - 0%
0   0   0
Hi to all. Like to ask do i need to use external 5v to drive my 8ch relay board,or just use the Raspberry 5v pin.Thank you
 

aquaalgae

Community Member
View Badges
Joined
Mar 22, 2017
Messages
48
Reaction score
30
Rating - 0%
0   0   0
Some changes required. you have imported time twice. remove the second import statement inside the loop. light_id 's are not light names. If I understand correctly , you have three lights defined, and each of them has 5 channels (East, West, Center). The final value has to be converted into int, pwm_value/40.96 can be a float, so wrap that in int(pwm_value/40.96). I'll share an updated code soon...
Question: your lights dim smoothly across the entire 0-100% range? For kessil i have seen we cant dim it below 13% (it flickers below that), i was under the assumption that all other lights have same limitations.
I've made the changes to the code that you said, except for the light id. Where do I find the light_id?
 

janos

Active Member
View Badges
Joined
Jun 4, 2017
Messages
267
Reaction score
259
Location
Toronto,Canada
Rating - 0%
0   0   0
Hi to all.try to install reef-pi now for 4-5 times,something always wrong.Yesterday was almost working,today morning i try again to log in with localhost:80 and something go wrong again,it try to download reef-pi when i go to web browser.Evennow i try to downgrade to reef-pi1.0 now go to the web browser but give me wrong msg. reef-pi is running but the msg is 404 not find
 

janos

Active Member
View Badges
Joined
Jun 4, 2017
Messages
267
Reaction score
259
Location
Toronto,Canada
Rating - 0%
0   0   0
Hi to all.try to install reef-pi now for 4-5 times,something always wrong.Yesterday was almost working,today morning i try again to log in with localhost:80 and something go wrong again,it try to download reef-pi when i go to web browser.Evennow i try to downgrade to reef-pi1.0 now go to the web browser but give me wrong msg. reef-pi is running but the msg is 404 not find
 

Erica-Renee

Valuable Member
View Badges
Joined
Oct 4, 2017
Messages
1,596
Reaction score
3,288
Location
lost
Rating - 0%
0   0   0
Hi to all.try to install reef-pi now for 4-5 times,something always wrong.Yesterday was almost working,today morning i try again to log in with localhost:80 and something go wrong again,it try to download reef-pi when i go to web browser.Evennow i try to downgrade to reef-pi1.0 now go to the web browser but give me wrong msg. reef-pi is running but the msg is 404 not find

are you running Headless and what version of pi are you using?
If you are running gui on the pi computer itself you type "localhost " into your browser..

You may need to clear cache and browser history on the Computer your using to access the pi.. Sometimes rebooting your Internet modem and router helps as well.
If the above does not apply try following the Troubleshooting guide here
https://reef-pi.github.io/additional-documentation/troubleshooting/

Note if you go into settings do not turn on the pca 9685 driver (check mark box) Unless you have board Connected and powered on.. It will Crash your reef-pi .....

Hope this helps
 
OP
OP
Ranjib

Ranjib

7500 Club Member
View Badges
Joined
Apr 16, 2016
Messages
9,876
Reaction score
16,680
Location
Pleasant Hill, Concord
Rating - 0%
0   0   0
Hey

Next dumb question :)

The wires on my FS-IR02 level sensor are way too short. Will it be a hassle if I extend them? I can't imagine so as it's only an on / off signal, not a reading like Ph or Temp??

Thanks
Should be ok. I have also bought other optical sensors (with same 4pin jst connector) with longer cable length
https://www.amazon.com/dp/B00Z9NUJWW/
 
OP
OP
Ranjib

Ranjib

7500 Club Member
View Badges
Joined
Apr 16, 2016
Messages
9,876
Reaction score
16,680
Location
Pleasant Hill, Concord
Rating - 0%
0   0   0
Hi to all. Like to ask do i need to use external 5v to drive my 8ch relay board,or just use the Raspberry 5v pin.Thank you
dont use pi's 5v pin. you cant draw a lot of current from there... you can power things like pca9685 or some other ICs, but not LEDs. Use a dedicated power supply for the LEDs.
 
OP
OP
Ranjib

Ranjib

7500 Club Member
View Badges
Joined
Apr 16, 2016
Messages
9,876
Reaction score
16,680
Location
Pleasant Hill, Concord
Rating - 0%
0   0   0
I've made the changes to the code that you said, except for the light id. Where do I find the light_id?
you can get the light ids by making an api call to list all lights and iterating over the result, each entry is one light

Code:
resp = requests.get("http://localhost/api/lights", auth=auth)
lights = resp.json()
lights[0]["name"]
lights[0]["id"]
 
OP
OP
Ranjib

Ranjib

7500 Club Member
View Badges
Joined
Apr 16, 2016
Messages
9,876
Reaction score
16,680
Location
Pleasant Hill, Concord
Rating - 0%
0   0   0
Hi to all.try to install reef-pi now for 4-5 times,something always wrong.Yesterday was almost working,today morning i try again to log in with localhost:80 and something go wrong again,it try to download reef-pi when i go to web browser.Evennow i try to downgrade to reef-pi1.0 now go to the web browser but give me wrong msg. reef-pi is running but the msg is 404 not find
Can you tell us more about your setup.. what pi, how you installed it, share the logs etc.
 

Erica-Renee

Valuable Member
View Badges
Joined
Oct 4, 2017
Messages
1,596
Reaction score
3,288
Location
lost
Rating - 0%
0   0   0

TOP 10 Trending Threads

WHAT AMOUNT OF LIVE ROCK AND SAND SHOULD BE PRIORITIZED FOR OPTIMAL BIODIVERSITY/FILTRATION?

  • 100% live rock + bagged sand

    Votes: 38 27.3%
  • 100% dry rock + 100% live sand

    Votes: 47 33.8%
  • 50/50 live/dry rock, 50/50 live/bagged sand

    Votes: 30 21.6%
  • 75% live rock, 25% live sand

    Votes: 14 10.1%
  • 25% live rock, 75% live sand

    Votes: 10 7.2%
Back
Top