Jump to content

Recommended Posts

Posted

I'm going to use an orange Pi zero to make a thermostat adjustable via lan; do you know how to point me to some easy to apply project?
I tried several projects, with ds1820b sensors and relais card for raspberry, but I have problems for example with the libraries RPi.GPIO because they do not match those OPi.GPIO.

I can currently turn the relays on and off with an android app or via terminal command.

Posted
46 minutes ago, FRANK333 said:

but I have problems for example with the libraries RPi.GPIO because they do not match those OPi.GPIO.

Provide details about errors/discrepancies you found between those 2 libs.

 

Posted

All right, now I do a clean installation and I start again, then I let you know. but I had decommented a few lines but the software did not start.Do you have any simple project to start from?

 

 

Posted
10 minutes ago, FRANK333 said:

Do you have any simple project to start from?

What do you mean ? Simple project to test this GPIO library ? Simple blinking LED on PA10 for example :

#!/usr/bin/python

import sys, time
from pyA20.gpio import gpio
from pyA20.gpio import port

gpio.init()

gpio.setcfg(port.PA10, gpio.OUTPUT)

while True:
	gpio.output(port.PA10, gpio.LOW)
	time.sleep(0.25)
	gpio.output(port.PA10, gpio.HIGH)
	time.sleep(0.25)

 

Posted

I'm looking for a software that through a web page (or an android app) makes the Opi 0 work as a thermostat or at least a software sketch. As for the test program I'll try, but that library is for A20 I have an H2 will work ?

 

Posted
11 minutes ago, FRANK333 said:

but that library is for A20 I have an H2 will work ?

The link I've provided is a port of the pyA20 library to H3, and H2 is equivalent to H3.

12 minutes ago, FRANK333 said:

I'm looking for a software that through a web page

There is the HTTPServer library part of standard python, but you will have to learn a lot about it. I'm using it to produce Web interfaces.

Posted

Martin, I installed the library and your test works. When I try to insert an if else line, the script doesn't work.

Spoiler

#!/usr/bin/env python

import os
import sys
if not os.getegid() == 0:
    sys.exit('Script must be run as root')


from time import sleep
from pyA20.gpio import gpio
from pyA20.gpio import port
from pyA20.gpio import connector

 

REL = port.PA0
maxTemp = 22

gpio.init()
gpio.setcfg(REL, gpio.OUTPUT)

while 1:
    #open the file for the sensor and read contents
    tempfile = open("/sys/bus/w1/devices/28-8000001f9605/w1_slave")
    thetext = tempfile.read()
    tempfile.close()
    #get the temperature
    tempdata = thetext.split("\n")[1].split(" ")[9]
    temperature = float(tempdata[2:])
    temperature = temperature / 1000
    #print out the temperature
    print temperature
    #switch the relays if temperature above maxTemp

while True:
       if temperature > maxTemp:
        gpio.output(REL, 0)

       else:
        gpio.output(REL, 1)

What's wrong? I don't know anything about Python ,I'm sorry.

Posted
1 hour ago, FRANK333 said:

What's wrong? I don't know anything about Python ,I'm sorry.

Indentation of line of code is important in Python !

Seeing your code above, the second "while" is not indented, so it never been executed since outside of the first one.

Lets rewrite your code here without second "while", since it is useless, but adding a delay of 30 seconds :

 

bad spoiler ...

 

 

#!/usr/bin/env python

import os
import sys
if not os.getegid() == 0:
    sys.exit('Script must be run as root')


from time import sleep
from pyA20.gpio import gpio
from pyA20.gpio import port
from pyA20.gpio import connector

 

REL = port.PA0
maxTemp = 22

gpio.init()
gpio.setcfg(REL, gpio.OUTPUT)

while 1:
    #open the file for the sensor and read contents
    tempfile = open("/sys/bus/w1/devices/28-8000001f9605/w1_slave")
    thetext = tempfile.read()
    tempfile.close()
    #get the temperature
    tempdata = thetext.split("\n")[1].split(" ")[9]
    temperature = float(tempdata[2:])
    temperature = temperature / 1000
    #print out the temperature
    print temperature
    #switch the relays if temperature above maxTemp

    if temperature > maxTemp:
        gpio.output(REL, 0)

    else:
        gpio.output(REL, 1) 

    sleep(30)

