diff --git a/data.txt b/data.txt index 5fd1016..763d435 100644 --- a/data.txt +++ b/data.txt @@ -1,4 +1,4 @@ kflg -9 -0 +8 +60 1 diff --git a/install.txt b/install.txt new file mode 100644 index 0000000..86a060d --- /dev/null +++ b/install.txt @@ -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. 'pi@192.163.86.71' +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 + + + + + + + + + + diff --git a/metar_display.py b/metar_display.py old mode 100644 new mode 100755 diff --git a/metar_layouts.py b/metar_layouts.py old mode 100644 new mode 100755 index 0c1fb15..ad9138a --- a/metar_layouts.py +++ b/metar_layouts.py @@ -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 # ########################### diff --git a/metar_main.py b/metar_main.py old mode 100644 new mode 100755 index d9c1f8e..53c7421 --- a/metar_main.py +++ b/metar_main.py @@ -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 @@ -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: @@ -141,9 +146,9 @@ 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 @@ -151,6 +156,12 @@ def main(): 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 @@ -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 diff --git a/metar_poweroff.py b/metar_poweroff.py old mode 100644 new mode 100755 diff --git a/metar_remarks.py b/metar_remarks.py old mode 100644 new mode 100755 diff --git a/metar_routines.py b/metar_routines.py old mode 100644 new mode 100755 index 57bf30f..0486486 --- a/metar_routines.py +++ b/metar_routines.py @@ -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 @@ -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 diff --git a/metar_settings.py b/metar_settings.py old mode 100644 new mode 100755 diff --git a/webapp.py b/webapp.py old mode 100644 new mode 100755 index 8abb015..f67a41e --- a/webapp.py +++ b/webapp.py @@ -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: @@ -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