diff --git a/CHANGELOG.md b/CHANGELOG.md index 50b5137e..d4ae9c9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,13 @@ #### Bug fixes - - more resilience to "UI state" diverging from "bioreactor state". Often, this occurred when two jobs stared almost immediately (often a networking issue), and the last job would halt since it couldn't get the required resources, however MQTT any data would be overwritten by the last job. Now, multiple places in the request pipeline will reduce duplication. + - more resilience to "UI state" diverging from "bioreactor state". Often, this occurred when two jobs stared almost immediately (often a networking issue), and the last job would halt since it couldn't get the required resources, however any MQTT data would be overwritten by the last job. Now, multiple places in the request pipeline will reduce duplication and prevent two jobs from starting too close to each other. - Improved stirring clean up when stopped in quick succession after starting. + - if a network isn't found, the `monitor` job will not stall, but warning an continue. #### Breaking changes - - in config.ini, the section `od_config` is now `od_reading.config`, and `stirring` is `stirring.config`. When you update, a script will run to automatically update these names in your config.inis. + - in config.ini, the section `od_config` renamed to `od_reading.config`, and `stirring` is `stirring.config`. When you update, a script will run to automatically update these names in your config.inis. ### 24.7.18 diff --git a/config.dev.ini b/config.dev.ini index b11e3e08..0443d5c7 100644 --- a/config.dev.ini +++ b/config.dev.ini @@ -31,7 +31,7 @@ initial_volume_ml=14 initial_alt_media_fraction=0.0 -[stirring] +[stirring.config] target_rpm=500 initial_duty_cycle=15 pwm_hz=200 @@ -47,7 +47,7 @@ Kd=0.0 1=REF 2=90 -[od_config] +[od_reading.config] # how many samples should the ADC publish per second? samples_per_second=0.2 diff --git a/pioreactor/background_jobs/monitor.py b/pioreactor/background_jobs/monitor.py index fa244ea6..ebf60a91 100644 --- a/pioreactor/background_jobs/monitor.py +++ b/pioreactor/background_jobs/monitor.py @@ -231,14 +231,23 @@ def check_for_network(self) -> None: self.wlan_mac_address = "d8:3a:dd:61:01:59" self.eth_mac_address = "d8:3a:dd:61:01:60" else: - ipv4 = get_ip() - while ipv4 == "127.0.0.1" or ipv4 is None: - # no connection? Sound the alarm. - self.logger.warning("Unable to connect to network...") - self.flicker_led_with_error_code(error_codes.NO_NETWORK_CONNECTION) - sleep(1) + + def did_find_network() -> bool: ipv4 = get_ip() + if ipv4 == "127.0.0.1" or ipv4 is None: + # no connection? Sound the alarm. + self.logger.warning("Unable to find a network...") + self.flicker_led_with_error_code(error_codes.NO_NETWORK_CONNECTION) + return False + else: + return True + + if utils.boolean_retry(did_find_network, retries=3, sleep_for=2): + ipv4: str = "" + else: + ipv4 = get_ip() or "" + self.ipv4 = ipv4 try: diff --git a/pioreactor/config.py b/pioreactor/config.py index bae1cdab..ce75c339 100644 --- a/pioreactor/config.py +++ b/pioreactor/config.py @@ -41,7 +41,13 @@ def invert_section(self, section: str) -> dict[str, str]: return reversed_section def _get_conv(self, section, option, conv, *, raw=False, vars=None, fallback=None, **kwargs): - return self._get(section, conv, option, raw=raw, vars=vars, fallback=fallback, **kwargs) + try: + return self._get(section, conv, option, raw=raw, vars=vars, fallback=fallback, **kwargs) + except TypeError as e: + from pioreactor.logging import create_logger + + create_logger("read config").error(e) + raise e def getboolean(self, section: str, option: str, *args, **kwargs) -> bool: # type: ignore try: diff --git a/pioreactor/utils/__init__.py b/pioreactor/utils/__init__.py index d96e1192..2056cbf3 100644 --- a/pioreactor/utils/__init__.py +++ b/pioreactor/utils/__init__.py @@ -420,8 +420,8 @@ def __getitem__(self, key: str) -> float: def boolean_retry( func: Callable[..., bool], - f_args: tuple, - f_kwargs: dict, + f_args: tuple = tuple(), + f_kwargs: dict = dict(), retries: int = 3, sleep_for: float = 0.25, ) -> bool: