A database backend for the Open Glider Network
 
 
 
 
 
 
Go to file
Konstantin Gründger ba7ae37ef2 Bugfix for getting receiver names 2016-02-21 15:28:19 +01:00
alembic DB update for hardware version 2016-02-20 15:26:32 +01:00
config Add note about special backend requirements for some tasks 2016-02-04 23:12:16 +01:00
ogn Bugfix for getting receiver names 2016-02-21 15:28:19 +01:00
tests Parse hardware version as hex 2016-02-19 17:59:23 +01:00
.gitignore gitignore: Add celerybeat-schedule 2016-02-17 18:26:00 +01:00
.travis.yml Add setup.py to create a package 2016-01-12 13:56:18 +01:00
CHANGELOG.md Move parsing from 'ogn.model.*' to 'ogn.parser' 2016-02-18 22:49:56 +01:00
CONTRIBUTORS Update README, CONTRIBUTORS. 2015-11-15 10:01:57 +01:00
LICENSE Create LICENSE 2015-11-14 22:47:25 +01:00
MANIFEST.in Add MANIFEST.in to include README,LICENSE & tests 2016-01-12 17:24:28 +01:00
README.md ogn.gateway: Remove implicit sqlalchemy dependency 2016-02-18 22:49:56 +01:00
alembic.ini alembic: Load configuration from ogn config 2016-01-31 02:20:00 +01:00
manage.py Add common CLI manage.py. 2015-11-15 09:59:48 +01:00
requirements.txt Add setup.py to create a package 2016-01-12 13:56:18 +01:00
setup.cfg Travis CI: Replace pep8 with flake8 2016-01-06 00:37:47 +01:00
setup.py setup.py: Change short description 2016-02-17 20:16:33 +01:00

README.md

ogn-python

[Build Status] (https://travis-ci.org/glidernet/ogn-python) [Coverage Status] (https://coveralls.io/r/glidernet/ogn-python) [PyPi Version] (https://pypi.python.org/pypi/ogn-python)

A python module for the Open Glider Network. The submodule 'ogn.gateway' is an aprs client which could be invoked via a CLI or used by other python projects. The CLI allows to save all received beacons into a database with SQLAlchemy. The sqlite-backend is sufficient for simple testing, but some tasks (e.g. logbook generation) require a proper backend like postgresql. An external python project would instantiate ogn.gateway and register a custom callback, called each time a beacon is received.

Examples

Usage - python module

Implement your own gateway by using ogn.gateway with a custom callback function. Each time a beacon is received, this function gets called and lets you process the incoming data.

Example:

#!/usr/bin/env python3
from ogn.gateway.client import ognGateway
from ogn.parser.parse import parse_aprs, parse_ogn_beacon
from ogn.parser.exceptions import ParseError


def process_beacon(raw_message):
    if raw_message[0] == '#':
        print('Server Status: {}'.format(raw_message))
        return

    try:
        message = parse_aprs(raw_message)
        message.update(parse_ogn_beacon(message['comment']))

        print('Received {beacon_type} from {name}'.format(**message))
    except ParseError as e:
        print('Error, {}'.format(e.message))


if __name__ == '__main__':
    gateway = ognGateway(aprs_user='N0CALL')
    gateway.connect()

    try:
        gateway.run(callback=process_beacon, autoreconnect=True)
    except KeyboardInterrupt:
        print('\nStop ogn gateway')

    gateway.disconnect()

Usage - CLI

Installation and Setup

  1. Checkout the repository

    git clone https://github.com/glidernet/ogn-python.git
    
  2. Install python requirements

    pip install -r requirements.txt
    
  3. Install redis for asynchronous tasks (like takeoff/landing-detection)

    apt-get install redis-server
    
  4. Create database

    ./manage.py db.init
    

Running the aprs client and task server

To schedule tasks like takeoff/landing-detection (logbook.compute), Celery with Redis is used. The following scripts run in the foreground and should be deamonized (eg. use supervisord).

  • Start the aprs client

    ./manage.py gateway.run
    
  • Start a task server (make sure redis is up and running)

    celery -A ogn.collect worker -l info
    
  • Start the task scheduler (make sure a task server is up and running)

    celery -A ogn.collect beat -l info
    

To load a custom configuration, create a file myconfig.py (see config/default.py) and set the environment variable OGN_CONFIG_MODULE accordingly.

touch myconfig.py
export OGN_CONFIG_MODULE="myconfig"
./manage.py gateway.run

manage.py - CLI options

usage: manage.py [<namespace>.]<command> [<args>]

positional arguments:
  command     the command to run

optional arguments:
  -h, --help  show this help message and exit

available commands:

  [db]
    drop                   Drop all tables.
    import_ddb             Import registered devices from the DDB.
    import_file            Import registered devices from a local file.
    init                   Initialize the database.
    upgrade                Upgrade database to the latest version.

  [gateway]
    run                    Run the aprs client.

  [logbook]
    compute                Compute takeoffs and landings.
    show                   Show a logbook for <airport_name> located at given position.

  [show.devices]
    stats                  Show some stats on registered devices.

  [show.receiver]
    hardware_stats         Show some statistics of receiver hardware.
    list_all               Show a list of all receivers.
    software_stats         Show some statistics of receiver software.

Only the command logbook.compute requires a running task server (celery) at the moment.

Available tasks

  • ogn.collect.database.import_ddb - Import registered devices from the ddb
  • ogn.collect.database.import_file - Import registered devices from a local file
  • ogn.collect.heatmap.update_beacon_receiver_distance_all - Calculate the distance between aircraft and receiver for the last aircraft beacons
  • ogn.collect.receiver.update_receivers - Populate/update receiver table (requires postgresql-backend)
  • ogn.collect.logbook.compute_takeoff_and_landing - Generate TakeoffLanding table (requires postgresql-backend)

If the task server is up and running, tasks could be started manually.

python3
>>>from ogn.collect.database import import_ddb
>>>import_ddb.delay()

License

Licensed under the AGPLv3.