Skip to content

Commit

Permalink
Bug Fixes for v2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
markyharris committed Jan 4, 2024
1 parent e9ec148 commit 9fd926e
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 116 deletions.
8 changes: 4 additions & 4 deletions data.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
KFLG
1
-2
60
0
2
0
0
1
0
0
0
1
5 changes: 3 additions & 2 deletions metar_layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<select name="data_field2" id="myselection">' option list
# metar.html to the '<select name="data_field2" id="myselection">' option list


# Imports
Expand Down Expand Up @@ -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
Expand Down
122 changes: 49 additions & 73 deletions metar_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

# Imports
from metar_layouts import *
from metar_settings import *
from metar_routines import *
import time
import requests
import json
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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()
Expand Down
8 changes: 5 additions & 3 deletions metar_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
23 changes: 15 additions & 8 deletions templates/metar.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,21 @@ <h2>METAR E-Paper Display Admin Page</h2>

<form action="{{ url_for('metar') }}" method="post">

<label for="display"><b>Choose a Function:</b></label><br>
<select name="display" id="display">
<option value="metar" {% if display=="metar" %} selected="selected" {% endif %}>Display METAR Info</option>
<option value="off" {% if display=="off" %} selected="selected" {% endif %}>Clear E-Paper Display</option>
<option value="reboot" {% if display=="reboot" %} selected="selected" {% endif %}>Reboot RPi</option>
<option value="powerdown" {% if display=="powerdown" %} selected="selected" {% endif %}>Power Down RPi</option>
</select>
<br><p>
<table class="table table-bordered">
<tbody>
<tr class="table-warning">
<td>
<label for="display"><b>Choose a Function:</b></label><br>
<select name="display" id="display">
<option value="metar" {% if display=="metar" %} selected="selected" {% endif %}>Display METAR Info</option>
<option value="off" {% if display=="off" %} selected="selected" {% endif %}>Clear E-Paper Display</option>
<option value="reboot" {% if display=="reboot" %} selected="selected" {% endif %}>Reboot RPi</option>
<option value="powerdown" {% if display=="powerdown" %} selected="selected" {% endif %}>Power Down RPi</option>
</select>
</td>
</tr>
</tbody>
</table>



Expand Down
48 changes: 22 additions & 26 deletions webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 + ' &')

Expand Down

0 comments on commit 9fd926e

Please sign in to comment.