From 9fd926e677370df9ba4069b90032ea09554457b8 Mon Sep 17 00:00:00 2001 From: markyharris Date: Wed, 3 Jan 2024 21:43:18 -0700 Subject: [PATCH] Bug Fixes for v2.1 --- data.txt | 8 +-- metar_layouts.py | 5 +- metar_main.py | 122 +++++++++++++++++-------------------------- metar_routines.py | 8 +-- templates/metar.html | 23 +++++--- webapp.py | 48 ++++++++--------- 6 files changed, 98 insertions(+), 116 deletions(-) diff --git a/data.txt b/data.txt index 2adc2ee..db147e2 100755 --- a/data.txt +++ b/data.txt @@ -1,9 +1,9 @@ KFLG -1 +-2 +60 0 +2 0 0 1 -0 -0 -0 +1 diff --git a/metar_layouts.py b/metar_layouts.py index 134bca9..36c23a0 100755 --- a/metar_layouts.py +++ b/metar_layouts.py @@ -20,7 +20,7 @@ # Then using the other layouts as a guide create your own. # You must add the name of your layout to 2 locations; # metar_main.py to the variable "layout_list" -# epaper.html to the '' option list # Imports @@ -68,12 +68,13 @@ def disp_ip(display, ip_address): 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) + + print('\nWeb Admin URL:',admin_url,'\n') # debug ########################### # Cycle Through Each -2 # ########################### - def cycle_layout(display,metar,remarks,print_table,use_remarks,use_disp_format,interval,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units,layout_list): global cycle_num print('Layout:',cycle_num) # debug diff --git a/metar_main.py b/metar_main.py index 014c2e9..df8f274 100755 --- a/metar_main.py +++ b/metar_main.py @@ -38,6 +38,8 @@ # Imports from metar_layouts import * +from metar_settings import * +from metar_routines import * import time import requests import json @@ -52,78 +54,53 @@ # Layouts - add new layouts to this list as necessary layout_list = [layout0,layout1,layout2,layout3,layout4,layout5,layout6,layout7,layout8,layout9] # ,layout6 Add layout routine names here - -# Check for cmdline args and use passed variables instead of the defaults above -# The args being passed are; -# airport,use_disp_format,interval,use_remarks,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units -# Example: kabe,1,60,1,2,0,0,1,1 -"""if len(sys.argv) > 1: - airport_tmp = str(sys.argv[1].upper()) - if len(airport_tmp) != 4: # verify that 4 character ICAO id was entered - airport_tmp = airport # otherwise use default airport from settings. - airport = airport_tmp - -if len(sys.argv) == 3: +global startup_flag +startup_flag = 0 # will be reset to 1 once the IP URL is displayed. + +# Check for cmdline args and use passed variables instead of the defaults +# example ['/home/pi/metar/metar_main.py', 'metar', 'kabe', '1', '0', '1', '2', '0', '0', '1', '1'] +print('len(sys.argv):',len(sys.argv)) # debug +print('sys.argv:',sys.argv,'\n') # debug + +# check to see if web admin is supplying the args. If not, use settings.py +if len(sys.argv) >= 10: + print('Using Args passed from web admin') + airport = str(sys.argv[1].upper()) use_disp_format = int(sys.argv[2]) - 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 < -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 < -3 or use_disp_format > len(layout_list)-1): - use_disp_format = -2 """ - -#print(len(sys.argv)) # debug -print(sys.argv) # debug -#['/home/pi/metar/metar_main.py', 'metar', 'kabe', '1', '0', '1', '2', '0', '0', '1', '1'] -#display = int(sys.argv[1]) -# airport,use_disp_format,interval,use_remarks,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units -# Example: kabe 1 60 1 2 0 0 1 1 -airport = str(sys.argv[1].upper()) -use_disp_format = int(sys.argv[2]) -interval = int(sys.argv[3]) -use_remarks = int(sys.argv[4]) -wind_speed_units = int(sys.argv[5]) -cloud_layer_units = int(sys.argv[6]) -visibility_units = int(sys.argv[7]) -temperature_units = int(sys.argv[8]) -pressure_units = int(sys.argv[9]) - -print(airport,use_disp_format,interval,use_remarks,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units) # debug - -print('len of args:',len(sys.argv)) # debug -print("Airport\t", "Layout\t", "Update\t", "Remarks") + wind_speed_units = int(sys.argv[5]) + cloud_layer_units = int(sys.argv[6]) + visibility_units = int(sys.argv[7]) + temperature_units = int(sys.argv[8]) + pressure_units = int(sys.argv[9]) +else: + print('Using Args from settings.py file') + +print("\nAirport\t", "Layout\t", "Update\t", "Remarks") print(str(airport)+"\t", str(use_disp_format)+"\t", str(interval)+"\t", str(use_remarks)+"\n") -def main(): - # Choose which layout to use. - if use_disp_format == -1: -# random_layout(display,metar,airport,use_disp_format,interval,use_remarks,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units,layout_list) +def main(): + global display,metar,remarks,print_table,use_remarks,use_disp_format,interval,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units,layout_list + global startup_flag + + # Choose which layout to use. + if startup_flag == 0: #use_disp_format == -3: + disp_ip(display, get_ip_address()) + print('---> use_disp_format:',use_disp_format) # debug + print('---> interval:',interval,'\n') # debug + + elif use_disp_format == -1: random_layout(display,metar,remarks,print_table,use_remarks,use_disp_format,interval,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units,layout_list) elif use_disp_format == -2: -# cycle_layout(display,metar,airport,use_disp_format,interval,use_remarks,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units,layout_list) cycle_layout(display,metar,remarks,print_table,use_remarks,use_disp_format,interval,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units,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: - print("Layout",index) # debug -# layout_list[index](display,metar,airport,use_disp_format,interval,use_remarks,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units,layout_list) # call appropriate layout + print("Layout -->",index,'<--') # debug layout_list[index](display,metar,remarks,print_table,use_remarks,use_disp_format,interval,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units) # call appropriate layout # Print to e-Paper - This is setup to display on 7x5 3 color waveshare panel. epd7in5b_V2 @@ -158,15 +135,14 @@ def main(): metar = Metar(airport) # pass to routines - remarks, print_table = decode_remarks(metar.data[0]['rawOb']) #["properties"]["rawMessage"] - print('remarks:',remarks,'print_table:',print_table) # debut + remarks, print_table = decode_remarks(get_rawOb(metar)) # metar.data[0]['rawOb']) + print('remarks:',remarks,'print_table:',print_table) # debug flightcategory, icon = flight_category(metar) - if len(metar.data[0]['rawOb']) > 0: - print(metar.data[0]['rawOb']+"\n") # debug + if len(get_rawOb(metar)) > 0: # metar.data[0]['rawOb']) > 0: + print(get_rawOb(metar)) # metar.data[0]['rawOb']+"\n") # debug else: print("No METAR Being Reported") -# print (len(metar.data[0]['rawOb'])) # debug print("Updated " + current_time) print("Creating display") @@ -184,27 +160,27 @@ def main(): # 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 + if startup_flag == 0: + startup_flag = 1 + print("sleep 1 min for Admin URL") + time.sleep(60) + + elif 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 + print("Auto Interval VFR - Sleep 1 hour") # debug time.sleep(3600) # 1 hour if weather is good elif flightcategory == "MVFR": - print("Sleep 1800") # debug + print("Auto Interval MVFR - Sleep 30 mins") # debug time.sleep(1800) # 30 mins if marginal elif flightcategory == "IFR": - print("Sleep 1200") # debug + print("Auto Interval IFR - Sleep 20 mins") # debug time.sleep(1200) # 20 mins if stormy elif flightcategory == "LIFR": - print("Sleep 600") # debug + print("Auto Interval LIFR - Sleep 10 mins") # debug time.sleep(600) # 10 mins if stormy and low visibility epd.init() diff --git a/metar_routines.py b/metar_routines.py index 5f8abc1..c42f27b 100755 --- a/metar_routines.py +++ b/metar_routines.py @@ -160,7 +160,7 @@ def get_rawOb(metar): # "Raw text of observation" string rawmetar = metar.data[0]['rawOb'] else: rawmetar = 'n/a' - print ('rawmetar:',rawmetar) # debug +# print ('rawmetar:',rawmetar) # debug return(rawmetar) def get_wdir(metar): # "Wind direction in degrees or VRB for variable winds" integer @@ -182,7 +182,7 @@ def get_wdir(metar): # "Wind direction in degrees or VRB for variable winds" int if winddir == "VRB": pass else: - winddir = winddir + chr(176) + winddir = winddir + chr(176) # chr(176) is the degree symbol if winddir == "000"+chr(176): winddir = "Calm" @@ -258,9 +258,11 @@ def get_ip_address(): 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/templates/metar.html b/templates/metar.html index 6a9a04a..4759eea 100755 --- a/templates/metar.html +++ b/templates/metar.html @@ -69,14 +69,21 @@

METAR E-Paper Display Admin Page

-
- -

+ + + + + + +
+
+ +
diff --git a/webapp.py b/webapp.py index d70a7f4..8a319ab 100755 --- a/webapp.py +++ b/webapp.py @@ -99,30 +99,30 @@ def metar(): # Functions def write_data(data_field1,data_field2,data_field3,data_field4,data_field5,data_field6,data_field7,data_field8,data_field9): f= open(PATH + "data.txt","w+") - f.write(data_field1+"\n") - f.write(data_field2+"\n") - f.write(data_field3+"\n") - f.write(data_field4+"\n") - f.write(data_field5+"\n") - f.write(data_field6+"\n") - f.write(data_field7+"\n") - f.write(data_field8+"\n") - f.write(data_field9+"\n") + f.write(data_field1+"\n") # airport + f.write(data_field2+"\n") # use_disp_format + f.write(data_field3+"\n") # interval + f.write(data_field4+"\n") # use_remarks + f.write(data_field5+"\n") # wind_speed_units + f.write(data_field6+"\n") # cloud_layer_units + f.write(data_field7+"\n") # visibility_units + f.write(data_field8+"\n") # temperature_units + f.write(data_field9+"\n") # pressure_units f.close() return (True) def get_data(): f=open(PATH + "data.txt", "r") Lines = f.readlines() - data_field1 = Lines[0].strip() - data_field2 = Lines[1].strip() - data_field3 = Lines[2].strip() - data_field4 = Lines[3].strip() - data_field5 = Lines[4].strip() - data_field6 = Lines[5].strip() - data_field7 = Lines[6].strip() - data_field8 = Lines[7].strip() - data_field9 = Lines[8].strip() + data_field1 = Lines[0].strip() # airport + data_field2 = Lines[1].strip() # use_disp_format + data_field3 = Lines[2].strip() # interval + data_field4 = Lines[3].strip() # use_remarks + data_field5 = Lines[4].strip() # wind_speed_units + data_field6 = Lines[5].strip() # cloud_layer_units + data_field7 = Lines[6].strip() # visibility_units + data_field8 = Lines[7].strip() # temperature_units + data_field9 = Lines[8].strip() # pressure_units f.close() return (data_field1,data_field2,data_field3,data_field4,data_field5,data_field6,data_field7,data_field8,data_field9) @@ -136,15 +136,11 @@ def get_data(): data_field1,data_field2,data_field3,data_field4, \ data_field5,data_field6,data_field7,data_field8,data_field9 = get_data() -# print(data_field1,data_field2,data_field3,data_field4, \ -# data_field5,data_field6,data_field7,data_field8,data_field9) # debug - - # create cmdline command to start the main program using the 'data.txt' variables to kick things off. -# print('sudo python3 ' + PATH + 'metar_main.py ' + 'metar' + ' ' + data_field1 + ' ' + data_field2 + ' ' + data_field3 + ' ' + data_field4 \ -# + ' ' + data_field5 + ' ' + data_field6 + ' ' + data_field7 + " " + data_field8 + ' ' + data_field9 + ' &') # debug + # create cmdline command to start the main program using the 'data.txt' variables to kick things off. print('sudo python3 ' + PATH + 'metar_main.py ' + ' ' + data_field1 + ' ' + data_field2 + ' ' + data_field3 + ' ' + data_field4 \ - + ' ' + data_field5 + ' ' + data_field6 + ' ' + data_field7 + " " + data_field8 + ' ' + data_field9 + ' &') # debug - + + ' ' + data_field5 + ' ' + data_field6 + ' ' + data_field7 + " " + data_field8 + ' ' + data_field9 + ' &') # debug + + # first run at startup. display web admin ip url for 60 seconds os.system('sudo python3 ' + PATH + 'metar_main.py ' + ' ' + data_field1 + ' ' + data_field2 + ' ' + data_field3 + ' ' + data_field4 \ + ' ' + data_field5 + ' ' + data_field6 + ' ' + data_field7 + ' ' + data_field8 + " " + data_field9 + ' &')