[/spoiler]

 

I've not tested it, but it should now work ...

 

Posted

here is the error it returns, it seems that I can't find the variable maxTemp, and yet I defined it with       maxTemp = 22

 

root@orangepizero:~# python test.py
  File "test.py", line 32
    if temperature > maxTemp:
                            ^
IndentationError: unindent does not match any outer indentation level
root@orangepizero:~# python -m tabnanny test.py
'test.py': Indentation Error: unindent does not match any outer indentation level (<tokenize>, line 32)
root@orangepizero:~#

 

 

Posted

    if temperature > maxTemp:
 

Remove that colon
Not that. I don't know python. I've got no idea.
My programming must have a semicolon on the end. I can't get used to seeing Python,
 

Posted
14 hours ago, FRANK333 said:

IndentationError: unindent does not match any outer indentation level

That is what I said earlier, indentation is critical ...

Did you take back my version ? It doesn't seems to, because the "if" in my version is located at line 29 ...

Posted

Okay Martin I solved was just a tabulation problem as I could tell from your example. Now the rudimentary thermostat works, I would like to make sure that it remains in operation as a daemon, insert different temperatures at different times of the day, and finally make a decent GUI. But the road is uphill....

 

Spoiler

#!/usr/bin/env python
import os
import sys
if not os.getegid() == 0:
    sys.exit('Script must be run as root')

from time import sleep
from pyA20.gpio import gpio
from pyA20.gpio import port
from pyA20.gpio import connector

REL = port.PA0
maxTemp = 22

gpio.init()
gpio.setcfg(REL, gpio.OUTPUT)
#gpio.output(REL, 1)
while 1:
    #open the file for the sensor and read contents
    tempfile = open("/sys/bus/w1/devices/28-8000001f9605/w1_slave")
    thetext = tempfile.read()
    tempfile.close()
    #get the temperature
    tempdata = thetext.split("\n")[1].split(" ")[9]
    temperature = float(tempdata[2:])
    temperature = temperature / 1000
    #print out the temperature
    print temperature
    #switch the relays if temperature above maxTemp
    if temperature > maxTemp:
            gpio.output(REL, 0)
    else:
            gpio.output(REL, 1)
sleep(1)

 

Posted

ok I corrected and added the lines to make the script a daemon, I noticed however that if I kill the script (kill 1234) or if I block the OPI0 the relays card remains in the last state in which it is, how could you do to reset it to off?

Spoiler

#!/usr/bin/env python
import os
import sys
if not os.getegid() == 0:
    sys.exit('Script must be run as root')

from time import sleep
from daemonize import Daemonize
from pyA20.gpio import gpio
from pyA20.gpio import port
from pyA20.gpio import connector

REL = port.PA0
maxTemp = 22

gpio.init()
gpio.setcfg(REL, gpio.OUTPUT)

pid = "/tmp/test.pid"

def main():
    while 1:
        #open the file for the sensor and read contents
        tempfile = open("/sys/bus/w1/devices/28-8000001f9605/w1_slave")
        thetext = tempfile.read()
        tempfile.close()
    #get the temperature
        tempdata = thetext.split("\n")[1].split(" ")[9]
        temperature = float(tempdata[2:])
        temperature = temperature / 1000
    #print out the temperature
        print temperature
    #switch the relays if temperature above maxTemp
        if temperature > maxTemp:
                gpio.output(REL, 0)
        else:
                gpio.output(REL, 1)
        sleep(1)

daemon = Daemonize(app="test_app", pid=pid, action=main)
daemon.start()

 

Posted

I tried to add at the end of the script, these 4 lines :

 

def signal_term_handler(signal, frame):

    print 'got SIGTERM'

    sys.exit(0)

signal.signal(signal.SIGTERM, signal_term_handler)

 

but the relays maintain the status, even after the kill command.

Posted
5 minutes ago, FRANK333 said:

but the relays maintain the status, even after the kill command.

While doing the kill, did you got the "got SIGTERM" ?

If yes, you should add "gpio.output(REL, 0)" just after the print and before the "sys.exit(0)" ...

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines