Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map control bash script #35

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,34 @@ For time timings of the dimming there are two options:
* `LOCATION` - set this to the city you want to use for sunset/sunrise timings
* Use the closest city from the list of supported cities from https://astral.readthedocs.io/en/latest/#cities

## Using `map_toggle.sh`

This script can be used to automatically update the crontab with a few preset values. Additionally, it is useful for controlling the map externally (via SSH or [Shortcuts](https://support.apple.com/guide/shortcuts/welcome/ios)).

Place the **[map_toggle.sh](map_toggle.sh)** script into the pi home directory (`/home/pi`).

The script can be called with four different parameters (`on`/`off`/`shutdown`/`##-##`). Examples are provided below.

1. Turn the map on: `bash map_toggle.sh on`

2. Turn the map off: `bash map_toggle.sh off`

3. Turn the map on from 8 AM - 10 PM: `bash map_toggle.sh 8-22`

4. Shutdown the Raspberry Pi: `bash map_toggle.sh shutdown`

Once the script is installed, edits should be made to the crontab file so it does not contain any conflicting jobs.

Add the following line to your crontab file in order to automatically turn on your METAR Map when the Raspberry Pi boots up: `@reboot sleep 15 && /home/pi/refresh.sh`

If you have an Apple device, you can install [this shortcut](https://www.icloud.com/shortcuts/89606c2285dc4cb69c5590a4beac9bfe) to launch utilize `map_toggle.sh` functionality remotely. With this, you are able to control your METAR Map while connected to your home network.

* You may need to [allow untrusted shortcuts](https://www.idownloadblog.com/2020/06/16/allow-untrusted-shortcuts-iphone-tutorial/) for this function to work.

* Once the shortcut is installed, click the three dots in the upper-right corner of the shortcut and edit the `HOST` (IP address) and `PASS` (password) text lines. Click the "x" when you are done.

* Execute the shortcut and select the desired menu option.

## Additional mini display to show METAR information functionality

This optional functionality allows you to connect a small mini LED display to show the METAR information of the airports.
Expand Down Expand Up @@ -123,7 +151,6 @@ If you want an interactive Legend to illustrate the possible behaviors you can d
* If you are not using any of these, then you only need 4 LEDs for the basic flight conditions for the Legend
* If you are only using the Wind condition feature, but not the Lightning, you will still need the total of 7 LEDs (but the 5th LED for Lightning will just stay blank) or you'd have to change the order in the code


## Changelist

To see a list of changes to the metar script over time, refer to [CHANGELIST.md](CHANGELIST.md)
88 changes: 88 additions & 0 deletions map_toggle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/bin/bash

if [[ $1 == "on" ]]; then
( crontab -l | grep -v -F "/home/pi/lightsoff.sh --auto1" ) | crontab -
( crontab -l | grep -v -F "/home/pi/refresh.sh --auto2" ) | crontab -
( crontab -l | grep -v -F "/home/pi/lightsoff.sh --auto2" ) | crontab -

croncmd="/home/pi/refresh.sh --auto1"
cronjob="*/5 * * * * $croncmd"
( crontab -l | grep -v -F "$croncmd" ; echo "$cronjob" ) | crontab -

./refresh.sh | grep 'Done' &> /dev/null
if [ $? == 0 ]; then
echo "METAR Map is on!"
fi
elif [[ $1 == "off" ]]; then
( crontab -l | grep -v -F "/home/pi/refresh.sh --auto1" ) | crontab -
( crontab -l | grep -v -F "/home/pi/refresh.sh --auto2" ) | crontab -
( crontab -l | grep -v -F "/home/pi/lightsoff.sh --auto2" ) | crontab -

croncmd="/home/pi/lightsoff.sh --auto1"
cronjob="*/10 * * * * $croncmd"
( crontab -l | grep -v -F "$croncmd" ; echo "$cronjob" ) | crontab -

./lightsoff.sh | grep 'LEDs off' &> /dev/null
if [ $? == 0 ]; then
echo "METAR Map is off!"
fi
elif [[ $1 == ??-?? ]] || [[ $1 == ?-?? ]] || [[ $1 == ??-? ]] || [[ $1 == ?-? ]]; then
input="$1"
arr=(${input//-/ })
time1=${arr[0]}
time2=${arr[1]}
time1=`expr $time1 + 0`
time2=`expr $time2 - 1`

if [[ $time1 == 24 ]]; then time1=0; fi
if [[ $time2 == 24 ]]; then time2=0; fi
if [[ $time2 == -1 ]]; then time2=23; fi

if [[ $time2 -lt $time1 ]]; then time2=23; fi

if [[ $time1 -lt 24 ]] && [[ $time2 -lt 24 ]]; then
( crontab -l | grep -v -F "/home/pi/refresh.sh --auto1" ) | crontab -
( crontab -l | grep -v -F "/home/pi/lightsoff.sh --auto1" ) | crontab -
( crontab -l | grep -v -F "/home/pi/refresh.sh --auto2" ) | crontab -
( crontab -l | grep -v -F "/home/pi/lightsoff.sh --auto2" ) | crontab -

dur="$time1-$time2"
time3=`expr $time2 + 1`
if [[ $time3 == 24 ]]; then time3=0; fi

croncmd="/home/pi/refresh.sh --auto2"
cronjob="*/5 $dur * * * $croncmd"
( crontab -l | grep -v -F "$croncmd" ; echo "$cronjob" ) | crontab
croncmd="/home/pi/lightsoff.sh --auto2"
cronjob="00 $time3 * * * $croncmd"
( crontab -l | grep -v -F "$croncmd" ; echo "$cronjob" ) | crontab

time_now=$( date +'%H' )
if [[ $time_now -gt $time1 ]] && [[ $time_now -le $time2 ]]; then
./refresh.sh | grep 'Done' &> /dev/null
if [ $? == 0 ]; then
echo "METAR Map is on!"
echo "Hours: $time1-$time3"
fi
else
./lightsoff.sh | grep 'LEDs off' &> /dev/null
if [ $? == 0 ]; then
echo "METAR Map is off!"
echo "Hours: $time1-$time3"
fi
fi
else
echo "METAR Map status unknown!"
echo "Hour range not valid!"
fi
elif [[ $1 == "shutdown" ]]; then
./lightsoff.sh | grep 'LEDs off' &> /dev/null
if [ $? == 0 ]; then
echo "METAR Map is off!"
echo "Raspberry Pi is shutting down!"
fi
(sleep 5 && sudo shutdown now &> /dev/null) &
else
echo "METAR Map status unknown!"
echo "Input not valid!"
fi