diff --git a/src/pi/temp_sensor/temp_sensor/temp_sensor.py b/src/pi/temp_sensor/temp_sensor/temp_sensor.py index 936bafa4..9576bd71 100644 --- a/src/pi/temp_sensor/temp_sensor/temp_sensor.py +++ b/src/pi/temp_sensor/temp_sensor/temp_sensor.py @@ -17,13 +17,16 @@ def __init__(self) -> None: self.timer = self.create_timer(timer_period, self.timer_callback) def timer_callback(self) -> None: - self.sensor.read() - temp_reading = self.sensor.temperature() - - # If any of the sensors detect water, send true to /tether/flooding - msg = Temperature() - msg.reading = temp_reading - self.publisher.publish(msg) + try: + self.sensor.read() + temp_reading = self.sensor.temperature() + + # If any of the sensors detect water, send true to /tether/flooding + msg = Temperature() + msg.reading = temp_reading + self.publisher.publish(msg) + except OSError: + print('Failed to read temperature, skipping this read') def main(args: None = None) -> None: diff --git a/src/pi/temp_sensor/temp_sensor/temp_sensor_dry_run.py b/src/pi/temp_sensor/temp_sensor/temp_sensor_dry_run.py index debb5eea..26bf1c96 100644 --- a/src/pi/temp_sensor/temp_sensor/temp_sensor_dry_run.py +++ b/src/pi/temp_sensor/temp_sensor/temp_sensor_dry_run.py @@ -9,12 +9,16 @@ def debug_log() -> None: sensor.init() while True: - sensor.read() - print( - sensor.temperature(), # Get temperature in default units (Centigrade) - '\t', - sensor.temperature(tsys01.UNITS_Farenheit) - ) + try: + sensor.read() # Sometimes throws OSError: [Errno 121] Remote I/O error + print( + sensor.temperature(), # Get temperature in default units (Centigrade) + '\t', + sensor.temperature(tsys01.UNITS_Farenheit) + ) + except OSError: + print('Failed to read temperature, trying again') + sleep(1)