mirror of
				https://github.com/NotAShelf/air-quality-monitor.git
				synced 2025-10-31 03:02:38 +00:00 
			
		
		
		
	handle serial port unavailable
This commit is contained in:
		
					parent
					
						
							
								a22882a169
							
						
					
				
			
			
				commit
				
					
						5c7691ba6b
					
				
			
		
					 1 changed files with 6 additions and 1 deletions
				
			
		|  | @ -17,7 +17,12 @@ class AirQualityMonitor: | ||||||
|     SERIAL_DEVICE = os.environ.get("SERIAL_DEVICE", "/dev/ttyUSB0") |     SERIAL_DEVICE = os.environ.get("SERIAL_DEVICE", "/dev/ttyUSB0") | ||||||
| 
 | 
 | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
|         self.ser = serial.Serial(self.SERIAL_DEVICE) |         # if path does not exist, error and exit | ||||||
|  |         if not os.path.exists(self.SERIAL_DEVICE): | ||||||
|  |             raise RuntimeError(f"Serial device {self.SERIAL_DEVICE} not found.") | ||||||
|  |         else: | ||||||
|  |             print(f"Serial device {self.SERIAL_DEVICE} found.") | ||||||
|  |             self.ser = serial.Serial(self.SERIAL_DEVICE) | ||||||
| 
 | 
 | ||||||
|     def get_measurement(self): |     def get_measurement(self): | ||||||
|         """Fetches a measurement from the sensor and returns it.""" |         """Fetches a measurement from the sensor and returns it.""" | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue