Commit f5d083bd authored by Ilias Daradimos's avatar Ilias Daradimos

GPS location retrieval

startup sequence
Lint
Set GPSD timeout to job interval
Signed-off-by: default avatarIlias Daradimos <ilias@libre.space>
parent d59f806f
Pipeline #46560697 passed with stage
in 2 minutes and 10 seconds
......@@ -14,8 +14,9 @@ import satnogsclient.config
from satnogsclient.settings import (SATNOGS_API_TOKEN, DEFAULT_LOGGING,
SATNOGS_STATION_ID, SATNOGS_STATION_LAT,
SATNOGS_STATION_LON, SATNOGS_STATION_ELEV,
SATNOGS_NETWORK_API_URL)
SATNOGS_NETWORK_API_URL, GPSD_ENABLED)
from satnogsclient.scheduler.tasks import status_listener, exec_rigctld
from satnogsclient.locator import locator
__author__ = satnogsclient.config.AUTHOR
__email__ = satnogsclient.config.EMAIL
......@@ -37,21 +38,22 @@ def main():
if not SATNOGS_STATION_ID:
raise Exception('SATNOGS_STATION_ID not configured.')
if not SATNOGS_STATION_LAT:
if not (SATNOGS_STATION_LAT or GPSD_ENABLED):
raise Exception('SATNOGS_STATION_LAT not configured')
if not SATNOGS_STATION_LON:
if not (SATNOGS_STATION_LON or GPSD_ENABLED):
raise Exception('SATNOGS_STATION_LON not configured')
if SATNOGS_STATION_ELEV is None:
if SATNOGS_STATION_ELEV is None and GPSD_ENABLED is False:
raise Exception('SATNOGS_STATION_ELEV not configured')
if not SATNOGS_API_TOKEN:
raise Exception('SATNOGS_API_TOKEN not configured')
logging.config.dictConfig(DEFAULT_LOGGING)
LOGGER.info('Starting status listener thread...')
gps_locator = locator.Locator(120)
gps_locator.update_location()
ser = threading.Thread(target=status_listener, args=())
ser.daemon = True
ser.start()
......
import time
import logging
import logging.config
from satnogsclient import settings
import gps
LOGGER = logging.getLogger('satnogsclient')
class Locator(object):
def __init__(self, timeout):
self.timeout = timeout
def show_location(self, gpsd):
print('mode ', gpsd.fix.mode)
print('status ', gpsd.status)
print('eps ', gpsd.fix.eps)
print('epx ', gpsd.fix.epx)
print('epv ', gpsd.fix.epv)
print('ept ', gpsd.fix.ept)
print('climb ', gpsd.fix.climb)
print('hdop ', gpsd.hdop)
print('timeout ', self.timeout)
print gpsd
def update_location(self):
if settings.GPSD_ENABLED is not True:
return
no_timeout = (self.timeout == 0)
if (settings.SATNOGS_STATION_LAT is None
or settings.SATNOGS_STATION_LON is None
or settings.SATNOGS_STATION_ELEV is None):
no_timeout = True
LOGGER.info('No default coordinates, GPS timeout disabled')
else:
LOGGER.info(
'Last coordinates %f %f %d', settings.SATNOGS_STATION_LAT,
settings.SATNOGS_STATION_LON, settings.SATNOGS_STATION_ELEV)
end_time = time.time() + self.timeout
try:
gpsd = gps.gps(mode=gps.WATCH_ENABLE)
gpsd.next()
LOGGER.info("Waiting for GPS")
while gpsd.fix.mode != gps.MODE_3D and (time.time() < end_time
or no_timeout):
# self.show_location(gpsd)
self.timeout -= 1
gpsd.next()
except StopIteration:
LOGGER.info('GPSD connection failed')
return
if gpsd.fix.mode == gps.MODE_3D:
settings.SATNOGS_STATION_LAT = gpsd.fix.latitude
settings.SATNOGS_STATION_LON = gpsd.fix.longitude
settings.SATNOGS_STATION_ELEV = gpsd.fix.altitude
LOGGER.info(
'Updating coordinates %f %f %d', settings.SATNOGS_STATION_LAT,
settings.SATNOGS_STATION_LON, settings.SATNOGS_STATION_ELEV)
else:
LOGGER.info("GPS timeout, using last known coordinates")
......@@ -14,6 +14,7 @@ from dateutil import parser
from satnogsclient.scheduler import SCHEDULER
from satnogsclient import settings
from satnogsclient.observer.observer import Observer
from satnogsclient.locator import locator
import requests
......@@ -148,9 +149,17 @@ def post_data():
def get_jobs():
"""Query SatNOGS Network API to GET jobs."""
gps_locator = locator.Locator(
settings.SATNOGS_NETWORK_API_QUERY_INTERVAL * 60)
gps_locator.update_location()
LOGGER.info('Get jobs started')
url = urljoin(settings.SATNOGS_NETWORK_API_URL, 'jobs/')
params = {'ground_station': settings.SATNOGS_STATION_ID}
params = {
'ground_station': settings.SATNOGS_STATION_ID,
'lat': settings.SATNOGS_STATION_LAT,
'lon': settings.SATNOGS_STATION_LON,
'alt': int(settings.SATNOGS_STATION_ELEV)
}
headers = {'Authorization': 'Token {0}'.format(settings.SATNOGS_API_TOKEN)}
LOGGER.debug('URL: %s', url)
LOGGER.debug('Params: %s', params)
......
......@@ -27,8 +27,9 @@ SATNOGS_STATION_LAT = _cast_or_none(float,
environ.get('SATNOGS_STATION_LAT', None))
SATNOGS_STATION_LON = _cast_or_none(float,
environ.get('SATNOGS_STATION_LON', None))
SATNOGS_STATION_ELEV = _cast_or_none(float,
SATNOGS_STATION_ELEV = _cast_or_none(int,
environ.get('SATNOGS_STATION_ELEV', None))
GPSD_ENABLED = _cast_or_none(bool, environ.get('GPSD_ENABLED', None))
# Output paths
SATNOGS_APP_PATH = environ.get('SATNOGS_APP_PATH', '/tmp/.satnogs')
......
......@@ -28,6 +28,7 @@ install_requires =
pytz
numpy
matplotlib
gps
packages = find:
include_package_data = True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment