Skip to content

Commit

Permalink
Release Version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
markyharris committed Jan 7, 2024
1 parent ace3215 commit 4197f79
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 75 deletions.
1 change: 1 addition & 0 deletions data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ kflg
1
1
1
na
72 changes: 36 additions & 36 deletions metar_layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# Misc Variables
d = " " # d = delimiter used to split metar on 'spaces' then re-join them into 2 parts
cycle_num = 0
pref_cycle = 0

# Utility routines
def center_line(display,text,font=font24b,pos_x=400):
Expand Down Expand Up @@ -65,21 +66,6 @@ def check_preferred_layout(layout_name):
return(False)


# test layout10
def layout10(display,metar,remarks,print_table,use_remarks,use_disp_format,interval,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units):
# Get metar data along with flightcategory and related icon
decoded_airport,decoded_time,decoded_wndir,decoded_wnspd,decoded_wngust,decoded_vis,\
decoded_alt,decoded_temp,decoded_dew,decoded_cloudlayers,decoded_weather,decoded_rvr \
= decode_rawmessage(get_rawOb(metar))
flightcategory, icon = flight_category(metar)
airport = decoded_airport
icaoid,obstime,elev,lat,lon,name = get_misc(metar)
print(lat,lon)

chart_url = "https://forecast.weather.gov/meteograms/Plotter.php?lat=37.431&lon=-122.253&wfo=MTR&zcode=CAZ508&gset=18&gdiff=3&unit=0&tinfo=PY8&ahour=0&pcmd=11011111000000000000000000000000000000000000000000000000000&lg=en&indu=1!1!1!&dd=1&bw=1&hrspan=48&pqpfhr=6&psnwhr=6"
display.show_pic(chart_url, 2, 2, "b") # COL0, LINE2, "b")


###########################
# Display IP Address -3 #
###########################
Expand Down Expand Up @@ -107,28 +93,24 @@ def disp_ip(display, ip_address):
###########################
# 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):
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,preferred_layouts,use_preferred):
global cycle_num
print('--> Layout:',cycle_num,'<--') # debug

if use_preferred == 1:
for j in range(len(preferred_layouts)):
if preferred_layouts[cycle_num] == 1:
print('!!! Layout:',cycle_num,' IN LIST !!!')
cycle_pick = layout_list[cycle_num]
cycle_pick(display,metar,remarks,print_table,use_remarks,use_disp_format,interval,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units)
cycle_num += 1
if cycle_num == len(layout_list):
cycle_num = 0
return
else:
print('!!! Layout:',cycle_num,' NOT IN LIST !!!')
pass
cycle_num += 1
if cycle_num == len(layout_list):
cycle_num = 0
global pref_cycle
# print('use_preferred:',use_preferred) # debug

if use_preferred == 1:
p_layouts_lst = [int(a) for a in str(preferred_layouts)]
print('p_layouts_lst:',p_layouts_lst) # debug

print('\033[96m!!! Preferred Layout:',p_layouts_lst[pref_cycle],' IN LIST !!!\033[0m')
cycle_pick = layout_list[p_layouts_lst[pref_cycle]]
cycle_pick(display,metar,remarks,print_table,use_remarks,use_disp_format,interval,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units)
pref_cycle += 1
if pref_cycle == len(p_layouts_lst):
pref_cycle = 0

else:
print('\033[91m--> cycle_num Layout:',cycle_num,'<--\033[0m') # debug
cycle_pick = layout_list[cycle_num]
cycle_pick(display,metar,remarks,print_table,use_remarks,use_disp_format,interval,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units)
cycle_num += 1
Expand All @@ -141,7 +123,7 @@ def cycle_layout(display,metar,remarks,print_table,use_remarks,use_disp_format,i
##################
def 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):
rand_pick = random.choice(layout_list)
print(str(rand_pick)[10:18]) # debug
print('\033[91m--> Random Layout:',str(rand_pick)[10:18],'<--\033[0m') # debug
rand_pick(display,metar,remarks,print_table,use_remarks,use_disp_format,interval,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units)


Expand Down Expand Up @@ -1701,4 +1683,22 @@ def layout9(display,metar,remarks,print_table,use_remarks,use_disp_format,interv
windsp = windsp + ' G'

windsp_txt = "Speed:"+windsp+gustsp+dis_unit
display.draw_black.text((center_line(display,windsp_txt,font24b,200), LINE4-25), windsp_txt, fill=0, font=font24b)
display.draw_black.text((center_line(display,windsp_txt,font24b,200), LINE4-25), windsp_txt, fill=0, font=font24b)

#################
# test layout10 #
#################
# used for testing/playing. Not part of the available layouts
def layout10(display,metar,remarks,print_table,use_remarks,use_disp_format,interval,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units):
# Get metar data along with flightcategory and related icon
decoded_airport,decoded_time,decoded_wndir,decoded_wnspd,decoded_wngust,decoded_vis,\
decoded_alt,decoded_temp,decoded_dew,decoded_cloudlayers,decoded_weather,decoded_rvr \
= decode_rawmessage(get_rawOb(metar))
flightcategory, icon = flight_category(metar)
airport = decoded_airport
icaoid,obstime,elev,lat,lon,name = get_misc(metar)
print(lat,lon)

chart_url = "https://forecast.weather.gov/meteograms/Plotter.php?lat=37.431&lon=-122.253&wfo=MTR&zcode=CAZ508&gset=18&gdiff=3&unit=0&tinfo=PY8&ahour=0&pcmd=11011111000000000000000000000000000000000000000000000000000&lg=en&indu=1!1!1!&dd=1&bw=1&hrspan=48&pqpfhr=6&psnwhr=6"
display.show_pic(chart_url, 2, 2, "b") # COL0, LINE2, "b")

41 changes: 28 additions & 13 deletions metar_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@
# https://aviationweather.gov/data/api/#/Dataserver/dataserverMetars
# This script also uses IFR Low maps from;
# https://vfrmap.com/map_api.html
#
#
# A new feature was added that allows the user to specify which layouts that should be displayed
# The user will have to setup a list variable in 'metar_setting.py' and set 'use_preferred' to 1
# See the file, 'metar_settings.py' for an example.
#
# Unit conversions were added to allow the user to choose ft vs meter, km/h vs knots etc.
# These will be selected from either the 'metar_settings.py' file or better, the web admin page.
#
# While not part of the scripts, it is suggested to setup a nightly reboot using crontab
# see; https://smarthomepursuits.com/how-to-reboot-raspberry-pi-on-a-schedule/ for information
#
# The script will then either display the json weather information provided,
# or if the json information is not given, the script will use the data scraped
# from the raw metar string provided. However, the json data is a bit more accurate.
Expand Down Expand Up @@ -56,12 +66,12 @@
# find 'epd = epd7in5b_V2.EPD()' towards bottom and change also if needed.
# These are located in the directory 'waveshare_epd'
from waveshare_epd import epd7in5b_V2

# Layouts - add new layouts to this list as necessary
layout_list = [layout0,layout1,layout2,layout3,layout4,layout5,layout6,layout7,layout8,layout9] # Add layout routine names here

# 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']
# example ['/home/pi/metar/metar_main.py', 'metar', 'kabe', '1', '0', '1', '2', '0', '0', '1', '1', '123']
print('len(sys.argv):',len(sys.argv)) # debug
print('sys.argv:',sys.argv,'\n') # debug

Expand All @@ -77,6 +87,16 @@
visibility_units = int(sys.argv[7])
temperature_units = int(sys.argv[8])
pressure_units = int(sys.argv[9])
preferred_layouts = (sys.argv[10]) # string representation of the the list. Needs to be converted back to list

print('\033[96mpreferred_layouts:',preferred_layouts,'\033[0m') # debug
if preferred_layouts == 'na':
use_preferred = 0
# print('DONT Use Preferred') # debug
else:
use_preferred = 1
# print('YES Use Preferred') # debug

else:
print('Using Args from settings.py file')

Expand All @@ -87,15 +107,12 @@
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

# testing
# layout10(display,metar,remarks,print_table,use_remarks,use_disp_format,interval,wind_speed_units,cloud_layer_units,visibility_units,temperature_units,pressure_units)

# Choose which layout to use.
if 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,remarks,print_table,use_remarks,use_disp_format,interval,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,preferred_layouts,use_preferred)

else:
for index, item in enumerate(layout_list):
Expand Down Expand Up @@ -127,10 +144,10 @@ def main():
epd = epd7in5b_V2.EPD() # Instantiate instance for display.

while True:
# try:
try:
# while True: # debug
# error = 1/0 #debug # forces error to test the try-except statements
if True: # used instead of the try-except statements for debug purposes.
# if True: # used instead of the try-except statements for debug purposes.
current_time = time.strftime("%m/%d/%Y %H:%M", time.localtime())

metar = Metar(airport) # pass to routines
Expand Down Expand Up @@ -182,8 +199,7 @@ def main():
epd.init()
epd.sleep()

# except Exception as e:
"""
except Exception as e:
time.sleep(2)
print("Error Occurred in Main While Loop")
exception_type, exception_object, exception_traceback = sys.exc_info()
Expand Down Expand Up @@ -223,5 +239,4 @@ def main():
print("Done")
time.sleep(60) # Sets interval of updates. 60 = 1 minute
epd.init()
epd.sleep()
"""
epd.sleep()
11 changes: 3 additions & 8 deletions metar_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@
temperature_units = 0 # 0=°C Celsius, 1=°F Farhenheit
pressure_units = 0 # 0=Hectopascal, 1=Inch Hg


# preferred_layouts - select the preferred layouts to cycle through by putting a '1' in its location.
# then change the 'use_preferred' variable below to '1'
use_preferred = 0 # 0 = No, 1 = Yes
# Map the list below to match the layout list here; [layout0,layout1,layout2,layout3,layout4,layout5,layout6,layout7,layout8,layout9]
# for instance - [1,0,0,0,0,0,0,0,0,1] will only display layout0 and layout9.
preferred_layouts = [0,0,0,1,1,0,0,0,0,1] # 0=Do Not Display layout, 1=Do Display Layout

# preferred_layouts: Populate with the integers of the layout that should be used. i.e. 123 will only display layouts 1, 2 and 3.
# If no preferred layouts are desired, populate with 'na'
preferred_layouts = 123

# Random Airports Choices (Layout5):
# This is the only layout that doesn't use cmd line arguments
Expand Down
Binary file modified temp_pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions templates/metar.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ <h2>METAR E-Paper Display Admin Page</h2>
<select name="data_field3" id="data_field3">
<option value="0" {% if data_field3=="0" %} selected="selected" {% endif %}>Auto Interval</option>
<option value="60" {% if data_field3=="60" %} selected="selected" {% endif %}>1 Minute</option>
<option value="120" {% if data_field3=="120" %} selected="selected" {% endif %}>2 Minutes</option>
<option value="300" {% if data_field3=="300" %} selected="selected" {% endif %}>5 Minutes</option>
<option value="600" {% if data_field3=="600" %} selected="selected" {% endif %}>10 Minutes</option>
<option value="900" {% if data_field3=="900" %} selected="selected" {% endif %}>15 Minutes</option>
<option value="1200" {% if data_field3=="1200" %} selected="selected" {% endif %}>20 Minutes</option>
<option value="1800" {% if data_field3=="1800" %} selected="selected" {% endif %}>30 Minutes</option>
<option value="3600" {% if data_field3=="3600" %} selected="selected" {% endif %}>1 Hour</option>
Expand Down Expand Up @@ -257,6 +260,34 @@ <h2>METAR E-Paper Display Admin Page</h2>
</table>
</div>


<table class="table table-bordered">
<tbody>
<tr class="table-danger">
<td width="50%">
<label for="fname"><b>Select Preferred Layouts to Display:</b></label><br>
<b>Note</b>: Select the layouts desired to be displayed.<p>
Works only with '<i>Cycle Through All Layouts</i>' function above.<p>
The function '<i>Display Random Layouts</i>' will randomly select from all Layouts.<p>
Leave all checkboxes blank if all Layouts are to be used (or select all of them).<p>
</td>
<td width="50%">
<input type="checkbox" value="0" class="danger" name='data_field10' {% if "0" in data_field10 %} checked {% endif %}> Large Flight Category and METAR<br>
<input type="checkbox" value="1" class="danger" name='data_field10' {% if "1" in data_field10 %} checked {% endif %}> METAR with Data Display<br>
<input type="checkbox" value="2" class="danger" name='data_field10' {% if "2" in data_field10 %} checked {% endif %}> Data Display with Icons<br>
<input type="checkbox" value="3" class="danger" name='data_field10' {% if "3" in data_field10 %} checked {% endif %}> Basic Large Flight Category<br>
<input type="checkbox" value="4" class="danger" name='data_field10' {% if "4" in data_field10 %} checked {% endif %}> 3 Area Display with METAR<br>
<input type="checkbox" value="5" class="danger" name='data_field10' {% if "5" in data_field10 %} checked {% endif %}> Multiple Airport Flight Categories<br>
<input type="checkbox" value="6" class="danger" name='data_field10' {% if "6" in data_field10 %} checked {% endif %}> Airport Map and Flight Category<br>
<input type="checkbox" value="7" class="danger" name='data_field10' {% if "7" in data_field10 %} checked {% endif %}> Flight Category In Circles<br>
<input type="checkbox" value="8" class="danger" name='data_field10' {% if "8" in data_field10 %} checked {% endif %}> Worst Class B & C Airport Weather<br>
<input type="checkbox" value="9" class="danger" name='data_field10' {% if "9" in data_field10 %} checked {% endif %}> Metar and Large Wind Icons<br>
</td>
</tr>
</tbody>
</table>


<table class="table table-bordered">
<tbody>
<tr class="table-secondary">
Expand Down
Loading

0 comments on commit 4197f79

Please sign in to comment.