cdwill
Posts: 1
Joined: Mon Apr 01, 2013 10:58 pm

hot tub

Wed Aug 14, 2013 9:53 pm

hi every body
I'm fairly new to the pi and programming, i have made a pi xbmx box with ir controle using tutorials of the internet and i have some experience flowing circuit diagrams and soldering pcb's (diy audio amp exe)

im wanting to run my hot tub with a raspberry pi as its own controller has fried its self bot the buttons and the temp controller as there separate

im thinking of using i2c (quick2wire) components for the relays, rtc and display
and 6 buttons running off the gpio's + a temperature probe

and im wondering if anyone has any suggestions, literature for me to read or different ways of doing it


on the programming side i don't know what os to use or how to program the comands

i want 2 relays runing off 2 butons with a timed turn off after a set time or re press buton to turn off for light and blower, a relay runing of an adjustable temprature limit with 2 buttons to set the temp and 1 as a adjust button for the heater ,and a master button that when presed turns the the motor on (single speed motor) and the heater on and when presed agane will turn all but the light off
i also want it to turn on at a set time(s) for like an hour or 2

thanks
daniel

Aesgarth
Posts: 9
Joined: Tue Jan 14, 2014 7:55 pm

Re: hot tub

Tue Jan 14, 2014 8:39 pm

I realise i'm bumping a fairly old thread here, but i'm in the middle of trying something similar and was wondering if you'd made any progress or if anyone else here had any suggestions to improve what i'm doing or make my life easier.

Hardware:
[img]http://i70.photobucket.com/albums/i112/ ... 5949e7.jpg[/img]
comes up small in img tags so link to slightly bigger:
http://i70.photobucket.com/albums/i112/ ... 5949e7.jpg
Raspberry Pi (obviously)
PiFace
2 * DS18B20 temperature sensors - 1 for air temp, one for water temp.
1 * toggle switch to simulate water level sensor
5 * 40a solid state relays - may be overkill, may be inadequate, need to check pump motor specs
8a 5v power supply
cheap usb hub
(Wifi will be added later)

The code i've written so far (Python) will read the temperature sensors, compare the reading to a set temperature stored in a text file and activate the pump and heater relays in sequence if the temperature is too low and deactivate them when it gets up to the specified level. I can also activate the other relays (for additional pumps and the air blower) via switches. I'd like to make this via button presses but the time the code loop currently takes may be too long for this - reading from the temperature sensors takes time.

Additional features i'd like:
increase the set temperature using button presses
display current and set temperature on some form of screen on the control panel as well as the status of the pumps, heater and blower.
set temperature and monitor status via network
ideally set temperature and operate all features via smartphone app
SMS and/or email alerts for low water or temperature outside a given range
Reset itself at specified times or intervals

I feel like i'm going about this the wrong way as i currently have everything in a single Python script. I'm new to both linux and python and haven't coded anything in about 8 years so i'm finding it quite challenging. I'll post my code shortly - i need to do that from the pi.

Aesgarth
Posts: 9
Joined: Tue Jan 14, 2014 7:55 pm

Re: hot tub

Tue Jan 14, 2014 8:44 pm

Here's the code to go with my previous post:

Code: Select all

#initiates piface board
import piface.pfio as pfio
import RPi.GPIO as GPIO
pfio.init()
from time import sleep
levelflag = 1
alertflag = 1
#on variable will be changed to a switch
on = 1

while on == 1:
    #Check Water level switch and deactivate if low:
    if pfio.digital_read(7) == 1:
        levelflag = 0
        alertflag = 0
        #Check switches and activate pumps/blower
        #blower
        if pfio.digital_read(0) == 1:
            pfio.digital_write(4,1)
            print ("blower on")
        else:
            pfio.digital_write(4,0)
            print ("blower off")
        #pump1
        if pfio.digital_read(1) == 1:
            pfio.digital_write(5,1)
            print ("pump1 on")
        else:
            pfio.digital_write(5,0)
            print ("pump1 off")
        #pump2
        if pfio.digital_read(2) == 1:
            pfio.digital_write(3,1)
            print ("pump2 on")
        else:
            pfio.digital_write(3,0)
            print ("pump2 off")
        #pump3
        if pfio.digital_read(3) == 1:
           pfio.digital_write(6,1)
           print ("pump3 on")
        else:
            print ("pump3 Automatic")
    
        #read temp sensor 1 and strip temp data
        tfile = open ("/sys/bus/w1/devices/28-000004cd6fed/w1_slave")
        text = tfile.read()
        tfile.close()
        secondline = text.split ("\n")[1]
        temperaturedata = secondline.split(" ")[9]
        temperature1 = float (temperaturedata[2:])
        temperature1 = temperature1 / 1000
        #Read sensor 2 and strip temperature data
        tfile = open ("/sys/bus/w1/devices/28-000004ce6524/w1_slave")
        text = tfile.read()
        tfile.close()
        secondline = text.split ("\n")[1]
        temperaturedata = secondline.split(" ")[9]
        temperature2 = float (temperaturedata[2:])
        temperature2 = temperature2 / 1000

        #Display readings from sensors
        print ("Water temp:")
        print (temperature1)
        print ("Air temp:")
        print (temperature2)

        #Read temperature setting file and isplay reading
        tfile = open ("/home/pi/settemp.txt")
        settempdata = tfile.read()
        tfile.close
        settemp = float (settempdata)
        print ("User set temp:")
        print (settemp)

        #compare temp1 (water temp) to user set temperature and print action required
        if temperature1 < settemp:
            print ("turn on heater")
            pfio.digital_write(6,1)
            sleep(1)
            pfio.digital_write(7,1)
        else:
            print ("turn off heater")
            pfio.digital_write(7,0)
            sleep(1)
            pfio.digital_write(6,0)
    elif alertflag == 0:
        print ("Water level low, pumps deactivated, sending alert")
        #Code for SMS or email alert goes here.
        pfio.digital_write(5,0)
        pfio.digital_write(3,0)
        pfio.digital_write(7,0)
        pfio.digital_write(6,0)
        pfio.digital_write(4,0)
        #update alertflag to show alert has been sent
        alertflag = 1
    else:
        sleep(5)
        print ("Water level low. System deactivated")

User avatar
nullx8
Posts: 20
Joined: Wed Jan 15, 2014 1:33 pm
Location: Bangkok, Thailand
Contact: ICQ Website Yahoo Messenger

Re: hot tub

Wed Jan 15, 2014 1:39 pm

how did you marry the DS18B20 over the PI-Face ?
could you maybe hint me in the right direction ?

i use a PI-Face for serval items on my home automation system, and really would like to use the 2 free inputs for temperature.

is it save to just solder over the pi-face pins (assuming they wont be used via the pi-face board) ?

Aesgarth
Posts: 9
Joined: Tue Jan 14, 2014 7:55 pm

Re: hot tub

Wed Jan 15, 2014 5:13 pm

nullx8 wrote:how did you marry the DS18B20 over the PI-Face ?
could you maybe hint me in the right direction ?

i use a PI-Face for serval items on my home automation system, and really would like to use the 2 free inputs for temperature.

is it save to just solder over the pi-face pins (assuming they wont be used via the pi-face board) ?
That's how i did it - soldered a wire onto the back of the piface (GPIO 4 if i remember correctly?)
here's a photo:
http://i70.photobucket.com/albums/i112/ ... f47296.jpg
both the DS18B20s are on the same wire. I really need to make a PCB for the power splitting and DS18B20 connections. As far as i know the piface will not work with a DS18B20 itself, it has to be wired via GPIO on one of the pins not used by piface. on the plus side you can connect as many (within reason) to the single GPIO pin. The sensor needs a connection to +5v, GND and a data line to gpio. The data line is linked to the +5v line with a pull up resistor (4.7k ohm in this case)

This is the guide i used to get it set up:
http://www.cl.cam.ac.uk/projects/raspbe ... mperature/

User avatar
nullx8
Posts: 20
Joined: Wed Jan 15, 2014 1:33 pm
Location: Bangkok, Thailand
Contact: ICQ Website Yahoo Messenger

Re: hot tub

Thu Jan 16, 2014 10:37 am

ah Great !
thanks to confirming this, i know about the setup for the Sensor, i was just afraid i'm gonna trash the pi-face ...
my plan was pretty much the same as you have done ... just solder on top of it ;)

and maybe remove or block the crew-in input on the pi-face to not getting any stupid ideas in 6 months while forgot of the analog usage ...

bgratch
Posts: 5
Joined: Tue Nov 05, 2013 5:05 pm

Re: hot tub

Thu Jan 16, 2014 4:41 pm

To send SMS (US only) or Email (anywhere) or even a phone call (anywhere), you can drop in this Python code and you are ready to roll. viewtopic.php?f=91&t=66588&p=487792&hilit=send+sms#p487792

Note: This can make calls to multiple recipients, so you can blast out a message to a group.

The GitHub example is here: viewtopic.php?f=91&t=66588&p=487792&hilit=send+sms#p487792

You'll need to set up a free account (to get your API key) at: http://developer.alertcaster.com - The core site is http://www.alertcaster.com

On the Alertcaster developer page (the admin panel) you can upload any audio files you want played for the phone call - e.g. different audio files for different events in your application. You just need to make sure you reference the right audio ID in the code to make the correct call.

Aesgarth
Posts: 9
Joined: Tue Jan 14, 2014 7:55 pm

Re: hot tub

Wed Jan 22, 2014 8:57 pm

Here's where i'm at with the coding so far. 3 scripts, all of which have to be running at the same time for the whole thing to work. I'm sure this isn't thebest way of doing this, but it is working. I'm also sure using files for the flags isn't the best way to work this but since i'm very new to this it will do for now.


tempmonitor.py -reads temperature sensors, compares to set temperature (from file) and flags turning on/off the heater. #commented bits are from a previous version, now redundant

Code: Select all


#initiates piface board
import piface.pfio as pfio
import RPi.GPIO as GPIO
pfio.init()
from time import sleep
#on variable will be changed to a switch
on = 1

while on == 1:
#read temp sensor 1 and strip temp data
        tfile = open ("/sys/bus/w1/devices/28-000004cd6fed/w1_slave")
        text = tfile.read()
        tfile.close()
        secondline = text.split ("\n")[1]
        temperaturedata = secondline.split(" ")[9]
        temperature1 = float (temperaturedata[2:])
        temperature1 = temperature1 / 1000
        #Read sensor 2 and strip temperature data
        tfile = open ("/sys/bus/w1/devices/28-000004ce6524/w1_slave")
        text = tfile.read()
        tfile.close()
        secondline = text.split ("\n")[1]
        temperaturedata = secondline.split(" ")[9]
        temperature2 = float (temperaturedata[2:])
        temperature2 = temperature2 / 1000

        #Display readings from sensors
        print ("Water temp:")
        print (temperature1)
        print ("Air temp:")
        print (temperature2)

        #Read temperature setting file and isplay reading
        tfile = open ("/home/pi/settemp.txt")
        settempdata = tfile.read()
        tfile.close
        settemp = float (settempdata)
        print ("User set temp:")
        print (settemp)

        #compare temp1 (water temp) to user set temperature and print action required
        if temperature1 < settemp:
            f = open ('/home/pi/tempflag', 'w')
            f.write (str('1'))
            f.close()
            #print ("turn on heater")
            #pfio.digital_write(6,1)
            #sleep(1)
            #pfio.digital_write(7,1)
        else:
            f = open ('/home/pi/tempflag', 'w')
            f.write (str('0'))
            f.close()
            #print ("turn off heater")
            #pfio.digital_write(7,0)
            #sleep(1)
            #pfio.digital_write(6,0)
switchmon.py monitors for button presses and flags accordingly. more to add to this but much of the same and i've run out of buttons.

Code: Select all

#
#Incomplete working script
#manual pump/blower controls working
#temperature controls to be added
#
#
#initiates piface board
import piface.pfio as pfio
import RPi.GPIO as GPIO
pfio.init()
from time import sleep
levelflag = 1
alertflag = 1
#on variable will be changed to a switch
on = 1

while on == 1:
    sleep (1)
    #Check Water level switch and deactivate if low:
    #if pfio.digital_read(7) == 1:
    #    levelflag = 0
    #    alertflag = 0
        #Check switches and activate pumps/blower
#blower
    if pfio.digital_read(0) == 1:
        f = open ('/home/pi/blower', 'r')
        blower = f.read()
        f.close()
        if blower == ('0'):
            f = open ('/home/pi/blower', 'w')
            f.write (str('1'))
            f.close()
            #pfio.digital_write(4,1)
            #print ("blower on")
        elif blower == ('1'):
            f = open ('/home/pi/blower', 'w')
            f.write (str('0'))
            f.close()                
            #pfio.digital_write(4,0)
            #print ("blower off")
#pump1
    if pfio.digital_read(1) == 1:
        f = open ('/home/pi/pump1', 'r')
        pump1 = f.read()
        f.close()
        if pump1 == ('0'):
            f = open ('/home/pi/pump1', 'w')
            f.write (str('1'))
            f.close()
            #pfio.digital_write(5,1)
            #print ("blower on")
        elif pump1 == ('1'):
            f = open ('/home/pi/pump1', 'w')
            f.write (str('0'))
            f.close()                
            #pfio.digital_write(5,0)
            #print ("blower off")
    #old code`   
        #if pfio.digital_read(1) == 1:
        #    pfio.digital_write(5,1)
        #    print ("pump1 on")
        #else:
        #    pfio.digital_write(5,0)
        #   print ("pump1 off")
        #
#pump2
    if pfio.digital_read(2) == 1:
        f = open ('/home/pi/pump2', 'r')
        pump2 = f.read()
        f.close()
        if pump2 == ('0'):
            f = open ('/home/pi/pump2', 'w')
            f.write (str('1'))
            f.close()
            #pfio.digital_write(3,1)
            #print ("pump2 on")
        elif pump2 == ('1'):
            f = open ('/home/pi/pump2', 'w')
            f.write (str('0'))
            f.close()                
            #pfio.digital_write(3,0)
            #print ("pump2 off")
       #
        #if pfio.digital_read(2) == 1:
        #    pfio.digital_write(3,1)
        #    print ("pump2 on")
        #else:
        #    pfio.digital_write(3,0)
        #    print ("pump2 off")
        #
#pump3

    if pfio.digital_read(3) == 1:
        f = open ('/home/pi/pump3', 'r')
        pump3 = f.read()
        f.close()
        if pump3 == ('0'):
            f = open ('/home/pi/pump3', 'w')
            f.write (str('1'))
            f.close()
            #pfio.digital_write(6,1)
            #print ("pump3 on")
        elif pump3 == ('1'):
            f = open ('/home/pi/pump3', 'w')
            f.write (str('0'))
            f.close()                
            #pfio.digital_write(6,0)
            #print ("pump3 off")
    #
        #if pfio.digital_read(3) == 1:
        #   pfio.digital_write(6,1)
        #   print ("pump3 on")
        #else:
        #    print ("pump3 Automatic")
        # 
and the bit that makes it all work... monitors the flag files and activates/deactivates the hardware:

Code: Select all


#initiates piface board
import piface.pfio as pfio
import RPi.GPIO as GPIO
pfio.init()
from time import sleep
levelflag = 1
alertflag = 1
#on variable will be changed to a switch
on = 1

while on == 1:
#if on == 1:
    #Check Water level switch and deactivate if low:
    if pfio.digital_read(7) == 1:
        levelflag = 0
        alertflag = 0
#***old switch code. now in switchmon.py
        #Check switches and activate pumps/blower
        #blower
        #if pfio.digital_read(0) == 1:
        #    pfio.digital_write(4,1)
        #    print ("blower on")
        #else:
        #    pfio.digital_write(4,0)
        #    print ("blower off")
        f = open ('/home/pi/blower', 'r')
        blower = f.read()
        f.close()
        if blower == ('1'):
            pfio.digital_write(4,1)
        elif blower ==('0'):
            pfio.digital_write(4,0)
        ##pump1
        #if pfio.digital_read(1) == 1:
        #    pfio.digital_write(5,1)
        #    print ("pump1 on")
        #else:
        #    pfio.digital_write(5,0)
        #    print ("pump1 off")
        f = open ('/home/pi/pump1', 'r')
        pump1 = f.read()
        f.close()
        if pump1 == ('1'):
            pfio.digital_write(5,1)
        elif pump1 ==('0'):
            pfio.digital_write(5,0)
        ##pump2
        #if pfio.digital_read(2) == 1:
        #    pfio.digital_write(3,1)
        #    print ("pump2 on")
        #else:
        #    pfio.digital_write(3,0)
        #    print ("pump2 off")
        f = open ('/home/pi/pump2', 'r')
        pump2 = f.read()
        f.close()
        if pump2 == ('1'):
            pfio.digital_write(3,1)
        elif pump2 ==('0'):
            pfio.digital_write(3,0)
        ##pump3
        #if pfio.digital_read(3) == 1:
        #   pfio.digital_write(6,1)
        #   print ("pump3 on")
        #else:
        #    print ("pump3 Automatic")
        f = open ('/home/pi/tempflag', 'r')
        tempflag = f.read()
        f.close()
        if tempflag == ('1'):
            pfio.digital_write(6,1)
            sleep(0.25)
            pfio.digital_write(7,1)
        elif tempflag ==('0'):
            pfio.digital_write(7,0)
            f = open ('/home/pi/pump3', 'r')
            pump3 = f.read()
            f.close
            if pump3 == ('0'):
                sleep(0.25)
                pfio.digital_write(6,0)
            elif pump3 == ('1'):
                pfio.digital_write(6,1)
#
    elif alertflag == 0:
        print ("Water level low, pumps deactivated, sending alert")
        #Code for SMS or email alert goes here.
        pfio.digital_write(5,0)
        pfio.digital_write(3,0)
        pfio.digital_write(7,0)
        pfio.digital_write(6,0)
        pfio.digital_write(4,0)
        #update alertflag to show alert has been sent
        alertflag = 1
    else:
        sleep(5)
        print ("Water level low. System deactivated")


ryanww
Posts: 1
Joined: Wed Mar 05, 2014 5:11 am

Re: hot tub

Wed Mar 05, 2014 2:35 pm

Hey,

I saw this post and figured I would chime in with what I did for my hot tub.

I used a sainsmart relay interface board to send 12v to larger omron relays (see link below). I have a 2 speed motor - just has two coils. On the sainsmart relay board, I have an 'enable' relay which will allow voltage to pass to the 'speed' relay. If the speed relay is open, it activates the first omron relay to send power to the low speed side. Then when it closes, it deactivates that relay and powers the other. That way its a bit of a fail-safe and won't power both motor coils (unless a relay goes bad and holds closed)

I also used two of the dallas temp probes. One on the heater, other in the spa. I don't have a blower and I haven't had a chance to get the light or the control panel that was pre-existing integrated.

Since I needed an interface, I decided to write a web sockets based hosted web page on the pi. It works really well. Had to thread some stuff and I used jquery mobile for the UI. it lets you set a pump on time and duration. I even made the scrip start on boot and run as a service, so you can start/stop it.

You can download the files here:
www.wiredms.com/installers/spaControllerApp.zip



Relays: http://www.ebay.com/itm/OMRON-G7L-2A-BJ ... 4d191cb12c

Aesgarth
Posts: 9
Joined: Tue Jan 14, 2014 7:55 pm

Re: hot tub

Sun Mar 23, 2014 4:32 pm

Update... I've got a PHP interface working but i don't really know PHP or HTML so it's messy and dosen't look how i want it to. Operates the hardware ok though

Code: Select all

<?php
$filename1 = '/home/pi/settemp.txt';
if (isset($_GET['settemp'])) file_put_contents($filename1, $_GET['settemp']);
$settemp = file_get_contents($filename1);
#
$filename2 = '/home/pi/pump1';
if (isset($_GET['pump1'])) file_put_contents($filename2, $_GET['pump1']);
$pump1 = file_get_contents($filename2);
#
$filename3 = '/home/pi/pump2';
if (isset($_GET['pump2'])) file_put_contents($filename3, $_GET['pump2']);
$pump2 = file_get_contents($filename3);
#
$filename4 = '/home/pi/pump3';
if (isset($_GET['pump3'])) file_put_contents($filename4, $_GET['pump3']);
$pump3 = file_get_contents($filename4);
#
$filename5 = '/home/pi/blower';
if (isset($_GET['blower'])) file_put_contents($filename5, $_GET['blower']);
$blower = file_get_contents($filename5);
#
$filename6 = '/home/pi/s1';
if (isset($_GET['current'])) file_put_contents($filename6, $_GET['current']);
$current = file_get_contents($filename6);
#
$filename7 = '/home/pi/s2';
if (isset($_GET['air'])) file_put_contents($filename7, $_GET['air']);
$air = file_get_contents($filename7);
?>

<html>
<head>
        <title>Hot tub control</title>
</head>
<body>
	<p>	
                Press F5 to update<br>
                Current Set Temperature:   <span style="color: #ff8000;"><?php echo $settemp; ?></span><br>
                Current Water Temperature: <span style="color: #ff8000;"><?php echo $current; ?></span><br>
                Current Air Temperature:   <span style="color: #ff8000;"><?php echo $air; ?></span><br>
				</form>
        </p>
        <p>
                Enter new temperature and click Submit...
        </p>
        <form method="GET" action="index.php">
                <?php echo '<input type="textarea" name="settemp" value="' . file_get_contents($filename) . "\">\n"; ?>
                <input type="submit" value="Submit">
				</form>
                Pump 1 Status: <span style="color: #ff8000;"><?php echo $pump1; ?></span><br>
				<form method="GET" action="index.php">
                <p>
<?php echo '0 <input type="radio" name="pump1" value="0" ' . (intval($pump1) == 0 ? 'checked' : '') . "><br>\n"; ?>
<?php echo '1 <input type="radio" name="pump1" value="1" ' . (intval($pump1) != 0 ? 'checked' : '') . ">\n"; ?>
                </p>
                <input type="submit" value="Submit">
				</form>
                Pump 2 Status: <span style="color: #ff8000;"><?php echo $pump2; ?></span><br>
				<form method="GET" action="index.php">
                <p>
<?php echo '0 <input type="radio" name="pump2" value="0" ' . (intval($pump2) == 0 ? 'checked' : '') . "><br>\n"; ?>
<?php echo '1 <input type="radio" name="pump2" value="1" ' . (intval($pump2) != 0 ? 'checked' : '') . ">\n"; ?>
                </p>
                <input type="submit" value="Submit">
				</form>
                Pump 3 Status: <span style="color: #ff8000;"><?php echo $pump3; ?></span><br>
                <form method="GET" action="index.php">
                <p>
<?php echo '0 <input type="radio" name="pump3" value="0" ' . (intval($pump3) == 0 ? 'checked' : '') . "><br>\n"; ?>
<?php echo '1 <input type="radio" name="pump3" value="1" ' . (intval($pump3) != 0 ? 'checked' : '') . ">\n"; ?>
                </p>
                <input type="submit" value="Submit">
				</form>
				Blower Status:  <span style="color: #ff8000;"><?php echo $blower; ?></span><br>
				<form method="GET" action="index.php">
                <p>
<?php echo '0 <input type="radio" name="blower" value="0" ' . (intval($blower) == 0 ? 'checked' : '') . "><br>\n"; ?>
<?php echo '1 <input type="radio" name="blower" value="1" ' . (intval($blower) != 0 ? 'checked' : '') . ">\n"; ?>
                </p>
                <input type="submit" value="Submit">

</body>
</html>

Ideally i want a black background with graphical power buttons that are either red or green depending on the state of whatever they're switching and + and - buttons for temperature. So far i can get the background black (though then most of my text dissapears because i can't for the life of me get that to change color (except for the bits that are already orange)

As for graphical buttons i don't know where to start :(

Frustrating since the hard bit is in theory done and working.

Tarcas
Posts: 740
Joined: Thu Jan 09, 2014 5:38 am
Location: USA

Re: hot tub

Sun Mar 23, 2014 11:06 pm

Ideally i want a black background with graphical power buttons that are either red or green depending on the state of whatever they're switching and + and - buttons for temperature. So far i can get the background black (though then most of my text dissapears because i can't for the life of me get that to change color (except for the bits that are already orange)

As for graphical buttons i don't know where to start :(
Start here.
I think it's exactly what you're looking for, as far as power buttons. It's also a good base to build on for the temperature controls. Just have the javascript read from a file, add or subtract 1 degree, and write the new value back to your control file.

Aesgarth
Posts: 9
Joined: Tue Jan 14, 2014 7:55 pm

Re: hot tub

Tue Mar 25, 2014 8:30 pm

Thanks :) That's almost exactly what i want it to look like but i'm struggling to adapt it to the way i've done things. (i need to get it to interact with my flag files rather than gpio, or i need to adapt my current PHP to use images like that instead of the radio switches it currently uses.) :|

Trouble is i don't really get PHP, and learning is taking a while since i've only got about an hour a day on a good day to throw at it, so most of the little progress i'm making i've forgotten by the next time i get to have a go at it.

on the plus side i've managed to get my CSS working - so at least the text and background colours are right on my version.

I'll get there eventually.

Edit: Also finally managed to get an FTP server working on the Pi, so i don't have to work in nano via ssh, or directly on the pi. It can sit out of the way. this should help.

User avatar
Tage
Posts: 287
Joined: Fri May 24, 2013 2:29 am
Location: St Thomas, Ontario Canada

Re: hot tub

Wed Mar 26, 2014 2:10 am

Interesting project.
I am an electrical engineer, and fairly familiar with the hazards of power electronics.
I have to STRONGLY WARN against using any relay boards bought off the internet or otherwise for projects like this!
the problem is that many relay boards I have seen are totally unfit to be used with mains voltage. the boards may contain relays that seem safe, but when you look closer you see that these relays are only intended to be used where the driving electronics is grounded, or is not accessible to a human.
Even if the relay would happen to be safe, most of the times the circuit board does not meet basic safety requirements.
the distances between traces connected to coil and traces connected to mains voltage are very short. some of these relays have pin placements that make it impossible to get enough distance between traces, so the only way to improve this is to machine slots into the circuit board (minimum 1mm wide) to make the creepage distance a bit longer.

the danger is that especially in the presence of humidity and perhaps dust, an electrical path will form across the too short distances on the circuit board or relay body, and the result can be deadly - especially when we are talking about a hot tub room and the victim being in the water and controlling buttons with wet hands! think about it...

the minimum precaution would be to make sure the relay board meets the electrical safety requirements, is mounted in a dry place, and this probably includes coating the circuit board with conformal coating to decrease the possibility that transients on the mains voltage will find its way to the control electronics and whoever is pressing the buttons.

Tarcas
Posts: 740
Joined: Thu Jan 09, 2014 5:38 am
Location: USA

Re: hot tub

Wed Mar 26, 2014 3:32 am

Trouble is i don't really get PHP, and learning is taking a while
As I recall, the java scripts use a system call to execute the gpio command from the command line. Using the format of the system call in their example, you can call any script, program, or application that you like, including one of your own creation in a language that makes more sense to you. That way all the PHP and javascript needs to do is handle the screen updating, and call other scripts that do the actual work.

Aesgarth
Posts: 9
Joined: Tue Jan 14, 2014 7:55 pm

Re: hot tub

Fri Mar 28, 2014 7:37 pm

Tage wrote:Interesting project.
I am an electrical engineer, and fairly familiar with the hazards of power electronics.
I have to STRONGLY WARN against using any relay boards bought off the internet or otherwise for projects like this!
the problem is that many relay boards I have seen are totally unfit to be used with mains voltage. the boards may contain relays that seem safe, but when you look closer you see that these relays are only intended to be used where the driving electronics is grounded, or is not accessible to a human.
Even if the relay would happen to be safe, most of the times the circuit board does not meet basic safety requirements.
the distances between traces connected to coil and traces connected to mains voltage are very short. some of these relays have pin placements that make it impossible to get enough distance between traces, so the only way to improve this is to machine slots into the circuit board (minimum 1mm wide) to make the creepage distance a bit longer.

the danger is that especially in the presence of humidity and perhaps dust, an electrical path will form across the too short distances on the circuit board or relay body, and the result can be deadly - especially when we are talking about a hot tub room and the victim being in the water and controlling buttons with wet hands! think about it...

the minimum precaution would be to make sure the relay board meets the electrical safety requirements, is mounted in a dry place, and this probably includes coating the circuit board with conformal coating to decrease the possibility that transients on the mains voltage will find its way to the control electronics and whoever is pressing the buttons.
Don't worry about that, i have it covered. The relay board (i assume you mean the PiFace) is used only for switches and providing the control power to (currently) 4 40a solid state relays for switching the mains voltage. This will all be inside a sealed IP rated box with both the mains and low voltage sides fused. The physical switches will not be within reach of anyone in the water (they're only really there to make switching things on and off for fault diagnostics easier) and i plan for any control while in the water to be done via wireless touchscreen (using the web interface i'm in the process of making) The inside of the hot tub where the current controller is housed is neither dusty or humid, though it is quite warm. keeping the relays cool may be an issue, but temperature within the control box will be monitored by a DS18B-20 at least during testing.

Tarcas wrote:
Trouble is i don't really get PHP, and learning is taking a while
As I recall, the java scripts use a system call to execute the gpio command from the command line. Using the format of the system call in their example, you can call any script, program, or application that you like, including one of your own creation in a language that makes more sense to you. That way all the PHP and javascript needs to do is handle the screen updating, and call other scripts that do the actual work.
Excellent plan... I've written some python scripts to do the switching and they work when executed manually but don't seem to work when called from PHP.... i can get php to run a test python script and get a result back but the scripts to alter the flag files don't seem to work when called by python.

Tarcas
Posts: 740
Joined: Thu Jan 09, 2014 5:38 am
Location: USA

Re: hot tub

Sat Mar 29, 2014 3:08 am

Aesgarth wrote:
Tarcas wrote:
Trouble is i don't really get PHP, and learning is taking a while
As I recall, the java scripts use a system call to execute the gpio command from the command line. Using the format of the system call in their example, you can call any script, program, or application that you like, including one of your own creation in a language that makes more sense to you. That way all the PHP and javascript needs to do is handle the screen updating, and call other scripts that do the actual work.
Excellent plan... I've written some python scripts to do the switching and they work when executed manually but don't seem to work when called from PHP.... i can get php to run a test python script and get a result back but the scripts to alter the flag files don't seem to work when called by python.
You're probably running into permissions issues then. When you execute them from the shell, are you calling them with sudo, or as root? If so, you probably need to elevate permissions also. If you're calling it with sudo already, try issuing a whoami to find out what user the script is running your python script as.

Code: Select all

<?php echo exec('whoami'); ?>
Then add that user to the sudoers file FOR THAT COMMAND ONLY. You DO NOT want to grant umbrella root access permissions to your web application, which is what just adding the user ID would do. I think what you want is the following format:

Code: Select all

www-data ALL=(root) /usr/bin/python

Return to “Automation, sensing and robotics”