How to extract OpenSky data

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
peterbos
Posts: 93
Joined: Saturday 07 November 2020 21:41
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

How to extract OpenSky data

Post by peterbos »

Hi,

We live in the vicinity of Schiphol Airport. I want to use domoticz to register the planes that fly over our house. At opensky-network.org you can obtain flight info of commercial airlines with JSON. The response from the server looks like this:

Code: Select all

{"time":1608762620,"states":
[["4b1809","SWR1059 ","Switzerland",1608762607,1608762607,8.5565,47.4536,null,true,0,5.62,null,null,null,null,false,0],
["4b1802","SWR979  ","Switzerland",1608762616,1608762616,8.56,47.4541,null,true,0,185.62,null,null,null,"1000",false,0],
["4b180b","SWR78J  ","Switzerland",1608762611,1608762616,8.5557,47.4544,null,true,0,185.62,null,null,null,null,false,0]]}
As you can see the fields have no names, only values. How can I make a textstring with - for example - only the second field of each record (i.e. 'SWR1059 SWR979 SWR78J')?

I tried this without success:

Code: Select all

rt = triggerObject.json
-- some checks left away
local textLines = ""
for j = 1,#rt.states do
	textLines = textLines .."\n" .. rt.states[j]
end
Thanks in advance,
Peter
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to extract OpenSky data

Post by waaren »

peterbos wrote: Thursday 24 December 2020 0:58 We live in the vicinity of Schiphol Airport. I want to use domoticz to register the planes that fly over our house.
As you can see the fields have no names, only values. How can I make a textstring with - for example - only the second field of each record (i.e. 'SWR1059 SWR979 SWR78J')?
This should do it.

Code: Select all

return
{
    on =
    {
        devices =
        {
            'jsonTrigger', -- just a test device to trigger the script
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all ok
        marker = 'Schiphol',
    },

    execute = function(dz, triggeredItem)

        local jsonString = '{"time":1608762620,"states":[["4b1809","SWR1059 ","Switzerland",1608762607,1608762607,8.5565,47.4536,null,true,0,5.62,null,null,null,null,false,0],["4b1802","SWR979  ","Switzerland",1608762616,1608762616,8.56,47.4541,null,true,0,185.62,null,null,null,"1000",false,0],["4b180b","SWR78J  ","Switzerland",1608762611,1608762616,8.5557,47.4544,null,true,0,185.62,null,null,null,null,false,0]]}'
        local rt = dz.utils.fromJSON(jsonString) -- convert json string to table

        -- dz.utils.dumpTable(rt) -- dumps structure of return table

        local flightCodes = ''

        for _, row in ipairs(rt.states) do
            dz.log('FlightCode ' .. row[2] .. ' is now at location lon:' .. row[6] .. ', lat:' .. row[7] , dz.LOG_FORCE)
            flightCodes = flightCodes .. row[2] .. ','
        end

        dz.log('FlightCodes in json: ' .. flightCodes:sub(1,-2) , dz.LOG_FORCE) -- string without trailing ,


    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: How to extract OpenSky data

Post by EddyG »

An other possibility is.
I have installed PiAware on a seperate Raspberry PI with a cheap USB SDR ADS-B Receiver. ( https://uk.flightaware.com/adsb/piaware/ )
This way you have a complete FlightAware Groundstation with a API you can use in Domoticzs.
Some of the API's are described here: https://blackswan.ch/archives/429
peterbos
Posts: 93
Joined: Saturday 07 November 2020 21:41
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: How to extract OpenSky data

Post by peterbos »

Hi Eddy,

The airplane script is just a gadget, so I stick with the OpenSky data which works quite okay. The only thing that can be improved is the actual airplane data. I receive these by a undocumented call to OpenSky: https://opensky-network.org/api/metadat ... cao/484129. The data that is send back is a real mess. The company name can be in different field and sometimes even misses. The aircraft model is not standardized etcetera. Do you have a better source, also free?

Peter
User avatar
FireWizard
Posts: 1968
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: How to extract OpenSky data

Post by FireWizard »

Hi,

This APi can easily be contacted by Node Red and the selected data can be pushed to e.g. a "Text" sensor in Domoticz. An alternative is to use a node of Flightradar24 in Node Red. Also this data can be written to OpenStreetMap. By default you get all the data from planes within 100km of your lat/lon co-ordinates.

Regards
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest