OpenSprinkler Forums Hardware Questions OpenSprinkler Pi (OSPi) Starting ospi.py automatically

  • This topic is empty.
Viewing 25 posts - 1 through 25 (of 43 total)
  • Author
    Posts
  • #22515

    mickeyshowers
    Participant

    OK. I have edited /etc/rc.local to look like this

    host=$(hostname -I | sed ‘s/ *$//g’)
    port=:80
    cd /home/pi/OSPi/
    /usr/bin/python ospi.py $host$port

    but when I reboot, I get an error that says:

    File “/home/pi/OSPi/web

    ValueError: :80 is not a valid ip address

    If I change rc.local back, I can start ospi.py manually just fine. I’m a linux beginner, so be gentle. Thanks!

    #24686

    ITDawg
    Member

    Sounds like your RPi is not getting an IP address or it is not getting one in time for the script… Before the “host=…” line, add “sleep 60” on a new line and see what that does…

    I had that same issue and that’s my current work around…

    #24687

    mickeyshowers
    Participant

    Thanks, I’ll try that tonight when I get home. I’m wondering if there isn’t something else going on too. I can’t look at it now but it seems to me that I remember seeing 0.0.0.0 returned after I kick off ospi.py even though I have verified that it does indeed have an IP and I can get to the page.

    #24688

    Samer
    Keymaster

    0.0.0.0 means its listening on all available IP addresses. This behavior is fine so long you don’t have multiple IPs bound to the same NIC.

    #24689

    kkpwrh2o
    Member

    Had the same problem.

    Did this, Before the “host=…” line, add “sleep 60” on a new line and see what that does…

    Failed with this

    socket.error: No socket could be created

    Suggestions appreciated

    Thanks,
    Kevin

    #24690

    Samer
    Keymaster

    Something is using that port, typically. To help diagnose we would need the port your using for your interval program and then make sure you don’t have anything else running on that port (HTTPd such as Apache run on port 80).

    Also, if you are trying to use port 80 it’s possible you don’t have privileges to open that port.

    #24691

    kkpwrh2o
    Member

    The only port I have been using is port 80 for the OSPi. Is there more than one somewhere else I need to configure?

    Not sure what else is running on the port. The router is setup by mac addr for the RSPi on port 80.

    BTW, during boot up I see the line

    Starting web server: apache2apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

    It has ok on the line following so I guess it is good to go?

    #24692

    Samer
    Keymaster

    Okay so you are using the same port twice based on what you said. You need to resolve it using one of the following ways:

    Use port 8080 for the interval program:

    I assume: your end goal is to get the mobile app working from anywhere, correct?
    If so, you want the interval program to launch with port 8080 and leave Apache to continue doing it’s thing.
    You would use your RPi’s LAN IP and the port 8080 when installing.

    Disable Apache:

    If your goal is to access the interval program from anywhere and subsequently have the ability to use Ray’s hosted mobile app, which also works anywhere than you can just disable Apache.
    This can be done by removing it from runtime, uninstalling it, or changing it’s port.

    #24693

    kkpwrh2o
    Member

    Correct. My goal is to have the mobile app work from anywhere.

    Tried both 80 and 8080

    host=$(hostname -I | sed 's/ *$//g')
    port=:80
    cd /home/pi/OSPi/
    /usr/bin/python ospi.py $host$port

    Both resulted in

    ValueError: :80 is not a valid ip address

    respectively

    #24694

    Andrew
    Participant

    As a related side note on this, if you want to know what is using what ports run

    sudo netstat -anp --ip

    You are mainly going to be interested in the listening TCP sockets so if you wish to ignore the rest:

    sudo netstat -anp --ip | grep LISTEN

    E.g. this example shows a Raspberry Pi running only ospi (python) and sshd for remote connections:

    tcp        0      0 192.168.26.15:80        0.0.0.0:*               LISTEN      7324/python
    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2279/sshd

    The first set of addresses will tell you the IP and port (like 192.168.26.15:80 or 0.0.0.0:22 above), then second should always be 0.0.0.0:* because listening sockets are not connected to anything yet, and the end part tells you the process ID and process name of what is listening on that port (python running ospi.py is listening on port 80 above).

    A busier server could have a lot more things running on it like this (notice apache on port 80 at the end):

    tcp        0      0 0.0.0.0:34355           0.0.0.0:*               LISTEN      -
    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 772/sshd
    tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 19913/master
    tcp 0 0 0.0.0.0:41119 0.0.0.0:* LISTEN 655/rpc.statd
    tcp 0 0 0.0.0.0:993 0.0.0.0:* LISTEN 1674/perdition.imap
    tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 9831/nrpe
    tcp 0 0 0.0.0.0:5667 0.0.0.0:* LISTEN 1221/nsca
    tcp 0 0 0.0.0.0:37 0.0.0.0:* LISTEN 2611/xinetd
    tcp 0 0 0.0.0.0:3493 0.0.0.0:* LISTEN 1537/upsd
    tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 32358/mysqld
    tcp 0 0 0.0.0.0:587 0.0.0.0:* LISTEN 19913/master
    tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 665/pop3-login
    tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 941/imap-login
    tcp 0 0 0.0.0.0:4559 0.0.0.0:* LISTEN 1113/hfaxd
    tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 605/portmap
    tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4439/apache2
    #24695

    Andrew
    Participant

    If both returned

    ValueError: :80 is not a valid ip address

    then you didn’t have it set to try port 8080 on either attempt.

    Could you post the output of

    sudo netstat -anp --ip | grep LISTEN

    And also, do you need apache? If not i suggest disabling or uninstalling it.

    #24696

    kkpwrh2o
    Member

    Good info. Thanks!

    This is what I have for port 80

    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2091/apache2
    #24697

    Andrew
    Participant

    So run:

    sudo service apache2 stop

    (I don’t have apache installed so the service name may be slightly different. Press the tab key twice after typing sudo service to get a list of possibilities.)
    Apache will start on the next boot after this though in case you still need it.

    If you don’t need apache then

    sudo apt-get remove apache2

    will remove it from your system.

    #24698

    kkpwrh2o
    Member

    looking at the out put of

    sudo netstat -anp --ip

    I also notice the IP 10.0.1.21 for the RSPi in this line

    udp        0      0 10.0.1.21:123             0.0.0.0:*                          2212/ntpd
    #24699

    Samer
    Keymaster

    @aradke He wants Apache for the mobile web app. That’s why he installed it to begin with, I believe.

    The better goal is to leave interval on default 8080. Use Apache on normal 80 and use the already existing port forward.

    #24700

    kkpwrh2o
    Member

    So I deleted apache and set rc.file to 8080 and rebotted.

    So looks like the main loop is looping

    http://10.0.1.21:8080

    Resulting in what appear to be a loop every 30 seconds or so with my RPi IP the time and date along with…

     GET /sn0 - 200 OK

    over and over (with different time of course)

    Is that what it is supposed to look like. Cant get the mobile app up as I did before the above changes.

    #24701

    Andrew
    Participant

    My apologies that I missed the desire for the web app for which you will need apache or another web server.

    The problem you had is that you hadn’t changed the port to 8080 for ospi.py and it couldn’t use port 80 which was already in use by apache. Only one thing can ever use a port on one machine at the same time.

    Your last post shows that you do now have ospi.py running on port 8080. Before doing anything else make sure you can access the OSPi on http://10.0.1.21:8080/ and only if that works reinstall apache with

    sudo apt-get install apache2

    By the way, a lesson here from a sysadmin is not to perform multiple steps and tasks at once since you won’t know which one caused or fixed the problem. And verify every step along the way. By uninstalling apache and changing the port to 8080 /etc/rc.local you will create confusion for yourself as to which did what. In this case you removed apache from running on port 80 and moved ospi.py to port 8080 at the same time. This allows ospi.py to now run but leaves you with nothing running on port 80 rather than two things competing for it.

    #24702

    kkpwrh2o
    Member

    Thanks for all the help guys. Much appreciated.

    I think I am missing a key bit of info.

    The only place I know that I am inputing port info is in the rc.local file

    port=:8080

    is that the way one changes the port for ospi.py?

    When I re-install apache, where then is the port 80 entered and how?

    I’ll wait to hear back so as to follow the advice and do one thing at a time so as to not confuse things further.

    Thanks!

    #24703

    Andrew
    Participant

    Apache will default to port 80 because that is the assigned port for http.

    And the line from /etc/rc.local with the port is the only place you need to specify it for ospi.py. Your previous post showing the following indicates that you have that set correctly:

     http://10.0.1.21:8080
    #24704

    kkpwrh2o
    Member

    Re installed apache

    resulting in

    ValueError: 8080 is not a valid IP addr/port

    [FAIL] startpar: service(s) returned failure: rc.local ... failed!

    netsat results after apache re-install with resulting failure above:

    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2082/apache2
    udp        0      0 10.0.1.21:123             0.0.0.0:*                          2203/ntpd

    Seems like the rc.local file is looking for an IP addr?

    #24705

    kkpwrh2o
    Member

    running manually by

    $ cd OSPi

    sudo python ospi.py

    result

    Starting main loop

    From my iMac pointed browser to

    http://10.0.1.21:8080

    result: Appears to go to Open Sprinkler Web App Yes!!!!!!
    Now if we can figure out how to have it run automatically and me figure out the App password, we will be golden.
    On the RPi screen I can see the various msgs come up from inputs on the App from my other computer. Cool

    #24706

    kkpwrh2o
    Member

    Figured out the password operation and how to change it.

    Customized my sprinkler configuration, GMT time, and zip code. Was able to save all and have it display. So that is working great.

    Only thing left is to have it run automatically.

    #24707

    Andrew
    Participant

    Can you post the entire contents of you /etc/rc.local file?

    I’ve just done a little digging to check and if you don’t specify either the ip address or port it will default to 0.0.0.0:8080 which is perfect for what you want, and hence why it runs perfectly from the command line for you. This would then be a solution for you but it is very bad practice because when you come back to it in a month or two’s time it will not be obvious what port ospi.py is running on or why it is there. And of course it would be far better to find out what is going on for you anyway! 🙂

    #24708

    kkpwrh2o
    Member

    aradke, Thanks a bunch for your continued assistance. I appreciate it greatly.

    Below is my rc.local file.

    #!/bin/sh -e
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "exit 0" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.

    # Print the IP address
    _IP=$(hostname -I) || true
    if [ "$_IP" ]; then
    printf "My IP address is %sn" "$_IP"
    fi
    host=$(hostname -I | sed 's/ *$//g')
    port=:8080
    cd /home/pi/OSPi/
    ## If you aren't sure that the path to python on your Pi is /usr/bin/, use $
    /usr/bin/python ospi.py $host$port
    exit 0

    #24709

    Michael
    Member

    Any reason nobody is suggesting adding a “&” after they start the python script in RC?local?

    I start it like this…

    /usr/bin/python ospi.py $host$port &

    That way it is sent to the background and rc.local gets to actually terminate. This is key since I also have a script that checks my wireless connection every five minutes to make sure it is up. I run that from rc.local also with a & ..

Viewing 25 posts - 1 through 25 (of 43 total)
  • You must be logged in to reply to this topic.

OpenSprinkler Forums Hardware Questions OpenSprinkler Pi (OSPi) Starting ospi.py automatically