I live 'close' to an airport AMS (Schiphol) and fortunately for me I love airplanes.
Sometimes when I hear them I quickly pickup my phone and look for the plane overhead (type, destination etc) in apps like flightradar24 or adsbexchange.
Apparently absd does have an API, so I started playing around with it. However unlike in e.g. the waze or google traffic app I cannot seem to get the data properly decode in JSON.
What I would liked to achieve is that a text sensor is updated with the information:
"Reg":"G-FBJC" "Call":"BEE6JB" "Type":"B738","Mdl":"Boeing 737NG 8BK/W","Man":"Boeing",""From":"LEIB Ibiza, Spain","To":"EHAM Amsterdam Airport Schiphol, Netherlands","Op":"Sunwing Airlines"
I could not get it working with (g)match...
Best regards
Code: Select all
time = os.date("*t")
day = tonumber(os.date("%w"))
commandArray = {}
function adsbexchange()
--import JSON.lua library
JSON = assert(loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- one-time load of the routines
-- get data from adsbexchange decode it in sAdsbDecode
local adsbdata = assert(io.popen('curl "https://public-api.adsbexchange.com/VirtualRadar/AircraftList.json?lat=51.9816377&lng=4.4690397&fDstL=0&fDstU=20"'))
print("type ".."adsbdata: "..type(adsbdata).." adsbdata: "..tostring(adsbdata))
local sAdsbdata = adsbdata:read('*all')
print("type ".."sAdsbdata: "..type(sAdsbdata).." sAdsbdata: "..tostring(sAdsbdata))
adsbdata:close()
--local JSONAdsb = JSON:decode(sAdsbdata)
--print("type ".."JSONAdsb: "..type(JSONAdsb).." JSONAdsb: "..tostring(JSONAdsb))
--print(unpack(JSONAdsb))
sAdsbdatamatch = string.match(sAdsbdata, '\"'..'Call'..'\"'..'..(......)')
print("type ".."sAdsbdatamatch: "..type(sAdsbdatamatch).." sAdsbdatamatch: "..tostring(sAdsbdatamatch))
sAdsbdatamatch1 = string.match(sAdsbdata, '\"'..'Reg'..'\"'..'..(......)')
print("type ".."sAdsbdatamatch1: "..type(sAdsbdatamatch1).." sAdsbdatamatch1: "..tostring(sAdsbdatamatch1))
return
end
-- call with this command
if((time.min % 1)==0) then
print("AirplanesADSB LUA script executed")
adsbexchange()
end
return commandArray