Skip to content

Commit

Permalink
Display Admin URL on Startup
Browse files Browse the repository at this point in the history
  • Loading branch information
markyharris committed Apr 13, 2022
1 parent c411e48 commit d98de8f
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 11 deletions.
4 changes: 2 additions & 2 deletions data.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kflg
9
0
8
60
1
152 changes: 152 additions & 0 deletions install.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
Install Steps

DOWNLOAD NEEDED APPS:
Download Balena Etcher - https://www.balena.io/etcher/
Download Berrylan Unix Bullseye Image - https://berrylan.org/
Download Berrylan App from either Apple App Store or Android Play Store to your phone
NOTE: The Berrylan image is not strictly required. It provides an easy way to setup the WiFi and enable SSH on a headless RPi system such as this. There are many other ways to do this temporarily connecting a keyboard and monitor to the RPi to start. However, if you choose to give this to a friend then having the ability to change the WiFi network through the Berrylan phone app is very handy. If Berrylan is not desired, visit; https://www.raspberrypi.com/software/operating-systems/ to download the latest image.

WRITE BERRYLAN IMAGE:
Using Balena Etcher, write Berrylan image to Micro SD Card
Put SD card into RPi and boot-up completely

SETUP WIFI USING BERRYLAN:
Open Berrylan app on phone and select for 'BT WLAN setup' or 'BT WLAN' or 'raspberrypi' depending on what is displayed. The most common is 'BT WLAN'. If you see more than one, then pick the first one and go through the steps. If it ends up not being this particular RPi, then run it again and select the next one. You may have to give the app alittle time to find it however, so don't be too impatient.
Select WiFi SSID to use
Enter the WiFi password
Write down the IP address that is displayed. You'll need this later. You can tap it and copy it to clipboard

LOGIN USING SSH CLIENT:
Open a SSH Client and enter the 'pi@IP address' to start the login process, i.e. '[email protected]'
Login using username 'pi' and password 'raspberry'. If a normal image was used, then SSH must be enabled before these clients will work. Berrylan automatically enables SSH. Otherwise use raspi-config to do so.
Note: There are a number of SSH Clients. A few of the more popular are;
KiTTY.
PuTTY and other PuTTY versions
MobaXterm
WinSCP
SmarTTY
Bitvise SSH Client
Terminal (for Mac)
Chrome SSH extension

SETUP SPI INTERFACE:
At the cmd line prompt; 'pi@raspberrypi:~ $' enter the following;
sudo raspi-config
3 - Interface Options
I4 SPI Enable this? Yes
Note: You can change the hostname and password if desired at this point, but its optional
Answer 'Yes' when you exit raspi-config to Reboot the RPi

SETUP GITHUB ON RPI:
After RPi boots up and you login through your SSH client, enter;
sudo apt update
sudo apt-get install git
git --version
If you receive a git version number than you are good to go.

COPY FILES FROM GITHUB:
Enter;
sudo git clone https://github.com/markyharris/metar.git
cd metar
ls -la
This should list the files copied from github to verify it worked properly

DEPENDENCIES:
Install necessary dependencies needed for the software;
sudo apt-get install python3-setuptools
sudo apt install python3-pil
sudo apt-get install python3-numpy
sudo pip3 install Flask

FONTS:
The code is written with 'NotoMono-Regular.ttf' and 'LiberationMono-Bold.ttf' in used, so at minimum these need to be installed. If not enter;
cd /usr/share/fonts/truetype/
sudo mkdir noto
sudo mkdir liberation2
cd noto
sudo wget https://github.com/markyharris/metar/raw/f1858d85ad3b79864fb6e082cd083346828661ef/fonts/noto/NotoMono-Regular.ttf
cd ..
cd liberation2
sudo wget https://github.com/markyharris/metar/raw/f1858d85ad3b79864fb6e082cd083346828661ef/fonts/liberation2/LiberationMono-Bold.ttf

TEST RUN METAR DISPLAY:
Enter;
cd ~
cd metar
sudo python3 metar_main.py
If all is well the cmd line will display debug data including a raw metar string. Watch your e-paper display to see if it starts to blink as it updates. The full refresh can take a number of seconds so be patient. After a bit a layout should be displayed showing the default airport from metar_settings.py
If so, you are good to go!

Now edit the metar_settings.py file as you wish. These values are defaults that the script falls back on.
# Default User Settings
airport = "KFLG" # enter default airport identifier to display. Be sure to use quotes
interval = 1800 # enter default time in seconds between METAR updates - 3600 = 1 hour, no quotes
use_disp_format = 7 # Choose which display layout to use. -1 = Random layout, -2 = Cycle layouts
use_remarks = 1 # 0 = display airport information, 1 = display metar remarks info
random_airports = ["KEYW","KDFW","KSEA","KORD", "KLAS","KCMR","KABQ","KDEN", \
"KPHX","KNBC","KBKV","KTTS"]

TEST CMD LINE CONTROL:
The script was written to except up to 4 cmd line arguments;
1st argument - airport identifier - must be 4 character ICAO format
2nd argument - layout number - will accept -2, -1, and 0-7
3rd argument - update interval in seconds - 60 = 1 minute, 3600 = 1 hour
4th argument - use remarks - 1 = display metar remarks key info, 0 = display airport information
They must be in the order shown, but not all of them are required. For instance only the Airport ID can be used, and the others will be filled in using the default settings in metar_settings.py
For example enter;
sudo python3 metar_main.py kflg 7 60 0
The display will show the Flagstaff Airport using Layout 7 for 60 seconds before updating using airport info.
Assuming this is works properly, then using the webapp.py and metar.html scripts below should work just fine.

TEST WEBAPP.PY:
From the metar directory enter;
sudo python3 webapp.py
This will run a Flask module that will start metar_main.py in last save configuration. Flask sets up a web server so we can also run an html file to control the display from any computer, tablet or phone that is on the same wifi network.
If all is good your display should be showing a layout of information.
Make note that when webapp.py starts, information will be displayed in your SSH client. You will need the URL that it provides. For instance; '* Running on http://192.168.86.71:5000/ (Press CTRL+C to quit)'

TEST METAR.HTML:
Using the URL from the previous step, open a web browser and enter it in the URL. If all is well you will see a web page that allows for easy configuration and change to the display.

SETUP RC.LOCAL FOR STARTUP:
This is optional, but if you would like the display to restart automatically after a shutdown, or accidental power outage then this is a good way to go. Also, the webapp.py must be running for the web interface to work properly.
Enter;
cd ~
cd /etc
sudo nano rc.local
Before the 'Exit' statement add;
sudo python3 /home/pi/metar/webapp.py &
Then to save and reboot;
ctrl-x
y
sudo reboot now
Note: There may be times when you don't want webapp.py to startup automatically, so simply open up rc.local again and comment out the line that was added then resave and reboot.

SETUP POWEROFF.SERVICE FOR SHUTDOWN:
This is optional as well, but its nice to blank the epaper display when the unit is shutdown. A power outage won't blank the screen, but once the power comes back on it will reset the display if you setup rc.local above.

Power Off Service installation:
Copy 'poweroff.service' into /lib/systemd/system;
cd ~
cd /lib/systemd/system
sudo wget https://raw.githubusercontent.com/markyharris/metar/main/poweroff.service

Enable the service by entering;
sudo systemctl enable poweroff.service

Copy the python script 'metar_poweroff.py' into /opt/metar_poweroff;
cd ~
cd /opt
sudo mkdir metar_poweroff
cd metar_poweroff
sudo wget https://raw.githubusercontent.com/markyharris/metar/main/metar_poweroff.py










Empty file modified metar_display.py
100644 → 100755
Empty file.
22 changes: 22 additions & 0 deletions metar_layouts.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ def last_update():
return(last_update)


###########################
# Display IP Address -3 #
###########################
def disp_ip(display, ip_address):
LINE0 = 120
LINE1 = 220
LINE2 = 300
LINE3 = 350
LINE4 = 420
RADIUS = 20

admin_url = "http://"+get_ip_address()+":5000"
msg1 = "METAR Display will show within 60 seconds"

display.round_line(40, 40, 725, 410, RADIUS, "r")
display.draw_red.text((center_line(display,"For Admin URL, Enter:",font48b), LINE0), "For Admin URL, Enter:", fill=0, font=font48b)
display.draw_black.text((center_line(display,admin_url,font36b), LINE1), admin_url, fill=0, font=font36b)
display.draw_red.text((center_line(display,"Into a Web Browser",font36b), LINE2), "Into a Web Browser", fill=0, font=font36b)
display.draw_red.text((center_line(display,"on Same Network",font36b), LINE3), "on Same Network", fill=0, font=font36b)
display.draw_black.text((center_line(display,msg1,font16b), LINE4), msg1, fill=0, font=font16b)


###########################
# Cycle Through Each -2 #
###########################
Expand Down
23 changes: 17 additions & 6 deletions metar_main.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@

if len(sys.argv) == 3:
use_disp_format = int(sys.argv[2])
if (use_disp_format < -2 or use_disp_format > len(layout_list)-1):
if (use_disp_format < -3 or use_disp_format > len(layout_list)-1):
use_disp_format = -2

if len(sys.argv) == 4:
interval = int(sys.argv[3])
use_disp_format = int(sys.argv[2])
if (use_disp_format < -2 or use_disp_format > len(layout_list)-1):
if (use_disp_format < -3 or use_disp_format > len(layout_list)-1):
use_disp_format = -2

if len(sys.argv) == 5:
use_remarks = int(sys.argv[4])
interval = int(sys.argv[3])
use_disp_format = int(sys.argv[2])
if (use_disp_format < -2 or use_disp_format > len(layout_list)-1):
if (use_disp_format < -3 or use_disp_format > len(layout_list)-1):
use_disp_format = -2

#print(len(sys.argv)) # debug
Expand All @@ -86,6 +86,11 @@ def main():
random_layout(display, metar, remarks, print_table, use_remarks, layout_list)
elif use_disp_format == -2:
cycle_layout(display, metar, remarks, print_table, use_remarks, layout_list)
elif use_disp_format == -3:
disp_ip(display, get_ip_address())
# use_disp_format = -2
# interval = 1800

else:
for index, item in enumerate(layout_list):
if index == use_disp_format:
Expand Down Expand Up @@ -141,16 +146,22 @@ def main():
# Update values
metar.update(airport)
print("Metar Updated")

main() # Build METAR data to display using specific layout

# Setup update interval
# The update interval can be selected via cmd line or web iterface
# If Auto Interval is selected, then Flight Category dictates update
# So the worse the weather, the more often it updates.
if interval != 0: # if not auto interval selected
print("sleep ",interval) # debug
time.sleep(interval) # Sets interval of updates. 3600 = 1 hour

# Reset display format and interval when RPi first boots up and displays URL
if use_disp_format == -3: # -3 = Display Admin URL
use_disp_format = -2 # -2 = Cycle through all layouts
interval = 1800

else:
if flightcategory == "VFR":
print("Sleep 3600") # debug
Expand All @@ -161,7 +172,7 @@ def main():
elif flightcategory == "IFR":
print("Sleep 1200") # debug
time.sleep(1200) # 20 mins if stormy
elif flightcategory == "LIFR":
elif flightcategory == "LIFR":
print("Sleep 600") # debug
time.sleep(600) # 10 mins if stormy and low visibility

Expand Down
Empty file modified metar_poweroff.py
100644 → 100755
Empty file.
Empty file modified metar_remarks.py
100644 → 100755
Empty file.
13 changes: 12 additions & 1 deletion metar_routines.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from metar_remarks import *
import urllib.request, urllib.error, urllib.parse
import xml.etree.ElementTree as ET
import socket

# Misc Variables
decode = [] # used to decode the raw metar
Expand All @@ -31,7 +32,17 @@
'KAUS', 'KCRP', 'KDLF', 'KDYS', 'KELP', 'KHRL', 'KLBB', 'KMAF', 'KSAT', 'KBTV', \
'KORF', 'KRIC', 'KROA', 'KGEG', 'KNUW', 'KSKA', 'KCRW', 'KGRB', 'KMKE', 'KMSN', \
'TJSJ', 'TIST']


# Get RPi IP address to display on Boot up.
def get_ip_address():
ip_address = '';
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8",80))
ip_address = s.getsockname()[0]
s.close()
# print(ip_address) # debug
return ip_address

# Get Flight Categories for Class B and Class C airports
def get_flightcat():
# api url
Expand Down
Empty file modified metar_settings.py
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions webapp.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def metar():

elif display == "off":
os.system("ps -ef | grep 'metar_main.py' | awk '{print $2}' | xargs sudo kill")
os.system('sudo python3 ' + PATH + 'shutdown.py &')
os.system('sudo python3 ' + PATH + 'metar_poweroff.py &')
flash("Turning Off E-Paper Display - One Moment...")

else:
Expand Down Expand Up @@ -83,7 +83,7 @@ def get_data():
# Start of Flask
if __name__ == '__main__':
# error = 1/0 # Force webapp to stop executing for debug purposes
data_field1, data_field2, data_field3, rem_data = get_data() # read what is in data.txt to get last run
data_field1, data_field2, data_field3, rem_data = "KFLG","-3","60","0" #get_data() # read what is in data.txt to get last run

os.system('sudo python3 ' + PATH + 'metar_main.py ' + data_field1 + ' ' + data_field2 + ' ' + data_field3 + " " + rem_data + ' &')
app.run(debug=True, use_reloader=False, host='0.0.0.0') # use use_reloader=False to stop double loading
Expand Down

0 comments on commit d98de8f

Please sign in to comment.