gopensky

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

README

Go OpenSKY Network API

PkgGoDev Go codecov Go Report

This is the golang implementation of the OpenSky network's live API. The API lets you retrieve live airspace information (ADS-B and Mode S data) for research and non-commerical purposes.

For documentation and examples visit Golang OpenSky Network API.

NOTE: there are some limitation sets for anonymous and OpenSky users, visit following links for more information:

Getting Started

Install the latest version of the library:

$ go get github.com/navidys/gopensky

Next, include gopensky in you application:

import "github.com/navidys/gopensky"

Features

Examples

Here is an example program of retrieving Elon Musk's primary private jet (he has many and one of them has the ICAO24 transponder address a835af) flights between Thu Aug 31 2023 23:11:04 and Fri Sep 29 2023 23:11:04.

Visit Golang OpenSky Network API for more examples.

package main

import (
	"context"
	"fmt"
	"os"
	"time"

	"github.com/navidys/gopensky"
)

func main() {
	conn, err := gopensky.NewConnection(context.Background(), "", "")
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// Retrieve Elon Musk's primary private jet flight data, he has many and one of
	// them has the ICAO24 transponder address a835af
	// begin time: 1693523464 (Thu Aug 31 2023 23:11:04)
	// end time: 1696029064 (Fri Sep 29 2023 23:11:04)

	flightsData, err := gopensky.GetFlightsByAircraft(conn, "a835af", 1693523464, 1696029064)
	if err != nil {
		fmt.Println(err)
		os.Exit(2)
	}

	for _, flightData := range flightsData {
		var (
			departedAirport string
			arrivalAriport  string
		)

		if flightData.EstDepartureAirport != nil {
			departedAirport = *flightData.EstDepartureAirport
		}

		if flightData.EstArrivalAirport != nil {
			arrivalAriport = *flightData.EstArrivalAirport
		}

		fmt.Printf("ICAO24: %s, Departed: %4s, Arrival: %4s, LastSeen: %s\n",
			flightData.Icao24,
			departedAirport,
			arrivalAriport,
			time.Unix(flightData.LastSeen, 0),
		)
	}
}

output:

ICAO24: a835af, Departed: KAUS, Arrival: KUVA, LastSeen: 2023-09-29 07:46:02 +1000 AEST
ICAO24: a835af, Departed:     , Arrival: 02XS, LastSeen: 2023-09-19 10:59:04 +1000 AEST
ICAO24: a835af, Departed:     , Arrival: KSLC, LastSeen: 2023-09-16 12:56:20 +1000 AEST
ICAO24: a835af, Departed: KAUS, Arrival: KIAD, LastSeen: 2023-09-13 14:35:18 +1000 AEST
ICAO24: a835af, Departed: KSJC, Arrival: 2TS2, LastSeen: 2023-09-09 18:40:39 +1000 AEST
ICAO24: a835af, Departed: KAUS, Arrival: KSJC, LastSeen: 2023-09-08 08:20:02 +1000 AEST

License

Licensed under the Apache 2.0 license.

Documentation

Overview

This is the golang implementation of the OpenSky network's live API. The API lets you retrieve live airspace information (ADS-B and Mode S data) for research and non-commercial purposes.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidAirportName  = errors.New("invalid airport name")
	ErrInvalidAircraftName = errors.New("invalid aircraft name")
	ErrInvalidUnixTime     = errors.New("invalid unix time")
)

Functions

func NewConnection

func NewConnection(ctx context.Context, username string, password string) (context.Context, error)

Types

type BoundingBoxOptions

type BoundingBoxOptions struct {
	// Lower bound for the latitude in decimal degrees.
	Lamin float64

	// lower bound for the longitude in decimal degrees.
	Lomin float64

	// upper bound for the latitude in decimal degrees.
	Lamax float64

	// upper bound for the longitude in decimal degrees.
	Lomax float64
}

func NewBoundingBox

func NewBoundingBox(lamin float64, lomin float64, lamax float64, lomax float64) *BoundingBoxOptions

NewBoundingBox returns new bounding box options for states information gathering.

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

type FlighData

type FlighData struct {
	// Unique ICAO 24-bit address of the transponder in hex string representation.
	// All letters are lower case.
	Icao24 string `json:"icao24"`

	// Estimated time of departure for the flight as Unix time (seconds since epoch).
	FirstSeen int64 `json:"firstSeen"`

	// ICAO code of the estimated departure airport.
	// Can be nil if the airport could not be identified.
	EstDepartureAirport *string `json:"estDepartureAirport"`

	// Estimated time of arrival for the flight as Unix time (seconds since epoch).
	LastSeen int64 `json:"lastSeen"`

	// ICAO code of the estimated arrival airport.
	// Can be nil if the airport could not be identified.
	EstArrivalAirport *string `json:"estArrivalAirport"`

	// Callsign of the vehicle (8 chars).
	// Can be nil if no callsign has been received.
	// If the vehicle transmits multiple callsigns during the flight,
	// we take the one seen most frequently.
	Callsign *string `json:"callsign"`

	// Horizontal distance of the last received airborne position
	// to the estimated departure airport in meters.
	EstDepartureAirportHorizDistance int64 `json:"estDepartureAirportHorizDistance"`

	// Vertical distance of the last received airborne position
	// to the estimated departure airport in meters.
	EstDepartureAirportVertDistance int64 `json:"estDepartureAirportVertDistance"`

	// Horizontal distance of the last received airborne position
	// to the estimated arrival airport in meters.
	EstArrivalAirportHorizDistance int64 `json:"estArrivalAirportHorizDistance"`

	// Vertical distance of the last received airborne position to
	// the estimated arrival airport in meters.
	EstArrivalAirportVertDistance int64 `json:"estArrivalAirportVertDistance"`

	// Number of other possible departure airports.
	// These are airports in short distance to estDepartureAirport.
	DepartureAirportCandidatesCount int `json:"departureAirportCandidatesCount"`

	// Number of other possible departure airports.
	ArrivalAirportCandidatesCount int `json:"arrivalAirportCandidatesCount"`
}

func GetArrivalsByAirport

func GetArrivalsByAirport(ctx context.Context, airport string, begin int64, end int64) ([]FlighData, error)

GetArrivalsByAirport retrieves flights for a certain airport which arrived within a given time interval [being, end]. The given time interval must not be larger than seven days!

func GetDeparturesByAirport

func GetDeparturesByAirport(ctx context.Context, airport string, begin int64, end int64) ([]FlighData, error)

GetDeparturesByAirport retrieves flights for a certain airport which departed The given time interval must not be larger than seven days!

func GetFlightsByAircraft

func GetFlightsByAircraft(ctx context.Context, icao24 string, begin int64, end int64) ([]FlighData, error)

GetFlightsByAircraft retrieves flights for a particular aircraft within a certain time interval. Resulting flights departed and arrived within [begin, end]. The given time interval must not be larger than 30 days!

func GetFlightsByInterval

func GetFlightsByInterval(ctx context.Context, begin int64, end int64) ([]FlighData, error)

GetFlightsByInterval retrieves flights for a certain time interval [begin, end]. The given time interval must not be larger than two hours!

type FlightTrack

type FlightTrack struct {
	// Unique ICAO 24-bit address of the transponder in hex string representation.
	Icao24 string `json:"icao24"`

	// Time of the first waypoint in seconds since epoch (Unix time).
	StartTime int64 `json:"startTime"`

	// Time of the last waypoint in seconds since epoch (Unix time).
	EndTime int64 `json:"endTime"`

	// Callsign (8 characters) that holds for the whole track. Can be nil.
	Callsign *string `json:"callsign"`

	// Waypoints of the trajectory (description below).
	Path []WayPoint `json:"path"`
}

func GetTrackByAircraft

func GetTrackByAircraft(ctx context.Context, icao24 string, time int64) (FlightTrack, error)

GetTrackByAircraft retrieves the trajectory for a certain aircraft at a given time.

type FlightTrackResponse

type FlightTrackResponse struct {
	Icao24    string          `json:"icao24"`
	StartTime float64         `json:"startTime"`
	EndTime   float64         `json:"endTime"`
	Callsign  *string         `json:"callsign"`
	Path      [][]interface{} `json:"path"`
}

type StateVector

