Text sensor displaying air traffic overhead

Moderator: leecollings

Damnet
Posts: 14
Joined: Friday 24 February 2017 20:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Text sensor displaying air traffic overhead

Post by Damnet »

Hi

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
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Text sensor displaying air traffic overhead

Post by zicht »

I have had this also once with an api
Did not take the effort to look into it and solved it the dirty way

Samply i used, you can tranform it any way for the data you need..

Code: Select all

function UpdateID(t)
	if (t ~= nil and string.find(t,'update_id":') ~= nil ) then
		 if (dbug == true) then print("UpdateID") end

		 local Reverse = string.reverse(t)
		 local zoekreverse = string.reverse('update_id":')
		 local lengte = string.len(t)
		 local findreverse = string.find(Reverse,zoekreverse)
		 local stringetje = string.sub(t,lengte - findreverse + 2, lengte)
 		 local gevonden2 = string.find(stringetje,',') - 1
		 UiD = string.sub(stringetje, 1, gevonden2) 
		 local tmp = tonumber(UiD)+1
		 UiD = tostring(tmp)
		 --print("UiD "..UiD)
		 commandArray['Variable:UiD'] = UiD
	end	
	return UiD
end
hope it helps
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Text sensor displaying air traffic overhead

Post by freijn »

Being also an airplane lover ( and close to Schiphol) I took an other Raspbery to monitor traffic over my City Purmerend.

I do like your Idea and will build it in my script :-)

Have you seen this? :
http://www.domoticz.com/forum/viewtopic.php?f=4&t=16730
Damnet
Posts: 14
Joined: Friday 24 February 2017 20:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Text sensor displaying air traffic overhead

Post by Damnet »

freijn wrote:Being also an airplane lover ( and close to Schiphol) I took an other Raspbery to monitor traffic over my City Purmerend.

I do like your Idea and will build it in my script :-)

Have you seen this? :
http://www.domoticz.com/forum/viewtopic.php?f=4&t=16730
No I didn't, thanks for sharing looks like fun that PiAware project.
I couldn't borrow from the python code, seems the JSON decode works fine in phyton.
Personally I like python better than LUA.
However I have transferred most of my scripts from Python to LUA now,
the event system is a nice feature.
Damnet
Posts: 14
Joined: Friday 24 February 2017 20:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Text sensor displaying air traffic overhead

Post by Damnet »

zicht wrote:I have had this also once with an api
Did not take the effort to look into it and solved it the dirty way

Samply i used, you can tranform it any way for the data you need..

Code: Select all

function UpdateID(t)
	if (t ~= nil and string.find(t,'update_id":') ~= nil ) then
		 if (dbug == true) then print("UpdateID") end

		 local Reverse = string.reverse(t)
		 local zoekreverse = string.reverse('update_id":')
		 local lengte = string.len(t)
		 local findreverse = string.find(Reverse,zoekreverse)
		 local stringetje = string.sub(t,lengte - findreverse + 2, lengte)
 		 local gevonden2 = string.find(stringetje,',') - 1
		 UiD = string.sub(stringetje, 1, gevonden2) 
		 local tmp = tonumber(UiD)+1
		 UiD = tostring(tmp)
		 --print("UiD "..UiD)
		 commandArray['Variable:UiD'] = UiD
	end	
	return UiD
end
hope it helps

Code: Select all

function AbsdCall(t)
   if (t ~= nil and string.find(t,'Call":') ~= nil ) then
       if (dbug == true) then print("AbsdCall") end
       local Reverse = string.reverse(t)
       local zoekreverse = string.reverse('Call":')
       local lengte = string.len(t)
       local findreverse = string.find(Reverse,zoekreverse)
       local stringetje = string.sub(t,lengte - findreverse + 2, lengte)
       local gevonden2 = string.find(stringetje,',') - 1
       UiD = string.sub(stringetje, 1, gevonden2) 
       UiD = tostring(tmp)
       print("UiD "..UiD)
         end   
   return UiD
end
Thanks modified the code a bit (not to do math on a string) however my input string returns.. LUA: UiD nil.
However when I print the string:

Code: Select all

LUA: type sAdsbdata: string sAdsbdata: {"src":1,"feeds":[{"id":1,"name":"From Consolidator","polarPlot":false}],"srcFeed":1,"showSil":true,"showFlg":true,"showPic":true,"flgH":20,"flgW":85,"acList":[{"Id":3425611,"Rcvr":1,"HasSig":true,"Sig":52,"Icao":"34454B","Bad":false,"Reg":"EC-MBY","FSeen":"\/Date(1495568456139)\/","TSecs":2946,"CMsgs":1732,"Alt":37000,"GAlt":37287,"InHg":30.2066936,"AltT":0,"Call":"VLG6321","Lat":51.942708,"Long":4.750017,"PosTime":1495571402200,"Mlat":false,"Tisb":false,"Spd":524.7,"Trak":122.0,"TrkH":false,"Type":"A320","Mdl":"Airbus A320 214","Man":"Airbus","CNum":"4674","From":"EGPH Edinburgh, United Kingdom","To":"LIRF Leonardo Da Vinci (Fiumicino), Rome, Italy","Op":"Vueling Airlines","OpIcao":"VLG","Sqk":"0732","Help":false,"Vsi":-64,"VsiT":0,"Dst":19.73,"Brng":102.6,"WTC":2,"Species":1,"Engines":"2","EngType":3,"EngMount":0,"Mil":false,"Cou":"Spain","HasPic":false,"Interested":false,"FlightsCount":0,"Gnd":false,"SpdTyp":0,"CallSus":false,"Trt":2,"Year":"2011"},{"Id":4198363,"Rcvr":1,"HasSig":false,"Icao":"400FDB","Bad":false,"Reg":"G-EZBJ","FSeen":"\/Date(1495568249857)\/","TSecs":3152,"CMsgs":1733,"Alt":6000,"GAlt":6287,"InHg":30.2066936,"AltT":0,"Call":"EZY25TK","Lat":52.044796,"Long":4.522287,"PosTime":1495571402184,"Mlat":false,"Tisb":false,"Spd":255.0,"Trak":83.3,"TrkH":false,"Type":"A319","Mdl":"Airbus A319 111","Man":"Airbus","CNum":"3036","From":"LFSB EuroAirport Basel-Mulhouse-Freiburg, Bâle/Mulhouse, France","To":"EHAM Amsterdam Airport Schiphol, Netherlands","Op":"easyJet","OpIcao":"EZY","Sqk":"1000","Help":false,"Vsi":-256,"VsiT":0,"Dst":7.91,"Brng":27.4,"WTC":2,"Species":1,"Engines":"2","EngType":3,"EngMount":0,"Mil":false,"Cou":"United Kingdom","HasPic":false,"Interested":false,"FlightsCount":0,"Gnd":false,"SpdTyp":0,"CallSus":false,"Trt":2,"Year":"2007"},{"Id":5023967,"Rcvr":1,"HasSig":false,"Icao":"4CA8DF","Bad":false,"Reg":"EI-IMF","FSeen":"\/Date(1495566437739)\/","TSecs":4964,"CMsgs":2807,"Alt":4975,"GAlt":5262,"InHg":30.2066936,"AltT":0,"TAlt":35000,"Lat":52.06
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Text sensor displaying air traffic overhead

Post by zicht »

i assume your message comes from UiD = tostring(tmp)
As you have no var in tmp

If you cannot find it do a print between each Line to see the result of each line for testing.
Will mess up the log but give you a clue on what goes wrong
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
Damnet
Posts: 14
Joined: Friday 24 February 2017 20:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Text sensor displaying air traffic overhead

Post by Damnet »

zicht wrote:i assume your message comes from UiD = tostring(tmp)
As you have no var in tmp

If you cannot find it do a print between each Line to see the result of each line for testing.
Will mess up the log but give you a clue on what goes wrong
Thanks for your answers did some dbug additions... output below... do you know if the log screen is limited to ~2000 characters per call?
  • 2017-05-28 22:25:00.542 LUA: AirplanesADSB4 LUA script executed
    2017-05-28 22:25:00.933 LUA: type sAdsbdata: string sAdsbdata: {"src":1,"feeds":[{"id":1,"name":"From Consolidator","polarPlot":false}],"srcFeed":1,"showSil":true,"showFlg":true,"showPic":true,"flgH":20,"flgW":85,"acList":[{"Id":4789004,"Rcvr":1,"HasSig":false,"Icao":"49130C","Bad":false,"Reg":"CS-DXL","FSeen":"\/Date(1495997487297)\/","TSecs":5695,"CMsgs":3335,"Alt":7000,"GAlt":7080,"InHg":30.0,"AltT":0,"Call":"NJE834D","Lat":52.006809,"Long":4.2707,"PosTime":1496003178511,"Mlat":false,"Tisb":false,"Spd":270.0,"Trak":42.9,"TrkH":false,"Type":"C56X","Mdl":"Cessna Citation XLS","Man":"Cessna","CNum":"560-5640","Op":"NetJets Europe","OpIcao":"NJE","Sqk":"1000","Help":false,"Vsi":-1280,"VsiT":0,"Dst":13.87,"Brng":281.7,"WTC":2,"Species":1,"Engines":"2","EngType":3,"EngMount":1,"Mil":false,"Cou":"Portugal","HasPic":false,"Interested":false,"FlightsCount":0,"Gnd":false,"SpdTyp":0,"CallSus":true,"Trt":2},{"Id":10952746,"Rcvr":1,"HasSig":false,"Icao":"A7202A","Bad":false,"Reg":"N5585","FSeen":"\/Date(1495991017863)\/","TSecs":12164,"CMsgs":2891,"Alt":34400,"GAlt":34480,"InHg":30.0,"AltT":0,"TAlt":25024,"Call":"N5585","Lat":51.950146,"Long":4.439163,"PosTime":1496002244744,"Mlat":false,"Tisb":false,"Spd":0.0,"Trak":236.3,"TrkH":false,"Type":"GLF5","Mdl":"2005 GULFSTREAM AEROSPACE GV-SP (G550)","Man":"Gulfstream Aerospace","CNum":"5085","Op":"JPMORGAN CHASE BANK NA - COLUMBUS, OH","Sqk":"6250","Help":false,"Vsi":-1344,"VsiT":0,"Dst":4.06,"Brng":210.3,"WTC":2,"Species":1,"Engines":"2","EngType":3,"EngMount":1,"Mil":false,"Cou":"United States","HasPic":false,"Interested":false,"FlightsCount":0,"Gnd":true,"SpdTyp":0,"CallSus":false,"Trt":5,"Year":"2005","Sat":true},{"Id":4197737,"Rcvr":1,"HasSig":false,"Icao":"400D69","Bad":false,"Reg":"G-EZIZ","FSeen":"\/Date(1495988478530)\/","TSecs":14704,"CMsgs":6013,"Alt":37025,"GAlt":37105,"InHg":30.0,"AltT":0,"Call":"EZY51KY","Lat":52.030876,"Long":4.499922,"PosTime":1496003178511,"Mlat":false,"Tisb":false,"Spd":437.0,"Trak":154.0,"TrkH":false,"Type":"A319","Mdl":"Airbus A319 111","Man":"Airbus","CNum":

    2017-05-28 22:25:00.934 LUA: AbsdCall
    2017-05-28 22:25:00.934 LUA: Reverse type: string Reverse data: }9962813006941:"mts",56:"ceSlrTths","877738293373513636":"vDtsal",8376:"cAlatot",]}"5002":"raeY",2:"trT",eslaf:"suSllaC",0:"pyTdpS",eslaf:"dnG",0:"tnuoCsthgilF",eslaf:"detseretnI",eslaf:"ciPsaH","modgniK detinU":"uoC",eslaf:"liM",0:"tnuoMgnE",3:"epyTgnE","2":"senignE",1:"seicepS",2:"CTW",1.12:"gnrB",78.5:"tsD",0:"TisV",0:"isV",eslaf:"pleH","3372":"kqS","YZE":"oacIpO","teJysae":"pO","ylatI ,naliM ,asneplaM CMIL":"oT","modgniK detinU ,hgrubnidE HPGE":"morF","6462":"muNC","subriA":"naM","111 913A subriA":"ldM","913A":"epyT",eslaf:"HkrT",0.451:"karT",0.734:"dpS",eslaf:"bsiT",eslaf:"talM",1158713006941:"emiTsoP",229994.4:"gnoL",678030.25:"taL","YK15YZE":"llaC",0:"TtlA",0.03:"gHnI",50173:"tlAG",52073:"tlA",3106:"sgsMC",40741:"sceST","/\)0358748895941(etaD/\":"neeSF","ZIZE-G":"geR",eslaf:"daB","96D004":"oacI",eslaf:"giSsaH",1:"rvcR",7377914:"dI"{,}eurt:"taS","5002":"raeY",5:"trT",eslaf:"suSllaC",0:"pyTdpS",eurt:"dnG",0:"tnuoCsthgilF",eslaf:"detseretnI",eslaf:"ciPsaH","setatS detinU":"uoC",eslaf:"liM",1:"tnuoMgnE",3:"epyTgnE","2":"senignE",1:"seicepS",2:"CTW",3.012:"gnrB",60.4:"tsD",0:"TisV",4431-:"isV",eslaf:"pleH","0526":"kqS","HO ,SUBMULOC - AN KNAB ESAHC NAGROMPJ":"pO","5805":"muNC","ecapsoreA maertsfluG":"naM",")055G( PS-VG ECAPSOREA MAERTSFLUG 5002":"ldM","5FLG":"epyT",eslaf:"HkrT",3.632:"karT",0.0:"dpS",eslaf:"bsiT",eslaf:"talM",4474422006941:"emiTsoP",361934.4:"gnoL",641059.15:"taL","5855N":"llaC",42052:"tlAT",0:"TtlA",0.03:"gHnI",08443:"tlAG",00443:"tlA",1982:"sgsMC",46121:"sceST","/\)3687101995941(etaD/\":"neeSF","5855N":"geR",eslaf:"daB","A2027A":"oacI",eslaf:"giSsaH",1:"rvcR",64725901:"dI"{,}2:"trT",eurt:"suSllaC",0:"pyTdpS",eslaf:"dnG",0:"tnuoCsthgilF",eslaf:"detseretnI",eslaf:"ciPsaH","lagutroP":"uoC",eslaf:"liM",1:"tnuoMgnE",3:"epyTgnE","2":"senignE",1:"seicepS",2:"CTW",7.182:"gnrB",78.31:"tsD",0:"TisV",0821-:"isV",eslaf:"pleH","0001":"kqS","EJN":"oacIpO","eporuE steJteN":"pO","0465-065":"muNC","ansseC":"naM","SLX noitatiC ansseC":"ldM","X65C":"epyT",eslaf:"HkrT

    2017-05-28 22:25:00.934 LUA: zoekreverse type: string zoekreverse data: :"llaC"
    2017-05-28 22:25:00.934 LUA: lengte type: number lengte data: 2474
    2017-05-28 22:25:00.934 LUA: findreverse type: number findreverse data: 657
    2017-05-28 22:25:00.934 LUA: stringetje type: string stringetje data: "EZY51KY","Lat":52.030876,"Long":4.499922,"PosTime":1496003178511,"Mlat":false,"Tisb":false,"Spd":437.0,"Trak":154.0,"TrkH":false,"Type":"A319","Mdl":"Airbus A319 111","Man":"Airbus","CNum":"2646","From":"EGPH Edinburgh, United Kingdom","To":"LIMC Malpensa, Milan, Italy","Op":"easyJet","OpIcao":"EZY","Sqk":"2733","Help":false,"Vsi":0,"VsiT":0,"Dst":5.87,"Brng":21.1,"WTC":2,"Species":1,"Engines":"2","EngType":3,"EngMount":0,"Mil":false,"Cou":"United Kingdom","HasPic":false,"Interested":false,"FlightsCount":0,"Gnd":false,"SpdTyp":0,"CallSus":false,"Trt":2,"Year":"2005"}],"totalAc":6738,"lastDv":"636315373392837778","shtTrlSec":65,"stm":1496003182699}
    2017-05-28 22:25:00.934 LUA: gevonden2 type: number gevonden2 data: 9
    2017-05-28 22:25:00.934 LUA: UiD type: string UiD data: "EZY51KY"
    2017-05-28 22:25:00.934 LUA: UiD "EZY51KY"

I tried with "Call" and now it returns 1 value, how to I iterate over the total values in LUA.
I did try around with for i,v in pairs do etc, but not succesfull so far...
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Text sensor displaying air traffic overhead

Post by zicht »

Hi

Nice that it works, bummer that you run into some string limitations.
I just was wondering if you make a function you could repeat the function for all the values ?
Meaning if it works for call: it should work for all.

I am not at home at the moment, but i suppose this should work for all the values inside your string.
If it really happens that you run into lenght limitations you indeed have to split the string.
But the principal should work the same (never had the issue and I cannot try right now)

(*sorry i am not a coder at all, most of my stuff is created by "trial and error" and trying to be smart sometimes.)
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Text sensor displaying air traffic overhead

Post by zicht »

Damnet wrote:
zicht wrote:i assume your message comes from UiD = tostring(tmp)
As you have no var in tmp

If you cannot find it do a print between each Line to see the result of each line for testing.
Will mess up the log but give you a clue on what goes wrong
Thanks for your answers did some dbug additions... output below... do you know if the log screen is limited to ~2000 characters per call?
  • 2017-05-28 22:25:00.542 LUA: AirplanesADSB4 LUA script executed
    2017-05-28 22:25:00.933 LUA: type sAdsbdata: string sAdsbdata: {"src":1,"feeds":[{"id":1,"name":"From Consolidator","polarPlot":false}],"srcFeed":1,"showSil":true,"showFlg":true,"showPic":true,"flgH":20,"flgW":85,"acList":[{"Id":4789004,"Rcvr":1,"HasSig":false,"Icao":"49130C","Bad":false,"Reg":"CS-DXL","FSeen":"\/Date(1495997487297)\/","TSecs":5695,"CMsgs":3335,"Alt":7000,"GAlt":7080,"InHg":30.0,"AltT":0,"Call":"NJE834D","Lat":52.006809,"Long":4.2707,"PosTime":1496003178511,"Mlat":false,"Tisb":false,"Spd":270.0,"Trak":42.9,"TrkH":false,"Type":"C56X","Mdl":"Cessna Citation XLS","Man":"Cessna","CNum":"560-5640","Op":"NetJets Europe","OpIcao":"NJE","Sqk":"1000","Help":false,"Vsi":-1280,"VsiT":0,"Dst":13.87,"Brng":281.7,"WTC":2,"Species":1,"Engines":"2","EngType":3,"EngMount":1,"Mil":false,"Cou":"Portugal","HasPic":false,"Interested":false,"FlightsCount":0,"Gnd":false,"SpdTyp":0,"CallSus":true,"Trt":2},{"Id":10952746,"Rcvr":1,"HasSig":false,"Icao":"A7202A","Bad":false,"Reg":"N5585","FSeen":"\/Date(1495991017863)\/","TSecs":12164,"CMsgs":2891,"Alt":34400,"GAlt":34480,"InHg":30.0,"AltT":0,"TAlt":25024,"Call":"N5585","Lat":51.950146,"Long":4.439163,"PosTime":1496002244744,"Mlat":false,"Tisb":false,"Spd":0.0,"Trak":236.3,"TrkH":false,"Type":"GLF5","Mdl":"2005 GULFSTREAM AEROSPACE GV-SP (G550)","Man":"Gulfstream Aerospace","CNum":"5085","Op":"JPMORGAN CHASE BANK NA - COLUMBUS, OH","Sqk":"6250","Help":false,"Vsi":-1344,"VsiT":0,"Dst":4.06,"Brng":210.3,"WTC":2,"Species":1,"Engines":"2","EngType":3,"EngMount":1,"Mil":false,"Cou":"United States","HasPic":false,"Interested":false,"FlightsCount":0,"Gnd":true,"SpdTyp":0,"CallSus":false,"Trt":5,"Year":"2005","Sat":true},{"Id":4197737,"Rcvr":1,"HasSig":false,"Icao":"400D69","Bad":false,"Reg":"G-EZIZ","FSeen":"\/Date(1495988478530)\/","TSecs":14704,"CMsgs":6013,"Alt":37025,"GAlt":37105,"InHg":30.0,"AltT":0,"Call":"EZY51KY","Lat":52.030876,"Long":4.499922,"PosTime":1496003178511,"Mlat":false,"Tisb":false,"Spd":437.0,"Trak":154.0,"TrkH":false,"Type":"A319","Mdl":"Airbus A319 111","Man":"Airbus","CNum":

    2017-05-28 22:25:00.934 LUA: AbsdCall
    2017-05-28 22:25:00.934 LUA: Reverse type: string Reverse data: }9962813006941:"mts",56:"ceSlrTths","877738293373513636":"vDtsal",8376:"cAlatot",]}"5002":"raeY",2:"trT",eslaf:"suSllaC",0:"pyTdpS",eslaf:"dnG",0:"tnuoCsthgilF",eslaf:"detseretnI",eslaf:"ciPsaH","modgniK detinU":"uoC",eslaf:"liM",0:"tnuoMgnE",3:"epyTgnE","2":"senignE",1:"seicepS",2:"CTW",1.12:"gnrB",78.5:"tsD",0:"TisV",0:"isV",eslaf:"pleH","3372":"kqS","YZE":"oacIpO","teJysae":"pO","ylatI ,naliM ,asneplaM CMIL":"oT","modgniK detinU ,hgrubnidE HPGE":"morF","6462":"muNC","subriA":"naM","111 913A subriA":"ldM","913A":"epyT",eslaf:"HkrT",0.451:"karT",0.734:"dpS",eslaf:"bsiT",eslaf:"talM",1158713006941:"emiTsoP",229994.4:"gnoL",678030.25:"taL","YK15YZE":"llaC",0:"TtlA",0.03:"gHnI",50173:"tlAG",52073:"tlA",3106:"sgsMC",40741:"sceST","/\)0358748895941(etaD/\":"neeSF","ZIZE-G":"geR",eslaf:"daB","96D004":"oacI",eslaf:"giSsaH",1:"rvcR",7377914:"dI"{,}eurt:"taS","5002":"raeY",5:"trT",eslaf:"suSllaC",0:"pyTdpS",eurt:"dnG",0:"tnuoCsthgilF",eslaf:"detseretnI",eslaf:"ciPsaH","setatS detinU":"uoC",eslaf:"liM",1:"tnuoMgnE",3:"epyTgnE","2":"senignE",1:"seicepS",2:"CTW",3.012:"gnrB",60.4:"tsD",0:"TisV",4431-:"isV",eslaf:"pleH","0526":"kqS","HO ,SUBMULOC - AN KNAB ESAHC NAGROMPJ":"pO","5805":"muNC","ecapsoreA maertsfluG":"naM",")055G( PS-VG ECAPSOREA MAERTSFLUG 5002":"ldM","5FLG":"epyT",eslaf:"HkrT",3.632:"karT",0.0:"dpS",eslaf:"bsiT",eslaf:"talM",4474422006941:"emiTsoP",361934.4:"gnoL",641059.15:"taL","5855N":"llaC",42052:"tlAT",0:"TtlA",0.03:"gHnI",08443:"tlAG",00443:"tlA",1982:"sgsMC",46121:"sceST","/\)3687101995941(etaD/\":"neeSF","5855N":"geR",eslaf:"daB","A2027A":"oacI",eslaf:"giSsaH",1:"rvcR",64725901:"dI"{,}2:"trT",eurt:"suSllaC",0:"pyTdpS",eslaf:"dnG",0:"tnuoCsthgilF",eslaf:"detseretnI",eslaf:"ciPsaH","lagutroP":"uoC",eslaf:"liM",1:"tnuoMgnE",3:"epyTgnE","2":"senignE",1:"seicepS",2:"CTW",7.182:"gnrB",78.31:"tsD",0:"TisV",0821-:"isV",eslaf:"pleH","0001":"kqS","EJN":"oacIpO","eporuE steJteN":"pO","0465-065":"muNC","ansseC":"naM","SLX noitatiC ansseC":"ldM","X65C":"epyT",eslaf:"HkrT

    2017-05-28 22:25:00.934 LUA: zoekreverse type: string zoekreverse data: :"llaC"
    2017-05-28 22:25:00.934 LUA: lengte type: number lengte data: 2474
    2017-05-28 22:25:00.934 LUA: findreverse type: number findreverse data: 657
    2017-05-28 22:25:00.934 LUA: stringetje type: string stringetje data: "EZY51KY","Lat":52.030876,"Long":4.499922,"PosTime":1496003178511,"Mlat":false,"Tisb":false,"Spd":437.0,"Trak":154.0,"TrkH":false,"Type":"A319","Mdl":"Airbus A319 111","Man":"Airbus","CNum":"2646","From":"EGPH Edinburgh, United Kingdom","To":"LIMC Malpensa, Milan, Italy","Op":"easyJet","OpIcao":"EZY","Sqk":"2733","Help":false,"Vsi":0,"VsiT":0,"Dst":5.87,"Brng":21.1,"WTC":2,"Species":1,"Engines":"2","EngType":3,"EngMount":0,"Mil":false,"Cou":"United Kingdom","HasPic":false,"Interested":false,"FlightsCount":0,"Gnd":false,"SpdTyp":0,"CallSus":false,"Trt":2,"Year":"2005"}],"totalAc":6738,"lastDv":"636315373392837778","shtTrlSec":65,"stm":1496003182699}
    2017-05-28 22:25:00.934 LUA: gevonden2 type: number gevonden2 data: 9
    2017-05-28 22:25:00.934 LUA: UiD type: string UiD data: "EZY51KY"
    2017-05-28 22:25:00.934 LUA: UiD "EZY51KY"

I tried with "Call" and now it returns 1 value, how to I iterate over the total values in LUA.
I did try around with for i,v in pairs do etc, but not succesfull so far...

maybe this one is also working for you http://www.domoticz.com/forum/viewtopic ... 61&t=17553
I personally never worked with this...
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
Damnet
Posts: 14
Joined: Friday 24 February 2017 20:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Text sensor displaying air traffic overhead

Post by Damnet »

Finally got the JSON part somewhat working using Online JSON viewer (e.g http://jsonviewer.stack.hu/) to figure out the right list.

Code: Select all

time = os.date("*t")
day = tonumber(os.date("%w"))
commandArray = {}
dbug = true

-- call with this command
if((time.min % 1)==0) then
print("AirplanesADSB LUA script executed")
json = assert(loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
local config = assert(io.popen('curl "https://public-api.adsbexchange.com/VirtualRadar/AircraftList.json?lat=51.9816377&lng=4.4690397&fDstL=0&fDstU=20"'))
local ADSB = config:read('*all')
config:close()
print(ADSB)
local jsonADSB = json:decode(ADSB)
local R1= jsonADSB.acList[1].Reg
local T1= jsonADSB.acList[1].Type
print('Plane1 Reg:'..R1..' Type:'..T1)
local R2= jsonADSB.acList[2].Reg
local T2= jsonADSB.acList[2].Type
print('Plane2 Reg:'..R2..' Type:'..T2)
local R3= jsonADSB.acList[3].Reg
local T3= jsonADSB.acList[3].Type
print('Plane3 Reg:'..R3..' Type:'..T3)
local R4= jsonADSB.acList[4].Reg
local T4= jsonADSB.acList[4].Type
print('Plane4 Reg:'..R4..' Type:'..T4)
end

return commandArray
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: Text sensor displaying air traffic overhead

Post by Westcott »

I use the JSONView Chrome Extension to view the result of a JSON url.
Damnet, thanks for the aeroplane link.
Are you running it every minute?
If you make it a Lua Time script, you won't need all that time stuff.
They run every minute anyway.
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
Damnet
Posts: 14
Joined: Friday 24 February 2017 20:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Text sensor displaying air traffic overhead

Post by Damnet »

Hi thanks for the info. I was aware of the built in 1 min trigger. Just left the os.time stuff in here if I wanted to make it less then every minute.
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Text sensor displaying air traffic overhead

Post by zicht »

Hi

Thanks for the code !

Just added a for do loop to display all in the planes in range and calculated distance from your Lat & lon (dont forget to adjust):

Code: Select all

function round(num, numDecimalPlaces)
  if numDecimalPlaces and numDecimalPlaces>0 then
    local mult = 10^numDecimalPlaces
    return math.floor(num * mult + 0.5) / mult
  end
  return math.floor(num + 0.5)
end

function geo_distance(lat1, lon1, lat2, lon2)
  if lat1 == nil or lon1 == nil or lat2 == nil or lon2 == nil then
    return nil
  end
  local dlat = math.rad(lat2-lat1)
  local dlon = math.rad(lon2-lon1)
  local sin_dlat = math.sin(dlat/2)
  local sin_dlon = math.sin(dlon/2)
  local a = sin_dlat * sin_dlat + math.cos(math.rad(lat1)) * math.cos(math.rad(lat2)) * sin_dlon * sin_dlon
  local c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
  -- 6378 km is the earth's radius at the equator.
  -- 6357 km would be the radius at the poles (earth isn't a perfect circle).
  -- Thus, high latitude distances will be slightly overestimated
  -- To get miles, use 3963 as the constant (equator again)
  local d = 6378 * c
  return d
end

function Airplanes()       
	print("AirplanesADSB LUA script executed")
	lat = 51.5xxxxx		--> fill in yours
	long = 4.4xxxx		--> fill in yours
	json = assert(loadfile "C:/PROGRA~2/domoticz/scripts/lua/JSON.lua")()   	--> adjust to your path
	local config = assert(io.popen('curl "https://public-api.adsbexchange.com/VirtualRadar/AircraftList.json?lat='..tostring(lat)..'&lng='..tostring(long)..'&fDstL=0&fDstU=20"'))
	local ADSB = config:read('*all')
	config:close()
	local jsonADSB = json:decode(ADSB)
	i = (#jsonADSB.acList)
	for j=1,i do
		local R = jsonADSB.acList[j].Reg 
		local T = jsonADSB.acList[j].Type 
		local M = jsonADSB.acList[j].Mdl
		local A = jsonADSB.acList[j].Alt  A=round((A*0.3048)/1000,0)
		local S = jsonADSB.acList[j].Spd  S=round((S*1.852),0) 
		local SP = jsonADSB.acList[j].Species
		local SQ = jsonADSB.acList[j].Sqk  
		local Lt = jsonADSB.acList[j].Lat
		local Lng = jsonADSB.acList[j].Long
		local distance = round(geo_distance(lat, long, Lt, Lng),2)
		print('Plane1 Reg:'..R..' Type:'..T..' '..M..' '..SP..' Alt:'..A..'km  Speed:'..S..'km  Sqk:'..SQ..' Afstand:'..distance..'Km')
     end
		
end

Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
Damnet
Posts: 14
Joined: Friday 24 February 2017 20:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Text sensor displaying air traffic overhead

Post by Damnet »

Just to share for who ever wants to use this as well.
I did get some errors when the values were like nil,
and the script triend to do math on nil values, or concatente the, so included some checks on that.
And I included an altitude limit in the api call of 5000 ft to limit the number of planes.

Code: Select all

commandArray = {}
function round(num, numDecimalPlaces)
  if numDecimalPlaces and numDecimalPlaces>0 then
    local mult = 10^numDecimalPlaces
    return math.floor(num * mult + 0.5) / mult
  end
  return math.floor(num + 0.5)
end

function geo_distance(lat1, lon1, lat2, lon2)
  if lat1 == nil or lon1 == nil or lat2 == nil or lon2 == nil then
    return nil
  end
  local dlat = math.rad(lat2-lat1)
  local dlon = math.rad(lon2-lon1)
  local sin_dlat = math.sin(dlat/2)
  local sin_dlon = math.sin(dlon/2)
  local a = sin_dlat * sin_dlat + math.cos(math.rad(lat1)) * math.cos(math.rad(lat2)) * sin_dlon * sin_dlon
  local c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
  -- 6378 km is the earth's radius at the equator.
  -- 6357 km would be the radius at the poles (earth isn't a perfect circle).
  -- Thus, high latitude distances will be slightly overestimated
  -- To get miles, use 3963 as the constant (equator again)
  local d = 6378 * c
  return d
end

function Airplanes()       
   print("AirplanesADSB LUA script executed")
   lat = XXX      --> fill in yours
   long = YYY      --> fill in yours
   json = assert(loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()      --> adjust to your path
   local config = assert(io.popen('curl "https://public-api.adsbexchange.com/VirtualRadar/AircraftList.json?lat='..tostring(lat)..'&lng='..tostring(long)..'&fDstL=0&fDstU=12&fAltL=0&fAltU=5000"'))
   local ADSB = config:read('*all')
   config:close()
   local jsonADSB = json:decode(ADSB)
   i = (#jsonADSB.acList)
   ADSBmessage = ""
   for j=1,i do
      ADSBmessage = ADSBmessage..'Plane'..j..': '
      local R = jsonADSB.acList[j].Reg 
      if R ~= nil then ADSBmessage = ADSBmessage..' Reg:'..R
      else
      end
      local T = jsonADSB.acList[j].Type 
      if T ~= nil then ADSBmessage = ADSBmessage..' Type:'..T
      else
      end
      local M = jsonADSB.acList[j].Mdl
      if M ~= nil then ADSBmessage = ADSBmessage.." "..M
      else
      end
      local SP = jsonADSB.acList[j].Species
      if SP ~= nil then ADSBmessage = ADSBmessage.." "..SP
      else
      end
      local O = jsonADSB.acList[j].Op
      if O ~= nil then ADSBmessage = ADSBmessage..' Operator:'..O
      else
      end
      local F = jsonADSB.acList[j].From
      if F ~= nil then ADSBmessage = ADSBmessage..' From:'..F
      else
      end
      local TO = jsonADSB.acList[j].To
      if TO ~= nil then ADSBmessage = ADSBmessage..' To:'..TO
      else
      end
      local A = jsonADSB.acList[j].Alt  
      if A ~= nil then A=round((A*0.3048)/1000,0) 
                        ADSBmessage = ADSBmessage..' Alt:'..A
      else
      end
      local S = jsonADSB.acList[j].Spd
      if S ~= nil then  S=round((S*1.852),0) 
                        ADSBmessage = ADSBmessage..' Spd:'..S
      else
      end
      local SQ = jsonADSB.acList[j].Sqk
      if SQ ~= nil then ADSBmessage = ADSBmessage..' Sqk:'..SQ
      else
      end
      
      local Lt = jsonADSB.acList[j].Lat
      local Lng = jsonADSB.acList[j].Long
      local distance = round(geo_distance(lat, long, Lt, Lng),2)
      if (Lt ~= nil and Lng ~= nil) then distance = round(geo_distance(lat, long, Lt, Lng),2)
          ADSBmessage = ADSBmessage..' Distance:'..distance
      else
      end
      -- print('Plane'..j.. ' Reg:'..R..' Type:'..T..' '..M..' '..SP..' Alt:'..A..'km  Speed:'..S..'km  Sqk:'..SQ..' Afstand:'..distance..'Km')
     end
     if (string.len(ADSBmessage) >= 1) then print(ADSBmessage)
     else
     end
     
end

Airplanes()

return commandArray
Podarcis
Posts: 7
Joined: Sunday 26 April 2015 18:05
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Text sensor displaying air traffic overhead

Post by Podarcis »

Is it me, or isn't there any commandArray to update the text sensor? I see only an update in the logfile, something like:

Code: Select all

2017-07-03 20:00:01.870 LUA: Plane1: 0 Alt:1 Spd:172 Sqk:7000 Distance:10.89
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Text sensor displaying air traffic overhead

Post by zicht »

Podarcis wrote:Is it me, or isn't there any commandArray to update the text sensor? I see only an update in the logfile, something like:

Code: Select all

2017-07-03 20:00:01.870 LUA: Plane1: 0 Alt:1 Spd:172 Sqk:7000 Distance:10.89
that can easy be done by :

Code: Select all

commandArray['UpdateDevice'] = #YOUR_IDX..'|0|'..#YOUR_VARIABLE
Where #your_idx needs to be replace by the idx of the text sensor, and #your_variable by the var holding the data :)
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
Podarcis
Posts: 7
Joined: Sunday 26 April 2015 18:05
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Text sensor displaying air traffic overhead

Post by Podarcis »

That was it! Thanks.
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Text sensor displaying air traffic overhead

Post by zicht »

Hi

Adsb abandoned public api as used above.
Has anybody succesfull ported the new rest api to lua ?

Thanks
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Text sensor displaying air traffic overhead

Post by EdwinK »

Getting this. Might due to changes they made:

Code: Select all

AirplanesADSB LUA script executed
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    93    0    93    0     0    324      0 --:--:-- --:--:-- --:--:--   325
lua: /home/pi/domoticz/scripts/lua/JSON.lua:660: html passed to JSON:decode(): <html><body><h1>403 Forbidden</h1>
Request forbidden by administrative rules.
</body></html>

stack traceback:
	[C]: in function 'assert'
	/home/pi/domoticz/scripts/lua/JSON.lua:660: in function 'onDecodeOfHTMLError'
	/home/pi/domoticz/scripts/lua/JSON.lua:975: in function 'decode'
	planes.lua:36: in function 'Airplanes'
	planes.lua:99: in main chunk
	[C]: ?
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Text sensor displaying air traffic overhead

Post by EdwinK »

[edit] Seems indeed because of the changes made to the website API's. Too bad.


Getting this. Might due to changes they made:

Code: Select all

AirplanesADSB LUA script executed
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    93    0    93    0     0    324      0 --:--:-- --:--:-- --:--:--   325
lua: /home/pi/domoticz/scripts/lua/JSON.lua:660: html passed to JSON:decode(): <html><body><h1>403 Forbidden</h1>
Request forbidden by administrative rules.
</body></html>

stack traceback:
	[C]: in function 'assert'
	/home/pi/domoticz/scripts/lua/JSON.lua:660: in function 'onDecodeOfHTMLError'
	/home/pi/domoticz/scripts/lua/JSON.lua:975: in function 'decode'
	planes.lua:36: in function 'Airplanes'
	planes.lua:99: in main chunk
	[C]: ?
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest