From 3b3ede79b67562518446fd19fe890c1da35946bd Mon Sep 17 00:00:00 2001 From: CamDavidsonPilon Date: Sun, 1 Oct 2023 20:55:57 -0400 Subject: [PATCH] change log and ipv4 --- CHANGELOG.md | 10 ++++++-- pioreactor/background_jobs/od_reading.py | 4 ++-- pioreactor/utils/networking.py | 30 +++++++++++++----------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf2c5e34..5c432c0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +### Upcoming + + - Fix OD calibration that would produce an extremely high value when the signal was below the minimum signal (the blank) during OD calibration. + - IPv4 is really IPv4 now. + + ### 23.9.20 The previous change: @@ -5,8 +11,8 @@ The previous change: had an import error that I didn't see in my testing. We changed this further to: -- Base automations now subclass from `pioreactor.automations.base.AutomationJob`. -- Fix bug on /updates page. + - Base automations now subclass from `pioreactor.automations.base.AutomationJob`. + - Fix bug on /updates page. ### 23.9.19 - When installing plugins, any leader-only commands would not be run. This is fixed. diff --git a/pioreactor/background_jobs/od_reading.py b/pioreactor/background_jobs/od_reading.py index e705a8de..223b4172 100644 --- a/pioreactor/background_jobs/od_reading.py +++ b/pioreactor/background_jobs/od_reading.py @@ -741,7 +741,7 @@ def calibration(observed_voltage: pt.Voltage) -> pt.OD: if not self.has_logged_warning: self.logger.warning( - f"Signal below suggested calibration range. Calibrated for OD=[{min_OD:0.3g}, {max_OD:0.3g}], V=[{min_voltage:0.3g}, {max_voltage:0.3g}]. Observed {observed_voltage:0.3f}V." + f"Signal below suggested calibration range. Trimming signal. Calibrated for OD=[{min_OD:0.3g}, {max_OD:0.3g}], V=[{min_voltage:0.3g}, {max_voltage:0.3g}]. Observed {observed_voltage:0.3f}V." ) self.has_logged_warning = True return min_OD @@ -749,7 +749,7 @@ def calibration(observed_voltage: pt.Voltage) -> pt.OD: else: if not self.has_logged_warning: self.logger.warning( - f"Signal outside suggested calibration range. Calibrated for OD=[{min_OD:0.3g}, {max_OD:0.3g}], V=[{min_voltage:0.3g}, {max_voltage:0.3g}]. Observed {observed_voltage:0.3f}V." + f"Signal outside suggested calibration range. Trimming signal. Calibrated for OD=[{min_OD:0.3g}, {max_OD:0.3g}], V=[{min_voltage:0.3g}, {max_voltage:0.3g}]. Observed {observed_voltage:0.3f}V." ) self.has_logged_warning = True return max_OD diff --git a/pioreactor/utils/networking.py b/pioreactor/utils/networking.py index e4c7f011..f54d69ff 100644 --- a/pioreactor/utils/networking.py +++ b/pioreactor/utils/networking.py @@ -79,20 +79,22 @@ def is_connected_to_network() -> bool: def get_ip() -> Optional[str]: - # TODO: is this always ipv4?? - from psutil import net_if_addrs # type: ignore - - # Check for IP address of wireless network interface 'wlan0' - try: - return net_if_addrs()["wlan0"][0].address - except Exception: - return None - - # Check for IP address of ethernet network interface 'eth0' - try: - return net_if_addrs()["eth0"][0].address - except Exception: - pass + # returns ipv4 + from psutil import net_if_addrs + + interfaces = ["wlan0", "eth0"] + + for iface in interfaces: + try: + ipv4_addresses = [ + addr.address for addr in net_if_addrs()[iface] if addr.family == 2 + ] # AddressFamily.AF_INET == 2 + if ipv4_addresses: + return ipv4_addresses[0] + except Exception: + continue + + return None def discover_workers_on_network(terminate: bool = False) -> Generator[str, None, None]: