From 6c1f7940caad1c0ba8fed9276eb5639430181df4 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 12 Aug 2025 11:35:42 -0700 Subject: [PATCH] refactor coastal weather changes to config.ini template if you use tide or mwx --- README.md | 9 +++++---- config.template | 13 ++++++++----- mesh_bot.py | 9 ++++++--- modules/locationdata.py | 7 +++---- modules/settings.py | 6 +++--- modules/system.py | 12 ++++++------ 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index b3c9b95..1c3deda 100644 --- a/README.md +++ b/README.md @@ -223,10 +223,11 @@ lat = 48.50 lon = -123.0 UseMeteoWxAPI = True -# NOAA Coastal Data Enable NOAA Coastal Waters Forecasts (PZZ) and tide cmd -pzzEnabled = False -pzzZoneID = 132 # My Forecast Zone ID, https://www.weather.gov/marine select location and then look at the 'Forecast-by-Zone Map' and select PZZ zone -pzzForecastDays = 3 # number of data points to return, default is 3 +coastalEnabled = False # NOAA Coastal Data Enable NOAA Coastal Waters Forecasts and Tide +# Find the correct costal weather directory at https://tgftp.nws.noaa.gov/data/forecasts/marine/coastal/ +# this map can help https://www.weather.gov/marine select location and then look at the 'Forecast-by-Zone Map' +myCoastalZone = https://tgftp.nws.noaa.gov/data/forecasts/marine/coastal/pz/pzz135.txt # myCoastalZone is the .txt file with the forecast data +castalForecastDays = 3 # number of data points to return, default is 3 ``` ### Module Settings diff --git a/config.template b/config.template index 1b6dace..b090bd9 100644 --- a/config.template +++ b/config.template @@ -150,12 +150,15 @@ NOAAalertCount = 2 # use Open-Meteo API for weather data not NOAA useful for non US locations UseMeteoWxAPI = False -# NOAA Coastal Data Enable NOAA Coastal Waters Forecasts (PZZ) and tide cmd -pzzEnabled = False -# My Forecast Zone ID, https://www.weather.gov/marine select location and then look at the 'Forecast-by-Zone Map' and select PZZ zone -pzzZoneID = 132 +# NOAA Coastal Data Enable NOAA Coastal Waters Forecasts and Tide +coastalEnabled = False +# Find the correct costal weather directory at https://tgftp.nws.noaa.gov/data/forecasts/marine/coastal/ +# pz = Puget Sound, ph = Honolulu HI, gm = Florida Keys, pk = Alaska +# this map can help https://www.weather.gov/marine select location and then look at the 'Forecast-by-Zone Map' +# myCoastalZone is the .txt file with the forecast data +myCoastalZone = https://tgftp.nws.noaa.gov/data/forecasts/marine/coastal/pz/pzz135.txt # number of data points to return, default is 3 -pzzForecastDays = 3 +castalForecastDays = 3 # USGS Hydrology unique identifiers, LID or USGS ID https://waterdata.usgs.gov riverListDefault = diff --git a/mesh_bot.py b/mesh_bot.py index c1e41ae..f575e4f 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -752,8 +752,11 @@ def handle_riverFlow(message, message_from_id, deviceID): return msg def handle_mwx(message_from_id, deviceID, cmd): - # NOAA Coastal and Marine Weather PZZ - return get_nws_marine(zone=pzzZoneID, days=pzzForecastDays) + # NOAA Coastal and Marine Weather + if myCoastalZone is None: + logger.warning("System: Coastal Zone not set, please set in config.ini") + return NO_ALERTS + return get_nws_marine(zone=myCoastalZone, days=castalForecastDays) def handle_wxc(message_from_id, deviceID, cmd): location = get_node_location(message_from_id, deviceID) @@ -1402,7 +1405,7 @@ async def start_rx(): logger.debug("System: Location Telemetry Enabled using NOAA API") if dad_jokes_enabled: logger.debug("System: Dad Jokes Enabled!") - if pzzEnabled: + if coastalEnabled: logger.debug("Coastal Forcast and Tide Enabled!") if games_enabled: logger.debug("System: Games Enabled!") diff --git a/modules/locationdata.py b/modules/locationdata.py index c61805a..6c7f0db 100644 --- a/modules/locationdata.py +++ b/modules/locationdata.py @@ -702,9 +702,8 @@ def get_volcano_usgs(lat=0, lon=0): def get_nws_marine(zone, days=3): # forcast from NWS coastal products - marine_pzz_url = "https://tgftp.nws.noaa.gov/data/forecasts/marine/coastal/pz/pzz" + str(zone) + ".txt" try: - marine_pzz_data = requests.get(marine_pzz_url, timeout=urlTimeoutSeconds) + marine_pzz_data = requests.get(zone, timeout=urlTimeoutSeconds) if not marine_pzz_data.ok: logger.warning("Location:Error fetching NWS Marine PZ data") return ERROR_FETCHING_DATA @@ -720,10 +719,10 @@ def get_nws_marine(zone, days=3): expires_date = expires[:8] if expires_date < todayDate: logger.debug("Location: NWS Marine PZ data expired") - return NO_DATA_NOGPS + return ERROR_FETCHING_DATA else: logger.debug("Location: NWS Marine PZ data not valid") - return NO_DATA_NOGPS + return ERROR_FETCHING_DATA # process the marine forecast data marine_pzz_lines = marine_pzz_data.split("\n") diff --git a/modules/settings.py b/modules/settings.py index 32509aa..51cdb64 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -251,9 +251,9 @@ try: n2yoAPIKey = config['location'].get('n2yoAPIKey', '') # default empty satListConfig = config['location'].get('satList', '25544').split(',') # default 25544 ISS riverListDefault = config['location'].get('riverList', '').split(',') # default 12061500 Skagit River - pzzEnabled = config['location'].getboolean('pzzEnabled', False) # default False - pzzZoneID = config['location'].getint('pzzZoneID', 100) # default 100, PZZ132 for Seattle area - pzzForecastDays = config['location'].getint('pzzForecastDays', 3) # default 3 days + coastalEnabled = config['location'].getboolean('coastalEnabled', False) # default False + myCoastalZone = config['location'].get('myCoastalZone', None) # default None + castalForecastDays = config['location'].getint('castalForecastDays', 3) # default 3 days # location alerts emergencyAlertBrodcastEnabled = config['location'].getboolean('eAlertBroadcastEnabled', False) # default False diff --git a/modules/system.py b/modules/system.py index 598985c..429a4c5 100644 --- a/modules/system.py +++ b/modules/system.py @@ -74,8 +74,8 @@ if enableCmdHistory: # Location Configuration if location_enabled: from modules.locationdata import * # from the spudgunman/meshing-around repo - trap_list = trap_list + trap_list_location + ("tide",) - help_message = help_message + ", whereami, wx, tide" + trap_list = trap_list + trap_list_location + help_message = help_message + ", whereami, wx" if enableGBalerts and not enableDEalerts: from modules.globalalert import * # from the spudgunman/meshing-around repo logger.warning(f"System: GB Alerts not functional at this time need to find a source API") @@ -101,11 +101,11 @@ if wxAlertBroadcastEnabled or emergencyAlertBrodcastEnabled or volcanoAlertBroad trap_list = trap_list + ("wx", "wxa", "wxalert", "ea", "ealert", "valert") help_message = help_message + ", wxalert, ealert, valert" -# NOAA Coastal Waters Forecasts PZZ -if pzzEnabled: +# NOAA Coastal Waters Forecasts +if coastalEnabled: from modules.locationdata import * # from the spudgunman/meshing-around repo - trap_list = trap_list + ("mwx",) - help_message = help_message + ", mwx" + trap_list = trap_list + ("mwx","tide",) + help_message = help_message + ", mwx, tide" # BBS Configuration if bbs_enabled: