Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix weather station autodetect #1254

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/panoptes/pocs/sensor/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class WeatherStation(PanBase):
"""

def __init__(self,
port: str = None,
serial_port: str = None,
name: str = 'Weather Station',
db_collection: str = 'weather',
*args, **kwargs):
"""Initialize the weather station.

Args:
port (str, optional): The dev port for the mount, usually the usb-serial converter.
serial_port (str, optional): The dev port for the mount, usually the usb-serial converter.
name (str): The user-friendly name for the weather station.
db_collection (str): Which collection (i.e. table) to store the values in, default 'weather'.
"""
Expand All @@ -29,12 +29,16 @@ def __init__(self,
conf.update(kwargs)
conf.pop('auto_detect', None)

self.port = port or conf.get('port', '/dev/ttyUSB0')
# Remove the conf port if passed one.
if serial_port is not None:
conf.pop('serial_port', None)

self.serial_port = serial_port or conf.get('serial_port', '/dev/ttyUSB0')
self.name = name
self.collection_name = db_collection

self.logger.debug(f'Setting up weather station connection for {name=} on {self.port}')
self.weather_station = CloudSensor(serial_port=self.port, **conf)
self.logger.debug(f'Setting up weather station connection for {name=} on {self.serial_port}')
self.weather_station = CloudSensor(serial_port=self.serial_port, **conf)

self.logger.debug(f'Weather station config: {self.weather_station.config}')
self.logger.info(f'{self.weather_station} initialized')
Expand Down
4 changes: 2 additions & 2 deletions src/panoptes/pocs/utils/service/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ async def startup():
if conf.get('auto_detect', False) is True:
ports = [p.device for p in get_comports()]
else:
ports = [conf['port']]
ports = [conf['serial_port']]

# Try to connect to the weather station.
for port in ports:
if 'ioptron' in port:
continue

conf['port'] = port
conf['serial_port'] = port
try:
weather_station = WeatherStation(**conf)
break
Expand Down
Loading