type StateVector struct {
	// Unique ICAO 24-bit address of the transponder in hex string representation.
	Icao24 string `json:"icao24"`

	// Callsign of the vehicle (8 chars). Can be nil if no callsign has been received.
	Callsign *string `json:"callsign"`

	// Country name inferred from the ICAO 24-bit address.
	OriginCountry string `json:"originCountry"`

	// Unix timestamp (seconds) for the last position update.
	// Can be nil if no position report was received by OpenSky within the past 15s.
	TimePosition *int64 `json:"timePosition"`

	// Unix timestamp (seconds) for the last update in general.
	//  This field is updated for any new, valid message received from the transponder.
	LastContact int64 `json:"lastContact"`

	// WGS-84 longitude in decimal degrees. Can be nil.
	Longitude *float64 `json:"longitude"`

	// WGS-84 latitude in decimal degrees. Can be nil.
	Latitude *float64 `json:"latitude"`

	// Barometric altitude in meters. Can be nil.
	BaroAltitude *float64 `json:"baroAltitude"`

	// Boolean value which indicates if the position was retrieved from a surface position report.
	OnGround bool `json:"onGround"`

	// Velocity over ground in m/s. Can be nil.
	Velocity *float64 `json:"velocity"`

	// True track in decimal degrees clockwise from north (north=0°). Can be nil.
	TrueTrack *float64 `json:"trueTrack"`

	// Vertical rate in m/s.
	// A positive value indicates that the airplane is climbing, a negative value indicates that it descends.
	// Can be nil.
	VerticalRate *float64 `json:"verticalTate"`

	// IDs of the receivers which contributed to this state vector.
	//  Is nil if no filtering for sensor was used in the request.
	Sensors []int `json:"sensors"`

	// Geometric altitude in meters. Can be nil.
	GeoAltitude *float64 `json:"geoAltitude"`

	// The transponder code aka Squawk. Can be nil.
	Squawk *string `json:"squawk"`

	// Whether flight status indicates special purpose indicator.
	Spi bool `json:"spi"`

	// Origin of this state’s position.
	// 0 = ADS-B
	// 1 = ASTERIX
	// 2 = MLAT
	// 3 = FLARM
	PositionSource int `json:"positionSource"`

	// Aircraft category.
	// 0 = No information at all
	// 1 = No ADS-B Emitter Category Information
	// 2 = Light (< 15500 lbs)
	// 3 = Small (15500 to 75000 lbs)
	// 4 = Large (75000 to 300000 lbs)
	// 5 = High Vortex Large (aircraft such as B-757)
	// 6 = Heavy (> 300000 lbs)
	// 7 = High Performance (> 5g acceleration and 400 kts)
	// 8 = Rotorcraft
	// 9 = Glider / sailplane
	// 10 = Lighter-than-air
	// 11 = Parachutist / Skydiver
	// 12 = Ultralight / hang-glider / paraglider
	// 13 = Reserved
	// 14 = Unmanned Aerial Vehicle
	// 15 = Space / Trans-atmospheric vehicle
	// 16 = Surface Vehicle – Emergency Vehicle
	// 17 = Surface Vehicle – Service Vehicle
	// 18 = Point Obstacle (includes tethered balloons)
	// 19 = Cluster Obstacle
	// 20 = Line Obstacle
	Category int `json:"category"`
}

type States

type States struct {
	// The time which the state vectors in this response are associated with.
	// All vectors represent the state of a vehicle with the interval.
	Time int64 `json:"time"`

	// The state vectors.
	// States []StateVector `json:"states"`
	States []StateVector `json:"states"`
}

func GetStates

func GetStates(ctx context.Context, time int64, icao24 []string,
	bBox *BoundingBoxOptions, extended bool,
) (*States, error)

Retrieve state vectors for a given time. If time = 0 the most recent ones are taken. It is possible to query a certain area defined by a bounding box of WGS84 coordinates. You can request the category of aircraft by setting extended to true.

type StatesResponse

type StatesResponse struct {
	// The time which the state vectors in this response are associated with.
	// All vectors represent the state of a vehicle with the interval.
	Time int64 `json:"time"`

	// The state vectors.
	States [][]interface{} `json:"states"`
}

type WayPoint

type WayPoint struct {
	// Time which the given waypoint is associated with in seconds since epoch (Unix time).
	Time int64 `json:"time"`

	// WGS-84 latitude in decimal degrees. Can be nil.
	Latitude *float64 `json:"latitude"`

	// WGS-84 longitude in decimal degrees. Can be nil.
	Longitude *float64 `json:"longitude"`

	// Barometric altitude in meters. Can be nil.
	BaroAltitude *float64 `json:"baroAltitude"`

	// True track in decimal degrees clockwise from north (north=0°). Can be nil.
	TrueTrack *float64 `json:"trueTrack"`

	// Boolean value which indicates if the position was retrieved from a surface position report.
	OnGround bool `json:"onGround"`
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL