From 100a743ecbe627a9833f3869c10601c3a404d9ad Mon Sep 17 00:00:00 2001 From: David Brooke Date: Sun, 17 Mar 2019 18:35:57 +0000 Subject: [PATCH 1/2] Add web server host setting to config --- auto_rx/auto_rx.py | 8 ++++---- auto_rx/autorx/config.py | 5 ++++- auto_rx/station.cfg.example | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/auto_rx/auto_rx.py b/auto_rx/auto_rx.py index 9a00150..137a6b9 100644 --- a/auto_rx/auto_rx.py +++ b/auto_rx/auto_rx.py @@ -466,7 +466,7 @@ def main(): # Start up the flask server. # This needs to occur AFTER logging is setup, else logging breaks horribly for some reason. - start_flask(port=config['web_port']) + start_flask(host=config['web_host'], port=config['web_port']) # If we have been supplied a frequency via the command line, override the whitelist settings # to only include the supplied frequency. @@ -610,7 +610,7 @@ def main(): # within a cronjob. if (_timeout > 0) and ((time.time()-_start_time) > _timeout): logging.info("Shutdown time reached. Closing.") - stop_flask(port=config['web_port']) + stop_flask(host=config['web_host'], port=config['web_port']) stop_all() break @@ -623,11 +623,11 @@ if __name__ == "__main__": main() except KeyboardInterrupt: # Upon CTRL+C, shutdown all threads and exit. - stop_flask(port=config['web_port']) + stop_flask(host=config['web_host'], port=config['web_port']) stop_all() except Exception as e: # Upon exceptions, attempt to shutdown threads and exit. traceback.print_exc() print("Main Loop Error - %s" % str(e)) - stop_flask(port=config['web_port']) + stop_flask(host=config['web_host'], port=config['web_port']) stop_all() diff --git a/auto_rx/autorx/config.py b/auto_rx/autorx/config.py index 7330e0e..ed49e60 100644 --- a/auto_rx/autorx/config.py +++ b/auto_rx/autorx/config.py @@ -84,6 +84,7 @@ def read_auto_rx_config(filename): 'station_beacon_comment': "radiosonde_auto_rx SondeGate v", 'station_beacon_icon': '/r', # Web Settings, + 'web_host' : '0.0.0.0', 'web_port' : 5000, 'web_archive_age': 120, # Advanced Parameters @@ -213,10 +214,12 @@ def read_auto_rx_config(filename): # New settings added in 20180624. try: + auto_rx_config['web_host'] = config.get('web', 'web_host') auto_rx_config['web_port'] = config.getint('web', 'web_port') auto_rx_config['web_archive_age'] = config.getint('web', 'archive_age') except: logging.error("Config - Missing Web Server settings. Using defaults.") + auto_rx_config['web_host'] = '0.0.0.0' auto_rx_config['web_port'] = 5000 auto_rx_config['web_archive_age'] = 120 @@ -312,4 +315,4 @@ if __name__ == '__main__': config = read_auto_rx_config(sys.argv[1]) - pprint.pprint(global_config) \ No newline at end of file + pprint.pprint(global_config) diff --git a/auto_rx/station.cfg.example b/auto_rx/station.cfg.example index 5f0f44b..1033447 100644 --- a/auto_rx/station.cfg.example +++ b/auto_rx/station.cfg.example @@ -264,6 +264,8 @@ per_sonde_log = True # WEB INTERFACE SETTINNGS # ########################### [web] +# Server Host - Can be set to :: to listen on IPv6 +web_host = 0.0.0.0 # Server Port - Ports below 1024 can only be used if you run auto_rx as root (not recommended) web_port = 5000 # Archive Age - How long to keep a sonde telemetry in memory for the web client to access, in minutes From 9bbb583841cddc51ef513ee10a4a5fe06552b134 Mon Sep 17 00:00:00 2001 From: Mark Jessop Date: Mon, 18 Mar 2019 18:31:08 +1030 Subject: [PATCH 2/2] Latch iMet ID on reception of first packet. --- auto_rx/autorx/decode.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/auto_rx/autorx/decode.py b/auto_rx/autorx/decode.py index b1dd8bb..b2be71c 100644 --- a/auto_rx/autorx/decode.py +++ b/auto_rx/autorx/decode.py @@ -124,6 +124,12 @@ class SondeDecoder(object): self.rs92_ephemeris = rs92_ephemeris self.imet_location = imet_location + # iMet ID store. We latch in the first iMet ID we calculate, to avoid issues with iMet-1-RS units + # which don't necessarily have a consistent packet count to time increment ratio. + # This is a tradeoff between being able to handle multiple iMet sondes on a single frequency, and + # not flooding the various databases with sonde IDs in the case of a bad sonde. + self.imet_id = None + # This will become our decoder thread. self.decoder = None @@ -434,7 +440,11 @@ class SondeDecoder(object): # Fix up the time. _telemetry['datetime_dt'] = imet_fix_datetime(_telemetry['datetime']) # Generate a unique ID based on the power-on time and frequency, as iMet sondes don't send one. - _telemetry['id'] = imet_unique_id(_telemetry, custom=self.imet_location) + # Latch this ID and re-use it for the entire decode run. + if self.imet_id == None: + self.imet_id = imet_unique_id(_telemetry, custom=self.imet_location) + + _telemetry['id'] = self.imet_id # If we have been provided a telemetry filter function, pass the telemetry data