Forum Replies Created

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • in reply to: Interval plugin: Auto-Program – v2 release now available! #27025

    fbret
    Member

    So I did a little instrumentation of the python code:
    print “ap zone”, str(z),” needs “, water_needed, ” – duration “, duration,”s”
    if duration < MIN_DURATION: continue # don't water too little
    duration *= gv.sd/100 # modify duration by water level if set
    if gv.sd: # sequential mode
    gv.rs[z][RS_STARTTIME] = accumulate_time
    gv.rs[z][RS_DURATION] = int(duration) # store duration scaled by water level
    accumulate_time += int(duration)
    gv.rs[z][RS_STOPTIME] = accumulate_time
    accumulate_time += gv.sd # add station delay
    gv.rs[z][RS_PROGID] = autoPid # store program number for scheduling
    gv.ps[z][PS_PROGID] = autoPid # store program number for display
    gv.ps[z][PS_DURATION] = int(duration)
    print “ap zone”, str(z),” starting “,gv.rs[z][RS_STARTTIME], ” – duration “, duration,”s – end itme:”,accumulate_time

    The output is then:
    pi@sprinkler ~/OSPi $ sudo python ospi.py
    sudo: unable to resolve host sprinkler
    Setting water level to 90%
    2014-08-11 Getting rainfall history…
    auto_program: job scheduled runAutoProgram (trigger: cron[hour=’5′, minute=’0′], next run at: 2014-08-12 05:00:00)
    plugins loaded:

    Starting timing loop

    http://0.0.0.0:8080/
    192.168.1.20:59181 – – [11/Aug/2014 16:16:49] “HTTP/1.1 GET /auto” – 200 OK
    auto_program starting automatic program loop
    ap zone 0 needs 0.5 – duration 1200.0 s
    ap zone 0 starting 1407774056 – duration 0.0 s – end itme: 1407774056
    ap zone 1 needs 0.5 – duration 1200.0 s
    ap zone 1 starting 1407774056 – duration 0.0 s – end itme: 1407774056
    ap zone 2 needs 0.5 – duration 1200.0 s
    ap zone 2 starting 1407774056 – duration 0.0 s – end itme: 1407774056
    ap zone 3 needs 0.5 – duration 1200.0 s
    ap zone 3 starting 1407774056 – duration 0.0 s – end itme: 1407774056
    ap zone 4 needs 0.5 – duration 1200.0 s
    ap zone 4 starting 1407774056 – duration 0.0 s – end itme: 1407774056
    ap zone 5 needs 0.5 – duration 1200.0 s
    ap zone 5 starting 1407774056 – duration 0.0 s – end itme: 1407774056
    ap zone 6 needs 0.5 – duration 1200.0 s
    ap zone 6 starting 1407774056 – duration 0.0 s – end itme: 1407774056
    ap zone 7 needs 0.5 – duration 1200.0 s
    ap zone 7 starting 1407774056 – duration 0.0 s – end itme: 1407774056

    Why is duration set to 0? It seems

    duration *= gv.sd/100                     # modify duration by water level if set

    Further debugging shows water level = 90…
    so I changed the line to:

    duration *= 1.0*gv.sd/100 

    issue looks fixed now… 🙂

    in reply to: Interval plugin: Auto-Program – v2 release now available! #27024

    fbret
    Member

    Scott, thanks for the support!

    I did a git pull just to be sure!

    Rain sensor is not enabled in the options tab.

    Here’s the log running it from console:
    pi@sprinkler ~/OSPi $ sudo python ospi.py
    sudo: unable to resolve host sprinkler
    Checking rain status…
    No rain detected
    Setting water level to 90%
    2014-08-11 Getting rainfall history…
    auto_program: job scheduled runAutoProgram (trigger: cron[hour=’5′, minute=’0′], next run at: 2014-08-12 05:00:00)
    plugins loaded:

    Starting timing loop

    http://0.0.0.0:8080/
    auto_program starting automatic program loop
    192.168.1.20:59077 – – [11/Aug/2014 15:57:52] “HTTP/1.1 GET /rap” – 303 See Other
    192.168.1.20:59077 – – [11/Aug/2014 15:57:57] “HTTP/1.1 GET /” – 200 OK
    192.168.1.20:59078 – – [11/Aug/2014 15:57:57] “HTTP/1.1 GET /api/status” – 200 OK
    192.168.1.20:59077 – – [11/Aug/2014 15:57:57] “HTTP/1.1 GET /api/log” – 200 OK
    192.168.1.20:59077 – – [11/Aug/2014 15:57:58] “HTTP/1.1 GET /api/status” – 200 OK
    192.168.1.20:59077 – – [11/Aug/2014 15:57:59] “HTTP/1.1 GET /api/status” – 200 OK
    192.168.1.20:59077 – – [11/Aug/2014 15:58:00] “HTTP/1.1 GET /api/status” – 200 OK
    192.168.1.20:59077 – – [11/Aug/2014 15:58:01] “HTTP/1.1 GET /api/status” – 200 OK

    nothing 🙁


    fbret
    Member

    Thanks!

    here are a few attachments…

    – zone settings seems to meet your requirement.
    – auto-program looks enabled and valid.

    When I click “run auto program now”, I get redirected to the OpenSprinkler Pi home page.
    If I go into the programs page, there are 0 programs showing and the calendar in the home page shows no scheduled plan for the next 48 hrs…

    It’s probably something real obvious!!!


    fbret
    Member

    So I installed your excellent auto-plugin a week ago…
    I did have an issue with apscheduler that I had to downgrade to 2.
    I did remove all scheduling constraints and everything looks great – except that the auto-scheduler never turned a single valve on all week. Being that I am in California and it has not rained in a couple of months, that’s very surprising!

    How do I diagnose / see that the scheduler is working? It seems that it is calculating the deficit accurately, but nothing shows up in the calendar or the logs.

    Thanks

    -Fred

    in reply to: sprinklers_pi & authentication #27096

    fbret
    Member

    If you set up ssl, the url sould be https://[ip]
    The “s” is the key!

    in reply to: sprinklers_pi & authentication #27094

    fbret
    Member

    Ok, here are the gory details! btw, I think WB50 is asking about the standard opensprinkler software… this is not about it but instead for the alternate software called sprinklers_pi. Most of my howto should be applicable to the default software, but I have not tested.

    1st, we want to configure apache as a proxy. This is important for several reasons:

    • while sprinklers_pi is an excellent web server, it is extremely limited in it’s support of the http protocol. Adding support for authentication or SSL would be serious work.
    • as I intend to have this device internet accessible, I trust apache infinitely more than I trust the sprinklers_pi code. Rich Z, I hope you do not take offense, but being a coder myself, I’m pretty sure you would agree with my statement!
    • why reinvent the wheel? Apache is the software running 40% of the sites on the internet.
    • Apache is infinitely configurable.

    I will assume you know how to ssh to the device.

    To verify that you have apache2 installed:

    sudo apt-get install apache2

    Now enable the proxy module:


    sudo a2enmod proxy_http
    sudo a2enmod rewrite
    sudo service apache2 restart

    Now, create the virtual host that will proxy the sprinklers_pi site:


    sudo nano /etc/apache2/sites-enabled/000-default

    The file should have the following content:



    LogLevel warn

    ProxyRequests On
    ProxyPass / http://127.0.0.1:8080/

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Now restart apache:


    sudo service apache2 restart

    Now verify that the proxy works by opening http://[IP of rPi]. It should behave identically to http://[IP of rPi]:8080

    Congratulations, you have successfully set up the proxy.

    Let’s move on to authentication. If you don’t care about authentication, you can skip the following.
    First, let’s create a password file that will contain all user names and passwords allowed to log onto the web site. I decided to call my user “admin” and store the password file in the home directory:


    pi@sprinkler ~ $ htpasswd -c /home/pi/.htpasswd admin
    New password:
    Re-type new password:
    Adding password for user admin
    pi@sprinkler ~ $

    Edit your apache config once more:


    sudo nano /etc/apache2/sites-enabled/000-default

    It should look like this once you added the location block:



    LogLevel warn

    AuthType Basic
    AuthName "OpenSprinkler"
    AuthUserFile /home/pi/.htpasswd
    Require valid-user


    ProxyRequests On
    ProxyPass / http://127.0.0.1:8080/

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Test again that the proxy works by opening http://[IP of rPi]. It should now ask for credentials first.
    But remember the site on port 8080? You did not block direct access to it. So going to http://[IP of rPi]:8080 should still allow you to anonymously access the sprinkler site. 🙁
    It might be ok. If for example you want to have internet access to the apache site where you need authentication, but still provide anonymous access when you are on the local network. If that’s not ok, we are going to block access to the 8080 site:

    We are going to have to edit the source code of sprinklers_pi and recompile it:


    cd sprinklers_pi/
    nano port.cpp

    Search for (should be on line 103):


    sin.sin_addr.s_addr = INADDR_ANY;

    and replace with:


    sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

    Save the file. The build and install:


    make
    sudo make install
    sudo /etc/init.d/sprinklers_pi restart

    Test again! Now, http://[IP of rPi] should work fine and require authentication, but http://[IP of rPi]:8080 should not respond.

    Now, the final part: turn the proxy to https…

    We’ll have to:

    • create an SSL certificate
    • allow apache to run over https
    • do some translation of the page

    Creation of the SSL certificate:


    cd ~
    openssl req -nodes -new -x509 -keyout server.key -out server.cert

    Fill out all the properties when prompted by openssl.

    Now enable SSL:


    sudo a2enmod ssl

    Edit the config:


    sudo nano /etc/apache2/sites-enabled/000-default

    It should look like this:




    LogLevel warn

    SSLEngine On
    SSLCertificateFile /home/pi/server.cert
    SSLCertificateKeyFile /home/pi/server.key


    AuthType Basic
    AuthName "OpenSprinkler"
    AuthUserFile /home/pi/.htpasswd
    Require valid-user


    ProxyRequests On
    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Now restart apache:


    sudo service apache2 restart

    Now i’m stuck! all pages have references to http://code.jquery.com/. This needs to be converted to https://code.jquery.com/. I’m pretty sure one can do it with the apache mod_rewrite, but I failed… so my (ugly) workaround:


    cd ~/sprinkler_pi/web
    find . -name "*.htm" -print | xargs sed -i 's/http:/https:/g'
    cd ~/sprinkler_pi
    make
    sudo make install
    sudo /etc/init.d/sprinklers_pi restart

    You now have a perfectly functional https site with authentication that is appropriate to NAT through your firewall.

    Enjoy!

    -Fred

Viewing 6 posts - 1 through 6 (of 6 total)