WeatherFlow PiConsole - Archive

peter…

GREAT - thanks for the insight.

It would be great to have a persistent *.ini file through updates, but it really isn’t a big deal to modify it with each update. Perhaps I have it a bit easier - as I have both of my piconsole monitors with SMB enabled - so I can just pull up the files with my favorite windows text editor (Notepad+) and cut-a-paste in my settings. Adding the ‘Feels Like’ settings along with that would be as easy. But making it even easier would be fantastic.!

I do modify several files each time you do an update, on my large screen piconsole - because of the layout and large screen format. I’ve got it down to where I can make all the changes in just a few minutes. What takes the time is trying to find what you might have changed that is not obvious? ie I noticed changes in the clock format / layout / syntax in the last version 1.8. I prefer a 12H format (more really for my wife). Adding that option would also be welcomed.
image

Hi Peter - I have a bash script that takes care of checking for / pulling updates and updating the parameters in the .ini file. I’m happy to post it, if you’re interested.

Rick Comito

2 Likes

Hi Rick,

Yea would be good to see what approach you have taken. I am working on a solution in Python that when the console is run for the very first time, will prompt you to enter API keys. etc directly into the console, and which will then be copied to the .ini file. Then for every new version update the code will compare your existing .ini file against a default version, transferring keys across as necessary, and perhaps asking for input if new keys are required.

Peter - Your solution sounds much more refined than mine.

I can’t figure out how to include a code block in this forum so I’ve attached it as a .txt file.

WFconsole.txt (5.7 KB)

Rename WFconsole.txt to WFconsole and push it to your PiConsole machine.

Maybe you can find something useful in it.

Rick Comito

to add some code you have to set 3 back tick before and behind the code, forum will set it as code (take out the double quotes as I had to set those to ‘hide’ the back ticks to the forum)

" ``` "
your code

" ``` "

1 Like

Peter, I keep configuration files in their own folder. I use a template file that I can update with new keys and save the users configuration to a working file that is read by the applications. You can see how this works by looking at config.ejs and server.js.

You are welcome to download and use any and all portions of my install.sh and updatefiles.sh scripts. And I am happy to answer any questions you may have.

2 Likes

Thanks Eric - Let’s try this again.

#!/usr/bin/env bash
#
# WFconsole             20181117 Rick Comito
#
# WeatherFlow console tool
#
# Install this script somewhere in your $PATH and make it executable:
#     e.g.: sudo mv WFconsole /usr/local/bin
#           sudo chmod 755 /usr/local/bin/WFconsole
#
#
# Assumes: Peter's WeatherFlow PiConsole software is installed in default location
#          Software will be started on boot with an entry in user pi's crontab sim
#              @reboot sleep 30; /usr/local/bin/WFconsole start
#                           or
#          Software is run as a service via systemctl:
#              sudo cp WeatherFlowPiConsole.service /etc/systemd/system/
#              sudo systemctl enable WeatherFlowPiConsole.service
#
# Usage: WFconsole <start|stop|restart|status|update>"
#
# WFconsole update updates the software preserving your WeatherFlowPiConsole.ini p
#
# ssh into your console to run the script.

USAGE="usage: WFconsole <start|stop|restart|status|update>"
if [ $# -eq 0 ]; then
    echo $USAGE
    exit
fi
CONSOLEDIR=~/wfpiconsole                # Default home of the console software
DLDIR=${CONSOLEDIR}/download            # Directory to download (potential) update
INI=WeatherFlowPiConsole.ini            # File with API keys etc.
PIDn=$(pgrep -f main.py | wc -l)

# wanisup - Returns 0 if we have an internet connection, 1 if not.
wanisup() {
    ping -c1 www.google.com >> /dev/null && return 0 || return 1
}

# gotinternet - Makes maxtrys trys to verify an internet connection with waittime
# Returns 0 on success, 1 on failure
gotinternet() {
    waittime=5  # Seconds
    maxtrys=12  # 1 minute
    thistry=1

    while [ ! wanisup -a $thistry -le $maxtrys ]; do    # Verify / wait for an int
        echo "Waiting for an internet connection ..."
        thistry=$(thistry + 1)
        sleep $waittime
    done

    return $(wanisup)
}

# isaservice - Returns 0 if console is running as a service.
isaservice () {
    systemctl | grep WeatherFlowPiConsole.service | grep enabled >> /dev/null && r
}

# startconsole - Start an instance of the console
startconsole () {
    if [ isaservice ]; then
        sudo systemctl start WeatherFlowPiConsole.service
    else
        cd $CONSOLEDIR
        python3 ./main.py 2>&1 /dev/null &
    fi
}

# stopconsole - Stop the console
stopconsole () {
    if [ isaservice ]; then
        sudo systemctl stop WeatherFlowPiConsole.service
    else
        pkill -HUP -f main.py
    fi
}

# updateini - Use the current INI to update the keys etc in the new one.
updateini () {
    grep "= [a-zA-Z0-9]" $CONSOLEDIR/$INI | grep -v Version |
    while read NAME EQ VALUE; do
        sed -i "/^$NAME =.*/s/.*/$NAME = $VALUE/" $DLDIR/$INI
    done
}

# updateconsole - Apply an update to the console if one is available
updateconsole () {
    if [ ! -d $DLDIR ]; then
        mkdir $DLDIR
    fi
    cd $DLDIR
    # Get the latest available software
    wget -q https://api.github.com/repos/peted-davis/WeatherFlow_PiConsole/tarball
    # and extract it from the compressed tarball
    tar -xvf PiConsole.tar.gz --strip 1 1>&2 >> /dev/null
    rm PiConsole.tar.gz
    # Get the version from the current INI file ...
    currentversion=$(grep Version $CONSOLEDIR/$INI | sed 's/ =/:/')
    # ... and the latest version from the downloaded INI file
    latestversion=$(grep Version $INI | sed 's/ =/:/')
    if [[ $currentversion != $latestversion ]]; then
        echo "Current $currentversion"
        echo "Latest  $latestversion"
        read -p "Update? <y/n> " -n 1 response
        echo
        case $response in
            y|Y)
                cd ~
                # Update the new INI file
                updateini
                stopconsole
                # rsync will update the files that have changed and remove deprica
                rsync -Halz --delete-after ${DLDIR}/ $CONSOLEDIR
                startconsole
                ;;
            *)
                echo "Update aborted."
                ;;
        esac
    else
        echo "Current $currentversion"
        echo "Latest  $latestversion"
        echo "No update needed"
    fi
    cd ~
    rm -rf $DLDIR
}


if [ gotinternet ]; then
    case $1 in
        start)
            if [ $PIDn -eq 1 ]; then
                echo Console running
            elif [ $PIDn -gt 1 ]; then
                echo "Restarting (PIDn: $PIDn)"
                stopconsole
                startconsole
            else
                echo Starting console
                startconsole
            fi
            ;;
        stop)
            if [ $PIDn -gt 0 ]; then
                echo Stopping console
                stopconsole
            else
                echo Console stopped
            fi
            ;;
        restart)
            echo Stopping console
            stopconsole
            echo Restarting console
            startconsole
            ;;
        status)
            if [ $PIDn -eq 0 ]; then
                echo Console stopped
            elif [ $PIDn -eq 1 ]; then
                echo Console running
            else
                echo "PIDn: $PIDn ... Restarting"
                stopconsole
                startconsole
            fi
            ;;
        update)
            updateconsole
            if [[ $latestversion != $currentversion ]]; then
                echo "Updated $currentversion to $latestversion"
            fi
            ;;
        *)
            echo $USAGE
            ;;
    esac
    exit 0
else
    echo "No internet connection.  Try again later"
    exit 1
fi

That worked great Eric. Thanks again.

Rick Comito

1 Like

Thanks @rcomito, that looks like a great script. Definitely going to have a good look at it. Also thank @GaryFunk for pointing me to useful bits of your code :smiley:.

I’m not getting any data on the pi console station id 5766 any ideas

Based on your previous message, you may be having DNS issues.

how can i fix it if its a DNS issue

PS I’am not familiar with coding

On the RPi, open the browser and go to smartweather.weatherflow.com and see if the page opens.

It does open @GaryFunk

Then it would seem DNS is working. Check the config file and make sure your station ID is correct and that the API key is correct. Otherwise, @peter will need to assist you.

What api needs to be checked station I’d is right @GaryFunk

1 Like

The API key needs to be in the ini file.

everything is good in API and station code

is this suppose to be at the end when program is started

2018-12-28 03:49:07+0000 [-] Client connection lost … retrying …
2018-12-28 03:49:07+0000 [WeatherFlowClientProtocol,client] <twisted.internet.tcp.Connector object at 0x70905b50> will retry in 60 seconds
2018-12-28 03:49:07+0000 [-] Stopping factory <main.WeatherFlowClientFactory object at 0x71a48150>

I got it to work i reinstalled dependencies thank you for your help @GaryFunk. And is it possible to change time to 12 hour clock? and I’m assuming the indoor temp will work when the indoor weather flow is released

1 Like

Peter will have to answer that. I only know what I read here.

Hi @dswally, glad to see you have managed to get in running. Which dependency did you have to reinstall? Thanks @GaryFunk for the troubleshooting help :smiley: .

It is currently not possible to show the time in a 12-hour format, but I am currently working on a new version that will have a settings screen allowing you to change things like the time format, and the temperature cutoffs for the “feels like” display. Sneak peak:

Capture

2 Likes